[ Index ]

PHP Cross Reference of vtigercrm-6.1.0

title

Body

[close]

/vtlib/Vtiger/ -> FieldBasic.php (source)

   1  <?php
   2  
   3  /* +**********************************************************************************
   4   * The contents of this file are subject to the vtiger CRM Public License Version 1.0
   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  /**
  13   * Provides basic API to work with vtiger CRM Fields
  14   * @package vtlib
  15   */
  16  class Vtiger_FieldBasic {
  17  
  18      /** ID of this field instance */
  19      var $id;
  20      var $name;
  21      var $label = false;
  22      var $table = false;
  23      var $column = false;
  24      var $columntype = false;
  25      var $helpinfo = '';
  26      var $summaryfield = 0;
  27      var $masseditable = 1; // Default: Enable massedit for field
  28      var $uitype = 1;
  29      var $typeofdata = 'V~O';
  30      var $displaytype = 1;
  31      var $generatedtype = 1;
  32      var $readonly = 1;
  33      var $presence = 2;
  34      var $defaultvalue = '';
  35      var $maximumlength = 100;
  36      var $sequence = false;
  37      var $quickcreate = 1;
  38      var $quicksequence = false;
  39      var $info_type = 'BAS';
  40      var $block;
  41  
  42      /**
  43       * Constructor
  44       */
  45      function __construct() {
  46          
  47      }
  48  
  49      /**
  50       * Initialize this instance
  51       * @param Array 
  52       * @param Vtiger_Module Instance of module to which this field belongs
  53       * @param Vtiger_Block Instance of block to which this field belongs
  54       * @access private
  55       */
  56      function initialize($valuemap, $moduleInstance = false, $blockInstance = false) {
  57          $this->id = $valuemap['fieldid'];
  58          $this->name = $valuemap['fieldname'];
  59          $this->label = $valuemap['fieldlabel'];
  60          $this->column = $valuemap['columnname'];
  61          $this->table = $valuemap['tablename'];
  62          $this->uitype = $valuemap['uitype'];
  63          $this->typeofdata = $valuemap['typeofdata'];
  64          $this->helpinfo = $valuemap['helpinfo'];
  65          $this->masseditable = $valuemap['masseditable'];
  66          $this->displaytype = $valuemap['displaytype'];
  67          $this->generatedtype = $valuemap['generatedtype'];
  68          $this->readonly = $valuemap['readonly'];
  69          $this->presence = $valuemap['presence'];
  70          $this->defaultvalue = $valuemap['defaultvalue'];
  71          $this->quickcreate = $valuemap['quickcreate'];
  72          $this->sequence = $valuemap['sequence'];
  73          $this->summaryfield = $valuemap['summaryfield'];
  74          $this->block = $blockInstance ? $blockInstance : Vtiger_Block::getInstance($valuemap['block'], $moduleInstance);
  75      }
  76  
  77      /** Cache (Record) the schema changes to improve performance */
  78      static $__cacheSchemaChanges = Array();
  79  
  80      /**
  81       * Initialize vtiger schema changes.
  82       * @access private
  83       */
  84      function __handleVtigerCoreSchemaChanges() {
  85  // Add helpinfo column to the vtiger_field table
  86          if (empty(self::$__cacheSchemaChanges['vtiger_field.helpinfo'])) {
  87              Vtiger_Utils::AddColumn('vtiger_field', 'helpinfo', ' TEXT');
  88              self::$__cacheSchemaChanges['vtiger_field.helpinfo'] = true;
  89          }
  90          if (empty(self::$__cacheSchemaChanges['vtiger_field.summaryfield'])) {
  91              Vtiger_Utils::AddColumn('vtiger_field', 'summaryfield', ' INT(10) NOT NULL DEFAULT 0');
  92              self::$__cacheSchemaChanges['vtiger_field.summaryfield'] = 0;
  93          }
  94      }
  95  
  96      /**
  97       * Get unique id for this instance
  98       * @access private
  99       */
 100      function __getUniqueId() {
 101          global $adb;
 102          return $adb->getUniqueID('vtiger_field');
 103      }
 104  
 105      /**
 106       * Get next sequence id to use within a block for this instance
 107       * @access private
 108       */
 109      function __getNextSequence() {
 110          global $adb;
 111          $result = $adb->pquery("SELECT MAX(sequence) AS max_seq FROM vtiger_field WHERE tabid=? AND block=?", Array($this->getModuleId(), $this->getBlockId()));
 112          $maxseq = 0;
 113          if ($result && $adb->num_rows($result)) {
 114              $maxseq = $adb->query_result($result, 0, 'max_seq');
 115              $maxseq += 1;
 116          }
 117          return $maxseq;
 118      }
 119  
 120      /**
 121       * Get next quick create sequence id for this instance
 122       * @access private
 123       */
 124      function __getNextQuickCreateSequence() {
 125          global $adb;
 126          $result = $adb->pquery("SELECT MAX(quickcreatesequence) AS max_quickcreateseq FROM vtiger_field WHERE tabid=?", Array($this->getModuleId()));
 127          $max_quickcreateseq = 0;
 128          if ($result && $adb->num_rows($result)) {
 129              $max_quickcreateseq = $adb->query_result($result, 0, 'max_quickcreateseq');
 130              $max_quickcreateseq += 1;
 131          }
 132          return $max_quickcreateseq;
 133      }
 134  
 135      /**
 136       * Create this field instance
 137       * @param Vtiger_Block Instance of the block to use
 138       * @access private
 139       */
 140      function __create($blockInstance) {
 141          $this->__handleVtigerCoreSchemaChanges();
 142  
 143          global $adb;
 144  
 145          $this->block = $blockInstance;
 146  
 147          $moduleInstance = $this->getModuleInstance();
 148  
 149          $this->id = $this->__getUniqueId();
 150  
 151          if (!$this->sequence) {
 152              $this->sequence = $this->__getNextSequence();
 153          }
 154  
 155          if ($this->quickcreate != 1) { // If enabled for display
 156              if (!$this->quicksequence) {
 157                  $this->quicksequence = $this->__getNextQuickCreateSequence();
 158              }
 159          } else {
 160              $this->quicksequence = null;
 161          }
 162  
 163  // Initialize other variables which are not done
 164          if (!$this->table)
 165              $this->table = $moduleInstance->basetable;
 166          if (!$this->column) {
 167              $this->column = strtolower($this->name);
 168              if (!$this->columntype)
 169                  $this->columntype = 'VARCHAR(100)';
 170          }
 171  
 172          if (!$this->label)
 173              $this->label = $this->name;
 174  
 175          $adb->pquery("INSERT INTO vtiger_field (tabid, fieldid, columnname, tablename, generatedtype,
 176  uitype, fieldname, fieldlabel, readonly, presence, defaultvalue, maximumlength, sequence,
 177  block, displaytype, typeofdata, quickcreate, quickcreatesequence, info_type, helpinfo, summaryfield) 
 178  VALUES (?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?)", Array($this->getModuleId(), $this->id, $this->column, $this->table, $this->generatedtype,
 179              $this->uitype, $this->name, $this->label, $this->readonly, $this->presence, $this->defaultvalue,
 180              $this->maximumlength, $this->sequence, $this->getBlockId(), $this->displaytype, $this->typeofdata,
 181              $this->quickcreate, $this->quicksequence, $this->info_type, $this->helpinfo, $this->summaryfield));
 182  
 183  // Set the field status for mass-edit (if set)
 184          $adb->pquery('UPDATE vtiger_field SET masseditable=? WHERE fieldid=?', Array($this->masseditable, $this->id));
 185  
 186          Vtiger_Profile::initForField($this);
 187  
 188          if (!empty($this->columntype)) {
 189              Vtiger_Utils::AddColumn($this->table, $this->column, $this->columntype);
 190          }
 191  
 192          self::log("Creating Field $this->name ... DONE");
 193          self::log("Module language mapping for $this->label ... CHECK");
 194      }
 195  
 196      /**
 197       * Update this field instance
 198       * @access private
 199       * @internal TODO
 200       */
 201      function __update() {
 202          self::log("Updating Field $this->name ... DONE");
 203      }
 204  
 205      /**
 206       * Delete this field instance
 207       * @access private
 208       */
 209      function __delete() {
 210          global $adb;
 211  
 212          Vtiger_Profile::deleteForField($this);
 213  
 214          $adb->pquery("DELETE FROM vtiger_field WHERE fieldid=?", Array($this->id));
 215          self::log("Deleteing Field $this->name ... DONE");
 216      }
 217  
 218      /**
 219       * Get block id to which this field instance is associated
 220       */
 221      function getBlockId() {
 222          return $this->block->id;
 223      }
 224  
 225      /**
 226       * Get module id to which this field instance is associated
 227       */
 228      function getModuleId() {
 229          return $this->block->module->id;
 230      }
 231  
 232      /**
 233       * Get module name to which this field instance is associated
 234       */
 235      function getModuleName() {
 236          return $this->block->module->name;
 237      }
 238  
 239      /**
 240       * Get module instance to which this field instance is associated
 241       */
 242      function getModuleInstance() {
 243          return $this->block->module;
 244      }
 245  
 246      /**
 247       * Save this field instance
 248       * @param Vtiger_Block Instance of block to which this field should be added.
 249       */
 250      function save($blockInstance = false) {
 251          if ($this->id)
 252              $this->__update();
 253          else
 254              $this->__create($blockInstance);
 255          return $this->id;
 256      }
 257  
 258      /**
 259       * Delete this field instance
 260       */
 261      function delete() {
 262          $this->__delete();
 263      }
 264  
 265      /**
 266       * Set Help Information for this instance.
 267       * @param String Help text (content)
 268       */
 269      function setHelpInfo($helptext) {
 270  // Make sure to initialize the core tables first
 271          $this->__handleVtigerCoreSchemaChanges();
 272  
 273          global $adb;
 274          $adb->pquery('UPDATE vtiger_field SET helpinfo=? WHERE fieldid=?', Array($helptext, $this->id));
 275          self::log("Updated help information of $this->name ... DONE");
 276      }
 277  
 278      /**
 279       * Set Masseditable information for this instance.
 280       * @param Integer Masseditable value
 281       */
 282      function setMassEditable($value) {
 283          global $adb;
 284          $adb->pquery('UPDATE vtiger_field SET masseditable=? WHERE fieldid=?', Array($value, $this->id));
 285          self::log("Updated masseditable information of $this->name ... DONE");
 286      }
 287      
 288      /** 
 289       * Set Summaryfield information for this instance. 
 290       * @param Integer Summaryfield value 
 291       */ 
 292      function setSummaryField($value) { 
 293          global $adb; 
 294          $adb->pquery('UPDATE vtiger_field SET summaryfield=? WHERE fieldid=?', Array($value, $this->id)); 
 295          self::log("Updated summaryfield information of $this->name ... DONE"); 
 296      } 
 297  
 298      /**
 299       * Helper function to log messages
 300       * @param String Message to log
 301       * @param Boolean true appends linebreak, false to avoid it
 302       * @access private
 303       */
 304      static function log($message, $delim = true) {
 305          Vtiger_Utils::Log($message, $delim);
 306      }
 307  }
 308  ?>


Generated: Fri Nov 28 20:08:37 2014 Cross-referenced by PHPXref 0.7.1