[ Index ]

PHP Cross Reference of vtigercrm-6.1.0

title

Body

[close]

/modules/Vtiger/models/ -> RecordStructure.php (source)

   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  /**
  12   * Vtiger Record Structure Model
  13   */
  14  class Vtiger_RecordStructure_Model extends Vtiger_Base_Model {
  15  
  16      protected $record = false;
  17      protected $module = false;
  18      protected $structuredValues = false;
  19  
  20      const RECORD_STRUCTURE_MODE_DEFAULT = '';
  21      const RECORD_STRUCTURE_MODE_DETAIL = 'Detail';
  22      const RECORD_STRUCTURE_MODE_EDIT = 'Edit';
  23      const RECORD_STRUCTURE_MODE_QUICKCREATE = 'QuickCreate';
  24      const RECORD_STRUCTURE_MODE_MASSEDIT = 'MassEdit';
  25      const RECORD_STRUCTURE_MODE_SUMMARY = 'Summary';
  26  
  27      /**
  28       * Function to set the record Model
  29       * @param <type> $record - record instance
  30       * @return Vtiger_RecordStructure_Model
  31       */
  32  	public function setRecord($record) {
  33          $this->record = $record;
  34          return $this;
  35      }
  36  
  37      /**
  38       * Function to get the record
  39       * @return <Vtiger_Record_Model>
  40       */
  41  	public function getRecord() {
  42          return $this->record;
  43      }
  44  
  45  	public function getRecordName() {
  46          return $this->record->getName();
  47      }
  48  
  49      /**
  50       * Function to get the module
  51       * @return <Vtiger_Module_Model>
  52       */
  53  	public function getModule() {
  54          return $this->module;
  55      }
  56  
  57      /**
  58       * Function to set the module
  59       * @param <type> $module - module model
  60       * @return Vtiger_RecordStructure_Model
  61       */
  62  	public function setModule($module) {
  63          $this->module = $module;
  64          return $this;
  65      }
  66  
  67      /**
  68       * Function to get the values in stuctured format
  69       * @return <array> - values in structure array('block'=>array(fieldinfo));
  70       */
  71  	public function getStructure() {
  72          if(!empty($this->structuredValues)) {
  73              return $this->structuredValues;
  74          }
  75  
  76          $values = array();
  77          $recordModel = $this->getRecord();
  78          $recordExists = !empty($recordModel);
  79          $moduleModel = $this->getModule();
  80          $blockModelList = $moduleModel->getBlocks();
  81          foreach($blockModelList as $blockLabel=>$blockModel) {
  82              $fieldModelList = $blockModel->getFields();
  83              if (!empty ($fieldModelList)) {
  84                  $values[$blockLabel] = array();
  85                  foreach($fieldModelList as $fieldName=>$fieldModel) {
  86                      if($fieldModel->isViewable()) {
  87                          if($recordExists) {
  88                              $fieldModel->set('fieldvalue', $recordModel->get($fieldName));
  89                          }
  90                          $values[$blockLabel][$fieldName] = $fieldModel;
  91                      }
  92                  }
  93              }
  94          }
  95          $this->structuredValues = $values;
  96          return $values;
  97      }
  98  
  99      /**
 100       * Function to retieve the instance from record model
 101       * @param <Vtiger_Record_Model> $recordModel - record instance
 102       * @return Vtiger_RecordStructure_Model
 103       */
 104  	public static function getInstanceFromRecordModel($recordModel, $mode=self::RECORD_STRUCTURE_MODE_DEFAULT) {
 105          $moduleModel = $recordModel->getModule();
 106          $className = Vtiger_Loader::getComponentClassName('Model', $mode.'RecordStructure', $moduleModel->getName(true));
 107          $instance = new $className();
 108          $instance->setModule($moduleModel)->setRecord($recordModel);
 109          return $instance;
 110      }
 111  
 112      /**
 113       * Function to retieve the instance from module model
 114       * @param <Vtiger_Module_Model> $moduleModel - module instance
 115       * @return Vtiger_RecordStructure_Model
 116       */
 117  	public static function getInstanceForModule($moduleModel, $mode=self::RECORD_STRUCTURE_MODE_DEFAULT) {
 118          $className = Vtiger_Loader::getComponentClassName('Model', $mode.'RecordStructure', $moduleModel->get('name'));
 119          $instance = new $className();
 120          $instance->setModule($moduleModel);
 121          return $instance;
 122      }
 123  }


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