[ Index ] |
PHP Cross Reference of vtigercrm-6.1.0 |
[Summary view] [Print] [Text view]
1 <?php 2 3 /*+********************************************************************************** 4 * The contents of this file are subject to the vtiger CRM Public License Version 1.1 5 * ("License"); You may not use this file except in compliance with the License 6 * The Original Code is: vtiger CRM Open Source 7 * The Initial Developer of the Original Code is vtiger. 8 * Portions created by vtiger are Copyright (C) vtiger. 9 * All Rights Reserved. 10 ************************************************************************************/ 11 12 class Settings_Picklist_Field_Model extends Vtiger_Field_Model { 13 14 15 16 public function isEditable() { 17 $nonEditablePickListValues = array( 'campaignrelstatus', 'duration_minutes','email_flag','hdnTaxType', 18 'payment_duration','recurringtype','recurring_frequency','visibility'); 19 if(in_array($this->getName(), $nonEditablePickListValues)) return false; 20 return true; 21 } 22 23 /** 24 * Function which will give the picklistvalues for given roleids 25 * @param type $roleIdList -- array of role ids 26 * @param type $groupMode -- Intersection/Conjuction , intersection will give only picklist values that exist for all roles 27 * @return type -- array 28 */ 29 public function getPicklistValues($roleIdList, $groupMode='INTERSECTION') { 30 if(!$this->isRoleBased()) { 31 return parent::getPicklistValues(); 32 } 33 $intersectionMode = false; 34 if($groupMode == 'INTERSECTION') { 35 $intersectionMode = true; 36 } 37 38 $db = PearDatabase::getInstance(); 39 $fieldName = $this->getName(); 40 $tableName = 'vtiger_'.$fieldName; 41 $idColName = $fieldName.'id'; 42 $query = 'SELECT '.$fieldName; 43 if($intersectionMode) { 44 $query .= ',count(roleid) as rolecount '; 45 } 46 $query .= ' FROM vtiger_role2picklist INNER JOIN '.$tableName.' ON vtiger_role2picklist.picklistvalueid = '.$tableName.'.picklist_valueid'. 47 ' WHERE roleid IN ('.generateQuestionMarks($roleIdList).') order by sortid'; 48 if($intersectionMode) { 49 $query .= ' GROUP BY picklistvalueid'; 50 } 51 $result = $db->pquery($query, $roleIdList); 52 $pickListValues = array(); 53 $num_rows = $db->num_rows($result); 54 for($i=0; $i<$num_rows; $i++) { 55 $rowData = $db->query_result_rowdata($result, $i); 56 if($intersectionMode) { 57 //not equal if specify that the picklistvalue is not present for all the roles 58 if($rowData['rolecount'] != count($roleIdList)){ 59 continue; 60 } 61 } 62 //Need to decode the picklist values twice which are saved from old ui 63 $pickListValues[] = decode_html(decode_html($rowData[$fieldName])); 64 } 65 return $pickListValues; 66 } 67 68 /** 69 * Function to get instance 70 * @param <String> $value - fieldname or fieldid 71 * @param <type> $module - optional - module instance 72 * @return <Vtiger_Field_Model> 73 */ 74 public static function getInstance($value, $module = false) { 75 $fieldObject = parent::getInstance($value, $module); 76 if($fieldObject) { 77 return self::getInstanceFromFieldObject($fieldObject); 78 } 79 return false; 80 } 81 82 /** 83 * Static Function to get the instance fo Vtiger Field Model from a given Vtiger_Field object 84 * @param Vtiger_Field $fieldObj - vtlib field object 85 * @return Vtiger_Field_Model instance 86 */ 87 public static function getInstanceFromFieldObject(Vtiger_Field $fieldObj) { 88 $objectProperties = get_object_vars($fieldObj); 89 $fieldModel = new self(); 90 foreach($objectProperties as $properName=>$propertyValue) { 91 $fieldModel->$properName = $propertyValue; 92 } 93 return $fieldModel; 94 } 95 96 /** 97 * Function which will give the editable picklist values for a field 98 * @param type $fieldName -- string 99 * @return type -- array of values 100 */ 101 public static function getEditablePicklistValues($fieldName){ 102 $cache = Vtiger_Cache::getInstance(); 103 $EditablePicklistValues = $cache->get('EditablePicklistValues', $fieldName); 104 if($EditablePicklistValues) { 105 return $EditablePicklistValues; 106 } 107 $db = PearDatabase::getInstance(); 108 $primaryKey = Vtiger_Util_Helper::getPickListId($fieldName); 109 110 $query="SELECT $primaryKey ,$fieldName FROM vtiger_$fieldName WHERE presence=1 AND $fieldName <> '--None--'"; 111 $values = array(); 112 $result = $db->pquery($query, array()); 113 $num_rows = $db->num_rows($result); 114 for($i=0; $i<$num_rows; $i++) { 115 //Need to decode the picklist values twice which are saved from old ui 116 $values[$db->query_result($result,$i,$primaryKey)] = decode_html(decode_html($db->query_result($result,$i,$fieldName))); 117 } 118 $cache->set('EditablePicklistValues', $fieldName, $values); 119 return $values; 120 } 121 122 /** 123 * Function which will give the non editable picklist values for a field 124 * @param type $fieldName -- string 125 * @return type -- array of values 126 */ 127 public static function getNonEditablePicklistValues($fieldName){ 128 $cache = Vtiger_Cache::getInstance(); 129 $NonEditablePicklistValues = $cache->get('NonEditablePicklistValues', $fieldName); 130 if($NonEditablePicklistValues) { 131 return $NonEditablePicklistValues; 132 } 133 $db = PearDatabase::getInstance(); 134 135 $query = "select $fieldName from vtiger_$fieldName where presence=0"; 136 $values = array(); 137 $result = $db->pquery($query, array()); 138 $num_rows = $db->num_rows($result); 139 for($i=0; $i<$num_rows; $i++) { 140 //Need to decode the picklist values twice which are saved from old ui 141 $values[] = decode_html(decode_html($db->query_result($result,$i,$fieldName))); 142 } 143 $cache->set('NonEditablePicklistValues', $fieldName, $values); 144 return $values; 145 } 146 147 }
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 |