Overview

Packages

  • Core
    • Authentication
    • Backend
    • Cache
    • CEC
    • Chain
    • ContentType
    • Database
    • Datatype
    • Debug
    • Exception
    • Frontend
      • Search
      • URI
      • Util
    • GenericDB
      • Model
    • GUI
      • HTML
    • I18N
    • LayoutHandler
    • Log
    • Security
    • Session
    • Util
    • Validation
    • Versioning
    • XML
  • Module
    • ContentSitemapHtml
    • ContentSitemapXml
    • ContentUserForum
    • NavigationMain
    • NavigationTop
  • mpAutoloaderClassMap
  • None
  • Plugin
    • ContentAllocation
    • CronjobOverview
    • FormAssistant
    • FrontendLogic
    • FrontendUsers
    • Linkchecker
    • ModRewrite
    • Newsletter
    • Repository
      • FrontendNavigation
      • KeywordDensity
    • SearchSolr
    • SmartyWrapper
    • UrlShortener
    • UserForum
    • Workflow
  • PluginManager
  • Setup
    • Form
    • GUI
    • Helper
      • Environment
      • Filesystem
      • MySQL
      • PHP
    • UpgradeJob

Classes

  • cApiAction
  • cApiActionCollection
  • cApiActionlog
  • cApiActionlogCollection
  • cApiArea
  • cApiAreaCollection
  • cApiArticle
  • cApiArticleCollection
  • cApiArticleLanguage
  • cApiArticleLanguageCollection
  • cApiArticleSpecification
  • cApiArticleSpecificationCollection
  • cApiCategory
  • cApiCategoryArticle
  • cApiCategoryArticleCollection
  • cApiCategoryCollection
  • cApiCategoryLanguage
  • cApiCategoryLanguageCollection
  • cApiCategoryTree
  • cApiCategoryTreeCollection
  • cApiClient
  • cApiClientCollection
  • cApiClientLanguage
  • cApiClientLanguageCollection
  • cApiCommunication
  • cApiCommunicationCollection
  • cApiContainer
  • cApiContainerCollection
  • cApiContainerConfiguration
  • cApiContainerConfigurationCollection
  • cApiContent
  • cApiContentCollection
  • cApiDbfs
  • cApiDbfsCollection
  • cApiFile
  • cApiFileCollection
  • cApiFileInformation
  • cApiFileInformationCollection
  • cApiFrameFile
  • cApiFrameFileCollection
  • cApiFrontendGroup
  • cApiFrontendGroupCollection
  • cApiFrontendGroupMember
  • cApiFrontendGroupMemberCollection
  • cApiFrontendPermission
  • cApiFrontendPermissionCollection
  • cApiFrontendUser
  • cApiFrontendUserCollection
  • cApiGroup
  • cApiGroupCollection
  • cApiGroupMember
  • cApiGroupMemberCollection
  • cApiGroupProperty
  • cApiGroupPropertyCollection
  • cApiInUse
  • cApiInUseCollection
  • cApiIso3166
  • cApiIso3166Collection
  • cApiIso6392
  • cApiIso6392Collection
  • cApiKeyword
  • cApiKeywordCollection
  • cApiLanguage
  • cApiLanguageCollection
  • cApiLayout
  • cApiLayoutCollection
  • cApiMailLog
  • cApiMailLogCollection
  • cApiMailLogSuccess
  • cApiMailLogSuccessCollection
  • cApiMetaTag
  • cApiMetaTagCollection
  • cApiMetaType
  • cApiMetaTypeCollection
  • cApiModule
  • cApiModuleCollection
  • cApiNavMain
  • cApiNavMainCollection
  • cApiNavSub
  • cApiNavSubCollection
  • cApiOnlineUser
  • cApiOnlineUserCollection
  • cApiPathresolveCache
  • cApiPathresolveCacheCollection
  • cApiProperty
  • cApiPropertyCollection
  • cApiRight
  • cApiRightCollection
  • cApiStat
  • cApiStatCollection
  • cApiSystemProperty
  • cApiSystemPropertyCollection
  • cApiTemplate
  • cApiTemplateCollection
  • cApiTemplateConfiguration
  • cApiTemplateConfigurationCollection
  • cApiType
  • cApiTypeCollection
  • cApiUpload
  • cApiUploadCollection
  • cApiUploadMeta
  • cApiUploadMetaCollection
  • cApiUser
  • cApiUserCollection
  • cApiUserProperty
  • cApiUserPropertyCollection
  • NoteCollection
  • NoteItem
  • TODOCollection
  • TODOItem
  • Overview
  • Package
  • Class
  • Tree
  • Deprecated
  • Todo
  1: <?php
  2: /**
  3:  * This file contains the category collection and item class.
  4:  *
  5:  * @package          Core
  6:  * @subpackage       GenericDB_Model
  7:  * @version          SVN Revision $Rev:$
  8:  *
  9:  * @author           Timo Hummel
 10:  * @copyright        four for business AG <www.4fb.de>
 11:  * @license          http://www.contenido.org/license/LIZENZ.txt
 12:  * @link             http://www.4fb.de
 13:  * @link             http://www.contenido.org
 14:  */
 15: 
 16: defined('CON_FRAMEWORK') || die('Illegal call: Missing framework initialization - request aborted.');
 17: 
 18: /**
 19:  * Category collection
 20:  *
 21:  * @package Core
 22:  * @subpackage GenericDB_Model
 23:  */
 24: class cApiCategoryCollection extends ItemCollection {
 25: 
 26:     /**
 27:      * Constructor function.
 28:      *
 29:      * @param string $select Select statement (see ItemCollection::select())
 30:      */
 31:     public function __construct($select = false) {
 32:         global $cfg;
 33:         parent::__construct($cfg['tab']['cat'], 'idcat');
 34:         $this->_setItemClass('cApiCategory');
 35: 
 36:         // set the join partners so that joins can be used via link() method
 37:         $this->_setJoinPartner('cApiClientCollection');
 38: 
 39:         if ($select !== false) {
 40:             $this->select($select);
 41:         }
 42:     }
 43: 
 44:     /**
 45:      * Creates a category entry.
 46:      *
 47:      * @param int $idclient
 48:      * @param int $parentid
 49:      * @param int $preid
 50:      * @param int $postid
 51:      * @param int $status
 52:      * @param string $author
 53:      * @param string $created
 54:      * @param string $lastmodified
 55:      * @return cApiCategory
 56:      */
 57:     public function create($idclient, $parentid = 0, $preid = 0, $postid = 0, $status = 0, $author = '', $created = '', $lastmodified = '') {
 58:         global $auth;
 59: 
 60:         if (empty($author)) {
 61:             $author = $auth->auth['uname'];
 62:         }
 63:         if (empty($created)) {
 64:             $created = date('Y-m-d H:i:s');
 65:         }
 66:         if (empty($lastmodified)) {
 67:             $lastmodified = date('Y-m-d H:i:s');
 68:         }
 69: 
 70:         $oItem = parent::createNewItem();
 71: 
 72:         $oItem->set('idclient', $idclient);
 73:         $oItem->set('parentid', $parentid);
 74:         $oItem->set('preid', $preid);
 75:         $oItem->set('postid', $postid);
 76:         $oItem->set('status', $status);
 77:         $oItem->set('author', $author);
 78:         $oItem->set('created', $created);
 79:         $oItem->set('lastmodified', $lastmodified);
 80:         $oItem->store();
 81: 
 82:         return $oItem;
 83:     }
 84: 
 85:     /**
 86:      * Returns the last category tree entry from the category table for a
 87:      * specific client.
 88:      * Last entry has no parentid and no postid.
 89:      *
 90:      * @param int $idclient
 91:      * @return cApiCategory|null
 92:      */
 93:     public function fetchLastCategoryTree($idclient) {
 94:         $where = 'parentid=0 AND postid=0 AND idclient=' . (int) $idclient;
 95:         $this->select($where);
 96:         return $this->next();
 97:     }
 98: 
 99:     /**
100:      * Returns list of categories (category ids) by passed client.
101:      *
102:      * @param int $idclient
103:      * @return array
104:      */
105:     public function getCategoryIdsByClient($idclient) {
106:         $list = array();
107:         $sql = 'SELECT idcat FROM `%s` WHERE idclient=%d';
108:         $this->db->query($sql, $this->table, $idclient);
109:         while ($this->db->nextRecord()) {
110:             $list[] = $this->db->f('idcat');
111:         }
112:         return $list;
113:     }
114: 
115:     /**
116:      * Returns the id of category which is located after passed category id.
117:      *
118:      * Example:
119:      * <pre>
120:      * ...
121:      * parent_category
122:      * this_category
123:      * post_category (*)
124:      * ...
125:      * (*) Returned category id
126:      * </pre>
127:      *
128:      * @param int $idcat
129:      * @return int
130:      */
131:     public function getNextPostCategoryId($idcat) {
132:         $sql = "SELECT idcat FROM `%s` WHERE preid = %d";
133:         $this->db->query($sql, $this->table, $idcat);
134:         if ($this->db->nextRecord()) {
135:             // Post element exists
136:             $idcat = $this->db->f('idcat');
137:             $sql = "SELECT parentid FROM `%s` WHERE idcat = %d";
138:             $this->db->query($sql, $this->table, $idcat);
139:             if ($this->db->nextRecord()) {
140:                 // Parent from post can't be 0
141:                 $parentid = (int) $this->db->f('parentid');
142:                 return ($parentid != 0)? $idcat : 0;
143:             } else {
144:                 return 99;
145:             }
146:         } else {
147:             // Post element does not exist
148:             return 0;
149:         }
150:     }
151: 
152:     /**
153:      * Returns the id of category which is located after passed category ids
154:      * parent category.
155:      *
156:      * Example:
157:      * <pre>
158:      * ...
159:      * root_category
160:      * parent_category
161:      * previous_cateory
162:      * this_category
163:      * post_category
164:      * parents_post_category (*)
165:      * ...
166:      * (*) Returned category id
167:      * </pre>
168:      *
169:      * @param int $idcat Category id
170:      * @return int
171:      */
172:     public function getParentsNextPostCategoryId($idcat) {
173:         $sql = "SELECT parentid FROM `%s` WHERE idcat = %d";
174:         $this->db->query($sql, $this->table, $idcat);
175:         if ($this->db->nextRecord()) {
176:             // Parent exists
177:             $idcat = $this->db->f('parentid');
178:             if ($idcat != 0) {
179:                 $sql = "SELECT idcat FROM `%s` WHERE preid = %d";
180:                 $this->db->query($sql, $this->table, $idcat);
181:                 if ($this->db->nextRecord()) {
182:                     // Parent has post
183:                     $idcat = (int) $this->db->f('idcat');
184:                     $sql = "SELECT parentid FROM `%s` WHERE idcat = %d";
185:                     $this->db->query($sql, $this->table, $idcat);
186:                     if ($this->db->nextRecord()) {
187:                         // Parent from post must not be 0
188:                         $parentid = (int) $this->db->f('parentid');
189:                         return ($parentid != 0)? $idcat : 0;
190:                     } else {
191:                         return 99;
192:                     }
193:                 } else {
194:                     // Parent has no post
195:                     return $this->getNextBackwardsCategoryId($idcat);
196:                 }
197:             } else {
198:                 return 0;
199:             }
200:         } else {
201:             // No parent
202:             return 0;
203:         }
204:     }
205: 
206:     /**
207:      * Returns id of first child category, where parent id is the same as passed
208:      * id and the previous id is 0.
209:      *
210:      * Example:
211:      * <pre>
212:      * ...
213:      * this_category
214:      * child_category (*)
215:      * child_category2
216:      * child_category3
217:      * ...
218:      * (*) Returned category id
219:      * </pre>
220:      *
221:      * @global array $cfg
222:      * @param int $idcat
223:      * @param int|null $idlang If defined, it checks also if there is a next
224:      *        deeper category in this language.
225:      * @return int
226:      */
227:     public function getFirstChildCategoryId($idcat, $idlang = null) {
228:         global $cfg;
229: 
230:         $sql = "SELECT idcat FROM `%s` WHERE parentid = %d AND preid = 0";
231:         $sql = $this->db->prepare($sql, $this->table, $idcat);
232:         $this->db->query($sql);
233:         if ($this->db->nextRecord()) {
234:             $midcat = (int) $this->db->f('idcat');
235:             if (null == $idlang) {
236:                 return $midcat;
237:             }
238: 
239:             // Deeper element exists, check for language dependent part
240:             $sql = "SELECT idcatlang FROM `%s` WHERE idcat = %d AND idlang = %d";
241:             $sql = $this->db->prepare($sql, $cfg['tab']['cat_lang'], $idcat, $idlang);
242:             $this->db->query($sql);
243:             return ($this->db->nextRecord())? $midcat : 0;
244:         } else {
245:             // Deeper element does not exist
246:             return 0;
247:         }
248:     }
249: 
250:     /**
251:      * Returns list of all child category ids, only them on next deeper level
252:      * (not recursive!)
253:      * The returned array contains already the order of the categories.
254:      * Example:
255:      * <pre>
256:      * ...
257:      * this_category
258:      * child_category (*)
259:      * child_category2 (*)
260:      * child_of_child_category2
261:      * child_category3 (*)
262:      * ...
263:      * (*) Returned category ids
264:      * </pre>
265:      *
266:      * @global array $cfg
267:      * @param int $idcat
268:      * @param int|null $idlang
269:      * @return array
270:      */
271:     public function getAllChildCategoryIds($idcat, $idlang = null) {
272:         global $cfg;
273: 
274:         $aCats = array();
275:         $bLoop = true;
276:         $db2 = $this->_getSecondDBInstance();
277: 
278:         $sql = "SELECT idcat FROM `%s` WHERE parentid = %d AND preid = 0";
279:         $this->db->query($sql, $this->table, $idcat);
280:         if ($this->db->nextRecord()) {
281:             while ($bLoop) {
282:                 $midcat = $this->db->f('idcat');
283:                 if (null == $idlang) {
284:                     $aCats[] = $midcat;
285:                 } else {
286:                     // Deeper element exists, check for language dependent part
287:                     $sql = "SELECT idcatlang FROM `%s` WHERE idcat = %d AND idlang = %d";
288:                     $db2->query($sql, $cfg['tab']['cat_lang'], $midcat, $idlang);
289:                     if ($db2->nextRecord()) {
290:                         $aCats[] = $midcat;
291:                     }
292:                 }
293: 
294:                 $sql = "SELECT idcat FROM `%s` WHERE parentid = %d AND preid = %d";
295:                 $this->db->query($sql, $this->table, $idcat, $midcat);
296:                 if (!$this->db->nextRecord()) {
297:                     $bLoop = false;
298:                 }
299:             }
300:         }
301:         return $aCats;
302:     }
303: 
304:     /**
305:      * Returns list of all child category ids and their child category ids of
306:      * passed category id.
307:      * The list also contains the id of passed category.
308:      *
309:      * The return value of this function could be used to perform bulk actions
310:      * on a specific category an all of its childcategories.
311:      *
312:      * NOTE: The returned array is not sorted!
313:      * Return value is similar to getAllCategoryIdsRecursive2, only the sorting
314:      * differs
315:      *
316:      * Example:
317:      * <pre>
318:      * ...
319:      * this_category (*)
320:      * child_category (*)
321:      * child_category2 (*)
322:      * child_of_child_category2 (*)
323:      * child_category3 (*)
324:      * child_of_child_category3 (*)
325:      * ...
326:      * (*) Returned category ids
327:      * </pre>
328:      *
329:      * @global array $cfg
330:      * @param int $idcat
331:      * @param int $idclient
332:      * @return array
333:      */
334:     public function getAllCategoryIdsRecursive($idcat, $idclient) {
335:         global $cfg;
336: 
337:         $catList = array();
338:         $openList = array();
339: 
340:         $openList[] = $idcat;
341: 
342:         while (($actId = array_pop($openList)) != null) {
343:             if (in_array($actId, $catList)) {
344:                 continue;
345:             }
346: 
347:             $catList[] = $actId;
348: 
349:             $sql = "SELECT * FROM `:cat_tree` AS A, `:cat` AS B WHERE A.idcat=B.idcat AND B.parentid=:parentid AND idclient=:idclient ORDER BY idtree";
350:             $sql = $this->db->prepare($sql, array(
351:                 'cat_tree' => $cfg['tab']['cat_tree'],
352:                 'cat' => $this->table,
353:                 'parentid' => (int) $actId,
354:                 'idclient' => (int) $idclient
355:             ));
356:             $this->db->query($sql);
357: 
358:             while ($this->db->nextRecord()) {
359:                 $openList[] = $this->db->f('idcat');
360:             }
361:         }
362: 
363:         return $catList;
364:     }
365: 
366:     /**
367:      * Returns list of all child category ids and their child category ids of
368:      * passed category id.
369:      * The list also contains the id of passed category.
370:      *
371:      * The return value of this function could be used to perform bulk actions
372:      * on a specific category an all of its childcategories.
373:      *
374:      * NOTE: Return value is similar to getAllCategoryIdsRecursive, only the
375:      * sorting differs
376:      *
377:      * Example:
378:      * <pre>
379:      * ...
380:      * this_category (*)
381:      * child_category (*)
382:      * child_category2 (*)
383:      * child_of_child_category2 (*)
384:      * child_category3 (*)
385:      * child_of_child_category3 (*)
386:      * ...
387:      * (*) Returned category ids
388:      * </pre>
389:      *
390:      * @global array $cfg
391:      * @param int $idcat
392:      * @param int $client
393:      * @return array Sorted by category id
394:      */
395:     public function getAllCategoryIdsRecursive2($idcat, $idclient) {
396:         global $cfg;
397: 
398:         $aCats = array();
399:         $found = false;
400:         $curLevel = 0;
401: 
402:         $sql = "SELECT * FROM `%s` AS a, `%s` AS b WHERE a.idcat = b.idcat AND idclient = %d ORDER BY idtree";
403:         $sql = $this->db->prepare($sql, $cfg['tab']['cat_tree'], $cfg['tab']['cat'], $idclient);
404:         $this->db->query($sql);
405: 
406:         while ($this->db->nextRecord()) {
407:             if ($found && $this->db->f('level') <= $curLevel) { // ending part
408:                                                                 // of tree
409:                 $found = false;
410:             }
411: 
412:             if ($this->db->f('idcat') == $idcat) { // starting part of tree
413:                 $found = true;
414:                 $curLevel = $this->db->f('level');
415:             }
416: 
417:             if ($found) {
418:                 $aCats[] = $this->db->f('idcat');
419:             }
420:         }
421: 
422:         return $aCats;
423:     }
424: 
425: }
426: 
427: /**
428:  * Category item
429:  *
430:  * @package Core
431:  * @subpackage GenericDB_Model
432:  */
433: class cApiCategory extends Item {
434: 
435:     /**
436:      * Constructor Function
437:      *
438:      * @param mixed $mId Specifies the ID of item to load
439:      */
440:     public function __construct($mId = false) {
441:         global $cfg;
442:         parent::__construct($cfg['tab']['cat'], 'idcat');
443:         $this->setFilters(array(), array());
444: 
445:         if ($mId !== false) {
446:             $this->loadByPrimaryKey($mId);
447:         }
448:     }
449: 
450:     /**
451:      * Updates lastmodified field and calls parents store method
452:      *
453:      * @return bool
454:      */
455:     public function store() {
456:         $this->set('lastmodified', date('Y-m-d H:i:s'));
457:         return parent::store();
458:     }
459: 
460:     /**
461:      * Userdefined setter for category fields.
462:      *
463:      * @param string $name
464:      * @param mixed $value
465:      * @param bool $safe Flag to run defined inFilter on passed value
466:      */
467:     public function setField($name, $value, $safe = true) {
468:         switch ($name) {
469:             case 'idcat':
470:             case 'idclient':
471:             case 'parentid':
472:             case 'preid':
473:             case 'postid':
474:             case 'status':
475:                 $value = (int) $value;
476:                 break;
477:         }
478: 
479:         parent::setField($name, $value, $safe);
480:     }
481: 
482:     /**
483:      * Returns the link to the current object.
484:      * @param integer $changeLangId change language id for URL (optional)
485:      * @return string link
486:      */
487:     public function getLink($changeLangId = 0) {
488:         if ($this->isLoaded() === false) {
489:             return '';
490:         }
491: 
492:         $options = array();
493:         $options['idcat'] = $this->get('idcat');
494:         $options['lang'] = ($changeLangId == 0) ? cRegistry::getLanguageId() : $changeLangId;
495:         if ($changeLangId > 0) {
496:             $options['changelang'] = $changeLangId;
497:         }
498: 
499: 
500: 
501:         return cUri::getInstance()->build($options);
502:     }
503: 
504: }
505: 
CMS CONTENIDO 4.9.0 API documentation generated by ApiGen 2.8.0