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