1: <?php
2: 3: 4: 5: 6: 7: 8: 9: 10: 11: 12:
13:
14: defined('CON_FRAMEWORK') || die('Illegal call: Missing framework initialization - request aborted.');
15:
16: cInclude('includes', 'functions.str.php');
17:
18: 19: 20: 21: 22: 23:
24: class cApiArticleCollection extends ItemCollection {
25:
26: 27: 28: 29: 30: 31:
32: public function __construct($select = false) {
33: global $cfg;
34: parent::__construct($cfg['tab']['art'], 'idart');
35: $this->_setItemClass('cApiArticle');
36:
37:
38: $this->_setJoinPartner('cApiClientCollection');
39:
40: if ($select !== false) {
41: $this->select($select);
42: }
43: }
44:
45: 46: 47: 48: 49: 50:
51: public function create($idclient) {
52: $item = $this->createNewItem();
53:
54: $item->set('idclient', $idclient);
55: $item->store();
56:
57: return $item;
58: }
59:
60: 61: 62: 63: 64: 65:
66: public function getIdsByClientId($idclient) {
67: $sql = "SELECT idart FROM `%s` WHERE idclient=%d";
68: $this->db->query($sql, $this->table, $idclient);
69: $list = array();
70: while ($this->db->next_record()) {
71: $list[] = $this->db->f('idart');
72: }
73: return $list;
74: }
75: }
76:
77: 78: 79: 80: 81: 82:
83: class cApiArticle extends Item {
84:
85: 86: 87: 88: 89: 90:
91: public function __construct($mId = false) {
92: global $cfg;
93: parent::__construct($cfg['tab']['art'], 'idart');
94: $this->setFilters(array(), array());
95: if ($mId !== false) {
96: $this->loadByPrimaryKey($mId);
97: }
98: }
99:
100: 101: 102: 103: 104: 105: 106: 107:
108: public function getLink($changeLangId = 0) {
109: if ($this->isLoaded() === false) {
110: return '';
111: }
112:
113: $options = array();
114: $options['idart'] = $this->get('idart');
115: $options['lang'] = ($changeLangId == 0) ? cRegistry::getLanguageId() : $changeLangId;
116: if ($changeLangId > 0) {
117: $options['changelang'] = $changeLangId;
118: }
119:
120: return cUri::getInstance()->build($options);
121: }
122:
123: 124: 125: 126: 127: 128: 129: 130: 131:
132: public function setField($name, $value, $bSafe = true) {
133: switch ($name) {
134: case 'idclient':
135: $value = (int) $value;
136: break;
137: }
138:
139: return parent::setField($name, $value, $bSafe);
140: }
141:
142: }
143: