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: 17: 18: 19: 20: 21:
22: class cApiCategoryArticleCollection extends ItemCollection {
23: 24: 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: 59: 60: 61: 62:
63: public function create($idcat, $idart, $status = 0, $author = "", $created = "", $lastmodified = "", $createcode = 1) {
64: global $auth;
65:
66: if (empty($author)) {
67: $author = $auth->auth['uname'];
68: }
69: if (empty($created)) {
70: $created = date('Y-m-d H:i:s');
71: }
72: if (empty($lastmodified)) {
73: $lastmodified = date('Y-m-d H:i:s');
74: }
75:
76: $item = $this->createNewItem();
77:
78: $item->set('idcat', $idcat);
79: $item->set('idart', $idart);
80: $item->set('status', $status);
81: $item->set('author', $author);
82: $item->set('created', $created);
83: $item->set('lastmodified', $lastmodified);
84: $item->set('createcode', $createcode);
85:
86: $item->store();
87: return $item;
88: }
89:
90: 91: 92: 93: 94: 95: 96: 97: 98: 99: 100: 101: 102: 103:
104: public function fetchFirstFromTreeByClientIdAndLangId($client, $lang) {
105: global $cfg;
106:
107: $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";
108:
109: $params = array(
110: 'cat_art' => $this->table,
111: 'cat_tree' => $cfg['tab']['cat_tree'],
112: 'cat' => $cfg['tab']['cat'],
113: 'cat_lang' => $cfg['tab']['cat_lang'],
114: 'art_lang' => $cfg['tab']['art_lang'],
115: 'lang' => (int) $lang,
116: 'client' => (int) $client
117: );
118:
119: $sql = $this->db->prepare($sql, $params);
120: $this->db->query($sql);
121: if ($this->db->nextRecord()) {
122: $oItem = new cApiCategoryArticle();
123: $oItem->loadByRecordSet($this->db->toArray());
124: return $oItem;
125: }
126: return NULL;
127: }
128:
129: 130: 131: 132: 133: 134: 135: 136: 137: 138: 139:
140: public function fetchByCategoryIdAndArticleId($idcat, $idart) {
141: $aProps = array(
142: 'idcat' => $idcat,
143: 'idart' => $idart
144: );
145: $aRecordSet = $this->_oCache->getItemByProperties($aProps);
146: if ($aRecordSet) {
147:
148: $oItem = new cApiCategoryArticle();
149: $oItem->loadByRecordSet($aRecordSet);
150: return $oItem;
151: } else {
152: $this->select('idcat = ' . (int) $idcat . ' AND idart = ' . (int) $idart);
153: return $this->next();
154: }
155: }
156:
157: 158: 159: 160: 161: 162: 163: 164: 165: 166:
167: public function getIdByCategoryIdAndArticleId($idcat, $idart) {
168: $where = $this->db->prepare("idcat = %d AND idart = %d", $idcat, $idart);
169: $aIds = $this->getIdsByWhereClause($where);
170: return (count($aIds) > 0) ? $aIds[0] : NULL;
171: }
172:
173: 174: 175: 176: 177: 178: 179: 180: 181:
182: public function getAllIdsByClientId($idclient) {
183: global $cfg;
184:
185: $aIds = array();
186:
187: $sql = "SELECT A.idcatart FROM `%s` as A, `%s` as B WHERE B.idclient = %d AND B.idcat = A.idcat";
188: $this->db->query($sql, $this->table, $cfg['tab']['cat'], $idclient);
189: while ($this->db->nextRecord()) {
190: $aIds[] = $this->db->f('idcatart');
191: }
192:
193: return $aIds;
194: }
195:
196: 197: 198: 199: 200: 201: 202: 203: 204:
205: public function getCategoryIdsByArticleId($idart) {
206: $aIdCats = array();
207:
208: $sql = "SELECT idcat FROM `:cat_art` WHERE idart=:idart";
209: $sql = $this->db->prepare($sql, array(
210: 'cat_art' => $this->table,
211: 'idart' => (int) $idart
212: ));
213: $this->db->query($sql);
214:
215: while ($this->db->nextRecord()) {
216: $aIdCats[] = $this->db->f('idcat');
217: }
218:
219: return $aIdCats;
220: }
221:
222: 223: 224: 225: 226: 227: 228: 229: 230: 231: 232: 233:
234: public function getHasArticles($idcat, $idlang) {
235: global $cfg;
236:
237: $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";
238: $sql = $this->db->prepare($sql, array(
239: 'cat_art' => $this->table,
240: 'art_lang' => $cfg['tab']['art_lang'],
241: 'idcat' => $idcat,
242: 'idlang' => $idlang
243: ));
244: $this->db->query($sql);
245:
246: return ($this->db->nextRecord()) ? true : false;
247: }
248:
249: 250: 251: 252: 253: 254: 255: 256: 257: 258: 259: 260: 261:
262: public function setCreateCodeFlag($idcatart, $createcode = 1) {
263: $createcode = ($createcode == 1) ? 1 : 0;
264: if (is_array($idcatart)) {
265:
266: if (count($idcatart) == 0) {
267: return;
268: }
269: foreach ($idcatart as $pos => $id) {
270: $idcatart[$pos] = (int) $id;
271: }
272: $inSql = implode(', ', $idcatart);
273: $sql = "UPDATE `%s` SET createcode = %d WHERE idcatart IN (" . $inSql . ")";
274: $sql = $this->db->prepare($sql, $this->table, $createcode);
275: } else {
276:
277: $sql = "UPDATE `%s` SET createcode = %d WHERE idcatart = %d";
278: $sql = $this->db->prepare($sql, $this->table, $createcode, $idcatart);
279: }
280: $this->db->query($sql);
281: return $this->db->affectedRows();
282: }
283: }
284:
285: 286: 287: 288: 289: 290:
291: class cApiCategoryArticle extends Item
292: {
293: 294: 295: 296: 297: 298: 299: 300: 301:
302: public function __construct($mId = false) {
303: global $cfg;
304: parent::__construct($cfg['tab']['cat_art'], 'idcatart');
305: $this->setFilters(array(), array());
306: if ($mId !== false) {
307: $this->loadByPrimaryKey($mId);
308: }
309: }
310:
311: 312: 313: 314: 315: 316: 317: 318: 319:
320: public function setField($name, $value, $bSafe = true) {
321: switch ($name) {
322: case 'idcat':
323: $value = cSecurity::toInteger($value);
324: break;
325: case 'idart':
326: $value = cSecurity::toInteger($value);
327: break;
328: case 'status':
329: $value = cSecurity::toInteger($value);
330: break;
331: case 'createcode':
332: $value = ($value == 1) ? 1 : 0;
333: break;
334: }
335:
336: return parent::setField($name, $value, $bSafe);
337: }
338:
339: }
340: