Overview

Packages

  • CONTENIDO
  • Core
    • Authentication
    • Backend
    • Cache
    • CEC
    • Chain
    • ContentType
    • Database
    • Debug
    • Exception
    • Frontend
      • Search
      • URI
      • Util
    • GenericDB
      • Model
    • GUI
      • HTML
    • I18N
    • LayoutHandler
    • Log
    • Security
    • Session
    • Util
    • Validation
    • Versioning
    • XML
  • Module
    • ContentRssCreator
    • ContentSitemapHtml
    • ContentSitemapXml
    • ContentUserForum
    • NavigationTop
    • ScriptCookieDirective
  • 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
  • Smarty
    • Cacher
    • Compiler
    • Config
    • Debug
    • PluginsBlock
    • PluginsFilter
    • PluginsFunction
    • PluginsInternal
    • PluginsModifier
    • PluginsModifierCompiler
    • PluginsShared
    • Security
    • Template
    • TemplateResources
  • Swift
    • ByteStream
    • CharacterStream
    • Encoder
    • Events
    • KeyCache
    • Mailer
    • Mime
    • Plugins
    • Transport

Classes

  • Swift_FailoverTransport
  • Swift_LoadBalancedTransport
  • Swift_MailTransport
  • Swift_Plugins_Loggers_ArrayLogger
  • Swift_Plugins_Loggers_EchoLogger
  • Swift_SendmailTransport
  • Swift_SmtpTransport
  • Swift_Transport_AbstractSmtpTransport
  • Swift_Transport_Esmtp_Auth_CramMd5Authenticator
  • Swift_Transport_Esmtp_Auth_LoginAuthenticator
  • Swift_Transport_Esmtp_Auth_PlainAuthenticator
  • Swift_Transport_Esmtp_AuthHandler
  • Swift_Transport_EsmtpTransport
  • Swift_Transport_FailoverTransport
  • Swift_Transport_LoadBalancedTransport
  • Swift_Transport_MailTransport
  • Swift_Transport_SendmailTransport
  • Swift_Transport_SimpleMailInvoker
  • Swift_Transport_StreamBuffer

Interfaces

  • Swift_Plugins_Logger
  • Swift_Plugins_Pop_Pop3Exception
  • Swift_Transport
  • Swift_Transport_Esmtp_Authenticator
  • Swift_Transport_EsmtpHandler
  • Swift_Transport_IoBuffer
  • Swift_Transport_MailInvoker
  • Swift_Transport_SmtpAgent
  • Swift_TransportException
  • Overview
  • Package
  • Function
  • Todo
  • Download
  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:      * Create a new collection of items.
 28:      *
 29:      * @param string $select where clause to use for selection (see
 30:      *            ItemCollection::select())
 31:      */
 32:     public function __construct($select = false) {
 33:         global $cfg;
 34:         parent::__construct($cfg['tab']['cat'], 'idcat');
 35:         $this->_setItemClass('cApiCategory');
 36: 
 37:         // set the join partners so that joins can be used via link() method
 38:         $this->_setJoinPartner('cApiClientCollection');
 39: 
 40:         if ($select !== false) {
 41:             $this->select($select);
 42:         }
 43:     }
 44: 
 45:     /**
 46:      * Creates a category entry.
 47:      *
 48:      * @param int $idclient
 49:      * @param int $parentid
 50:      * @param int $preid
 51:      * @param int $postid
 52:      * @param int $status
 53:      * @param string $author
 54:      * @param string $created
 55:      * @param string $lastmodified
 56:      * @return cApiCategory
 57:      */
 58:     public function create($idclient, $parentid = 0, $preid = 0, $postid = 0, $status = 0, $author = '', $created = '', $lastmodified = '') {
 59:         global $auth;
 60: 
 61:         if (empty($author)) {
 62:             $author = $auth->auth['uname'];
 63:         }
 64:         if (empty($created)) {
 65:             $created = date('Y-m-d H:i:s');
 66:         }
 67:         if (empty($lastmodified)) {
 68:             $lastmodified = date('Y-m-d H:i:s');
 69:         }
 70: 
 71:         $oItem = $this->createNewItem();
 72: 
 73:         $oItem->set('idclient', $idclient);
 74:         $oItem->set('parentid', $parentid);
 75:         $oItem->set('preid', $preid);
 76:         $oItem->set('postid', $postid);
 77:         $oItem->set('status', $status);
 78:         $oItem->set('author', $author);
 79:         $oItem->set('created', $created);
 80:         $oItem->set('lastmodified', $lastmodified);
 81:         $oItem->store();
 82: 
 83:         return $oItem;
 84:     }
 85: 
 86:     /**
 87:      * Returns the last category tree entry from the category table for a
 88:      * specific client.
 89:      * Last entry has no parentid and no postid.
 90:      *
 91:      * @param int $idclient
 92:      * @return cApiCategory NULL
 93:      */
 94:     public function fetchLastCategoryTree($idclient) {
 95:         $where = 'parentid=0 AND postid=0 AND idclient=' . (int) $idclient;
 96:         $this->select($where);
 97:         return $this->next();
 98:     }
 99: 
100:     /**
101:      * Returns list of categories (category ids) by passed client.
102:      *
103:      * @param int $idclient
104:      * @return array
105:      */
106:     public function getCategoryIdsByClient($idclient) {
107:         $list = array();
108:         $sql = 'SELECT idcat FROM `%s` WHERE idclient=%d';
109:         $this->db->query($sql, $this->table, $idclient);
110:         while ($this->db->nextRecord()) {
111:             $list[] = $this->db->f('idcat');
112:         }
113:         return $list;
114:     }
115: 
116:     /**
117:      * Returns the id of category which is located after passed category id.
118:      *
119:      * Example:
120:      * <pre>
121:      * ...
122:      * parent_category
123:      * this_category
124:      * post_category (*)
125:      * ...
126:      * (*) Returned category id
127:      * </pre>
128:      *
129:      * @param int $idcat
130:      * @return int
131:      */
132:     public function getNextPostCategoryId($idcat) {
133:         $sql = "SELECT idcat FROM `%s` WHERE preid = %d";
134:         $this->db->query($sql, $this->table, $idcat);
135:         if ($this->db->nextRecord()) {
136:             // Post element exists
137:             $idcat = $this->db->f('idcat');
138:             $sql = "SELECT parentid FROM `%s` WHERE idcat = %d";
139:             $this->db->query($sql, $this->table, $idcat);
140:             if ($this->db->nextRecord()) {
141:                 // Parent from post can't be 0
142:                 $parentid = (int) $this->db->f('parentid');
143:                 return ($parentid != 0) ? $idcat : 0;
144:             } else {
145:                 return 99;
146:             }
147:         } else {
148:             // Post element does not exist
149:             return 0;
150:         }
151:     }
152: 
153:     /**
154:      * Returns the id of category which is located after passed category ids
155:      * parent category.
156:      *
157:      * Example:
158:      * <pre>
159:      * ...
160:      * root_category
161:      * parent_category
162:      * previous_cateory
163:      * this_category
164:      * post_category
165:      * parents_post_category (*)
166:      * ...
167:      * (*) Returned category id
168:      * </pre>
169:      *
170:      * @param int $idcat Category id
171:      * @return int
172:      */
173:     public function getParentsNextPostCategoryId($idcat) {
174:         $sql = "SELECT parentid FROM `%s` WHERE idcat = %d";
175:         $this->db->query($sql, $this->table, $idcat);
176:         if ($this->db->nextRecord()) {
177:             // Parent exists
178:             $idcat = $this->db->f('parentid');
179:             if ($idcat != 0) {
180:                 $sql = "SELECT idcat FROM `%s` WHERE preid = %d";
181:                 $this->db->query($sql, $this->table, $idcat);
182:                 if ($this->db->nextRecord()) {
183:                     // Parent has post
184:                     $idcat = (int) $this->db->f('idcat');
185:                     $sql = "SELECT parentid FROM `%s` WHERE idcat = %d";
186:                     $this->db->query($sql, $this->table, $idcat);
187:                     if ($this->db->nextRecord()) {
188:                         // Parent from post must not be 0
189:                         $parentid = (int) $this->db->f('parentid');
190:                         return ($parentid != 0) ? $idcat : 0;
191:                     } else {
192:                         return 99;
193:                     }
194:                 } else {
195:                     // Parent has no post
196:                     return $this->getNextBackwardsCategoryId($idcat);
197:                 }
198:             } else {
199:                 return 0;
200:             }
201:         } else {
202:             // No parent
203:             return 0;
204:         }
205:     }
206: 
207:     /**
208:      * Returns id of first child category, where parent id is the same as passed
209:      * id and the previous id is 0.
210:      *
211:      * Example:
212:      * <pre>
213:      * ...
214:      * this_category
215:      * child_category (*)
216:      * child_category2
217:      * child_category3
218:      * ...
219:      * (*) Returned category id
220:      * </pre>
221:      *
222:      * @global array $cfg
223:      * @param int $idcat
224:      * @param int|NULL $idlang If defined, it checks also if there is a next
225:      *        deeper category in this language.
226:      * @return int
227:      */
228:     public function getFirstChildCategoryId($idcat, $idlang = NULL) {
229:         global $cfg;
230: 
231:         $sql = "SELECT idcat FROM `%s` WHERE parentid = %d AND preid = 0";
232:         $sql = $this->db->prepare($sql, $this->table, $idcat);
233:         $this->db->query($sql);
234:         if ($this->db->nextRecord()) {
235:             $midcat = (int) $this->db->f('idcat');
236:             if (NULL == $idlang) {
237:                 return $midcat;
238:             }
239: 
240:             // Deeper element exists, check for language dependent part
241:             $sql = "SELECT idcatlang FROM `%s` WHERE idcat = %d AND idlang = %d";
242:             $sql = $this->db->prepare($sql, $cfg['tab']['cat_lang'], $idcat, $idlang);
243:             $this->db->query($sql);
244:             return ($this->db->nextRecord()) ? $midcat : 0;
245:         } else {
246:             // Deeper element does not exist
247:             return 0;
248:         }
249:     }
250: 
251:     /**
252:      * Returns list of all child category ids, only them on next deeper level
253:      * (not recursive!)
254:      * The returned array contains already the order of the categories.
255:      * Example:
256:      * <pre>
257:      * ...
258:      * this_category
259:      * child_category (*)
260:      * child_category2 (*)
261:      * child_of_child_category2
262:      * child_category3 (*)
263:      * ...
264:      * (*) Returned category ids
265:      * </pre>
266:      *
267:      * @global array $cfg
268:      * @param int $idcat
269:      * @param int|NULL $idlang
270:      * @return array
271:      */
272:     public function getAllChildCategoryIds($idcat, $idlang = NULL) {
273:         global $cfg;
274: 
275:         $aCats = array();
276:         $bLoop = true;
277:         $db2 = $this->_getSecondDBInstance();
278: 
279:         $sql = "SELECT idcat FROM `%s` WHERE parentid = %d AND preid = 0";
280:         $this->db->query($sql, $this->table, $idcat);
281:         if ($this->db->nextRecord()) {
282:             while ($bLoop) {
283:                 $midcat = $this->db->f('idcat');
284:                 if (NULL == $idlang) {
285:                     $aCats[] = $midcat;
286:                 } else {
287:                     // Deeper element exists, check for language dependent part
288:                     $sql = "SELECT idcatlang FROM `%s` WHERE idcat = %d AND idlang = %d";
289:                     $db2->query($sql, $cfg['tab']['cat_lang'], $midcat, $idlang);
290:                     if ($db2->nextRecord()) {
291:                         $aCats[] = $midcat;
292:                     }
293:                 }
294: 
295:                 $sql = "SELECT idcat FROM `%s` WHERE parentid = %d AND preid = %d";
296:                 $this->db->query($sql, $this->table, $idcat, $midcat);
297:                 if (!$this->db->nextRecord()) {
298:                     $bLoop = false;
299:                 }
300:             }
301:         }
302:         return $aCats;
303:     }
304: 
305:     /**
306:      * Returns list of all child category ids and their child category ids of
307:      * passed category id.
308:      * The list also contains the id of passed category.
309:      *
310:      * The return value of this function could be used to perform bulk actions
311:      * on a specific category an all of its childcategories.
312:      *
313:      * NOTE: The returned array is not sorted!
314:      * Return value is similar to getAllCategoryIdsRecursive2, only the sorting
315:      * differs
316:      *
317:      * Example:
318:      * <pre>
319:      * ...
320:      * this_category (*)
321:      * child_category (*)
322:      * child_category2 (*)
323:      * child_of_child_category2 (*)
324:      * child_category3 (*)
325:      * child_of_child_category3 (*)
326:      * ...
327:      * (*) Returned category ids
328:      * </pre>
329:      *
330:      * @global array $cfg
331:      * @param int $idcat
332:      * @param int $idclient
333:      * @return array
334:      */
335:     public function getAllCategoryIdsRecursive($idcat, $idclient) {
336:         global $cfg;
337: 
338:         $catList = array();
339:         $openList = array();
340: 
341:         $openList[] = $idcat;
342: 
343:         while (($actId = array_pop($openList)) != NULL) {
344:             if (in_array($actId, $catList)) {
345:                 continue;
346:             }
347: 
348:             $catList[] = $actId;
349: 
350:             $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";
351:             $sql = $this->db->prepare($sql, array(
352:                 'cat_tree' => $cfg['tab']['cat_tree'],
353:                 'cat' => $this->table,
354:                 'parentid' => (int) $actId,
355:                 'idclient' => (int) $idclient
356:             ));
357:             $this->db->query($sql);
358: 
359:             while ($this->db->nextRecord()) {
360:                 $openList[] = $this->db->f('idcat');
361:             }
362:         }
363: 
364:         return $catList;
365:     }
366: 
367:     /**
368:      * Returns list of all child category ids and their child category ids of
369:      * passed category id.
370:      * The list also contains the id of passed category.
371:      *
372:      * The return value of this function could be used to perform bulk actions
373:      * on a specific category an all of its childcategories.
374:      *
375:      * NOTE: Return value is similar to getAllCategoryIdsRecursive, only the
376:      * sorting differs
377:      *
378:      * Example:
379:      * <pre>
380:      * ...
381:      * this_category (*)
382:      * child_category (*)
383:      * child_category2 (*)
384:      * child_of_child_category2 (*)
385:      * child_category3 (*)
386:      * child_of_child_category3 (*)
387:      * ...
388:      * (*) Returned category ids
389:      * </pre>
390:      *
391:      * @global array $cfg
392:      * @param int $idcat
393:      * @param int $client
394:      * @return array Sorted by category id
395:      */
396:     public function getAllCategoryIdsRecursive2($idcat, $idclient) {
397:         global $cfg;
398: 
399:         $aCats = array();
400:         $found = false;
401:         $curLevel = 0;
402: 
403:         $sql = "SELECT * FROM `%s` AS a, `%s` AS b WHERE a.idcat = b.idcat AND idclient = %d ORDER BY idtree";
404:         $sql = $this->db->prepare($sql, $cfg['tab']['cat_tree'], $cfg['tab']['cat'], $idclient);
405:         $this->db->query($sql);
406: 
407:         while ($this->db->nextRecord()) {
408:             if ($found && $this->db->f('level') <= $curLevel) { // ending part
409:                                                                 // of tree
410:                 $found = false;
411:             }
412: 
413:             if ($this->db->f('idcat') == $idcat) { // starting part of tree
414:                 $found = true;
415:                 $curLevel = $this->db->f('level');
416:             }
417: 
418:             if ($found) {
419:                 $aCats[] = $this->db->f('idcat');
420:             }
421:         }
422: 
423:         return $aCats;
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:      * @todo should return return value of overloaded method
467:      */
468:     public function setField($name, $value, $safe = true) {
469:         switch ($name) {
470:             case 'idcat':
471:             case 'idclient':
472:             case 'parentid':
473:             case 'preid':
474:             case 'postid':
475:             case 'status':
476:                 $value = (int) $value;
477:                 break;
478:         }
479: 
480:         parent::setField($name, $value, $safe);
481:     }
482: 
483:     /**
484:      * Returns the link to the current object.
485:      *
486:      * @param int $changeLangId change language id for URL (optional)
487:      * @return string link
488:      */
489:     public function getLink($changeLangId = 0) {
490:         if ($this->isLoaded() === false) {
491:             return '';
492:         }
493: 
494:         $options = array();
495:         $options['idcat'] = $this->get('idcat');
496:         $options['lang'] = ($changeLangId == 0) ? cRegistry::getLanguageId() : $changeLangId;
497:         if ($changeLangId > 0) {
498:             $options['changelang'] = $changeLangId;
499:         }
500: 
501:         return cUri::getInstance()->build($options);
502:     }
503: }
504: 
CMS CONTENIDO 4.9.7 API documentation generated by ApiGen