[ 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 Settings MenuItem Model Class 13 */ 14 class Settings_Vtiger_MenuItem_Model extends Vtiger_Base_Model { 15 16 protected static $itemsTable = 'vtiger_settings_field'; 17 protected static $itemId = 'fieldid'; 18 19 public static $transformedUrlMapping = array( 20 'index.php?module=Administration&action=index&parenttab=Settings' => 'index.php?module=Users&parent=Settings&view=List', 21 'index.php?module=Settings&action=listroles&parenttab=Settings' => 'index.php?module=Roles&parent=Settings&view=Index', 22 'index.php?module=Settings&action=ListProfiles&parenttab=Settings' => 'index.php?module=Profiles&parent=Settings&view=List', 23 'index.php?module=Settings&action=listgroups&parenttab=Settings' => 'index.php?module=Groups&parent=Settings&view=List', 24 'index.php?module=Settings&action=OrgSharingDetailView&parenttab=Settings' => 'index.php?module=SharingAccess&parent=Settings&view=Index', 25 'index.php?module=Settings&action=DefaultFieldPermissions&parenttab=Settings' => 'index.php?module=FieldAccess&parent=Settings&view=Index', 26 'index.php?module=Settings&action=ListLoginHistory&parenttab=Settings' => 'index.php?module=LoginHistory&parent=Settings&view=List', 27 'index.php?module=Settings&action=ModuleManager&parenttab=Settings' => 'index.php?module=ModuleManager&parent=Settings&view=List', 28 'index.php?module=PickList&action=PickList&parenttab=Settings' => 'index.php?parent=Settings&module=Picklist&view=Index', 29 'index.php?module=Settings&action=listemailtemplates&parenttab=Settings' => 'index.php?module=Emails&view=ListTemplates', 30 'index.php?module=Settings&action=listwordtemplates&parenttab=Settings' => 'index.php?module=Settings&submodule=ModuleManager&view=WordTemplates', 31 'index.php?module=Settings&action=listnotificationschedulers&parenttab=Settings' => 'index.php?module=Settings&submodule=Vtiger&view=Schedulers', 32 'index.php?module=Settings&action=listinventorynotifications&parenttab=Settings' => 'index.php?module=Settings&submodule=Notifications&view=InventoryAlerts', 33 'index.php?module=Settings&action=OrganizationConfig&parenttab=Settings' => 'index.php?parent=Settings&module=Vtiger&view=CompanyDetails', 34 'index.php?module=Settings&action=EmailConfig&parenttab=Settings' => 'index.php?parent=Settings&module=Vtiger&view=OutgoingServerDetail', 35 'index.php?module=Settings&action=CurrencyListView&parenttab=Settings' => 'index.php?parent=Settings&module=Currency&view=List', 36 'index.php?module=Settings&action=TaxConfig&parenttab=Settings' => 'index.php?module=Vtiger&parent=Settings&view=TaxIndex', 37 'index.php?module=Settings&action=ProxyServerConfig&parenttab=Settings' => 'index.php?module=Settings&submodule=Server&view=ProxyConfig', 38 'index.php?module=Settings&action=OrganizationTermsandConditions&parenttab=Settings' => 'index.php?parent=Settings&module=Vtiger&view=TermsAndConditionsEdit', 39 'index.php?module=Settings&action=CustomModEntityNo&parenttab=Settings' => 'index.php?module=Vtiger&parent=Settings&view=CustomRecordNumbering', 40 'index.php?module=Settings&action=MailScanner&parenttab=Settings' => 'index.php?parent=Settings&module=MailConverter&view=List', 41 'index.php?module=com_vtiger_workflow&action=workflowlist&parenttab=Settings' => 'index.php?module=Workflows&parent=Settings&view=List', 42 'index.php?module=com_vtiger_workflow&action=workflowlist' => 'index.php?module=Workflows&parent=Settings&view=List', 43 'index.php?module=ConfigEditor&action=index' => 'index.php?module=Vtiger&parent=Settings&view=ConfigEditorDetail', 44 'index.php?module=Tooltip&action=QuickView&parenttab=Settings' => 'index.php?module=Settings&submodule=Tooltip&view=Index', 45 'index.php?module=CustomerPortal&action=index&parenttab=Settings' => 'index.php?module=CustomerPortal&parent=Settings&view=Index', 46 'index.php?module=Settings&action=Announcements&parenttab=Settings' => 'index.php?parent=Settings&module=Vtiger&view=AnnouncementEdit', 47 'index.php?module=PickList&action=PickListDependencySetup&parenttab=Settings' => 'index.php?parent=Settings&module=PickListDependency&view=List', 48 'index.php?module=ModTracker&action=BasicSettings&parenttab=Settings&formodule=ModTracker' => 'index.php?module=Settings&submodule=ModTracker&view=Index', 49 'index.php?module=CronTasks&action=ListCronJobs&parenttab=Settings' => 'index.php?module=CronTasks&parent=Settings&view=List', 50 'index.php?module=Webforms&action=index&parenttab=Settings' => 'index.php?module=Webforms&parent=Settings&view=List', 51 'index.php?module=Settings&action=MenuEditor&parenttab=Settings' => 'index.php?module=MenuEditor&parent=Settings&view=Index', 52 'index.php?module=ExchangeConnector&action=index&parenttab=Settings' => 'index.php?module=ExchangeConnector&parent=Settings&view=Index' 53 ); 54 55 /** 56 * Function to get the Id of the menu item 57 * @return <Number> - Menu Item Id 58 */ 59 public function getId() { 60 return $this->get(self::$itemId); 61 } 62 63 /** 64 * Function to get the Menu to which the Item belongs 65 * @return Settings_Vtiger_Menu_Model instance 66 */ 67 public function getMenu() { 68 return $this->menu; 69 } 70 71 /** 72 * Function to set the Menu to which the Item belongs, given Menu Id 73 * @param <Number> $menuId 74 * @return Settings_Vtiger_MenuItem_Model 75 */ 76 public function setMenu($menuId) { 77 $this->menu = Settings_Vtiger_Menu_Model::getInstanceById($menuId); 78 return $this; 79 } 80 81 /** 82 * Function to set the Menu to which the Item belongs, given Menu Model instance 83 * @param <Settings_Vtiger_Menu_Model> $menu - Settings Menu Model instance 84 * @return Settings_Vtiger_MenuItem_Model 85 */ 86 public function setMenuFromInstance($menu) { 87 $this->menu = $menu; 88 return $this; 89 } 90 91 /** 92 * Function to get the url to get to the Settings Menu Item 93 * @return <String> - Menu Item landing url 94 */ 95 public function getUrl() { 96 $url = $this->get('linkto'); 97 $url = decode_html($url); 98 if(isset(self::$transformedUrlMapping[$url])) { 99 $url = self::$transformedUrlMapping[$url]; 100 } 101 $url .= '&block='.$this->getMenu()->getId().'&fieldid='.$this->getId(); 102 return $url; 103 } 104 105 /** 106 * Function to get the module name, to which the Settings Menu Item belongs to 107 * @return <String> - Module to which the Menu Item belongs 108 */ 109 public function getModuleName() { 110 return 'Settings:Vtiger'; 111 } 112 /** 113 * Function to get the pin and unpin action url 114 */ 115 public function getPinUnpinActionUrl() { 116 return 'index.php?module=Vtiger&parent=Settings&action=Basic&mode=updateFieldPinnedStatus&fieldid='.$this->getId(); 117 } 118 119 /** 120 * Function to verify whether menuitem is pinned or not 121 * @return <Boolean> true to pinned, false to not pinned. 122 */ 123 public function isPinned() { 124 $pinStatus = $this->get('pinned'); 125 return $pinStatus == '1' ? true : false; 126 } 127 128 /** 129 * Function which will update the pin status 130 * @param <Boolean> $pinned - true to enable , false to disable 131 */ 132 private function updatePinStatus($pinned=false){ 133 $db = PearDatabase::getInstance(); 134 135 $pinnedStaus = 0; 136 if($pinned) { 137 $pinnedStaus = 1; 138 } 139 140 $query = 'UPDATE '.self::$itemsTable.' SET pinned='.$pinnedStaus.' WHERE '.self::$itemId.'='.$this->getId(); 141 $db->pquery($query,array()); 142 } 143 144 /** 145 * Function which will enable the field as pinned 146 */ 147 public function markPinned() { 148 $this->updatePinStatus(1); 149 } 150 151 /** 152 * Function which will disable the field pinned status 153 */ 154 public function unMarkPinned() { 155 $this->updatePinStatus(); 156 } 157 158 /** 159 * Function to get the instance of the Menu Item model given the valuemap array 160 * @param <Array> $valueMap 161 * @return Settings_Vtiger_MenuItem_Model instance 162 */ 163 public static function getInstanceFromArray($valueMap) { 164 return new self($valueMap); 165 } 166 167 /** 168 * Function to get the instance of the Menu Item model, given name and Menu instance 169 * @param <String> $name 170 * @param <Settings_Vtiger_Menu_Model> $menuModel 171 * @return Settings_Vtiger_MenuItem_Model instance 172 */ 173 public static function getInstance($name, $menuModel=false) { 174 $db = PearDatabase::getInstance(); 175 176 $sql = 'SELECT * FROM '.self::$itemsTable. ' WHERE name = ?'; 177 $params = array($name); 178 179 if($menuModel) { 180 $sql .= ' WHERE blockid = ?'; 181 $params[] = $menuModel->getId(); 182 } 183 $result = $db->pquery($sql, $params); 184 185 if($db->num_rows($result) > 0) { 186 $rowData = $db->query_result_rowdata($result, 0); 187 $menuItem = Settings_Vtiger_MenuItem_Model::getInstanceFromArray($rowData); 188 if($menuModel) { 189 $menuItem->setMenuFromInstance($menuModel); 190 } else { 191 $menuItem->setMenu($rowData['blockid']); 192 } 193 return $menuItem; 194 } 195 return false; 196 } 197 198 /** 199 * Function to get the instance of the Menu Item model, given item id and Menu instance 200 * @param <String> $name 201 * @param <Settings_Vtiger_Menu_Model> $menuModel 202 * @return Settings_Vtiger_MenuItem_Model instance 203 */ 204 public static function getInstanceById($id, $menuModel=false) { 205 $db = PearDatabase::getInstance(); 206 207 $sql = 'SELECT * FROM '.self::$itemsTable. ' WHERE ' .self::$itemId. ' = ?'; 208 $params = array($id); 209 210 if($menuModel) { 211 $sql .= ' WHERE blockid = ?'; 212 $params[] = $menuModel->getId(); 213 } 214 $result = $db->pquery($sql, $params); 215 216 if($db->num_rows($result) > 0) { 217 $rowData = $db->query_result_rowdata($result, 0); 218 $menuItem = Settings_Vtiger_MenuItem_Model::getInstanceFromArray($rowData); 219 if($menuModel) { 220 $menuItem->setMenuFromInstance($menuModel); 221 } else { 222 $menuItem->setMenu($rowData['blockid']); 223 } 224 return $menuItem; 225 } 226 return false; 227 } 228 229 /** 230 * Static function to get the list of all the items of the given Menu, all items if Menu is not specified 231 * @param <Settings_Vtiger_Menu_Model> $menuModel 232 * @return <Array> - List of Settings_Vtiger_MenuItem_Model instances 233 */ 234 public static function getAll($menuModel=false, $onlyActive=true) { 235 $skipMenuItemList = array('LBL_AUDIT_TRAIL', 'LBL_SYSTEM_INFO', 'LBL_PROXY_SETTINGS', 'LBL_DEFAULT_MODULE_VIEW', 236 'LBL_FIELDFORMULAS', 'LBL_FIELDS_ACCESS', 'LBL_MAIL_MERGE', 'NOTIFICATIONSCHEDULERS', 237 'INVENTORYNOTIFICATION', 'ModTracker', 'LBL_WORKFLOW_LIST','LBL_TOOLTIP_MANAGEMENT','Webforms Configuration Editor'); 238 239 $db = PearDatabase::getInstance(); 240 $sql = 'SELECT * FROM '.self::$itemsTable; 241 $params = array(); 242 243 $conditionsSqls = array(); 244 if($menuModel != false) { 245 $conditionsSqls[] = 'blockid = ?'; 246 $params[] = $menuModel->getId(); 247 } 248 if($onlyActive) { 249 $conditionsSqls[] = 'active = 0'; 250 } 251 if(count($conditionsSqls) > 0) { 252 $sql .= ' WHERE '. implode(' AND ', $conditionsSqls); 253 } 254 $sql .= ' AND name NOT IN ('.generateQuestionMarks($skipMenuItemList).')'; 255 256 $sql .= ' ORDER BY sequence'; 257 $result = $db->pquery($sql, array_merge($params, $skipMenuItemList)); 258 $noOfMenus = $db->num_rows($result); 259 260 $menuItemModels = array(); 261 for($i=0; $i<$noOfMenus; ++$i) { 262 $fieldId = $db->query_result($result, $i, self::$itemId); 263 $rowData = $db->query_result_rowdata($result, $i); 264 $menuItem = Settings_Vtiger_MenuItem_Model::getInstanceFromArray($rowData); 265 if($menuModel) { 266 $menuItem->setMenuFromInstance($menuModel); 267 } else { 268 $menuItem->setMenu($rowData['blockid']); 269 } 270 $menuItemModels[$fieldId] = $menuItem; 271 } 272 return $menuItemModels; 273 } 274 275 /** 276 * Function to get the pinned items 277 * @param array of fieldids. 278 * @return <Array> - List of Settings_Vtiger_MenuItem_Model instances 279 */ 280 public static function getPinnedItems($fieldList = array()) { 281 $skipMenuItemList = array('LBL_AUDIT_TRAIL', 'LBL_SYSTEM_INFO', 'LBL_PROXY_SETTINGS', 'LBL_DEFAULT_MODULE_VIEW', 282 'LBL_FIELDFORMULAS', 'LBL_FIELDS_ACCESS', 'LBL_MAIL_MERGE', 'NOTIFICATIONSCHEDULERS', 283 'INVENTORYNOTIFICATION', 'ModTracker', 'LBL_WORKFLOW_LIST','LBL_TOOLTIP_MANAGEMENT','Webforms Configuration Editor'); 284 285 $db = PearDatabase::getInstance(); 286 287 $query = 'SELECT * FROM '.self::$itemsTable.' WHERE pinned=1 AND active = 0'; 288 if(!empty($fieldList)) { 289 if(!is_array($fieldList)){ 290 $fieldList = array($fieldList); 291 } 292 $query .=' AND '.self::$itemsId.' IN ('.generateQuestionMarks($fieldList).')'; 293 } 294 $query .= ' AND name NOT IN ('.generateQuestionMarks($skipMenuItemList).')'; 295 296 $result = $db->pquery($query, array_merge($fieldList, $skipMenuItemList)); 297 $noOfMenus = $db->num_rows($result); 298 299 $menuItemModels = array(); 300 for($i=0; $i<$noOfMenus; ++$i) { 301 $fieldId = $db->query_result($result, $i, self::$itemId); 302 $rowData = $db->query_result_rowdata($result, $i); 303 $menuItem = Settings_Vtiger_MenuItem_Model::getInstanceFromArray($rowData); 304 $menuItem->setMenu($rowData['blockid']); 305 $menuItemModels[$fieldId] = $menuItem; 306 } 307 return $menuItemModels; 308 } 309 }
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 |