1: <?php
2: 3: 4: 5: 6: 7: 8: 9: 10: 11: 12: 13: 14:
15:
16: defined('CON_FRAMEWORK') || die('Illegal call: Missing framework initialization - request aborted.');
17:
18: cInclude('includes', 'functions.str.php');
19:
20: 21: 22: 23: 24: 25:
26: class cApiArticleCollection extends ItemCollection {
27:
28: 29: 30: 31: 32: 33:
34: public function __construct($select = false) {
35: global $cfg;
36: parent::__construct($cfg['tab']['art'], 'idart');
37: $this->_setItemClass('cApiArticle');
38:
39:
40: $this->_setJoinPartner('cApiClientCollection');
41:
42: if ($select !== false) {
43: $this->select($select);
44: }
45: }
46:
47: 48: 49: 50: 51: 52:
53: public function create($idclient) {
54: $item = $this->createNewItem();
55:
56: $item->set('idclient', $idclient);
57: $item->store();
58:
59: return $item;
60: }
61:
62: 63: 64: 65: 66: 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: 81: 82: 83: 84:
85: class cApiArticle extends Item {
86:
87: 88: 89: 90: 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: 103: 104: 105: 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: 123: 124: 125: 126: 127: 128:
129: public function setField($name, $value, $bSafe = true) {
130: switch ($name) {
131: case 'idclient':
132: $value = (int) $value;
133: break;
134: }
135:
136: return parent::setField($name, $value, $bSafe);
137: }
138:
139: }
140: