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 cApiCategoryLanguageCollection 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_lang'], 'idcatlang');
35: $this->_setItemClass('cApiCategoryLanguage');
36:
37:
38: $this->_setJoinPartner('cApiCategoryCollection');
39: $this->_setJoinPartner('cApiLanguageCollection');
40: $this->_setJoinPartner('cApiTemplateConfigurationCollection');
41:
42: if ($select !== false) {
43: $this->select($select);
44: }
45: }
46:
47: 48: 49: 50: 51: 52: 53: 54: 55: 56: 57: 58: 59: 60: 61: 62: 63: 64: 65: 66: 67: 68:
69: public function create($idcat, $idlang, $name, $urlname, $urlpath = '', $idtplcfg = 0, $visible = 0, $public = 0, $status = 0, $author = '', $startidartlang = 0, $created = '', $lastmodified = '') {
70: global $auth;
71:
72: if (empty($author)) {
73: $author = $auth->auth['uname'];
74: }
75: if (empty($created)) {
76: $created = date('Y-m-d H:i:s');
77: }
78: if (empty($lastmodified)) {
79: $lastmodified = date('Y-m-d H:i:s');
80: }
81:
82: $oItem = $this->createNewItem();
83:
84: $oItem->set('idcat', $idcat);
85: $oItem->set('idlang', $idlang);
86: $oItem->set('name', $name);
87: $oItem->set('urlname', $urlname);
88: $oItem->set('urlpath', $urlpath);
89: $oItem->set('idtplcfg', $idtplcfg);
90: $oItem->set('visible', $visible);
91: $oItem->set('public', $public);
92: $oItem->set('status', $status);
93: $oItem->set('author', $author);
94: $oItem->set('created', $created);
95: $oItem->set('lastmodified', $lastmodified);
96: $oItem->store();
97:
98: return $oItem;
99: }
100:
101: 102: 103: 104: 105: 106: 107: 108:
109: public function getStartIdartlangByIdcatAndIdlang($idcat, $idlang) {
110: $sql = "SELECT startidartlang FROM `" . $this->table . "` WHERE idcat = " . (int) $idcat . " AND idlang = " . (int) $idlang . " AND startidartlang != 0";
111: $this->db->query($sql);
112: return ($this->db->nextRecord()) ? $this->db->f('startidartlang') : 0;
113: }
114:
115: 116: 117: 118: 119: 120: 121: 122: 123:
124: public function getStartIdartByIdcatAndIdlang($idcat, $idlang) {
125: global $cfg;
126: $sql = "SELECT al.idart FROM `" . $cfg['tab']['art_lang'] . "` AS al, `" . $this->table . "` " . "AS cl WHERE cl.idcat = " . (int) $idcat . " AND cl.startidartlang != 0 AND " . "cl.idlang = " . (int) $idlang . " AND cl.idlang = al.idlang AND cl.startidartlang = al.idartlang";
127: $this->db->query($sql);
128: return ($this->db->nextRecord()) ? $this->db->f('idart') : 0;
129: }
130:
131: 132: 133: 134: 135: 136: 137: 138: 139: 140: 141:
142: public function isStartArticle($idartlang, $idcat = NULL, $idlang = NULL) {
143: $where = 'startidartlang = ' . (int) $idartlang;
144: if (is_numeric($idcat)) {
145: $where .= ' AND idcat = ' . $idcat;
146: }
147: if (is_numeric($idlang)) {
148: $where .= ' AND idlang = ' . $idlang;
149: }
150: $where .= ' AND startidartlang != 0';
151:
152: $sql = "SELECT startidartlang FROM `" . $this->table . "` WHERE " . $where;
153: $this->db->query($sql);
154: return ($this->db->nextRecord() && $this->db->f('startidartlang') != 0);
155: }
156: }
157:
158: 159: 160: 161: 162: 163:
164: class cApiCategoryLanguage extends Item
165: {
166: 167: 168: 169: 170: 171: 172: 173: 174:
175: public function __construct($mId = false) {
176: global $cfg;
177: parent::__construct($cfg['tab']['cat_lang'], 'idcatlang');
178: $this->setFilters(array(), array());
179: if ($mId !== false) {
180: $this->loadByPrimaryKey($mId);
181: }
182: }
183:
184: 185: 186: 187: 188: 189: 190: 191: 192: 193: 194: 195: 196:
197: public function loadByCategoryIdAndLanguageId($idcat, $idlang) {
198: $aProps = array(
199: 'idcat' => $idcat,
200: 'idlang' => $idlang
201: );
202: $aRecordSet = $this->_oCache->getItemByProperties($aProps);
203: if ($aRecordSet) {
204:
205: $this->loadByRecordSet($aRecordSet);
206: return true;
207: } else {
208: $where = $this->db->prepare('idcat = %d AND idlang = %d', $idcat, $idlang);
209: return $this->_loadByWhereClause($where);
210: }
211: }
212:
213: 214: 215: 216: 217: 218: 219: 220: 221: 222:
223: public function setField($name, $value, $safe = true) {
224: switch ($name) {
225: case 'name':
226: $this->setField('urlname', conHtmlSpecialChars($value, ENT_QUOTES), $safe);
227: break;
228: case 'urlname':
229: $value = conHtmlSpecialChars(cString::cleanURLCharacters($value), ENT_QUOTES);
230: break;
231: case 'visible':
232: case 'public':
233: $value = ($value == 1) ? 1 : 0;
234: break;
235: case 'idcat':
236: case 'idlang':
237: case 'idtplcfg':
238: case 'status':
239: $value = (int) $value;
240: break;
241: }
242:
243: return parent::setField($name, $value, $safe);
244: }
245:
246: 247: 248: 249: 250: 251: 252: 253: 254: 255: 256:
257: public function assignTemplate($idtpl) {
258: $oTplConfColl = new cApiTemplateConfigurationCollection();
259:
260: if ($this->get('idtplcfg') != 0) {
261:
262: $oTplConfColl->delete($this->get('idtplcfg'));
263: }
264:
265: $oTplConf = $oTplConfColl->create($idtpl);
266:
267:
268:
269: $oTplConfColl->copyTemplatePreconfiguration($idtpl, $oTplConf->get('idtplcfg'));
270:
271: $this->set('idtplcfg', $oTplConf->get('idtplcfg'));
272: $this->store();
273:
274: return $oTplConf;
275: }
276:
277: 278: 279: 280: 281:
282: public function getTemplate() {
283: $oTplConf = new cApiTemplateConfiguration($this->get('idtplcfg'));
284: return $oTplConf->get('idtpl');
285: }
286:
287: 288: 289: 290: 291:
292: public function hasStartArticle() {
293: cInclude('includes', 'functions.str.php');
294: return strHasStartArticle($this->get('idcat'), $this->get('idlang'));
295: }
296:
297: 298: 299: 300: 301: 302: 303:
304: public function store() {
305: $this->set('lastmodified', date('Y-m-d H:i:s'));
306: return parent::store();
307: }
308:
309: 310: 311: 312: 313: 314: 315: 316: 317: 318:
319: public function getLink($changeLangId = 0) {
320: if ($this->isLoaded() === false) {
321: return '';
322: }
323:
324: $options = array();
325: $options['idcat'] = $this->get('idcat');
326: $options['lang'] = ($changeLangId == 0) ? $this->get('idlang') : $changeLangId;
327: if ($changeLangId > 0) {
328: $options['changelang'] = $changeLangId;
329: }
330:
331: return cUri::getInstance()->build($options);
332: }
333: }
334: