$record - record instance * @return Vtiger_RecordStructure_Model */ public function setRecord($record) { $this->record = $record; return $this; } /** * Function to get the record * @return */ public function getRecord() { return $this->record; } public function getRecordName() { return $this->record->getName(); } /** * Function to get the module * @return */ public function getModule() { return $this->module; } /** * Function to set the module * @param $module - module model * @return Vtiger_RecordStructure_Model */ public function setModule($module) { $this->module = $module; return $this; } /** * Function to get the values in stuctured format * @return - values in structure array('block'=>array(fieldinfo)); */ public function getStructure() { if(!empty($this->structuredValues)) { return $this->structuredValues; } $values = array(); $recordModel = $this->getRecord(); $recordExists = !empty($recordModel); $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($recordExists) { $fieldModel->set('fieldvalue', $recordModel->get($fieldName)); } $values[$blockLabel][$fieldName] = $fieldModel; } } } } $this->structuredValues = $values; return $values; } /** * Function to retieve the instance from record model * @param $recordModel - record instance * @return Vtiger_RecordStructure_Model */ public static function getInstanceFromRecordModel($recordModel, $mode=self::RECORD_STRUCTURE_MODE_DEFAULT) { $moduleModel = $recordModel->getModule(); $className = Vtiger_Loader::getComponentClassName('Model', $mode.'RecordStructure', $moduleModel->getName(true)); $instance = new $className(); $instance->setModule($moduleModel)->setRecord($recordModel); return $instance; } /** * Function to retieve the instance from module model * @param $moduleModel - module instance * @return Vtiger_RecordStructure_Model */ public static function getInstanceForModule($moduleModel, $mode=self::RECORD_STRUCTURE_MODE_DEFAULT) { $className = Vtiger_Loader::getComponentClassName('Model', $mode.'RecordStructure', $moduleModel->get('name')); $instance = new $className(); $instance->setModule($moduleModel); return $instance; } }