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

  • cCategoryHelper
  • cFrontendHelper
  • Overview
  • Package
  • Class
  • Tree
  • Deprecated
  • Todo
  1: <?php
  2: /**
  3:  * This file contains the frontend helper class.
  4:  *
  5:  * @package    Core
  6:  * @subpackage Frontend_Util
  7:  * @version    SVN Revision $Rev:$
  8:  *
  9:  * @author     Dominik Ziegler
 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:  * This class contains functions for the frontend helper class in CONTENIDO.
 20:  *
 21:  * @package    Core
 22:  * @subpackage Frontend_Util
 23:  */
 24: class cFrontendHelper {
 25:     /**
 26:      * Instance of the helper class.
 27:      * @var cFrontendHelper
 28:      */
 29:     static private $_instance = NULL;
 30: 
 31:     /**
 32:      * Returns the instance of this class.
 33:      * @return    cFrontendHelper
 34:      */
 35:     public static function getInstance() {
 36:         if (self::$_instance === NULL) {
 37:             self::$_instance = new self();
 38:         }
 39: 
 40:         return self::$_instance;
 41:     }
 42: 
 43:     /**
 44:      * Constructor of the class.
 45:      * @return    void
 46:      */
 47:     protected function __construct() {
 48:     }
 49: 
 50:     /**
 51:      * Fetches the requested category tree.
 52:      * @param    int            $baseCategoryId        root category ID
 53:      * @param    int            $depth                maximum depth
 54:      * @param    int            $currentCategoryId    the current category ID
 55:      * @return    array    category tree
 56:      */
 57:     protected function _fetchCategoryTree($baseCategoryId, $depth, $currentCategoryId) {
 58:         if ((int) $baseCategoryId == 0) {
 59:             throw new cUnexpectedValueException("Expect category ID greater than 0.");
 60:         }
 61: 
 62:         $categoryHelper = cCategoryHelper::getInstance();
 63:         $categoryHelper->setAuth(cRegistry::getAuth());
 64: 
 65:         $categoryTree = $categoryHelper->getSubCategories($baseCategoryId, $depth);
 66: 
 67:         $tree = array();
 68: 
 69:         $parentCategories = $categoryHelper->getParentCategoryIds($currentCategoryId);
 70: 
 71:         foreach ($categoryTree as $treeData) {
 72:             $catId = $treeData['idcat'];
 73: 
 74:             $firstChildId = $lastChildId = 0;
 75:             if (count($treeData['subcats']) > 0) {
 76:                 $lastIndex = count($treeData['subcats']) - 1;
 77: 
 78:                 $firstChildId = $treeData['subcats'][0]['idcat'];
 79:                 $lastChildId = $treeData['subcats'][$lastIndex]['idcat'];
 80:             }
 81: 
 82:             $markActive = ($currentCategoryId == $catId);
 83:             if ($markActive == false && in_array($catId, $parentCategories)) {
 84:                 $markActive = true;
 85:             }
 86: 
 87:             $treeItem['first_child_id'] = $firstChildId;
 88:             $treeItem['last_child_id'] = $lastChildId;
 89:             $treeItem['tree_data'] = $treeData;
 90:             $treeItem['active'] = $markActive;
 91:             $tree[] = $treeItem;
 92:         }
 93: 
 94:         return $tree;
 95:     }
 96: 
 97:     /**
 98:      * Helper function to render the navigation.
 99:      * @param    int            $baseCategoryId        root category ID
100:      * @param    int            $depth                maximum depth
101:      * @param    int            $currentCategoryId    the current category ID
102:      */
103:     public function renderNavigation($baseCategoryId, $depth, $currentCategoryId) {
104:         $tree = $this->_fetchCategoryTree($baseCategoryId, $depth, $currentCategoryId);
105: 
106:         return $tree;
107:     }
108: 
109:     /**
110:      * Helper function to render the sitemap.
111:      * @param    int            $baseCategoryId        root category ID
112:      * @param    int            $depth                maximum depth
113:      * @param    cTemplate    $tpl                template reference
114:      * @return    void
115:      */
116:     public function renderSitemap($baseCategoryId, $depth, cTemplate &$tpl) {
117:         $tree = $this->_fetchCategoryTree($baseCategoryId, $depth, 0);
118: 
119:         foreach ($tree as $treeItem) {
120:             $treeData = $treeItem['tree_data'];
121:             $catId = $treeData['idcat'];
122: 
123:             $firstChildId = $treeItem['first_child_id'];
124: 
125:             $tpl->set('d', 'name', $treeData['item']->getField('name'));
126:             $tpl->set('d', 'css_level', $treeData['level']);
127:             $tpl->set('d', 'url', $treeData['item']->getLink());
128:             $tpl->next();
129: 
130:             if ($firstChildId != 0) {
131:                 $this->renderSitemap($catId, $depth, $tpl);
132:             }
133:         }
134:     }
135: }
CMS CONTENIDO 4.9.0 API documentation generated by ApiGen 2.8.0