[ Index ]

PHP Cross Reference of vtigercrm-6.1.0

title

Body

[close]

/modules/Settings/Workflows/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  class Settings_Workflows_RecordStructure_Model extends Vtiger_RecordStructure_Model {
  12  
  13      const RECORD_STRUCTURE_MODE_DEFAULT = '';
  14      const RECORD_STRUCTURE_MODE_FILTER = 'Filter';
  15      const RECORD_STRUCTURE_MODE_EDITTASK = 'EditTask';
  16  
  17  	function setWorkFlowModel($workFlowModel) {
  18          $this->workFlowModel = $workFlowModel;
  19      }
  20  
  21  	function getWorkFlowModel() {
  22          return $this->workFlowModel;
  23      }
  24      /**
  25       * Function to get the values in stuctured format
  26       * @return <array> - values in structure array('block'=>array(fieldinfo));
  27       */
  28  	public function getStructure() {
  29          if(!empty($this->structuredValues)) {
  30              return $this->structuredValues;
  31          }
  32  
  33          $recordModel = $this->getWorkFlowModel();
  34          $recordId = $recordModel->getId();
  35  
  36          $values = array();
  37  
  38          $baseModuleModel = $moduleModel = $this->getModule();
  39          $blockModelList = $moduleModel->getBlocks();
  40          foreach($blockModelList as $blockLabel=>$blockModel) {
  41              $fieldModelList = $blockModel->getFields();
  42              if (!empty ($fieldModelList)) {
  43                  $values[$blockLabel] = array();
  44                  foreach($fieldModelList as $fieldName=>$fieldModel) {
  45                      if($fieldModel->isViewable()) {
  46                          if (in_array($moduleModel->getName(), array('Calendar', 'Events'))&& $fieldName != 'modifiedby'  && $fieldModel->getDisplayType() == 3) {
  47                              /* Restricting the following fields(Event module fields) for "Calendar" module
  48                               * time_start, time_end, eventstatus, activitytype,    visibility, duration_hours,
  49                               * duration_minutes, reminder_time, recurringtype, notime
  50                               */
  51                              continue;
  52                          }
  53                          if(!empty($recordId)) {
  54                              //Set the fieldModel with the valuetype for the client side.
  55                              $fieldValueType = $recordModel->getFieldFilterValueType($fieldName);
  56                              $fieldInfo = $fieldModel->getFieldInfo();
  57                              $fieldInfo['workflow_valuetype'] = $fieldValueType;
  58                              $fieldModel->setFieldInfo($fieldInfo);
  59                          }
  60                          // This will be used during editing task like email, sms etc
  61                          $fieldModel->set('workflow_columnname', $fieldName)->set('workflow_columnlabel', vtranslate($fieldModel->get('label'), $moduleModel->getName()));
  62                          // This is used to identify the field belongs to source module of workflow
  63                          $fieldModel->set('workflow_sourcemodule_field', true);
  64                          $values[$blockLabel][$fieldName] = clone $fieldModel;
  65                      }
  66                  }
  67              }
  68          }
  69  
  70          //All the reference fields should also be sent
  71          $fields = $moduleModel->getFieldsByType(array('reference', 'owner', 'multireference'));
  72          foreach($fields as $parentFieldName => $field) {
  73              $type = $field->getFieldDataType();
  74              $referenceModules = $field->getReferenceList();
  75              if($type == 'owner') $referenceModules = array('Users');
  76              foreach($referenceModules as $refModule) {
  77                  $moduleModel = Vtiger_Module_Model::getInstance($refModule);
  78                  $blockModelList = $moduleModel->getBlocks();
  79                  foreach($blockModelList as $blockLabel=>$blockModel) {
  80                      $fieldModelList = $blockModel->getFields();
  81                      if (!empty ($fieldModelList)) {
  82                          foreach($fieldModelList as $fieldName=>$fieldModel) {
  83                              if($fieldModel->isViewable()) {
  84                                  $name = "($parentFieldName : ($refModule) $fieldName)";
  85                                  $label = vtranslate($field->get('label'), $baseModuleModel->getName()).' : ('.vtranslate($refModule, $refModule).') '.vtranslate($fieldModel->get('label'), $refModule);
  86                                  $fieldModel->set('workflow_columnname', $name)->set('workflow_columnlabel', $label);
  87                                  if(!empty($recordId)) {
  88                                      $fieldValueType = $recordModel->getFieldFilterValueType($name);
  89                                      $fieldInfo = $fieldModel->getFieldInfo();
  90                                      $fieldInfo['workflow_valuetype'] = $fieldValueType;
  91                                      $fieldModel->setFieldInfo($fieldInfo);
  92                                  }
  93                                  $values[$field->get('label')][$name] = clone $fieldModel;
  94                              }
  95                          }
  96                      }
  97                  }
  98              }
  99          }
 100          $this->structuredValues = $values;
 101          return $values;
 102      }
 103  
 104      /**
 105       * Function returns all the email fields for the workflow record structure
 106       * @return type
 107       */
 108  	public function getAllEmailFields() {
 109          return $this->getFieldsByType('email');
 110      }
 111  
 112      /**
 113       * Function returns all the date time fields for the workflow record structure
 114       * @return type
 115       */
 116  	public function getAllDateTimeFields() {
 117          $fieldTypes = array('date','datetime');
 118          return $this->getFieldsByType($fieldTypes);
 119      }
 120  
 121      /**
 122       * Function returns fields based on type
 123       * @return type
 124       */
 125  	public function getFieldsByType($fieldTypes) {
 126          $fieldTypesArray = array();
 127          if(gettype($fieldTypes) == 'string'){
 128              array_push($fieldTypesArray,$fieldTypes);
 129          } else {
 130              $fieldTypesArray = $fieldTypes;
 131          }
 132          $structure = $this->getStructure();
 133          $fieldsBasedOnType = array();
 134          if(!empty($structure)) {
 135              foreach($structure as $block => $fields) {
 136                  foreach($fields as $metaKey => $field) {
 137                      $type = $field->getFieldDataType();
 138                      if(in_array($type, $fieldTypesArray)){
 139                          $fieldsBasedOnType[$metaKey] = $field;
 140                      }
 141                  }
 142              }
 143          }
 144          return $fieldsBasedOnType;
 145      }
 146  
 147  	public static function getInstanceForWorkFlowModule($workFlowModel, $mode) {
 148          $className = Vtiger_Loader::getComponentClassName('Model', $mode.'RecordStructure', 'Settings:Workflows');
 149          $instance = new $className();
 150          $instance->setWorkFlowModel($workFlowModel);
 151          $instance->setModule($workFlowModel->getModule());
 152          return $instance;
 153      }
 154  
 155  	public function getNameFields() {
 156          $moduleModel = $this->getModule();
 157          $nameFieldsList[$moduleModel->getName()] = $moduleModel->getNameFields();
 158  
 159          $fields = $moduleModel->getFieldsByType(array('reference', 'owner', 'multireference'));
 160          foreach($fields as $parentFieldName => $field) {
 161              $type = $field->getFieldDataType();
 162              $referenceModules = $field->getReferenceList();
 163              if($type == 'owner') $referenceModules = array('Users');
 164              foreach($referenceModules as $refModule) {
 165                  $moduleModel = Vtiger_Module_Model::getInstance($refModule);
 166                  $nameFieldsList[$refModule] = $moduleModel->getNameFields();
 167              }
 168          }
 169  
 170          $nameFields = array();
 171          $recordStructure = $this->getStructure();
 172          foreach ($nameFieldsList as $moduleName => $fieldNamesList) {
 173              foreach ($fieldNamesList as $fieldName) {
 174                  foreach($recordStructure as $block => $fields) {
 175                      foreach($fields as $metaKey => $field) {
 176                          if ($fieldName === $field->get('name')) {
 177                              $nameFields[$metaKey] = $field;
 178                          }
 179                      }
 180                  }
 181              }
 182          }
 183          return $nameFields;
 184      }
 185  }


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