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
    • ContentSitemapHtml
    • ContentSitemapXml
    • ContentUserForum
    • NavigationTop
    • ScriptCookieDirective
  • mpAutoloaderClassMap
  • None
  • PHP
  • Plugin
    • ContentAllocation
    • CronjobOverview
    • FormAssistant
    • FrontendLogic
    • FrontendUsers
    • Linkchecker
    • ModRewrite
    • Newsletter
    • Repository
      • FrontendNavigation
      • KeywordDensity
    • SIWECOS
    • SmartyWrapper
    • UrlShortener
    • UserForum
    • Workflow
  • PluginManager
  • Setup
    • Form
    • GUI
    • Helper
      • Environment
      • Filesystem
      • MySQL
      • PHP
    • UpgradeJob

Classes

  • FrontendNavigation
  • Overview
  • Package
  • Class
  • Tree
  • Deprecated
  • Todo
  1: <?php
  2: /**
  3:  * This file includes the "frontend navigation" sub plugin from the old plugin repository.
  4:  *
  5:  * @package    Plugin
  6:  * @subpackage Repository_FrontendNavigation
  7:  * @author     Willi Man
  8:  * @copyright  four for business AG <www.4fb.de>
  9:  * @license    http://www.contenido.org/license/LIZENZ.txt
 10:  * @link       http://www.4fb.de
 11:  * @link       http://www.contenido.org
 12:  */
 13: 
 14: defined('CON_FRAMEWORK') || die('Illegal call: Missing framework initialization - request aborted.');
 15: 
 16: /**
 17:  * file FrontendNavigation.php
 18:  *
 19:  * @package    Plugin
 20:  * @subpackage Repository_FrontendNavigation
 21:  */
 22: class FrontendNavigation {
 23: 
 24:     /**
 25:      * References database object
 26:      *
 27:      * @var cDb
 28:      */
 29:     protected $_db = null;
 30: 
 31:     /*
 32:      *
 33:      * @var boolean
 34:      */
 35:     protected $_debug = false;
 36: 
 37:     /**
 38:      * @var integer
 39:      */
 40:     protected $_client = 0;
 41: 
 42:     /**
 43:      * @var array
 44:      */
 45:     protected $_cfgClient = array();
 46: 
 47:     /**
 48:      * @var array
 49:      */
 50:     protected $_cfg = array();
 51: 
 52:     /**
 53:      * @var integer
 54:      */
 55:     protected $_lang = 0;
 56: 
 57:     /**
 58:      * FrontendNavigation constructor
 59:      */
 60:     public function __construct() {
 61:         $this->_db = cRegistry::getDb();
 62:         $this->_cfgClient = cRegistry::getClientConfig();
 63:         $this->_cfg = cRegistry::getConfig();
 64:         $this->_client = cRegistry::getClientId();
 65:         $this->_lang = cRegistry::getLanguageId();
 66:     }
 67: 
 68:     /**
 69:      * Old constructor
 70:      *
 71:      * @deprecated [2016-02-11]
 72:      *                This method is deprecated and is not needed any longer. Please use __construct() as constructor function.
 73:      * @return FrontendNavigation
 74:      */
 75:     public function FrontendNavigation() {
 76:         cDeprecated('This method is deprecated and is not needed any longer. Please use __construct() as constructor function.');
 77:         return $this->__construct();
 78:     }
 79: 
 80:     /**
 81:      * Get child categories by given parent category
 82:      *
 83:      * @param integer $parentCategory
 84:      *
 85:      * @return array
 86:      * @throws cDbException
 87:      */
 88:     public function getSubCategories($parentCategory) {
 89:         if (!is_int((int) $parentCategory)) {
 90:             return array();
 91:         }
 92: 
 93:         $sql = "SELECT
 94:                     A.idcat
 95:                 FROM
 96:                     " . $this->_cfg["tab"]["cat_tree"] . " AS A,
 97:                     " . $this->_cfg["tab"]["cat"] . " AS B,
 98:                     " . $this->_cfg["tab"]["cat_lang"] . " AS C
 99:                 WHERE
100:                     A.idcat    = B.idcat AND
101:                     B.idcat    = C.idcat AND
102:                     B.idclient = " . $this->_client . " AND
103:                     C.idlang   = " . $this->_lang . " AND
104:                     C.visible  = 1 AND
105:                     C.public   = 1 AND
106:                     B.parentid = " . $parentCategory . "
107:                 ORDER BY
108:                     A.idtree ";
109: 
110:         if ($this->_debug) {
111:             echo "<pre>";
112:             print_r($sql);
113:             echo "</pre>";
114:         }
115: 
116:         $this->_db->query($sql);
117: 
118:         $navigation = array();
119:         while ($this->_db->nextRecord()) {
120:             $navigation[] = $this->_db->f("idcat");
121:         }
122: 
123:         return $navigation;
124:     }
125: 
126:     /**
127:      * Check if child categories of a given parent category exist
128:      *
129:      * @param integer $parentCategory
130:      *
131:      * @return boolean
132:      * @throws cDbException
133:      */
134:     public function hasChildren($parentCategory) {
135:         if (!is_int((int) $parentCategory)) {
136:             return false;
137:         }
138: 
139:         $sql = "SELECT
140:                     B.idcat
141:                 FROM
142:                     " . $this->_cfg["tab"]["cat"] . " AS B,
143:                     " . $this->_cfg["tab"]["cat_lang"] . " AS C
144:                 WHERE
145:                     B.idcat    = C.idcat AND
146:                     B.idclient = " . $this->_client . " AND
147:                     C.idlang   = " . $this->_lang . " AND
148:                     C.visible  = 1 AND
149:                     C.public   = 1 AND
150:                     B.parentid = " . $parentCategory . " ";
151: 
152:         if ($this->_debug) {
153:             echo "<pre>";
154:             print_r($sql);
155:             echo "</pre>";
156:         }
157: 
158:         $this->_db->query($sql);
159: 
160:         if ($this->_db->nextRecord()) {
161:             return true;
162:         } else {
163:             return false;
164:         }
165:     }
166: 
167:     /**
168:      * Get direct successor of a given category
169:      * Note: does not work if direct successor (with preid 0) is not visible
170:      * or not public
171:      *
172:      * @param integer $category
173:      *
174:      * @return integer
175:      * @throws cDbException
176:      */
177:     public function getSuccessor($category) {
178:         if (!is_int((int) $category)) {
179:             return -1;
180:         }
181: 
182:         $sql = "SELECT
183:                     B.idcat
184:                 FROM
185:                     " . $this->_cfg["tab"]["cat"] . " AS B,
186:                     " . $this->_cfg["tab"]["cat_lang"] . " AS C
187:                 WHERE
188:                     B.idcat    = C.idcat AND
189:                     B.idclient = " . $this->_client . " AND
190:                     C.idlang   = " . $this->_lang . " AND
191:                     C.visible  = 1 AND
192:                     C.public   = 1 AND
193:                     B.preid    = 0 AND
194:                     B.parentid = " . $category . " ";
195: 
196:         if ($this->_debug) {
197:             echo "<pre>";
198:             print_r($sql);
199:             echo "</pre>";
200:         }
201: 
202:         $this->_db->query($sql);
203: 
204:         if ($this->_db->nextRecord()) {
205:             return $this->_db->f("idcat");
206:         } else {
207:             return -1;
208:         }
209:     }
210: 
211:     /**
212:      * Check if a given category has a direct successor
213:      *
214:      * @param integer $category
215:      *
216:      * @return boolean
217:      * @throws cDbException
218:      */
219:     public function hasSuccessor($category) {
220:         if (!is_int((int) $category)) {
221:             return false;
222:         }
223: 
224:         $sql = "SELECT
225:                     B.idcat
226:                 FROM
227:                     " . $this->_cfg["tab"]["cat"] . " AS B,
228:                     " . $this->_cfg["tab"]["cat_lang"] . " AS C
229:                 WHERE
230:                     B.idcat    = C.idcat AND
231:                     B.idclient = " . $this->_client . " AND
232:                     C.idlang   = " . $this->_lang . " AND
233:                     C.visible  = 1 AND
234:                     C.public   = 1 AND
235:                     B.preid    = 0 AND
236:                     B.parentid = " . $category . " ";
237: 
238:         if ($this->_debug) {
239:             echo "<pre>";
240:             print_r($sql);
241:             echo "</pre>";
242:         }
243: 
244:         $this->_db->query($sql);
245: 
246:         if ($this->_db->nextRecord()) {
247:             return true;
248:         } else {
249:             return false;
250:         }
251:     }
252: 
253:     /**
254:      * Get category name
255:      *
256:      * @param integer $cat_id
257:      *
258:      * @return string
259:      * @throws cDbException
260:      */
261:     public function getCategoryName($cat_id) {
262:         if (!is_int((int) $cat_id)) {
263:             return '';
264:         }
265: 
266:         $sql = "SELECT
267:                     B.name
268:                 FROM
269:                     " . $this->_cfg["tab"]["cat"] . " AS A,
270:                     " . $this->_cfg["tab"]["cat_lang"] . " AS B
271:                 WHERE
272:                     A.idcat    = B.idcat AND
273:                     A.idcat    = $cat_id AND
274:                     A.idclient = " . $this->_client . " AND
275:                     B.idlang   = " . $this->_lang . "
276:                 ";
277: 
278:         if ($this->_debug) {
279:             echo "<pre>";
280:             print_r($sql);
281:             echo "</pre>";
282:         }
283: 
284:         $this->_db->query($sql);
285: 
286:         if ($this->_db->nextRecord()) {
287:             return $this->_db->f("name");
288:         } else {
289:             return '';
290:         }
291:     }
292: 
293:     /**
294:      * Get category urlname
295:      *
296:      * @param integer $cat_id
297:      *
298:      * @return string
299:      * @throws cDbException
300:      */
301:     public function getCategoryURLName($cat_id) {
302:         if (!is_int((int) $cat_id)) {
303:             return '';
304:         }
305: 
306:         $sql = "SELECT
307:                     B.urlname
308:                 FROM
309:                     " . $this->_cfg["tab"]["cat"] . " AS A,
310:                     " . $this->_cfg["tab"]["cat_lang"] . " AS B
311:                 WHERE
312:                     A.idcat    = B.idcat AND
313:                     A.idcat    = $cat_id AND
314:                     A.idclient = " . $this->_client . " AND
315:                     B.idlang   = " . $this->_lang . "
316:                 ";
317: 
318:         if ($this->_debug) {
319:             echo "<pre>";
320:             print_r($sql);
321:             echo "</pre>";
322:         }
323: 
324:         $this->_db->query($sql);
325: 
326:         if ($this->_db->nextRecord()) {
327:             return $this->_db->f("urlname");
328:         } else {
329:             return '';
330:         }
331:     }
332: 
333:     /**
334:      * Check if category is visible
335:      *
336:      * @param integer $cat_id
337:      *
338:      * @return boolean
339:      * @throws cDbException
340:      */
341:     public function isVisible($cat_id) {
342:         if (!is_int((int) $cat_id)) {
343:             return false;
344:         }
345: 
346:         $sql = "SELECT
347:                     B.visible
348:                 FROM
349:                     " . $this->_cfg["tab"]["cat"] . " AS A,
350:                     " . $this->_cfg["tab"]["cat_lang"] . " AS B
351:                 WHERE
352:                     A.idcat    = B.idcat AND
353:                     A.idcat    = $cat_id AND
354:                     A.idclient = " . $this->_client . " AND
355:                     B.idlang   = " . $this->_lang . "
356:                 ";
357: 
358:         if ($this->_debug) {
359:             echo "<pre>";
360:             print_r($sql);
361:             echo "</pre>";
362:         }
363: 
364:         $this->_db->query($sql);
365:         $this->_db->nextRecord();
366: 
367:         if ($this->_db->f("visible") == 1) {
368:             return true;
369:         } else {
370:             return false;
371:         }
372:     }
373: 
374:     /**
375:      * Check if category is public
376:      *
377:      * @param integer $cat_id
378:      *
379:      * @return boolean
380:      * @throws cDbException
381:      */
382:     public function isPublic($cat_id) {
383:         if (!is_int((int) $cat_id)) {
384:             return false;
385:         }
386: 
387:         $sql = "SELECT
388:                     B.public
389:                 FROM
390:                     " . $this->_cfg["tab"]["cat"] . " AS A,
391:                     " . $this->_cfg["tab"]["cat_lang"] . " AS B
392:                 WHERE
393:                     A.idcat    = B.idcat AND
394:                     A.idcat    = $cat_id AND
395:                     A.idclient = " . $this->_client . " AND
396:                     B.idlang   = " . $this->_lang . "
397:                 ";
398: 
399:         if ($this->_debug) {
400:             echo "<pre>";
401:             print_r($sql);
402:             echo "</pre>";
403:         }
404: 
405:         $this->_db->query($sql);
406:         $this->_db->nextRecord();
407: 
408:         if ($this->_db->f("public") == 1) {
409:             return true;
410:         } else {
411:             return false;
412:         }
413:     }
414: 
415:     /**
416:      * Return true if $parentid is parent of $catid
417:      *
418:      * @param integer $parentid
419:      * @param integer $catid
420:      *
421:      * @return boolean
422:      * @throws cDbException
423:      */
424:     public function isParent($parentid, $catid) {
425:         if (!is_int((int) $parentid)) {
426:             return false;
427:         }
428: 
429:         $sql = "SELECT
430:                 a.parentid
431:                 FROM
432:                     " . $this->_cfg["tab"]["cat"] . " AS a,
433:                     " . $this->_cfg["tab"]["cat_lang"] . " AS b
434:                 WHERE
435:                     a.idclient = " . $this->_client . " AND
436:                     b.idlang   = " . $this->_lang . " AND
437:                     a.idcat    = b.idcat AND
438:                     a.idcat    = " . $catid . " ";
439: 
440:         $this->_db->query($sql);
441:         $this->_db->nextRecord();
442: 
443:         if ($this->_debug) {
444:             echo "<pre>";
445:             print_r($sql);
446:             echo "</pre>";
447:         }
448: 
449:         $pre = $this->_db->f("parentid");
450: 
451:         if ($parentid == $pre) {
452:             return true;
453:         } else {
454:             return false;
455:         }
456:     }
457: 
458:     /**
459:      * Get parent id of a category
460:      *
461:      * @param integer $preid
462:      *
463:      * @return integer
464:      * @throws cDbException
465:      */
466:     public function getParent($preid) {
467:         if (!is_int((int) $preid)) {
468:             return -1;
469:         }
470: 
471:         $sql = "SELECT
472:                 a.parentid
473:                 FROM
474:                     " . $this->_cfg["tab"]["cat"] . " AS a,
475:                     " . $this->_cfg["tab"]["cat_lang"] . " AS b
476:                 WHERE
477:                     a.idclient = " . $this->_client . " AND
478:                     b.idlang   = " . $this->_lang . " AND
479:                     a.idcat    = b.idcat AND
480:                     a.idcat    = " . $preid . " ";
481: 
482:         $this->_db->query($sql);
483: 
484:         if ($this->_debug) {
485:             echo "<pre>";
486:             print_r($sql);
487:             echo "</pre>";
488:         }
489: 
490:         if ($this->_db->nextRecord()) {
491:             return $this->_db->f("parentid");
492:         } else {
493:             return -1;
494:         }
495:     }
496: 
497:     /**
498:      * Check if a category has a parent
499:      *
500:      * @param integer $preid
501:      *
502:      * @return boolean
503:      * @throws cDbException
504:      */
505:     public function hasParent($preid) {
506:         if (!is_int((int) $preid)) {
507:             return false;
508:         }
509: 
510:         $sql = "SELECT
511:                 a.parentid
512:                 FROM
513:                     " . $this->_cfg["tab"]["cat"] . " AS a,
514:                     " . $this->_cfg["tab"]["cat_lang"] . " AS b
515:                 WHERE
516:                     a.idclient = " . $this->_client . " AND
517:                     b.idlang   = " . $this->_lang . " AND
518:                     a.idcat    = b.idcat AND
519:                     a.idcat    = " . $preid . " ";
520: 
521:         $this->_db->query($sql);
522: 
523:         if ($this->_debug) {
524:             echo "<pre>";
525:             print_r($sql);
526:             echo "</pre>";
527:         }
528: 
529:         if ($this->_db->nextRecord()) {
530:             return true;
531:         } else {
532:             return false;
533:         }
534:     }
535: 
536:     /**
537:      * Get level of a category
538:      *
539:      * @param integer $catid
540:      *
541:      * @return integer
542:      * @throws cDbException
543:      */
544:     public function getLevel($catid) {
545:         if (!is_int((int) $catid)) {
546:             return -1;
547:         }
548: 
549:         $sql = "SELECT
550:                     level
551:                 FROM
552:                     " . $this->_cfg["tab"]["cat_tree"] . "
553:                 WHERE
554:                     idcat = " . $catid . " ";
555: 
556:         $this->_db->query($sql);
557: 
558:         if ($this->_debug) {
559:             echo "<pre>";
560:             print_r($sql);
561:             echo "</pre>";
562:         }
563: 
564:         if ($this->_db->nextRecord()) {
565:             return $this->_db->f("level");
566:         } else {
567:             return -1;
568:         }
569:     }
570: 
571:     /**
572:      * Get URL by given category in front_content.php style
573:      *
574:      * @param int $idcat
575:      * @param int $idart
576:      * @param bool $absolute return absolute path or not [optional]
577:      * @return string $url
578:      */
579:     public function getFrontContentUrl($idcat, $idart, $absolute = true) {
580:         if (!is_int((int) $idcat) && $idcat < 0) {
581:             return '';
582:         }
583: 
584:         if ($absolute === true) {
585:             # add absolute web path to urlpath
586:             if (is_int((int) $idart) && $idart > 0) {
587:                 $url = $this->_cfgClient[$this->_client]['path']['htmlpath'] . 'front_content.php?idcat=' . $idcat . '&idart=' . $idart;
588:             } else {
589:                 $url = $this->_cfgClient[$this->_client]['path']['htmlpath'] . 'front_content.php?idcat=' . $idcat;
590:             }
591:         } else {
592:             if (is_int((int) $idart) && $idart > 0) {
593:                 $url = 'front_content.php?idcat=' . $idcat . '&idart=' . $idart;
594:             } else {
595:                 $url = 'front_content.php?idcat=' . $idcat;
596:             }
597:         }
598: 
599:         return $url;
600:     }
601: 
602:     /**
603:      * Get urlpath by given category and/or idart and level.
604:      * The urlpath looks like /Home/Product/Support/ where the directory-like string equals a category path.
605:      *
606:      * @requires functions.pathresolver.php
607:      * @param int $idcat
608:      * @param int $idart
609:      * @param bool $absolute return absolute path or not [optional]
610:      * @param integer $level [optional]
611:      * @param string $urlSuffix [optional]
612:      * @return string path information or empty string
613:      */
614:     public function getUrlPath($idcat, $idart, $absolute = true, $level = 0, $urlSuffix = 'index.html') {
615:         if (!is_int((int) $idcat) && $idcat < 0) {
616:             return '';
617:         }
618: 
619:         $cat_str = '';
620:         prCreateURLNameLocationString($idcat, "/", $cat_str, false, "", $level, $this->_lang, true, false);
621: 
622:         if (cString::getStringLength($cat_str) <= 1) {
623:             # return empty string if no url location is available
624:             return '';
625:         }
626: 
627:         if ($absolute === true) {
628:             # add absolute web path to urlpath
629:             if (is_int((int) $idart) && $idart > 0) {
630:                 return $this->_cfgClient[$this->_client]['path']['htmlpath'] . $cat_str . '/index-d-' . $idart . '.html';
631:             } else {
632:                 return $this->_cfgClient[$this->_client]['path']['htmlpath'] . $cat_str . '/' . $urlSuffix;
633:             }
634:         } else {
635:             if (is_int((int) $idart) && $idart > 0) {
636:                 return $cat_str . '/index-d-' . $idart . '.html';
637:             } else {
638:                 return $cat_str . '/' . $urlSuffix;
639:             }
640:         }
641:     }
642: 
643:     /**
644:      * Get urlpath by given category and/or selected param and level.
645:      *
646:      * @requires functions.pathresolver.php
647:      * @param int $idcat
648:      * @param int $selectedNumber
649:      * @param bool $absolute return absolute path or not [optional]
650:      * @param integer $level [optional]
651:      * @return string path information or empty string
652:      */
653:     public function getUrlPathGenParam($idcat, $selectedNumber, $absolute = true, $level = 0) {
654:         if (!is_int((int) $idcat) && $idcat < 0) {
655:             return '';
656:         }
657: 
658:         $cat_str = '';
659:         prCreateURLNameLocationString($idcat, "/", $cat_str, false, "", $level, $this->_lang, true, false);
660: 
661:         if (cString::getStringLength($cat_str) <= 1) {
662:             // return empty string if no url location is available
663:             return '';
664:         }
665: 
666:         if ($absolute === true) {
667:             // add absolute web path to urlpath
668:             if (is_int((int) $selectedNumber)) {
669:                 return $this->_cfgClient[$this->_client]['path']['htmlpath'] . $cat_str . '/index-g-' . $selectedNumber . '.html';
670:             }
671:         } else {
672:             if (is_int((int) $selectedNumber)) {
673:                 return $cat_str . '/index-g-' . $selectedNumber . '.html';
674:             }
675:         }
676:     }
677: 
678:     /**
679:      * Get URL by given categoryid and/or articleid
680:      *
681:      * @param int     $idcat    url name to create for
682:      * @param int     $idart
683:      * @param string  $type
684:      * @param bool    $absolute return absolute path or not [optional]
685:      * @param integer $level
686:      *
687:      * @return string $url or empty
688:      */
689:     public function getURL($idcat, $idart, $type = '', $absolute = true, $level = 0) {
690:         if (!is_int((int) $idcat) AND $idcat < 0) {
691:             return '';
692:         }
693: 
694:         switch ($type) {
695:             case 'urlpath':
696:                 $url = $this->getUrlPath($idcat, $idart, $absolute, $level);
697:                 break;
698:             case 'frontcontent':
699:                 $url = $this->getFrontContentUrl($idcat, $idart, $absolute);
700:                 break;
701:             case 'index-a':
702:                 # not implemented
703:                 $url = '';
704:                 break;
705:             default:
706:                 $url = $this->getFrontContentUrl($idcat, $idart, $absolute);
707:         }
708: 
709:         return $url;
710:     }
711: 
712:     /**
713:      * Get category of article.
714:      *
715:      * If an article is assigned to more than one category take the first
716:      * category.
717:      *
718:      * @param  int $idart
719:      *
720:      * @return int category id or negative integer
721:      * @throws cDbException
722:      */
723:     public function getCategoryOfArticle($idart) {
724: 
725:         # validate input
726:         if (!is_int((int) $idart) || $idart <= 0) {
727:             return -1;
728:         }
729: 
730:         $sql = '
731:         SELECT
732:             c.idcat
733:         FROM
734:             ' . $this->_cfg['tab']['art_lang'] . ' AS a,
735:             ' . $this->_cfg['tab']['art'] . ' AS b,
736:             ' . $this->_cfg['tab']['cat_art'] . ' AS c
737:         WHERE
738:             a.idart = ' . $idart . ' AND
739:             b.idclient = ' . $this->_client . ' AND
740:             a.idlang = ' . $this->_lang . ' AND
741:             b.idart = c.idart AND
742:             a.idart = b.idart ';
743: 
744:         if ($this->_debug) {
745:             echo "<pre>" . $sql . "</pre>";
746:         }
747: 
748:         $this->_db->query($sql);
749: 
750:         # $this->db->getErrorNumber() returns 0 (zero) if no error occurred.
751:         if ($this->_db->getErrorNumber() == 0) {
752:             if ($this->_db->nextRecord()) {
753:                 return $this->_db->f('idcat');
754:             } else {
755:                 return -1;
756:             }
757:         } else {
758:             if ($this->_debug) {
759:                 echo "<pre>Mysql Error:" . $this->_db->getErrorMessage() . "(" . $this->_db->getErrorNumber() . ")</pre>";
760:             }
761:             return -1; # error occurred.
762:         }
763:     }
764: 
765:     /**
766:      * Get path  of a given category up to a certain level
767:      *
768:      * @param integer $cat_id
769:      * @param integer $level [optional]
770:      * @param boolean $reverse
771:      *
772:      * @return array
773:      * @throws cDbException
774:      */
775:     public function getCategoryPath($cat_id, $level = 0, $reverse = true) {
776:         if (!is_int((int) $cat_id) && $cat_id < 0) {
777:             return array();
778:         }
779: 
780:         $root_path = array();
781:         array_push($root_path, $cat_id);
782:         $parent_id = $cat_id;
783: 
784:         while ($this->getLevel($parent_id) >= 0 && $this->getLevel($parent_id) > $level) {
785:             $parent_id = $this->getParent($parent_id);
786:             if ($parent_id >= 0) {
787:                 array_push($root_path, $parent_id);
788:             }
789:         }
790: 
791:         if ($reverse == true) {
792:             $root_path = array_reverse($root_path);
793:         }
794: 
795:         return $root_path;
796:     }
797: 
798:     /**
799:      * Get root category of a given category
800:      *
801:      * @param integer $cat_id
802:      *
803:      * @return array
804:      * @throws cDbException
805:      */
806:     function getRoot($cat_id) {
807:         if (!is_int((int) $cat_id) && $cat_id < 0) {
808:             return array();
809:         }
810: 
811:         $parent_id = $cat_id;
812: 
813:         while ($this->getLevel($parent_id) >= 0) {
814:             $rootCategory = $parent_id;
815:             $parent_id = $this->getParent($parent_id);
816:         }
817: 
818:         return $rootCategory;
819:     }
820: 
821:     /**
822:      * get subtree by a given id
823:      *
824:      * @param int $idcat_start Id of category
825:      *
826:      * @return array Array with subtree
827:      * @throws cDbException
828:      */
829:     function getSubTree($idcat_start) {
830: 
831:         if (!is_int((int) $idcat_start)) {
832:             return array();
833:         }
834: 
835:         $sql = "SELECT
836:                     B.idcat, A.level
837:                 FROM
838:                     " . $this->_cfg["tab"]["cat_tree"] . " AS A,
839:                     " . $this->_cfg["tab"]["cat"] . " AS B
840:                 WHERE
841:                     A.idcat  = B.idcat AND
842:                     idclient = " . $this->_client . "
843:                 ORDER BY
844:                     idtree";
845: 
846:         if ($this->_debug) {
847:             echo "<pre>";
848:             print_r($sql);
849:             echo "</pre>";
850:         }
851: 
852:         $this->_db->query($sql);
853: 
854:         $i = false;
855:         $curLevel = 0;
856: 
857:         while ($this->_db->nextRecord()) {
858:             if ($this->_db->f("idcat") == $idcat_start) {
859:                 $curLevel = $this->_db->f("level");
860:                 $i = true;
861:             } else {
862:                 if ($curLevel == $this->_db->f("level")) {
863:                     # ending part of tree
864:                     $i = false;
865:                 }
866:             }
867: 
868:             if ($i == true) {
869:                 $deeper_cats[] = $this->_db->f("idcat");
870:             }
871:         }
872:         return $deeper_cats;
873:     }
874: 
875: }
876: ?>
CMS CONTENIDO 4.10.1 API documentation generated by ApiGen 2.8.0