[ 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 include_once 'vtlib/Vtiger/Link.php'; 12 13 /** 14 * Vtiger Link Model Class 15 */ 16 class Vtiger_Link_Model extends Vtiger_Link { 17 18 // Class variable to store the child links 19 protected $childlinks = array(); 20 21 22 /** 23 * Function to get the value of a given property 24 * @param <String> $propertyName 25 * @return <Object> 26 * @throws Exception 27 */ 28 public function get($propertyName) { 29 if(property_exists($this,$propertyName)){ 30 return $this->$propertyName; 31 } 32 } 33 34 /** 35 * Function to set the value of a given property 36 * @param <String> $propertyName 37 * @param <Object> $propertyValue 38 * @return Vtiger_Link_Model instance 39 */ 40 public function set($propertyName, $propertyValue) { 41 $this->$propertyName = $propertyValue; 42 return $this; 43 } 44 45 /** 46 * Function to get the link url 47 * @return <String> 48 */ 49 public function getUrl() { 50 return $this->convertToNativeLink(); 51 } 52 53 /** 54 * Function to get the link label 55 * @return <String> 56 */ 57 public function getLabel() { 58 return $this->linklabel; 59 } 60 61 /** 62 * Function to get the link type 63 * @return <String> 64 */ 65 public function getType() { 66 return $this->linktype; 67 } 68 69 /** 70 * Function to get the link icon name 71 * @return <String> 72 */ 73 public function getIcon() { 74 return $this->linkicon; 75 } 76 77 /** 78 * Function to check whether link has icon or not 79 * @return <Boolean> true/false 80 */ 81 public function isIconExists() { 82 $linkIcon = $this->getIcon(); 83 if(empty($linkIcon)) { 84 return false; 85 } 86 return true; 87 } 88 89 /** 90 * Function to retrieve the icon path for the link icon 91 * @return <String/Boolean> - returns image path if icon exits 92 * else returns false; 93 */ 94 public function getIconPath() { 95 if(!$this->isIconExists()) { 96 return false; 97 } 98 return Vtiger_Theme::getImagePath($this->getIcon()); 99 } 100 101 /** 102 * Function to get the link id 103 * @return <Number> 104 */ 105 public function getId() { 106 return $this->linkid; 107 } 108 109 /** 110 * Function to Add link to the child link list 111 * @param Vtiger_Link_Model $link - link model 112 * @result Vtiger_Link_Model - current Instance; 113 */ 114 public function addChildLink(Vtiger_Link_Model $link) { 115 $this->childlinks[] = $link; 116 return $this; 117 } 118 119 /** 120 * Function to get all the child links 121 * @result <array> - list of Vtiger_Link_Model instances 122 */ 123 public function getChildLinks() { 124 //See if indexing is need depending only user selection 125 return $this->childlinks; 126 } 127 128 /** 129 * Function to check whether the link model has any child links 130 * @return <Boolean> true/false 131 */ 132 public function hasChild() { 133 (count($this->childlinks) > 0)? true : false; 134 } 135 136 public function isPageLoadLink() { 137 $url = $this->get('linkurl'); 138 if(strpos($url, 'index') === 0){ 139 return true; 140 } 141 return false; 142 } 143 144 public function convertToNativeLink() { 145 $url = $this->get('linkurl'); 146 if(empty($url)){ 147 return $url; 148 } 149 //Check if the link is not javascript 150 if(!$this->isPageLoadLink()){ 151 //To convert single quotes and double quotes 152 $url = Vtiger_Util_Helper::toSafeHTML($url); 153 return $url; 154 } 155 156 $module = false; 157 $sourceModule = false; 158 $sourceRecord = false; 159 $parametersParts = explode('&',$url); 160 foreach($parametersParts as $index => $keyValue){ 161 $urlParts = explode('=', $keyValue); 162 $key = $urlParts[0]; 163 $value = $urlParts[1]; 164 if(strcmp($key, 'module')== 0){ 165 $module = $value; 166 } 167 168 if(strcmp($key,'action')== 0) { 169 if(strpos($value,'View')) { 170 $value = str_replace('View', '', $value); 171 $key = 'view'; 172 } 173 } 174 if(strcmp($key, 'return_module')== 0) { 175 $key = 'sourceModule'; 176 //Indicating that it is an relation operation 177 $parametersParts[] = 'relationOperation=true'; 178 } 179 if(strcmp($key, 'return_id')== 0) { 180 $key = 'sourceRecord'; 181 } 182 183 if(strcmp($key, 'sourceRecord') == 0) { 184 $sourceRecord = $value; 185 } 186 187 if(strcmp($key, 'sourceModule') == 0) { 188 $sourceModule = $value; 189 190 } 191 $newUrlParts = array(); 192 array_push($newUrlParts, $key); 193 array_push($newUrlParts, $value); 194 $parametersParts[$index] = implode('=', $newUrlParts); 195 } 196 197 //to append the reference field in one to many relation 198 if(!empty($module) && !empty ($sourceModule) && !empty($sourceRecord)) { 199 $sourceModuleModel = Vtiger_Module_Model::getInstance($sourceModule); 200 $relatedModuleModel = Vtiger_Module_Model::getInstance($module); 201 $relationModel = Vtiger_Relation_Model::getInstance($sourceModuleModel, $relatedModuleModel); 202 if($relationModel->isDirectRelation()){ 203 $fieldList = $relatedModuleModel->getFields(); 204 foreach($fieldList as $fieldName=>$fieldModel) { 205 if($fieldModel->getFieldDataType() == Vtiger_Field_Model::REFERENCE_TYPE) { 206 $referenceList = $fieldModel->getReferenceList(); 207 if(in_array($sourceModuleModel->get('name'), $referenceList)) { 208 $parametersParts[] = $fieldModel->get('name').'='.$sourceRecord; 209 } 210 } 211 } 212 } 213 } 214 215 $url = implode('&', $parametersParts); 216 //To convert single quotes and double quotes 217 $url = Vtiger_Util_Helper::toSafeHTML($url); 218 return $url; 219 } 220 221 /** 222 * Function to get the instance of Vtiger Link Model from the given array of key-value mapping 223 * @param <Array> $valueMap 224 * @return Vtiger_Link_Model instance 225 */ 226 public static function getInstanceFromValues($valueMap) { 227 $linkModel = new self(); 228 $linkModel->initialize($valueMap); 229 230 // To set other properties for Link Model 231 foreach($valueMap as $property => $value) { 232 if(!isset($linkModel->$property)) { 233 $linkModel->$property = $value; 234 } 235 } 236 237 return $linkModel; 238 } 239 240 /** 241 * Function to get the instance of Vtiger Link Model from a given Vtiger_Link object 242 * @param Vtiger_Link $linkObj 243 * @return Vtiger_Link_Model instance 244 */ 245 public static function getInstanceFromLinkObject (Vtiger_Link $linkObj) { 246 $objectProperties = get_object_vars($linkObj); 247 $linkModel = new self(); 248 foreach($objectProperties as $properName=>$propertyValue) { 249 $linkModel->$properName = $propertyValue; 250 } 251 return $linkModel; 252 } 253 254 /** 255 * Function to get all the Vtiger Link Models for a module of the given list of link types 256 * @param <Number> $tabid 257 * @param <Array> $type 258 * @param <Array> $parameters 259 * @return <Array> - List of Vtiger_Link_Model instances 260 */ 261 public static function getAllByType($tabid, $type = false, $parameters = false) { 262 $links = Vtiger_Cache::get('links-'.$tabid, $type); 263 if(!$links) { 264 $links = parent::getAllByType($tabid, $type, $parameters); 265 Vtiger_Cache::set('links-'.$tabid, $type, $links); 266 } 267 268 $linkModels = array(); 269 foreach($links as $linkType => $linkObjects) { 270 foreach($linkObjects as $linkObject) { 271 $linkModels[$linkType][] = self::getInstanceFromLinkObject($linkObject); 272 } 273 } 274 275 if (!is_array($type)) { 276 $type = array($type); 277 } 278 279 $diffTypes = array_diff($type, array_keys($linkModels)); 280 foreach ($diffTypes as $linkType) { 281 $linkModels[$linkType] = array(); 282 } 283 284 return $linkModels; 285 } 286 287 /** 288 * Function to get the relatedModuleName 289 * @return <String> 290 */ 291 public function getRelatedModuleName() { 292 return $this->relatedModuleName; 293 } 294 }
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 |