HomeHelpTrac

Changeset 15901


Ignore:
Timestamp:
01/19/12 23:13:21 (4 months ago)
Author:
Alexander Trofimov
Message:

Menu - docs, hidden_for_levels renamed to visibile_for_levels

Location:
trunk
Files:
3 edited

Legend:

Unmodified
Added
Removed
  • trunk/inc/classes/BxDolMenu.php

    r15854 r15901  
    2020 * Menus.  
    2121 * 
    22  * It allows to display menu using different templates. 
     22 * Menu uses some set of items and the template to display it,  
     23 * so it is possible to have several menus which uses the same set of items but different templates. 
     24 * 
     25 * Menu is any set of some links or actions, for example menu can be links in site's footer or actions in profile view. 
     26 * 
     27 * 
     28 * @section menu_create Creating the Menu object: 
     29 * 
     30 * 1. Add record to 'sys_objects_menu' table: 
     31 * 
     32 * - object: name of the menu object, in the format: vendor prefix, underscore, module prefix, underscore, internal identifier or nothing; for example: bx_groups_actions - actions menu in group view.  
     33 * - title: name of the menu, displayed in the studio menu builder. 
     34 * - set_name: name of items' set. 
     35 * - module: the module this menu belongs to. 
     36 * - template_id: the template to use for menu displaying, this is id from 'sys_menu_templates' table. 
     37 * - deleteable: it determines if menu can be deleted from the studio menu builder. 
     38 * - active: it is possible to disable particular menu, then it will not be displayed. 
     39 * - override_class_name: user defined class name which is derived from BxTemplMenu. 
     40 * - override_class_file: the location of the user defined class, leave it empty if class is located in system folders. 
     41 *  
     42 * Menu templates are stored in 'sys_menu_templates' table: 
     43 * - id: template id. 
     44 * - template: template file. 
     45 * - title: template title to display in the studio menu builder. 
     46 * All menu templates iterate through 'bx_repeat:menu_items' and use the following template variables for each menu item: __link__, __target__, __onclick__, __title__, __class_add__. 
     47 * 
     48 * 
     49 * 2. Add menu an empty menu set to 'sys_menu_sets' table (if you want to use new set of items for created menu): 
     50 * - set_name: the set name. 
     51 * - module: the module this set belongs to. 
     52 * - title: name of the set, displayed in studio menu builder. 
     53 * - deletable: it determines if the set can be deleted from menu builder. 
     54 * 
     55 * 
     56 * 3. Add menu items to the set by adding records to 'sys_menu_items' table: 
     57 * - set_name: the set name this item belogs to. 
     58 * - module: the module this item belongs to. 
     59 * - name: name of the item (not displayed to the end user), unique in the particular set. 
     60 * - title: menu item title to display to the end user, please note that some templates can still display menu as icons without text titles. 
     61 * - link: menu item URL. 
     62 * - onclick: menu item onclick event. 
     63 * - target: menu item target. 
     64 * - icon: menu item icon, please note that some templates can still display menu as text without icons. 
     65 * - visibile_for_levels: bit field with set of member level ids. To use member level id in bit field - the level id minus 1 as power of 2 is used, for example: 
     66 *      - user level id = 1 -> 2^(1-1) = 1 
     67 *      - user level id = 2 -> 2^(2-1) = 2 
     68 *      - user level id = 3 -> 2^(3-1) = 4 
     69 *      - user level id = 4 -> 2^(4-1) = 8 
     70 * - active: it is possible to disable particular menu item, then it will not be displayed. 
     71 * - order: menu item order in the particular set. 
     72 * 
     73 * 
     74 * 4. Display Menu. 
     75 * Use the following sample code to display menu: 
     76 * @code 
     77 *     bx_import('BxTemplMenu'); 
     78 *     $oMenu = BxTemplMenu::getObjectInstance('sample_menu'); // 'sample_menu' is 'object' field from 'sys_objects_menu' table. 
     79 *     if ($oMenu) 
     80 *         echo $oMenu->getCode; // display menu 
     81 * @endcode 
     82 * 
     83 * But in most cases you don't need to use above code to display menu,  
     84 * menu objects are integrated into pages - there is special 'menu' page block type for it. 
     85 *  
    2386 */ 
    24  
    2587class BxDolMenu extends BxDol { 
    2688 
     
    97159        return true; 
    98160    } 
    99      
     161   
     162    /** 
     163     * Check if menu items is selected. 
     164     * @param $a menu item array 
     165     * @return boolean 
     166     */  
    100167    protected function _isSelected ($a) { 
    101168        return $a['module'] == self::$SEL_MODULE && $a['name'] == self::$SEL_NAME ? true : false; 
    102169    } 
    103170 
     171    /** 
     172     * Check if menu items is visible. 
     173     * @param $a menu item array 
     174     * @return boolean 
     175     */  
    104176    protected function _isVisible ($a) { 
    105         if (!$a['hidden_for_levels']) 
    106             return true; 
    107         bx_import('BxTemplAcl'); 
    108         $oACL = BxTemplAcl::getInstance(); 
    109         $iProfileId = 1; // TODO: get current profile id 
    110         $aACL = $oACL->getMemberMembershipInfo($iProfileId); 
    111         return !($a['hidden_for_levels'] & pow(2, $aACL['id'] - 1)); 
     177        bx_import('BxDolAcl'); 
     178        return BxDolAcl::getInstance()->isMemberLevelInSet($a['visibile_for_levels']); 
    112179    } 
    113180 
     181    /** 
     182     * Replace provided markers in menu item array, curently markers are replaced in title, link and onclick fields. 
     183     * @param $a menu item array 
     184     * @return array where markes are replaced with real values 
     185     */  
    114186    protected function _replaceMarkers ($a) { 
    115187        if (empty($this->_aMarkers)) 
  • trunk/install/sql/v70.sql

    r15897 r15901  
    45644564  `onclick` varchar(255) NOT NULL, 
    45654565  `target` varchar(255) NOT NULL, 
    4566   `icon` varchar(255) NOT NULL, 
    4567   `hidden_for_levels` int(10) unsigned NOT NULL DEFAULT '0', 
     4566  `icon` varchar(255) NOT NULL,   
     4567  `visibile_for_levels` int(11) NOT NULL DEFAULT '2147483647', 
    45684568  `active` tinyint(4) NOT NULL DEFAULT '1', 
    45694569  `order` int(11) NOT NULL, 
  • trunk/templates/base/scripts/BxBaseMenu.php

    r15865 r15901  
    1313/** 
    1414 * Menu representation. 
    15  * @see BxDolmenu 
     15 * @see BxDolMenu 
    1616 */ 
    1717class BxBaseMenu extends BxDolMenu { 
     
    2828    } 
    2929 
    30  
     30    /**  
     31     * Get menu code. 
     32     * @return string 
     33     */ 
    3134    public function getCode () {         
    3235 
     
    4144    } 
    4245 
     46    /**  
     47     * Get menu items array, which are ready to pass to template. 
     48     * @return array 
     49     */ 
    4350    protected function _getMenuItems () { 
    4451        $aRet = array(); 
     
    6673        return $aRet; 
    6774    } 
    68      
     75 
     76    /** 
     77     * Add css/js files which are needed for menu display and functionality. 
     78     */     
    6979    protected function _addJsCss() { 
    7080        $this->_oTemplate->addCss('menu.css'); 
Note: See TracChangeset for help on using the changeset viewer.