[ 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 include_once ('vtlib/Vtiger/Utils.php'); 11 require_once 'includes/runtime/Cache.php'; 12 13 /** 14 * Provides API to work with vtiger CRM Module Blocks 15 * @package vtlib 16 */ 17 class Vtiger_Block { 18 /** ID of this block instance */ 19 var $id; 20 /** Label for this block instance */ 21 var $label; 22 23 var $sequence; 24 var $showtitle = 0; 25 var $visible = 0; 26 var $increateview = 0; 27 var $ineditview = 0; 28 var $indetailview = 0; 29 30 var $display_status=1; 31 var $iscustom=0; 32 33 var $module; 34 35 /** 36 * Constructor 37 */ 38 function __construct() { 39 } 40 41 /** 42 * Get unquie id for this instance 43 * @access private 44 */ 45 function __getUniqueId() { 46 global $adb; 47 48 /** Sequence table was added from 5.1.0 */ 49 $maxblockid = $adb->getUniqueID('vtiger_blocks'); 50 return $maxblockid; 51 } 52 53 /** 54 * Get next sequence value to use for this block instance 55 * @access private 56 */ 57 function __getNextSequence() { 58 global $adb; 59 $result = $adb->pquery("SELECT MAX(sequence) as max_sequence from vtiger_blocks where tabid = ?", Array($this->module->id)); 60 $maxseq = 0; 61 if($adb->num_rows($result)) { 62 $maxseq = $adb->query_result($result, 0, 'max_sequence'); 63 } 64 return ++$maxseq; 65 } 66 67 /** 68 * Initialize this block instance 69 * @param Array Map of column name and value 70 * @param Vtiger_Module Instance of module to which this block is associated 71 * @access private 72 */ 73 function initialize($valuemap, $moduleInstance=false) { 74 $this->id = $valuemap[blockid]; 75 $this->label= $valuemap[blocklabel]; 76 $this->display_status = $valuemap[display_status]; 77 $this->sequence = $valuemap[sequence]; 78 $this->iscustom = $valuemap[iscustom]; 79 $this->module=$moduleInstance? $moduleInstance: Vtiger_Module::getInstance($valuemap[tabid]); 80 } 81 82 /** 83 * Create vtiger CRM block 84 * @access private 85 */ 86 function __create($moduleInstance) { 87 global $adb; 88 89 $this->module = $moduleInstance; 90 91 $this->id = $this->__getUniqueId(); 92 if(!$this->sequence) $this->sequence = $this->__getNextSequence(); 93 94 $adb->pquery("INSERT INTO vtiger_blocks(blockid,tabid,blocklabel,sequence,show_title,visible,create_view,edit_view,detail_view,iscustom) 95 VALUES(?,?,?,?,?,?,?,?,?,?)", Array($this->id, $this->module->id, $this->label,$this->sequence, 96 $this->showtitle, $this->visible,$this->increateview, $this->ineditview, $this->indetailview, $this->iscustom)); 97 self::log("Creating Block $this->label ... DONE"); 98 self::log("Module language entry for $this->label ... CHECK"); 99 } 100 101 /** 102 * Update vtiger CRM block 103 * @access private 104 * @internal TODO 105 */ 106 function __update() { 107 self::log("Updating Block $this->label ... DONE"); 108 } 109 110 /** 111 * Delete this instance 112 * @access private 113 */ 114 function __delete() { 115 global $adb; 116 self::log("Deleting Block $this->label ... ", false); 117 $adb->pquery("DELETE FROM vtiger_blocks WHERE blockid=?", Array($this->id)); 118 self::log("DONE"); 119 } 120 121 /** 122 * Save this block instance 123 * @param Vtiger_Module Instance of the module to which this block is associated 124 */ 125 function save($moduleInstance=false) { 126 if($this->id) $this->__update(); 127 else $this->__create($moduleInstance); 128 return $this->id; 129 } 130 131 /** 132 * Delete block instance 133 * @param Boolean True to delete associated fields, False to avoid it 134 */ 135 function delete($recursive=true) { 136 if($recursive) { 137 $fields = Vtiger_Field::getAllForBlock($this); 138 foreach($fields as $fieldInstance) $fieldInstance->delete($recursive); 139 } 140 $this->__delete(); 141 } 142 143 /** 144 * Add field to this block 145 * @param Vtiger_Field Instance of field to add to this block. 146 * @return Reference to this block instance 147 */ 148 function addField($fieldInstance) { 149 $fieldInstance->save($this); 150 return $this; 151 } 152 153 /** 154 * Helper function to log messages 155 * @param String Message to log 156 * @param Boolean true appends linebreak, false to avoid it 157 * @access private 158 */ 159 static function log($message, $delim=true) { 160 Vtiger_Utils::Log($message, $delim); 161 } 162 163 /** 164 * Get instance of block 165 * @param mixed block id or block label 166 * @param Vtiger_Module Instance of the module if block label is passed 167 */ 168 static function getInstance($value, $moduleInstance=false) { 169 global $adb; 170 $cache = Vtiger_Cache::getInstance(); 171 if($moduleInstance && $cache->getBlockInstance($value, $moduleInstance->id)){ 172 return $cache->getBlockInstance($value, $moduleInstance->id); 173 } else { 174 $instance = false; 175 $query = false; 176 $queryParams = false; 177 if(Vtiger_Utils::isNumber($value)) { 178 $query = "SELECT * FROM vtiger_blocks WHERE blockid=?"; 179 $queryParams = Array($value); 180 } else { 181 $query = "SELECT * FROM vtiger_blocks WHERE blocklabel=? AND tabid=?"; 182 $queryParams = Array($value, $moduleInstance->id); 183 } 184 $result = $adb->pquery($query, $queryParams); 185 if($adb->num_rows($result)) { 186 $instance = new self(); 187 $instance->initialize($adb->fetch_array($result), $moduleInstance); 188 } 189 $cache->setBlockInstance($value,$instance->module->id, $instance); 190 return $instance; 191 } 192 } 193 194 /** 195 * Get all block instances associated with the module 196 * @param Vtiger_Module Instance of the module 197 */ 198 static function getAllForModule($moduleInstance) { 199 global $adb; 200 $instances = false; 201 202 $query = "SELECT * FROM vtiger_blocks WHERE tabid=? ORDER BY sequence"; 203 $queryParams = Array($moduleInstance->id); 204 205 $result = $adb->pquery($query, $queryParams); 206 for($index = 0; $index < $adb->num_rows($result); ++$index) { 207 $instance = new self(); 208 $instance->initialize($adb->fetch_array($result), $moduleInstance); 209 $instances[] = $instance; 210 } 211 return $instances; 212 } 213 214 /** 215 * Delete all blocks associated with module 216 * @param Vtiger_Module Instnace of module to use 217 * @param Boolean true to delete associated fields, false otherwise 218 * @access private 219 */ 220 static function deleteForModule($moduleInstance, $recursive=true) { 221 global $adb; 222 if($recursive) Vtiger_Field::deleteForModule($moduleInstance); 223 $adb->pquery("DELETE FROM vtiger_blocks WHERE tabid=?", Array($moduleInstance->id)); 224 self::log("Deleting blocks for module ... DONE"); 225 } 226 } 227 ?>
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 |