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