/**
  * Function to get the values in stuctured format
  * @return <array> - values in structure array('block'=>array(fieldinfo));
  */
 public function getStructure()
 {
     if (!empty($this->structuredValues)) {
         return $this->structuredValues;
     }
     $recordModel = $this->getWorkFlowModel();
     $recordId = $recordModel->getId();
     $values = array();
     $baseModuleModel = $moduleModel = $this->getModule();
     $blockModelList = $moduleModel->getBlocks();
     foreach ($blockModelList as $blockLabel => $blockModel) {
         $fieldModelList = $blockModel->getFields();
         if (!empty($fieldModelList)) {
             $values[$blockLabel] = array();
             foreach ($fieldModelList as $fieldName => $fieldModel) {
                 if ($fieldModel->isViewable()) {
                     if (in_array($moduleModel->getName(), array('Calendar', 'Events')) && $fieldModel->getDisplayType() == 3) {
                         /* Restricting the following fields(Event module fields) for "Calendar" module
                          * time_start, time_end, eventstatus, activitytype,	visibility, duration_hours,
                          * duration_minutes, reminder_time, recurringtype, notime
                          */
                         continue;
                     }
                     if (!empty($recordId)) {
                         //Set the fieldModel with the valuetype for the client side.
                         $fieldValueType = $recordModel->getFieldFilterValueType($fieldName);
                         $fieldInfo = $fieldModel->getFieldInfo();
                         $fieldInfo['workflow_valuetype'] = $fieldValueType;
                         $fieldModel->setFieldInfo($fieldInfo);
                     }
                     // This will be used during editing task like email, sms etc
                     $fieldModel->set('workflow_columnname', $fieldName)->set('workflow_columnlabel', vtranslate($fieldModel->get('label'), $moduleModel->getName()));
                     // This is used to identify the field belongs to source module of workflow
                     $fieldModel->set('workflow_sourcemodule_field', true);
                     $values[$blockLabel][$fieldName] = clone $fieldModel;
                 }
             }
         }
     }
     if ($moduleModel->isCommentEnabled()) {
         $commentFieldModel = Settings_Workflows_Field_Model::getCommentFieldForFilterConditions($moduleModel);
         $commentFieldModelsList = array($commentFieldModel->getName() => $commentFieldModel);
         $labelName = vtranslate($moduleModel->getSingularLabelKey(), $moduleModel->getName()) . ' ' . vtranslate('LBL_COMMENTS', $moduleModel->getName());
         foreach ($commentFieldModelsList as $commentFieldName => $commentFieldModel) {
             $commentFieldModel->set('workflow_columnname', $commentFieldName)->set('workflow_columnlabel', vtranslate($commentFieldModel->get('label'), $moduleModel->getName()))->set('workflow_sourcemodule_field', true);
             $values[$labelName][$commentFieldName] = $commentFieldModel;
         }
     }
     //All the reference fields should also be sent
     $fields = $moduleModel->getFieldsByType(array('reference', 'owner', 'multireference'));
     foreach ($fields as $parentFieldName => $field) {
         $type = $field->getFieldDataType();
         $referenceModules = $field->getReferenceList();
         if ($type == 'owner') {
             $referenceModules = array('Users');
         }
         foreach ($referenceModules as $refModule) {
             $moduleModel = Vtiger_Module_Model::getInstance($refModule);
             $blockModelList = $moduleModel->getBlocks();
             foreach ($blockModelList as $blockLabel => $blockModel) {
                 $fieldModelList = $blockModel->getFields();
                 if (!empty($fieldModelList)) {
                     foreach ($fieldModelList as $fieldName => $fieldModel) {
                         if ($fieldModel->isViewable()) {
                             $name = "({$parentFieldName} : ({$refModule}) {$fieldName})";
                             $label = vtranslate($field->get('label'), $baseModuleModel->getName()) . ' : (' . vtranslate($refModule, $refModule) . ') ' . vtranslate($fieldModel->get('label'), $refModule);
                             $fieldModel->set('workflow_columnname', $name)->set('workflow_columnlabel', $label);
                             if (!empty($recordId)) {
                                 $fieldValueType = $recordModel->getFieldFilterValueType($name);
                                 $fieldInfo = $fieldModel->getFieldInfo();
                                 $fieldInfo['workflow_valuetype'] = $fieldValueType;
                                 $fieldModel->setFieldInfo($fieldInfo);
                             }
                             $values[$field->get('label')][$name] = clone $fieldModel;
                         }
                     }
                 }
             }
             $commentFieldModelsList = array();
         }
     }
     $this->structuredValues = $values;
     return $values;
 }
Ejemplo n.º 2
0
 public function process(Vtiger_Request $request)
 {
     $recordId = $request->get('record');
     $blockId = $request->get('blockid');
     $views = $request->get('views');
     $qualifiedModuleName = $request->getModule(false);
     $mode = '';
     $viewer = $this->getViewer($request);
     if ($views != '') {
         $views = implode($views, ',');
     }
     if ($recordId) {
         $mode = 'edit';
     } else {
     }
     $moduleModel = Settings_HideBlocks_Record_Model::getModuleInstanceByBlockId($blockId);
     $recordStrucure = Vtiger_RecordStructure_Model::getInstanceForModule($moduleModel);
     $structuredValues = $recordStrucure->getStructure();
     $viewer->assign('RECORD_STRUCTURE', $structuredValues);
     $blockInstance = Vtiger_Block::getInstance($blockId, $moduleModel);
     $blockLabel = $blockInstance->label;
     $blockModelList = $moduleModel->getBlocks();
     $blockModel = $blockModelList[$blockLabel];
     $fieldModelList = $blockModel->getFields();
     $mandatoryFields = array();
     if (!empty($fieldModelList)) {
         $values[$blockLabel] = array();
         foreach ($fieldModelList as $fieldName => $fieldModel) {
             if ($fieldModel->isMandatory()) {
                 $mandatoryFields[$fieldName] = $fieldModel;
             }
         }
     }
     $viewer->assign('MANDATORY_FIELDS', $mandatoryFields);
     //var_dump($structuredValues);
     $dateFilters = Vtiger_Field_Model::getDateFilterTypes();
     foreach ($dateFilters as $comparatorKey => $comparatorInfo) {
         $comparatorInfo['startdate'] = DateTimeField::convertToUserFormat($comparatorInfo['startdate']);
         $comparatorInfo['enddate'] = DateTimeField::convertToUserFormat($comparatorInfo['enddate']);
         $comparatorInfo['label'] = vtranslate($comparatorInfo['label'], $qualifiedModuleName);
         $dateFilters[$comparatorKey] = $comparatorInfo;
     }
     $viewer->assign('DATE_FILTERS', $dateFilters);
     $viewer->assign('ADVANCED_FILTER_OPTIONS', Settings_Workflows_Field_Model::getAdvancedFilterOptions());
     $viewer->assign('ADVANCED_FILTER_OPTIONS_BY_TYPE', Settings_Workflows_Field_Model::getAdvancedFilterOpsByFieldType());
     $viewer->assign('COLUMNNAME_API', 'getName');
     $recordModel = Settings_HideBlocks_Record_Model::getInstanceById($recordId, $qualifiedModuleName);
     if ($recordModel) {
         $viewer->assign('ADVANCE_CRITERIA', $this->transformToAdvancedFilterCondition($recordModel->get('conditions')));
     }
     $viewer->assign('MODE', $mode);
     $viewer->assign('RECORD_ID', $recordId);
     $viewer->assign('MODULE', 'HideBlocks');
     $viewer->assign('SOURCE_MODULE', $moduleModel->get('name'));
     $viewer->assign('QUALIFIED_MODULE', $qualifiedModuleName);
     $viewer->assign('BLOCKID', $blockId);
     $viewer->assign('ENABLED', $request->get('enabled'));
     $viewer->assign('VIEWS', $views);
     $viewer->assign('USER_MODEL', Users_Record_Model::getCurrentUserModel());
     $viewer->view('Conditions.tpl', $qualifiedModuleName);
 }
 /**
  * Function to get the values in stuctured format
  * @return <array> - values in structure array('block'=>array(fieldinfo));
  */
 public function getStructure($FieldDataType = false)
 {
     if ($FieldDataType) {
         $this->no_skip = false;
     }
     if (!empty($this->structuredValues) && $this->no_skip == true) {
         return $this->structuredValues;
     }
     $recordModel = $this->getWorkFlowModel();
     $recordId = $recordModel->getId();
     $values = array();
     $baseModuleModel = $moduleModel = $this->getModule();
     $blockModelList = $moduleModel->getBlocks();
     foreach ($blockModelList as $blockLabel => $blockModel) {
         $fieldModelList = $blockModel->getFields();
         if (!empty($fieldModelList)) {
             $values[$blockLabel] = array();
             foreach ($fieldModelList as $fieldName => $fieldModel) {
                 $DataType = true;
                 if ($FieldDataType && $fieldModel->getFieldDataType() != $FieldDataType) {
                     $DataType = false;
                 }
                 if ($fieldModel->isViewable() && $DataType) {
                     if ($moduleModel->getName() == "Documents" && $fieldName == "filename") {
                         continue;
                     }
                     if (in_array($moduleModel->getName(), array('Calendar', 'Events')) && $fieldModel->getDisplayType() == 3) {
                         /* Restricting the following fields(Event module fields) for "Calendar" module
                          * time_start, time_end, eventstatus, activitytype,	visibility, duration_hours,
                          * duration_minutes, reminder_time, recurringtype, notime
                          */
                         continue;
                     }
                     if (!empty($recordId)) {
                         //Set the fieldModel with the valuetype for the client side.
                         $fieldValueType = $recordModel->getFieldFilterValueType($fieldName);
                         $fieldInfo = $fieldModel->getFieldInfo();
                         $fieldInfo['workflow_valuetype'] = $fieldValueType;
                         $fieldModel->setFieldInfo($fieldInfo);
                     }
                     switch ($fieldModel->getFieldDataType()) {
                         case 'date':
                             if ($moduleName === 'Events' && in_array($fieldName, array('date_start', 'due_date')) || $moduleName === 'Calendar' && $fieldName === 'date_start') {
                                 $fieldName = $fieldName . ' ($(general : (__VtigerMeta__) usertimezone))';
                             } else {
                                 $fieldName = $fieldName . ' ($_DATE_FORMAT_)';
                             }
                             break;
                         case 'datetime':
                             $fieldName = $fieldName . ' ($(general : (__VtigerMeta__) usertimezone))';
                             break;
                         default:
                             $fieldName;
                     }
                     // This will be used during editing task like email, sms etc
                     $fieldModel->set('workflow_columnname', $fieldName)->set('workflow_columnlabel', vtranslate($fieldModel->get('label'), $moduleModel->getName()));
                     // This is used to identify the field belongs to source module of workflow
                     $fieldModel->set('workflow_sourcemodule_field', true);
                     $fieldModel->set('selectOption', $fieldName);
                     $values[$blockLabel][$fieldName] = clone $fieldModel;
                 }
             }
         }
     }
     if ($moduleModel->isCommentEnabled()) {
         $commentFieldModelsList = Settings_Workflows_Field_Model::getCommentFieldsListForTasks($moduleModel);
         $labelName = vtranslate($moduleModel->getSingularLabelKey(), $moduleModel->getName()) . ' ' . vtranslate('LBL_COMMENTS', $moduleModel->getName());
         foreach ($commentFieldModelsList as $commentFieldName => $commentFieldModel) {
             switch ($commentFieldModel->getFieldDataType()) {
                 case 'date':
                     $commentFieldName = $commentFieldName . ' ($_DATE_FORMAT_)';
                     break;
                 case 'datetime':
                     $commentFieldName = $commentFieldName . ' ($(general : (__VtigerMeta__) usertimezone)_)';
                     break;
                 default:
                     $commentFieldName;
             }
             $commentFieldModel->set('workflow_columnname', $commentFieldName)->set('workflow_columnlabel', vtranslate($commentFieldModel->get('label'), $moduleModel->getName()))->set('workflow_sourcemodule_field', true);
             $values[$labelName][$commentFieldName] = $commentFieldModel;
         }
     }
     //All the reference fields should also be sent
     $fields = $moduleModel->getFieldsByType(array('reference', 'owner', 'multireference'));
     foreach ($fields as $parentFieldName => $field) {
         $type = $field->getFieldDataType();
         $referenceModules = $field->getReferenceList();
         if ($type == 'owner') {
             $referenceModules = array('Users');
         }
         foreach ($referenceModules as $refModule) {
             $moduleModel = Vtiger_Module_Model::getInstance($refModule);
             $blockModelList = $moduleModel->getBlocks();
             foreach ($blockModelList as $blockLabel => $blockModel) {
                 $fieldModelList = $blockModel->getFields();
                 if (!empty($fieldModelList)) {
                     foreach ($fieldModelList as $fieldName => $fieldModel) {
                         $DataType = true;
                         if ($FieldDataType && $fieldModel->getFieldDataType() != $FieldDataType) {
                             $DataType = false;
                         }
                         if ($fieldModel->isViewable() && $DataType) {
                             $name = "({$parentFieldName} : ({$refModule}) {$fieldName})";
                             $label = vtranslate($field->get('label'), $baseModuleModel->getName()) . ' : (' . vtranslate($refModule, $refModule) . ') ' . vtranslate($fieldModel->get('label'), $refModule);
                             switch ($fieldModel->getFieldDataType()) {
                                 case 'date':
                                     if ($moduleName === 'Events' && in_array($fieldName, array('date_start', 'due_date')) || $moduleName === 'Calendar' && $fieldName === 'date_start') {
                                         $workflowColumnName = $name . ' ($(general : (__VtigerMeta__) usertimezone))';
                                     } else {
                                         $workflowColumnName = $name . ' ($_DATE_FORMAT_)';
                                     }
                                     break;
                                 case 'datetime':
                                     $workflowColumnName = $name . ' ($(general : (__VtigerMeta__) usertimezone))';
                                     break;
                                 default:
                                     $workflowColumnName = $name;
                             }
                             $fieldModel->set('workflow_columnname', $workflowColumnName)->set('workflow_columnlabel', $label);
                             if (!empty($recordId)) {
                                 $fieldValueType = $recordModel->getFieldFilterValueType($name);
                                 $fieldInfo = $fieldModel->getFieldInfo();
                                 $fieldInfo['workflow_valuetype'] = $fieldValueType;
                                 $fieldModel->setFieldInfo($fieldInfo);
                             }
                             $fieldModel->set('selectOption', $parentFieldName . '=' . $refModule . '=' . $fieldName);
                             $values[$field->get('label')][$name] = clone $fieldModel;
                         }
                     }
                 }
             }
             $commentFieldModelsList = array();
             if ($moduleModel->isCommentEnabled() && $FieldDataType == false) {
                 $labelName = vtranslate($moduleModel->getSingularLabelKey(), $moduleModel->getName()) . ' ' . vtranslate('LBL_COMMENTS', $moduleModel->getName());
                 $commentFieldModelsList = Settings_Workflows_Field_Model::getCommentFieldsListForTasks($moduleModel);
                 foreach ($commentFieldModelsList as $commentFieldName => $commentFieldModel) {
                     $name = "({$parentFieldName} : ({$refModule}) {$commentFieldName})";
                     $label = vtranslate($field->get('label'), $baseModuleModel->getName()) . ' : (' . vtranslate($refModule, $refModule) . ') ' . vtranslate($commentFieldModel->get('label'), $refModule);
                     $commentFieldModel->set('workflow_columnname', $name)->set('workflow_columnlabel', $label);
                     $values[$labelName][$name] = $commentFieldModel;
                 }
             }
         }
     }
     if ($FieldDataType === false) {
         $this->no_skip = true;
     }
     $this->structuredValues = $values;
     return $values;
 }
Ejemplo n.º 4
0
 public function step2(Vtiger_Request $request)
 {
     $viewer = $this->getViewer($request);
     $moduleName = $request->getModule();
     $qualifiedModuleName = $request->getModule(false);
     $recordId = $request->get('record');
     if ($recordId) {
         $workFlowModel = Settings_Workflows_Record_Model::getInstance($recordId);
         $selectedModule = $workFlowModel->getModule();
         $selectedModuleName = $selectedModule->getName();
     } else {
         $selectedModuleName = $request->get('module_name');
         $selectedModule = Vtiger_Module_Model::getInstance($selectedModuleName);
         $workFlowModel = Settings_Workflows_Record_Model::getCleanInstance($selectedModuleName);
     }
     $requestData = $request->getAll();
     foreach ($requestData as $name => $value) {
         if ($name == 'schdayofweek' || $name == 'schdayofmonth' || $name == 'schannualdates') {
             if (is_string($value)) {
                 // need to save these as json data
                 $value = array($value);
             }
         }
         if ($name == 'summary') {
             $value = htmlspecialchars($value);
         }
         $workFlowModel->set($name, $value);
     }
     //Added to support advance filters
     $recordStructureInstance = Settings_Workflows_RecordStructure_Model::getInstanceForWorkFlowModule($workFlowModel, Settings_Workflows_RecordStructure_Model::RECORD_STRUCTURE_MODE_FILTER);
     $viewer->assign('RECORD_STRUCTURE_MODEL', $recordStructureInstance);
     $recordStructure = $recordStructureInstance->getStructure();
     if (in_array($selectedModuleName, getInventoryModules())) {
         $itemsBlock = "LBL_ITEM_DETAILS";
         unset($recordStructure[$itemsBlock]);
     }
     $viewer->assign('RECORD_STRUCTURE', $recordStructure);
     $viewer->assign('WORKFLOW_MODEL', $workFlowModel);
     $viewer->assign('MODULE_MODEL', $selectedModule);
     $viewer->assign('SELECTED_MODULE_NAME', $selectedModuleName);
     $dateFilters = Vtiger_Field_Model::getDateFilterTypes();
     foreach ($dateFilters as $comparatorKey => $comparatorInfo) {
         $comparatorInfo['startdate'] = DateTimeField::convertToUserFormat($comparatorInfo['startdate']);
         $comparatorInfo['enddate'] = DateTimeField::convertToUserFormat($comparatorInfo['enddate']);
         $comparatorInfo['label'] = vtranslate($comparatorInfo['label'], $qualifiedModuleName);
         $dateFilters[$comparatorKey] = $comparatorInfo;
     }
     $viewer->assign('DATE_FILTERS', $dateFilters);
     $viewer->assign('ADVANCED_FILTER_OPTIONS', Settings_Workflows_Field_Model::getAdvancedFilterOptions());
     $viewer->assign('ADVANCED_FILTER_OPTIONS_BY_TYPE', Settings_Workflows_Field_Model::getAdvancedFilterOpsByFieldType());
     $viewer->assign('COLUMNNAME_API', 'getWorkFlowFilterColumnName');
     $viewer->assign('FIELD_EXPRESSIONS', Settings_Workflows_Module_Model::getExpressions());
     $viewer->assign('META_VARIABLES', Settings_Workflows_Module_Model::getMetaVariables());
     // Added to show filters only when saved from vtiger6
     if ($workFlowModel->isFilterSavedInNew()) {
         $viewer->assign('ADVANCE_CRITERIA', $workFlowModel->transformToAdvancedFilterCondition());
     } else {
         $viewer->assign('ADVANCE_CRITERIA', "");
     }
     $viewer->assign('IS_FILTER_SAVED_NEW', $workFlowModel->isFilterSavedInNew());
     $viewer->assign('MODULE', $moduleName);
     $viewer->assign('QUALIFIED_MODULE', $qualifiedModuleName);
     $viewer->view('Step2.tpl', $qualifiedModuleName);
 }