[ Index ]

PHP Cross Reference of vtigercrm-6.1.0

title

Body

[close]

/modules/Vtiger/models/ -> TooltipView.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  vimport('~~/include/Webservices/Query.php');
  12  
  13  class Vtiger_TooltipView_Model extends Vtiger_DetailRecordStructure_Model {
  14  
  15      protected $fields = false;
  16  
  17      /**
  18       * Function to set the module instance
  19       * @param <Vtiger_Module_Model> $moduleInstance - module model
  20       * @return Vtiger_DetailView_Model>
  21       */
  22  	public function setModule($moduleInstance) {
  23          $this->module = $moduleInstance;
  24          $this->fields = $this->module->getSummaryViewFieldsList();
  25          if (empty($this->fields)) {
  26              $this->fields = $this->module->getMandatoryFieldModels();
  27          }
  28          return $this;
  29      }
  30      
  31      /**
  32       * Function to get list of tooltip enabled field model.
  33       * @return <Vtiger_Field_Model>
  34       */
  35  	public function getFields() {
  36          return $this->fields;
  37      }
  38  
  39      /**
  40       * Function to load record
  41       * @param <Number> $recordId
  42       * @return <Vtiger_Record_Model>
  43       */
  44  	protected function loadRecord($recordId) {
  45          $moduleName = $this->module->getName();
  46          
  47          // Preparation to pull required tool-tip field values.
  48          $referenceFields = array(); $fieldNames = array();
  49          foreach ($this->fields as $fieldModel) {
  50              $fieldType = $fieldModel->getFieldDataType();
  51              $fieldName = $fieldModel->get('name');
  52              
  53              $fieldNames[] = $fieldName;
  54              if ($fieldType == 'reference' || $fieldType == 'owner') {
  55                  $referenceFields[] = $fieldName;
  56              }
  57          }
  58          $wsid = vtws_getWebserviceEntityId($moduleName, $recordId);
  59          $q = sprintf("SELECT %s FROM %s WHERE id='%s' LIMIT 1;", implode(',', $fieldNames), $moduleName, $wsid);
  60          
  61          // Retrieves only required fields of the record with permission check.
  62          try {
  63              $data = array_shift(vtws_query($q, Users_Record_Model::getCurrentUserModel()));
  64  
  65              if ($data) {
  66                  // De-transform the webservice ID to CRM ID.
  67                  foreach ($data as $key => $value) {
  68                      if (in_array($key, $referenceFields)) {
  69                          $value = array_pop(explode('x', $value));
  70                      }
  71                      $data[$key] = $value;
  72                  }
  73              }
  74              
  75              $this->record = Vtiger_Record_Model::getCleanInstance($moduleName);
  76              $this->record->setData($data);
  77              
  78          } catch(WebServiceException $wex) {
  79              // Error retrieving information !
  80          }
  81          return $this;
  82      }
  83      
  84      /**
  85       * Function to get the values in stuctured format
  86       * @return <array> - values in structure array('block'=>array(fieldinfo));
  87       */
  88  	public function getStructure() {
  89          if (!$this->structuredValues) {
  90              $tooltipFieldsList = $this->fields;
  91              $recordModel = $this->getRecord();
  92              $this->structuredValues = array('TOOLTIP_FIELDS' => array());
  93              if ($tooltipFieldsList) {
  94                  foreach ($tooltipFieldsList as $fieldModel) {
  95                      $fieldName = $fieldModel->get('name');
  96                      if($fieldModel->isViewableInDetailView()) {
  97                          $fieldModel->set('fieldvalue', $recordModel->get($fieldName));
  98                          $this->structuredValues['TOOLTIP_FIELDS'][$fieldName] = $fieldModel;
  99                      }
 100                  }
 101              }
 102          }
 103          
 104          return $this->structuredValues;
 105      }
 106      
 107      /**
 108       * Function to get the instance
 109       * @param <String> $moduleName - module name
 110       * @param <String> $recordId - record id
 111       * @return <Vtiger_DetailView_Model>
 112       */
 113  	public static function getInstance($moduleName,$recordId) {
 114          $modelClassName = Vtiger_Loader::getComponentClassName('Model', 'TooltipView', $moduleName);
 115          $instance = new $modelClassName();
 116  
 117          $moduleModel = Vtiger_Module_Model::getInstance($moduleName);
 118          
 119          return $instance->setModule($moduleModel)->loadRecord($recordId);
 120      }
 121  }


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