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