[ 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 vimport('~~modules/PickList/DependentPickListUtils.php'); 11 12 class Settings_PickListDependency_Record_Model extends Settings_Vtiger_Record_Model { 13 14 private $mapping = false; 15 private $sourcePickListValues = false; 16 private $targetPickListValues = false; 17 private $nonMappedSourcePickListValues = false; 18 19 /** 20 * Function to get the Id 21 * @return <Number> 22 */ 23 public function getId() { 24 return ''; 25 } 26 27 public function getName() { 28 return ''; 29 } 30 31 public function getRecordLinks() { 32 $soureModule = $this->get('sourceModule'); 33 $sourceField = $this->get('sourcefield'); 34 $targetField = $this->get('targetfield'); 35 $editLink = array( 36 'linkurl' => "javascript:Settings_PickListDependency_Js.triggerEdit(event, '$soureModule', '$sourceField', '$targetField')", 37 'linklabel' => 'LBL_EDIT', 38 'linkicon' => 'icon-pencil' 39 ); 40 $editLinkInstance = Vtiger_Link_Model::getInstanceFromValues($editLink); 41 42 $deleteLink = array( 43 'linkurl' => "javascript:Settings_PickListDependency_Js.triggerDelete(event, '$soureModule','$sourceField', '$targetField')", 44 'linklabel' => 'LBL_DELETE', 45 'linkicon' => 'icon-trash' 46 ); 47 $deleteLinkInstance = Vtiger_Link_Model::getInstanceFromValues($deleteLink); 48 return array($editLinkInstance,$deleteLinkInstance); 49 } 50 51 public function getAllPickListFields() { 52 $db = PearDatabase::getInstance(); 53 $tabId = getTabid($this->get('sourceModule')); 54 55 $query="select vtiger_field.fieldlabel,vtiger_field.fieldname FROM vtiger_field" . 56 " where displaytype=1 and vtiger_field.tabid=? and vtiger_field.uitype in ('15','16') " . 57 " and vtiger_field.presence in ('0','2') and vtiger_field.block != 'NULL'"; 58 59 $result = $db->pquery($query, array($tabId)); 60 $noofrows = $db->num_rows($result); 61 62 $fieldlist = array(); 63 if($noofrows > 0) { 64 for($i=0; $i<$noofrows; ++$i) { 65 $fieldlist[$db->query_result($result,$i,"fieldname")] = $db->query_result($result,$i,"fieldlabel"); 66 } 67 } 68 return $fieldlist; 69 } 70 71 public function getPickListDependency() { 72 if(empty($this->mapping)) { 73 $dependency = Vtiger_DependencyPicklist::getPickListDependency($this->get('sourceModule'), $this->get('sourcefield'), $this->get('targetfield')); 74 $this->mapping = $dependency['valuemapping']; 75 } 76 return $this->mapping; 77 } 78 79 private function getPickListValues($fieldName) { 80 //Need to decode the picklist values twice which are saved from old ui 81 return array_map('decode_html', getAllPickListValues($fieldName)); 82 } 83 84 public function getSourcePickListValues() { 85 if(empty($this->sourcePickListValues)) { 86 $this->sourcePickListValues = $this->getPickListValues($this->get('sourcefield')); 87 } 88 return $this->sourcePickListValues; 89 } 90 91 public function getTargetPickListValues() { 92 if(empty($this->targetPickListValues)) { 93 $this->targetPickListValues = $this->getPickListValues($this->get('targetfield')); 94 } 95 return $this->targetPickListValues; 96 } 97 98 public function getNonMappedSourcePickListValues() { 99 if(empty($this->nonMappedSourcePickListValues)) { 100 $sourcePickListValues = $this->getSourcePickListValues(); 101 $dependencyMapping = $this->getPickListDependency(); 102 foreach($dependencyMapping as $mappingDetails) { 103 unset($sourcePickListValues[$mappingDetails['sourcevalue']]); 104 } 105 $this->nonMappedSourcePickListValues = $sourcePickListValues; 106 } 107 return $this->nonMappedSourcePickListValues; 108 } 109 110 public function save($mapping) { 111 $dependencyMap = array(); 112 $dependencyMap['sourcefield'] = $this->get('sourcefield'); 113 $dependencyMap['targetfield'] = $this->get('targetfield'); 114 $dependencyMap['valuemapping'] = $mapping; 115 Vtiger_DependencyPicklist::savePickListDependencies($this->get('sourceModule'), $dependencyMap); 116 return true; 117 } 118 119 public function delete() { 120 Vtiger_DependencyPicklist::deletePickListDependencies($this->get('sourceModule'), $this->get('sourcefield'), $this->get('targetfield')); 121 return true; 122 } 123 124 private function loadFieldLabels() { 125 $db = PearDatabase::getInstance(); 126 127 $tabId = getTabid($this->get('sourceModule')); 128 $fieldNames = array($this->get('sourcefield'),$this->get('targetfield')); 129 130 $query = 'SELECT fieldlabel,fieldname FROM vtiger_field WHERE fieldname IN ('.generateQuestionMarks($fieldNames).') AND tabid = ?'; 131 $params = array($fieldNames, $tabId); 132 $result = $db->pquery($query, $params); 133 $num_rows = $db->num_rows($result); 134 for($i=0; $i<$num_rows; $i++) { 135 $row = $db->query_result_rowdata($result,$i); 136 $fieldName = $row['fieldname']; 137 if($fieldName == $this->get('sourcefield')) { 138 $this->set('sourcelabel', $row['fieldlabel']); 139 }else{ 140 $this->set('targetlabel', $row['fieldlabel']); 141 } 142 } 143 } 144 145 public function getSourceFieldLabel() { 146 $sourceFieldLabel = $this->get('sourcelabel'); 147 if(empty($sourceFieldLabel)) { 148 $this->loadFieldLabels(); 149 } 150 return vtranslate($this->get('sourcelabel'), $this->get('sourceModule')); 151 } 152 153 public function getTargetFieldLabel() { 154 $targetFieldLabel = $this->get('targetlabel'); 155 if(empty($targetFieldLabel)) { 156 $this->loadFieldLabels(); 157 } 158 return vtranslate($this->get('targetlabel'), $this->get('sourceModule')); 159 } 160 161 public static function getInstance($module, $sourceField, $targetField) { 162 $self = new self(); 163 $self->set('sourceModule', $module) 164 ->set('sourcefield', $sourceField) 165 ->set('targetfield', $targetField); 166 return $self; 167 } 168 169 }
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 |