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: public function setField($name, $value, $safe = true) {
208: switch ($name) {
209: case 'name':
210: $this->setField('urlname', conHtmlSpecialChars($value, ENT_QUOTES), $safe);
211: break;
212: case 'urlname':
213: $value = conHtmlSpecialChars(cString::cleanURLCharacters($value), ENT_QUOTES);
214: break;
215: case 'visible':
216: case 'public':
217: $value = ($value == 1) ? 1 : 0;
218: break;
219: case 'idcat':
220: case 'idlang':
221: case 'idtplcfg':
222: case 'status':
223: $value = (int) $value;
224: break;
225: }
226:
227: parent::setField($name, $value, $safe);
228: }
229:
230: 231: 232: 233: 234: 235:
236: public function assignTemplate($idtpl) {
237: $oTplConfColl = new cApiTemplateConfigurationCollection();
238:
239: if ($this->get('idtplcfg') != 0) {
240:
241: $oTplConfColl->delete($this->get('idtplcfg'));
242: }
243:
244: $oTplConf = $oTplConfColl->create($idtpl);
245:
246:
247:
248: $oTplConfColl->copyTemplatePreconfiguration($idtpl, $oTplConf->get('idtplcfg'));
249:
250: $this->set('idtplcfg', $oTplConf->get('idtplcfg'));
251: $this->store();
252:
253: return $oTplConf;
254: }
255:
256: 257: 258: 259: 260:
261: public function getTemplate() {
262: $oTplConf = new cApiTemplateConfiguration($this->get('idtplcfg'));
263: return $oTplConf->get('idtpl');
264: }
265:
266: 267: 268: 269: 270:
271: public function hasStartArticle() {
272: cInclude('includes', 'functions.str.php');
273: return strHasStartArticle($this->get('idcat'), $this->get('idlang'));
274: }
275:
276: 277: 278: 279: 280:
281: public function store() {
282: $this->set('lastmodified', date('Y-m-d H:i:s'));
283: return parent::store();
284: }
285:
286: 287: 288: 289: 290: 291: 292: 293:
294: public function getLink($changeLangId = 0) {
295: if ($this->isLoaded() === false) {
296: return '';
297: }
298:
299: $options = array();
300: $options['idcat'] = $this->get('idcat');
301: $options['lang'] = ($changeLangId == 0) ? $this->get('idlang') : $changeLangId;
302: if ($changeLangId > 0) {
303: $options['changelang'] = $changeLangId;
304: }
305:
306: return cUri::getInstance()->build($options);
307: }
308: }
309: