1: <?php
2: /**
3: * This file contains the article collection and item class.
4: *
5: * @package Core
6: * @subpackage GenericDB_Model
7: * @version SVN Revision $Rev:$
8: *
9: * @author Timo Hummel
10: * @copyright four for business AG <www.4fb.de>
11: * @license http://www.contenido.org/license/LIZENZ.txt
12: * @link http://www.4fb.de
13: * @link http://www.contenido.org
14: */
15:
16: defined('CON_FRAMEWORK') || die('Illegal call: Missing framework initialization - request aborted.');
17:
18: cInclude('includes', 'functions.str.php');
19:
20: /**
21: * Article collection
22: *
23: * @package Core
24: * @subpackage GenericDB_Model
25: */
26: class cApiArticleCollection extends ItemCollection {
27:
28: /**
29: * Create a new collection of items.
30: *
31: * @param string $select where clause to use for selection (see
32: * ItemCollection::select())
33: */
34: public function __construct($select = false) {
35: global $cfg;
36: parent::__construct($cfg['tab']['art'], 'idart');
37: $this->_setItemClass('cApiArticle');
38:
39: // set the join partners so that joins can be used via link() method
40: $this->_setJoinPartner('cApiClientCollection');
41:
42: if ($select !== false) {
43: $this->select($select);
44: }
45: }
46:
47: /**
48: * Creates an article item entry
49: *
50: * @param int $idclient
51: * @return cApiArticle
52: */
53: public function create($idclient) {
54: $item = parent::createNewItem();
55:
56: $item->set('idclient', (int) $idclient);
57: $item->store();
58:
59: return $item;
60: }
61:
62: /**
63: * Returns list of ids by given client id.
64: *
65: * @param int $idclient
66: * @return array
67: */
68: public function getIdsByClientId($idclient) {
69: $sql = "SELECT idart FROM `%s` WHERE idclient=%d";
70: $this->db->query($sql, $this->table, $idclient);
71: $list = array();
72: while ($this->db->next_record()) {
73: $list[] = $this->db->f('idart');
74: }
75: return $list;
76: }
77: }
78:
79: /**
80: * Article item
81: *
82: * @package Core
83: * @subpackage GenericDB_Model
84: */
85: class cApiArticle extends Item {
86:
87: /**
88: * Constructor Function
89: *
90: * @param mixed $mId Specifies the ID of item to load
91: */
92: public function __construct($mId = false) {
93: global $cfg;
94: parent::__construct($cfg['tab']['art'], 'idart');
95: $this->setFilters(array(), array());
96: if ($mId !== false) {
97: $this->loadByPrimaryKey($mId);
98: }
99: }
100:
101: /**
102: * Returns the link to the current object.
103: *
104: * @param integer $changeLangId change language id for URL (optional)
105: * @return string link
106: */
107: public function getLink($changeLangId = 0) {
108: if ($this->isLoaded() === false) {
109: return '';
110: }
111:
112: $options = array();
113: $options['idart'] = $this->get('idart');
114: $options['lang'] = ($changeLangId == 0) ? cRegistry::getLanguageId() : $changeLangId;
115: if ($changeLangId > 0) {
116: $options['changelang'] = $changeLangId;
117: }
118:
119: return cUri::getInstance()->build($options);
120: }
121: }
122: