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