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: public function __construct($select = false) {
29: global $cfg;
30: parent::__construct($cfg['tab']['art'], 'idart');
31: $this->_setItemClass('cApiArticle');
32:
33: // set the join partners so that joins can be used via link() method
34: $this->_setJoinPartner('cApiClientCollection');
35:
36: if ($select !== false) {
37: $this->select($select);
38: }
39: }
40:
41: /**
42: * Creates an article item entry
43: *
44: * @param int $idclient
45: * @return cApiArticle
46: */
47: public function create($idclient) {
48: $item = parent::createNewItem();
49:
50: $item->set('idclient', (int) $idclient);
51: $item->store();
52:
53: return $item;
54: }
55:
56: /**
57: * Returns list of ids by given client id.
58: *
59: * @param int $idclient
60: * @return array
61: */
62: public function getIdsByClientId($idclient) {
63: $sql = "SELECT idart FROM `%s` WHERE idclient=%d";
64: $this->db->query($sql, $this->table, $idclient);
65: $list = array();
66: while ($this->db->next_record()) {
67: $list[] = $this->db->f('idart');
68: }
69: return $list;
70: }
71:
72: }
73:
74: /**
75: * Article item
76: *
77: * @package Core
78: * @subpackage GenericDB_Model
79: */
80: class cApiArticle extends Item {
81:
82: /**
83: * Constructor Function
84: *
85: * @param mixed $mId Specifies the ID of item to load
86: */
87: public function __construct($mId = false) {
88: global $cfg;
89: parent::__construct($cfg['tab']['art'], 'idart');
90: $this->setFilters(array(), array());
91: if ($mId !== false) {
92: $this->loadByPrimaryKey($mId);
93: }
94: }
95:
96: /**
97: * Returns the link to the current object.
98: * @param integer $changeLangId change language id for URL (optional)
99: * @return string link
100: */
101: public function getLink($changeLangId = 0) {
102: if ($this->isLoaded() === false) {
103: return '';
104: }
105:
106: $options = array();
107: $options['idart'] = $this->get('idart');
108: $options['lang'] = ($changeLangId == 0) ? cRegistry::getLanguageId() : $changeLangId;
109: if ($changeLangId > 0) {
110: $options['changelang'] = $changeLangId;
111: }
112:
113: return cUri::getInstance()->build($options);
114: }
115:
116: }
117: