[ 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 vimport('~~/vtlib/Vtiger/Net/Client.php'); 12 vimport('~~/vtlib/Vtiger/Package.php'); 13 14 class Settings_ModuleManager_Extension_Model extends Vtiger_Base_Model { 15 16 17 var $fileName; 18 19 public static function getUploadDirectory($isChild = false) { 20 $uploadDir .= 'test/vtlib'; 21 if ($isChild) { 22 $uploadDir = '../'.$uploadDir; 23 } 24 return $uploadDir; 25 } 26 27 /** 28 * Function to set id for this instance 29 * @param <Integer> $extensionId 30 * @return <type> 31 */ 32 public function setId($extensionId) { 33 $this->set('id', $extensionId); 34 return $this; 35 } 36 37 /** 38 * Function to set file name for this instance 39 * @param <type> $fileName 40 * @return <type> 41 */ 42 public function setFileName($fileName) { 43 $this->fileName = $fileName; 44 return $this; 45 } 46 47 /** 48 * Function to get Id of this instance 49 * @return <Integer> id 50 */ 51 public function getId() { 52 return $this->get('id'); 53 } 54 55 /** 56 * Function to get name of this instance 57 * @return <String> module name 58 */ 59 public function getName() { 60 return $this->get('name'); 61 } 62 63 /** 64 * Function to get file name of this instance 65 * @return <String> file name 66 */ 67 public function getFileName() { 68 return $this->fileName; 69 } 70 71 /** 72 * Function to get package of this instance 73 * @return <Vtiger_Package> package object 74 */ 75 public function getPackage() { 76 $packageModel = new Vtiger_Package(); 77 $moduleName = $packageModel->getModuleNameFromZip(self::getUploadDirectory(). '/' .$this->getFileName()); 78 if ($moduleName) { 79 return $packageModel; 80 } 81 return false; 82 } 83 84 /** 85 * Function to check whether it is compatible with vtiger or not 86 * @return <boolean> true/false 87 */ 88 public function isVtigerCompatible() { 89 vimport('~~/vtlib/Vtiger/Version.php'); 90 $vtigerVersion = $this->get('vtigerVersion'); 91 $vtigerMaxVersion = $this->get('vtigerMaxVersion'); 92 93 if ((Vtiger_Version::check($vtigerVersion, '>=') && $vtigerMaxVersion && Vtiger_Version::check($vtigerMaxVersion, '<')) 94 || Vtiger_Version::check($vtigerVersion, '=')) { 95 return true; 96 } 97 return false; 98 } 99 100 /** 101 * Function to check whether the module is already exists or not 102 * @return <true/false> 103 */ 104 public function isAlreadyExists() { 105 $moduleName = $this->getName(); 106 $moduleModel = Vtiger_Module_Model::getInstance($moduleName); 107 if($moduleModel) { 108 return true; 109 } 110 return false; 111 } 112 113 /** 114 * Function to check whether the module is upgradable or not 115 * @return <type> 116 */ 117 public function isUpgradable() { 118 $moduleName = $this->getName(); 119 $moduleModel = Vtiger_Module_Model::getInstance($moduleName); 120 if ($moduleModel) { 121 if ($moduleModel->get('version') < $this->get('pkgVersion')) { 122 return true; 123 } 124 } 125 return false; 126 } 127 128 /** 129 * Function to get instance by using XML node 130 * @param <XML DOM> $extensionXMLNode 131 * @return <Settings_ModuleManager_Extension_Model> $extensionModel 132 */ 133 public static function getInstanceFromXMLNodeObject($extensionXMLNode) { 134 $extensionModel = new self(); 135 $objectProperties = get_object_vars($extensionXMLNode); 136 137 foreach($objectProperties as $propertyName => $propertyValue) { 138 $propertyValue = (string)$propertyValue; 139 if ($propertyName === 'description') { 140 $propertyValue = nl2br(str_replace(array('<','>'), array('<', '>'), br2nl(trim($propertyValue)))); 141 } 142 $extensionModel->set($propertyName, $propertyValue); 143 } 144 145 $label = $extensionModel->get('label'); 146 if (!$label) { 147 $extensionModel->set('label', $extensionModel->getName()); 148 } 149 return $extensionModel; 150 } 151 152 /** 153 * Function to get instance by using id 154 * @param <Integer> $extensionId 155 * @param <String> $fileName 156 * @return <Settings_ModuleManager_Extension_Model> $extension Model 157 */ 158 public static function getInstanceById($extensionId, $fileName = false) { 159 $uploadDir = self::getUploadDirectory(); 160 if ($fileName) { 161 if (is_dir($uploadDir)) { 162 $uploadFileName = "$uploadDir/$fileName"; 163 checkFileAccess(self::getUploadDirectory()); 164 165 $extensionModel = new self(); 166 $extensionModel->setId($extensionId)->setFileName($fileName); 167 return $extensionModel; 168 } 169 } else { 170 if (!is_dir($uploadDir)) { 171 mkdir($uploadDir); 172 } 173 $uploadFile = 'usermodule_'. time() . '.zip'; 174 $uploadFileName = "$uploadDir/$uploadFile"; 175 checkFileAccess(self::getUploadDirectory()); 176 177 $packageAvailable = Settings_ModuleManager_Extension_Model::download($extensionId, $uploadFileName); 178 if ($packageAvailable) { 179 $extensionModel = new self(); 180 $extensionModel->setId($extensionId)->setFileName($uploadFile); 181 return $extensionModel; 182 } 183 } 184 return false; 185 } 186 187 188 /** 189 * Function to download the file of this instance 190 * @param <Integer> $extensionId 191 * @param <String> $targetFileName 192 * @return <boolean> true/false 193 */ 194 public static function download($extensionId, $targetFileName) { 195 $extensions = self::getAll(); 196 $downloadURL = $extensions[$extensionId]->get('downloadURL'); 197 198 if ($downloadURL) { 199 $clientModel = new Vtiger_Net_Client($downloadURL); 200 file_put_contents($targetFileName, $clientModel->doGet()); 201 return true; 202 } 203 return false; 204 } 205 }
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 |