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: 19: 20: 21: 22: 23:
24: class cApiCategoryArticleCollection extends ItemCollection {
25:
26: 27: 28: 29: 30: 31:
32: public function __construct($select = false) {
33: global $cfg;
34: parent::__construct($cfg['tab']['cat_art'], 'idcatart');
35: $this->_setItemClass('cApiCategoryArticle');
36:
37:
38: $this->_setJoinPartner('cApiCategoryCollection');
39: $this->_setJoinPartner('cApiArticleCollection');
40:
41: if ($select !== false) {
42: $this->select($select);
43: }
44: }
45:
46: 47: 48: 49: 50: 51: 52: 53: 54: 55: 56: 57:
58: public function create($idcat, $idart, $status = 0, $author = "", $created = "", $lastmodified = "", $createcode = 1) {
59: global $auth;
60:
61: if (empty($author)) {
62: $author = $auth->auth['uname'];
63: }
64: if (empty($created)) {
65: $created = date('Y-m-d H:i:s');
66: }
67: if (empty($lastmodified)) {
68: $lastmodified = date('Y-m-d H:i:s');
69: }
70:
71: $item = parent::createNewItem();
72:
73: $item->set('idcat', (int) $idcat);
74: $item->set('idart', (int) $idart);
75: $item->set('status', (int) $status);
76: $item->set('author', $this->escape($author));
77: $item->set('created', $this->escape($created));
78: $item->set('lastmodified', $this->escape($lastmodified));
79: $item->set('createcode', ($createcode == 1) ? 1 : 0);
80:
81: $item->store();
82: return $item;
83: }
84:
85: 86: 87: 88: 89: 90: 91: 92: 93: 94: 95:
96: public function fetchFirstFromTreeByClientIdAndLangId($client, $lang) {
97: global $cfg;
98:
99: $sql = "SELECT A.* FROM `:cat_art` AS A, `:cat_tree` AS B, `:cat` AS C, `:cat_lang` AS D, `:art_lang` AS E " . "WHERE A.idcat = B.idcat AND B.idcat = C.idcat AND D.startidartlang = E.idartlang AND D.idlang = :lang AND E.idart = A.idart AND E.idlang = :lang AND idclient = :client " . "ORDER BY idtree ASC LIMIT 1";
100:
101: $params = array(
102: 'cat_art' => $this->table,
103: 'cat_tree' => $cfg['tab']['cat_tree'],
104: 'cat' => $cfg['tab']['cat'],
105: 'cat_lang' => $cfg['tab']['cat_lang'],
106: 'art_lang' => $cfg['tab']['art_lang'],
107: 'lang' => (int) $lang,
108: 'client' => (int) $client
109: );
110:
111: $sql = $this->db->prepare($sql, $params);
112: $this->db->query($sql);
113: if ($this->db->nextRecord()) {
114: $oItem = new cApiCategoryArticle();
115: $oItem->loadByRecordSet($this->db->toArray());
116: return $oItem;
117: }
118: return NULL;
119: }
120:
121: 122: 123: 124: 125: 126: 127:
128: public function fetchByCategoryIdAndArticleId($idcat, $idart) {
129: $aProps = array(
130: 'idcat' => $idcat,
131: 'idart' => $idart
132: );
133: $aRecordSet = $this->_oCache->getItemByProperties($aProps);
134: if ($aRecordSet) {
135:
136: $oItem = new cApiCategoryArticle();
137: $oItem->loadByRecordSet($aRecordSet);
138: return $oItem;
139: } else {
140: $this->select('idcat = ' . (int) $idcat . ' AND idart = ' . (int) $idart);
141: return $this->next();
142: }
143: }
144:
145: 146: 147: 148: 149: 150: 151:
152: public function getIdByCategoryIdAndArticleId($idcat, $idart) {
153: $where = "idcat = %d AND idart = %d";
154: $where = $this->db->prepare("idcat = %d AND idart = %d", $idcat, $idart);
155: $aIds = $this->getIdsByWhereClause($where);
156: return (count($aIds) > 0) ? $aIds[0] : NULL;
157: }
158:
159: 160: 161: 162: 163: 164:
165: public function getAllIdsByClientId($idclient) {
166: global $cfg;
167:
168: $aIds = array();
169:
170: $sql = "SELECT A.idcatart FROM `%s` as A, `%s` as B WHERE B.idclient = %d AND B.idcat = A.idcat";
171: $this->db->query($sql, $this->table, $cfg['tab']['cat'], $idclient);
172: while ($this->db->nextRecord()) {
173: $aIds[] = $this->db->f('idcatart');
174: }
175:
176: return $aIds;
177: }
178:
179: 180: 181: 182: 183: 184:
185: public function getCategoryIdsByArticleId($idart) {
186: $aIdCats = array();
187:
188: $sql = "SELECT idcat FROM `:cat_art` WHERE idart=:idart";
189: $sql = $this->db->prepare($sql, array(
190: 'cat_art' => $this->table,
191: 'idart' => (int) $idart
192: ));
193: $this->db->query($sql);
194:
195: while ($this->db->nextRecord()) {
196: $aIdCats[] = $this->db->f('idcat');
197: }
198:
199: return $aIdCats;
200: }
201:
202: 203: 204: 205: 206: 207: 208:
209: public function getHasArticles($idcat, $idlang) {
210: global $cfg;
211:
212: $sql = "SELECT b.idartlang AS idartlang FROM `:cat_art` AS a, `:art_lang` AS b " . "WHERE a.idcat = :idcat AND a.idart = b.idart AND b.idlang = :idlang";
213: $sql = $this->db->prepare($sql, array(
214: 'cat_art' => $this->table,
215: 'art_lang' => $cfg['tab']['art_lang'],
216: 'idcat' => $idcat,
217: 'idlang' => $idlang
218: ));
219: $this->db->query($sql);
220:
221: return ($this->db->nextRecord()) ? true : false;
222: }
223:
224: 225: 226: 227: 228: 229: 230: 231:
232: public function setCreateCodeFlag($idcatart, $createcode = 1) {
233: $createcode = ($createcode == 1) ? 1 : 0;
234: if (is_array($idcatart)) {
235:
236: if (count($idcatart) == 0) {
237: return;
238: }
239: foreach ($idcatart as $pos => $id) {
240: $idcatart[$pos] = (int) $id;
241: }
242: $inSql = implode(', ', $idcatart);
243: $sql = "UPDATE `%s` SET createcode = %d WHERE idcatart IN (" . $inSql . ")";
244: $sql = $this->db->prepare($sql, $this->table, $createcode);
245: } else {
246:
247: $sql = "UPDATE `%s` SET createcode = %d WHERE idcatart = %d";
248: $sql = $this->db->prepare($sql, $this->table, $createcode, $idcatart);
249: }
250: $this->db->query($sql);
251: return $this->db->affectedRows();
252: }
253: }
254:
255: 256: 257: 258: 259: 260:
261: class cApiCategoryArticle extends Item {
262:
263: 264: 265: 266: 267:
268: public function __construct($mId = false) {
269: global $cfg;
270: parent::__construct($cfg['tab']['cat_art'], 'idcatart');
271: $this->setFilters(array(), array());
272: if ($mId !== false) {
273: $this->loadByPrimaryKey($mId);
274: }
275: }
276: }
277: