[ 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 * Sharng Access Vtiger Module Model Class 13 */ 14 class Settings_SharingAccess_Module_Model extends Vtiger_Module_Model { 15 16 /** 17 * Constants for mapping module's Sharing Access permissions editable 18 */ 19 const EDITABLE = 0; 20 const READONLY = 1; 21 const HIDDEN = 2; 22 23 /** 24 * Constants used for mapping module's Sharing Access Permission 25 */ 26 const SHARING_ACCESS_READ_ONLY = 0; 27 const SHARING_ACCESS_READ_CREATE = 1; 28 const SHARING_ACCESS_PUBLIC = 2; 29 const SHARING_ACCESS_PRIVATE = 3; 30 31 public function getPermissionValue() { 32 return $this->get('permission'); 33 } 34 35 /** 36 * Function checks if the sharing access for the module is enabled or not 37 * @return <Boolean> 38 */ 39 public function isSharingEditable() { 40 return ($this->get('editstatus') == self::EDITABLE); 41 } 42 43 /** 44 * Function checks if the module is Private 45 * @return Boolean 46 */ 47 public function isPrivate() { 48 return ((int)$this->get('permission') == self::SHARING_ACCESS_PRIVATE); 49 } 50 51 /** 52 * Function checks if the module is Public 53 * @return Boolean 54 */ 55 public function isPublic() { 56 return ($this->get('editstatus') == self::SHARING_ACCESS_PUBLIC); 57 } 58 59 public function getRulesListUrl() { 60 return '?module=SharingAccess&parent=Settings&view=IndexAjax&mode=showRules&for_module='.$this->getId(); 61 } 62 63 public function getCreateRuleUrl() { 64 return '?module=SharingAccess&parent=Settings&view=IndexAjax&mode=editRule&for_module='.$this->getId(); 65 } 66 67 public function getSharingRules() { 68 return Settings_SharingAccess_Rule_Model::getAllByModule($this); 69 } 70 71 public function getRules() { 72 return Settings_SharingAccess_Rule_Model::getAllByModule($this); 73 } 74 75 public function save() { 76 $db = PearDatabase::getInstance(); 77 78 $sql = 'UPDATE vtiger_def_org_share SET permission = ? WHERE tabid = ?'; 79 $params = array($this->get('permission'), $this->getId()); 80 $db->pquery($sql, $params); 81 } 82 83 /** 84 * Static Function to get the instance of Vtiger Module Model for the given id or name 85 * @param mixed id or name of the module 86 */ 87 public static function getInstance($value) { 88 $db = PearDatabase::getInstance(); 89 $instance = false; 90 91 $query = false; 92 if(Vtiger_Utils::isNumber($value)) { 93 $query = 'SELECT * FROM vtiger_def_org_share INNER JOIN vtiger_tab ON vtiger_tab.tabid = vtiger_def_org_share.tabid WHERE vtiger_tab.tabid=?'; 94 } else { 95 $query = 'SELECT * FROM vtiger_def_org_share INNER JOIN vtiger_tab ON vtiger_tab.tabid = vtiger_def_org_share.tabid WHERE name=?'; 96 } 97 $result = $db->pquery($query, array($value)); 98 if($db->num_rows($result)) { 99 $row = $db->query_result_rowdata($result, 0); 100 $instance = new Settings_SharingAccess_Module_Model(); 101 $instance->initialize($row); 102 $instance->set('permission', $row['permission']); 103 $instance->set('editstatus', $row['editstatus']); 104 } 105 return $instance; 106 } 107 108 /** 109 * Static Function to get the instance of Vtiger Module Model for all the modules 110 * @return <Array> - List of Vtiger Module Model or sub class instances 111 */ 112 public static function getAll($editable=false) { 113 $db = PearDatabase::getInstance(); 114 115 $moduleModels = array(); 116 117 $query = 'SELECT * FROM vtiger_def_org_share INNER JOIN vtiger_tab ON vtiger_tab.tabid = vtiger_def_org_share.tabid'; 118 $params = array(); 119 if($editable) { 120 $query .= ' WHERE editstatus = ?'; 121 array_push($params, self::EDITABLE); 122 } 123 $result = $db->pquery($query, $params); 124 $noOfModules = $db->num_rows($result); 125 for($i=0; $i<$noOfModules; ++$i) { 126 $row = $db->query_result_rowdata($result, $i); 127 $instance = new Settings_SharingAccess_Module_Model(); 128 $instance->initialize($row); 129 $instance->set('permission', $row['permission']); 130 $instance->set('editstatus', $row['editstatus']); 131 $moduleModels[$row['tabid']] = $instance; 132 } 133 return $moduleModels; 134 } 135 136 /** 137 * Static Function to get the instance of Vtiger Module Model for all the modules 138 * @return <Array> - List of Vtiger Module Model or sub class instances 139 */ 140 public static function getDependentModules() { 141 $dependentModulesList = array(); 142 $dependentModulesList['Accounts'] = array('Potentials', 'HelpDesk', 'Quotes', 'SalesOrder', 'Invoice'); 143 144 return $dependentModulesList; 145 } 146 /** 147 * Function recalculate the sharing rules 148 */ 149 public static function recalculateSharingRules() { 150 set_time_limit(vglobal('php_max_execution_time')); 151 $db = PearDatabase::getInstance(); 152 153 require_once ('modules/Users/CreateUserPrivilegeFile.php'); 154 $result = $db->pquery('SELECT id FROM vtiger_users WHERE deleted = ?', array(0)); 155 $numOfRows = $db->num_rows($result); 156 157 for($i=0; $i<$numOfRows; $i++) { 158 createUserSharingPrivilegesfile($db->query_result($result, $i, 'id')); 159 } 160 } 161 162 }
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 |