[ 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 Action Model Class 13 */ 14 class Vtiger_Action_Model extends Vtiger_Base_Model { 15 16 static $standardActions = array('0' => 'Save','1' => 'EditView','2' => 'Delete','3' => 'index','4' => 'DetailView'); 17 static $nonConfigurableActions = array('Save', 'index', 'SavePriceBook', 'SaveVendor', 18 'DetailViewAjax', 'PriceBookEditView', 'QuickCreate', 'VendorEditView', 19 'DeletePriceBook', 'DeleteVendor', 'Popup', 'PriceBookDetailView', 20 'TagCloud', 'VendorDetailView'); 21 static $utilityActions = array('5' => 'Import', '6' => 'Export', '8' => 'Merge', '9' => 'ConvertLead', '10' => 'DuplicatesHandling'); 22 23 public function getId() { 24 return $this->get('actionid'); 25 } 26 27 public function getName() { 28 return $this->get('actionname'); 29 } 30 31 public function isUtilityTool() { 32 return false; 33 } 34 35 public function isModuleEnabled($module) { 36 $db = PearDatabase::getInstance(); 37 if(!$module->isEntityModule()) { 38 return false; 39 } 40 if(in_array($this->getName(), self::$standardActions)) { 41 return true; 42 } 43 $tabId = $module->getId(); 44 $sql = 'SELECT 1 FROM vtiger_profile2standardpermissions WHERE tabid = ? AND operation = ? LIMIT 1'; 45 $params = array($tabId, $this->getId()); 46 $result = $db->pquery($sql, $params); 47 if($result && $db->num_rows($result) > 0) { 48 return true; 49 } 50 return false; 51 } 52 53 public static function getInstanceFromQResult($result, $rowNo=0) { 54 $db = PearDatabase::getInstance(); 55 $row = $db->query_result_rowdata($result, $rowNo); 56 $className = 'Vtiger_Action_Model'; 57 $actionName = $row['actionname']; 58 if(!in_array($actionName, self::$standardActions)) { 59 $className = 'Vtiger_Utility_Model'; 60 } 61 $actionModel = new $className(); 62 return $actionModel->setData($row); 63 } 64 65 protected static $cachedInstances = NULL; 66 public static function getInstance($value, $force=false) { 67 if (!self::$cachedInstances || $force) { 68 self::$cachedInstances = self::getAll(); 69 } 70 if (self::$cachedInstances) { 71 $actionid = Vtiger_Utils::isNumber($value) ? $value : false; 72 foreach (self::$cachedInstances as $instance) { 73 if($actionid !== false) { 74 if ($instance->get('actionid') == $actionid) { 75 return $instance; 76 } 77 } else { 78 if ($instance->get('actionname') == $value) { 79 return $instance; 80 } 81 } 82 } 83 } 84 return null; 85 } 86 87 public static function getInstanceWithIdOrName($value) { 88 $db = PearDatabase::getInstance(); 89 90 if(Vtiger_Utils::isNumber($value)) { 91 $sql = 'SELECT * FROM vtiger_actionmapping WHERE actionid=? LIMIT 1'; 92 } else { 93 $sql = 'SELECT * FROM vtiger_actionmapping WHERE actionname=?'; 94 } 95 $params = array($value); 96 $result = $db->pquery($sql, $params); 97 if($db->num_rows($result) > 0) { 98 return self::getInstanceFromQResult($result); 99 } 100 return null; 101 } 102 103 public static function getAll($configurable=false) { 104 $actionModels = Vtiger_Cache::get('vtiger', 'actions'); 105 if(!$actionModels){ 106 $db = PearDatabase::getInstance(); 107 108 $sql = 'SELECT * FROM vtiger_actionmapping'; 109 $params = array(); 110 if($configurable) { 111 $sql .= ' WHERE actionname NOT IN ('. generateQuestionMarks(self::$nonConfigurableActions) .')'; 112 array_push($params, self::$nonConfigurableActions); 113 } 114 $result = $db->pquery($sql, $params); 115 $noOfRows = $db->num_rows($result); 116 $actionModels = array(); 117 for($i=0; $i<$noOfRows; ++$i) { 118 $actionModels[] = self::getInstanceFromQResult($result, $i); 119 } 120 Vtiger_Cache::set('vtiger','actions', $actionModels); 121 } 122 return $actionModels; 123 } 124 125 public static function getAllBasic($configurable=false) { 126 $db = PearDatabase::getInstance(); 127 128 $basicActionIds = array_keys(self::$standardActions); 129 $sql = 'SELECT * FROM vtiger_actionmapping WHERE actionid IN ('. generateQuestionMarks($basicActionIds) .')'; 130 $params = $basicActionIds; 131 if($configurable) { 132 $sql .= ' AND actionname NOT IN ('. generateQuestionMarks(self::$nonConfigurableActions) .')'; 133 $params = array_merge($params, self::$nonConfigurableActions); 134 } 135 $result = $db->pquery($sql, $params); 136 $noOfRows = $db->num_rows($result); 137 $actionModels = array(); 138 for($i=0; $i<$noOfRows; ++$i) { 139 $actionModels[] = self::getInstanceFromQResult($result, $i); 140 } 141 return $actionModels; 142 } 143 144 public static function getAllUtility($configurable=false) { 145 $db = PearDatabase::getInstance(); 146 147 $basicActionIds = array_keys(self::$standardActions); 148 $sql = 'SELECT * FROM vtiger_actionmapping WHERE actionid NOT IN ('. generateQuestionMarks($basicActionIds) .')'; 149 $params = $basicActionIds; 150 if($configurable) { 151 $sql .= ' AND actionname NOT IN ('. generateQuestionMarks(self::$nonConfigurableActions) .')'; 152 $params = array_merge($params, self::$nonConfigurableActions); 153 } 154 $result = $db->pquery($sql, $params); 155 $noOfRows = $db->num_rows($result); 156 $actionModels = array(); 157 for($i=0; $i<$noOfRows; ++$i) { 158 $actionModels[] = self::getInstanceFromQResult($result, $i); 159 } 160 return $actionModels; 161 } 162 163 }
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 |