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:
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: public function create($idcat, $idlang, $name, $urlname, $urlpath = '', $idtplcfg = 0, $visible = 0, $public = 0, $status = 0, $author = '', $startidartlang = 0, $created = '', $lastmodified = '') {
66: global $auth;
67:
68: if (empty($author)) {
69: $author = $auth->auth['uname'];
70: }
71: if (empty($created)) {
72: $created = date('Y-m-d H:i:s');
73: }
74: if (empty($lastmodified)) {
75: $lastmodified = date('Y-m-d H:i:s');
76: }
77:
78: $oItem = $this->createNewItem();
79:
80: $oItem->set('idcat', $idcat);
81: $oItem->set('idlang', $idlang);
82: $oItem->set('name', $name);
83: $oItem->set('urlname', $urlname);
84: $oItem->set('urlpath', $urlpath);
85: $oItem->set('idtplcfg', $idtplcfg);
86: $oItem->set('visible', $visible);
87: $oItem->set('public', $public);
88: $oItem->set('status', $status);
89: $oItem->set('author', $author);
90: $oItem->set('created', $created);
91: $oItem->set('lastmodified', $lastmodified);
92: $oItem->store();
93:
94: return $oItem;
95: }
96:
97: 98: 99: 100: 101: 102: 103:
104: public function getStartIdartlangByIdcatAndIdlang($idcat, $idlang) {
105: $sql = "SELECT startidartlang FROM `" . $this->table . "` WHERE idcat = " . (int) $idcat . " AND idlang = " . (int) $idlang . " AND startidartlang != 0";
106: $this->db->query($sql);
107: return ($this->db->nextRecord()) ? $this->db->f('startidartlang') : 0;
108: }
109:
110: 111: 112: 113: 114: 115: 116: 117:
118: public function getStartIdartByIdcatAndIdlang($idcat, $idlang) {
119: global $cfg;
120: $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";
121: $this->db->query($sql);
122: return ($this->db->nextRecord()) ? $this->db->f('idart') : 0;
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: 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:
202: public function setField($name, $value, $safe = true) {
203: switch ($name) {
204: case 'name':
205: $this->setField('urlname', conHtmlSpecialChars($value, ENT_QUOTES), $safe);
206: break;
207: case 'urlname':
208: $value = conHtmlSpecialChars(cApiStrCleanURLCharacters($value), ENT_QUOTES);
209: break;
210: case 'visible':
211: case 'public':
212: $value = ($value == 1) ? 1 : 0;
213: break;
214: case 'idcat':
215: case 'idlang':
216: case 'idtplcfg':
217: case 'status':
218: $value = (int) $value;
219: break;
220: }
221:
222: parent::setField($name, $value, $safe);
223: }
224:
225: 226: 227: 228: 229: 230:
231: public function assignTemplate($idtpl) {
232: $oTplConfColl = new cApiTemplateConfigurationCollection();
233:
234: if ($this->get('idtplcfg') != 0) {
235:
236: $oTplConfColl->delete($this->get('idtplcfg'));
237: }
238:
239: $oTplConf = $oTplConfColl->create($idtpl);
240:
241:
242:
243: $oTplConfColl->copyTemplatePreconfiguration($idtpl, $oTplConf->get('idtplcfg'));
244:
245: $this->set('idtplcfg', $oTplConf->get('idtplcfg'));
246: $this->store();
247:
248: return $oTplConf;
249: }
250:
251: 252: 253: 254: 255:
256: public function getTemplate() {
257: $oTplConf = new cApiTemplateConfiguration($this->get('idtplcfg'));
258: return $oTplConf->get('idtpl');
259: }
260:
261: 262: 263: 264: 265:
266: public function hasStartArticle() {
267: cInclude('includes', 'functions.str.php');
268: return strHasStartArticle($this->get('idcat'), $this->get('idlang'));
269: }
270:
271: 272: 273: 274: 275:
276: public function store() {
277: $this->set('lastmodified', date('Y-m-d H:i:s'));
278: return parent::store();
279: }
280:
281: 282: 283: 284: 285: 286:
287: public function getLink($changeLangId = 0) {
288: if ($this->isLoaded() === false) {
289: return '';
290: }
291:
292: $options = array();
293: $options['idcat'] = $this->get('idcat');
294: $options['lang'] = ($changeLangId == 0) ? $this->get('idlang') : $changeLangId;
295: if ($changeLangId > 0) {
296: $options['changelang'] = $changeLangId;
297: }
298:
299: return cUri::getInstance()->build($options);
300: }
301: }
302: