[ Index ] |
PHP Cross Reference of vtigercrm-6.1.0 |
[Summary view] [Print] [Text view]
1 <?php 2 /*+*********************************************************************************** 3 * The contents of this file are subject to the vtiger CRM Public License Version 1.0 4 * ("License"); You may not use this file except in compliance with the License 5 * The Original Code is: vtiger CRM Open Source 6 * The Initial Developer of the Original Code is vtiger. 7 * Portions created by vtiger are Copyright (C) vtiger. 8 * All Rights Reserved. 9 *************************************************************************************/ 10 11 /** 12 * Vtiger MenuStructure Model 13 */ 14 class Vtiger_MenuStructure_Model extends Vtiger_Base_Model { 15 16 protected $limit = 5; // Max. limit of persistent top-menu items to display. 17 protected $enableResponsiveMode = true; // Should the top-menu items be responsive (width) on UI? 18 19 const TOP_MENU_INDEX = 'top'; 20 const MORE_MENU_INDEX = 'more'; 21 22 /** 23 * Function to get all the top menu models 24 * @return <array> - list of Vtiger_Menu_Model instances 25 */ 26 public function getTop() { 27 return $this->get(self::TOP_MENU_INDEX); 28 } 29 30 /** 31 * Function to get all the more menu models 32 * @return <array> - Associate array of Parent name mapped to Vtiger_Menu_Model instances 33 */ 34 public function getMore() { 35 $moreTabs = $this->get(self::MORE_MENU_INDEX); 36 foreach($moreTabs as $key=>$value){ 37 if(!$value){ 38 unset($moreTabs[$key]); 39 } 40 } 41 return $moreTabs; 42 } 43 44 /** 45 * Function to get the limit for the number of menu models on the Top list 46 * @return <Number> 47 */ 48 public function getLimit() { 49 return $this->limit; 50 } 51 52 /** 53 * Function to determine if the structure should support responsive UI. 54 */ 55 public function getResponsiveMode() { 56 return $this->enableResponsiveMode; 57 } 58 59 /** 60 * Function to get an instance of the Vtiger MenuStructure Model from list of menu models 61 * @param <array> $menuModelList - array of Vtiger_Menu_Model instances 62 * @return Vtiger_MenuStructure_Model instance 63 */ 64 public static function getInstanceFromMenuList($menuModelList, $selectedMenu='') { 65 $structureModel = new self(); 66 $topMenuLimit = $structureModel->getResponsiveMode() ? 0 : $structureModel->getLimit(); 67 $currentTopMenuCount = 0; 68 69 $menuListArray = array(); 70 $menuListArray[self::TOP_MENU_INDEX] = array(); 71 $menuListArray[self::MORE_MENU_INDEX] = $structureModel->getEmptyMoreMenuList(); 72 73 foreach($menuModelList as $menuModel) { 74 if(($menuModel->get('tabsequence') != -1 && (!$topMenuLimit || $currentTopMenuCount < $topMenuLimit)) ) { 75 $menuListArray[self::TOP_MENU_INDEX][$menuModel->get('name')] = $menuModel; 76 $currentTopMenuCount++; 77 } 78 79 $parent = $menuModel->get('parent'); 80 if($parent == 'Sales' || $parent == 'Marketing'){ 81 $parent = 'MARKETING_AND_SALES'; 82 } 83 $menuListArray[self::MORE_MENU_INDEX][strtoupper($parent)][$menuModel->get('name')] = $menuModel; 84 } 85 86 if(!empty($selectedMenu) && !array_key_exists($selectedMenu, $menuListArray[self::TOP_MENU_INDEX])) { 87 $selectedMenuModel = $menuModelList[$selectedMenu]; 88 if($selectedMenuModel) { 89 $menuListArray[self::TOP_MENU_INDEX][$selectedMenuModel->get('name')] = $selectedMenuModel; 90 } 91 } 92 93 // Apply custom comparator 94 foreach ($menuListArray[self::MORE_MENU_INDEX] as $parent => &$values) { 95 uksort($values, array('Vtiger_MenuStructure_Model', 'sortMenuItemsByProcess')); 96 } 97 //uksort($menuListArray[self::TOP_MENU_INDEX], array('Vtiger_MenuStructure_Model', 'sortMenuItemsByProcess')); 98 99 return $structureModel->setData($menuListArray); 100 } 101 102 /** 103 * Custom comparator to sort the menu items by process. 104 * Refer: http://php.net/manual/en/function.uksort.php 105 */ 106 static function sortMenuItemsByProcess($a, $b) { 107 static $order = NULL; 108 if ($order == NULL) { 109 $order = array( 110 'Campaigns', 111 'Leads', 112 'Contacts', 113 'Accounts', 114 'Potentials', 115 'Quotes', 116 'Invoice', 117 'SalesOrder', 118 'HelpDesk', 119 'Faq', 120 'Project', 121 'Assets', 122 'ServiceContracts', 123 'Products', 124 'Services', 125 'PriceBooks', 126 'Vendors', 127 'PurchaseOrder', 128 'MailManager', 129 'Calendar', 130 'Documents', 131 'SMSNotifier', 132 'RecycleBin' 133 ); 134 } 135 $apos = array_search($a, $order); 136 $bpos = array_search($b, $order); 137 138 if ($apos === false) return PHP_INT_MAX; 139 if ($bpos === false) return -1*PHP_INT_MAX; 140 141 return ($apos - $bpos); 142 } 143 144 145 private function getEmptyMoreMenuList(){ 146 return array('MARKETING_AND_SALES'=>array(),'SUPPORT'=>array(),'INVENTORY'=>array(),'TOOLS'=>array(),'ANALYTICS'=>array()); 147 } 148 }
title
Description
Body
title
Description
Body
title
Description
Body
title
Body
Generated: Fri Nov 28 20:08:37 2014 | Cross-referenced by PHPXref 0.7.1 |