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

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