public function delete(Vtiger_Request $request) { $response = new Vtiger_Response(); $blockId = $request->get('blockid'); $checkIfFieldsExists = Vtiger_Block_Model::checkFieldsExists($blockId); if ($checkIfFieldsExists) { $response->setError('502', 'Fields exists for the block'); $response->emit(); return; } $blockInstance = Vtiger_Block_Model::getInstance($blockId); if (!$blockInstance->isCustomized()) { $response->setError('502', 'Cannot delete non custom blocks'); $response->emit(); return; } try { $blockInstance->delete(false); $response->setResult(array('success' => true)); } catch (Exception $e) { $response->setError($e->getCode(), $e->getMessage()); } $response->emit(); }
public function delete(Vtiger_Request $request) { $response = new Vtiger_Response(); $blockId = $request->get('blockid'); $checkIfFieldsExists = Vtiger_Block_Model::checkFieldsExists($blockId); if ($checkIfFieldsExists) { $response->setError('502', vtranslate('LBL_FIELDS_EXISTS_IN_BLOCK', $request->getModule(false))); $response->emit(); return; } $blockInstance = Vtiger_Block_Model::getInstance($blockId); if (!$blockInstance->isCustomized()) { $response->setError('502', vtranslate('LBL_DELETE_CUSTOM_BLOCKS', $request->getModule(false))); $response->emit(); return; } try { $blockInstance->delete(false); $response->setResult(array('success' => true)); } catch (Exception $e) { $response->setError($e->getCode(), $e->getMessage()); } $response->emit(); }
/** * Function returns all the blocks for the module * @return <Array of Vtiger_Block_Model> - list of block models */ public function getBlocks() { if (empty($this->blocks)) { $blocksList = array(); $moduleBlocks = Vtiger_Block_Model::getAllForModule($this); foreach ($moduleBlocks as $block) { $blocksList[$block->get('label')] = $block; } $this->blocks = $blocksList; } return $this->blocks; }
public function addField($fieldType, $blockId, $params) { $db = PearDatabase::getInstance(); $label = $params['fieldLabel']; $type = $params['fieldTypeList']; $name = strtolower($params['fieldName']); $fieldparams = ''; if ($this->checkFieldLableExists($label)) { throw new Exception(vtranslate('LBL_DUPLICATE_FIELD_EXISTS', 'Settings::LayoutEditor'), 513); } if ($this->checkFieldNameCharacters($name)) { throw new Exception(vtranslate('LBL_INVALIDCHARACTER', 'Settings::LayoutEditor'), 512); } if ($this->checkFieldNameExists($name)) { throw new Exception(vtranslate('LBL_DUPLICATE_FIELD_EXISTS', 'Settings::LayoutEditor'), 512); } $supportedFieldTypes = $this->getAddSupportedFieldTypes(); if (!in_array($fieldType, $supportedFieldTypes)) { throw new Exception(vtranslate('LBL_WRONG_FIELD_TYPE', 'Settings::LayoutEditor'), 513); } $moduleName = $this->getName(); $focus = CRMEntity::getInstance($moduleName); if ($type == 0) { $columnName = $name; $tableName = $focus->table_name; } elseif ($type == 1) { $max_fieldid = $db->getUniqueID("vtiger_field"); $columnName = 'cf_' . $max_fieldid; $custfld_fieldid = $max_fieldid; if (isset($focus->customFieldTable)) { $tableName = $focus->customFieldTable[0]; } else { $tableName = 'vtiger_' . strtolower($moduleName) . 'cf'; } } if ($fieldType == 'Tree') { $fieldparams = (int) $params['tree']; } elseif ($fieldType == 'MultiReferenceValue') { $fieldparams['module'] = $params['MRVModule']; $fieldparams['field'] = $params['MRVField']; $fieldparams['filterField'] = $params['MRVFilterField']; $fieldparams['filterValue'] = $params['MRVFilterValue']; } $details = $this->getTypeDetailsForAddField($fieldType, $params); $uitype = $details['uitype']; $typeofdata = $details['typeofdata']; $dbType = $details['dbType']; $quickCreate = in_array($moduleName, getInventoryModules()) ? 3 : 1; $fieldModel = new Settings_LayoutEditor_Field_Model(); $fieldModel->set('name', $columnName)->set('table', $tableName)->set('generatedtype', 2)->set('uitype', $uitype)->set('label', $label)->set('typeofdata', $typeofdata)->set('quickcreate', $quickCreate)->set('fieldparams', Zend_Json::encode($fieldparams))->set('columntype', $dbType); if (isset($details['displayType'])) { $fieldModel->set('displaytype', $details['displayType']); } $blockModel = Vtiger_Block_Model::getInstance($blockId, $this); $blockModel->addField($fieldModel); if ($fieldType == 'Picklist' || $fieldType == 'MultiSelectCombo') { $pickListValues = $params['pickListValues']; if (is_string($pickListValues)) { $pickListValues = [$pickListValues]; } $fieldModel->setPicklistValues($pickListValues); } if ($fieldType == 'Related1M') { if (!is_array($params['referenceModule'])) { $moduleList[] = $params['referenceModule']; } else { $moduleList = $params['referenceModule']; } $fieldModel->setRelatedModules($moduleList); foreach ($moduleList as $module) { $targetModule = Vtiger_Module::getInstance($module); $targetModule->setRelatedList($this, $moduleName, array('Add'), 'get_dependents_list'); } } return $fieldModel; }
/** * Function to retrieve block instances for a module * @param <type> $moduleModel - module instance * @return <array> - list of Vtiger_Block_Model */ public static function getAllForModule($moduleModel) { $blockObjects = parent::getAllForModule($moduleModel); $blockModelList = array(); if ($blockObjects) { foreach ($blockObjects as $blockObject) { $blockModelList[] = self::getInstanceFromBlockObject($blockObject); } } return $blockModelList; }
public function addField($fieldType, $blockId, $params) { $db = PearDatabase::getInstance(); $label = $params['fieldLabel']; if ($this->checkFIeldExists($label)) { throw new Exception(vtranslate('LBL_DUPLICATE_FIELD_EXISTS', 'Settings::LayoutEditor'), 513); } $supportedFieldTypes = $this->getAddSupportedFieldTypes(); if (!in_array($fieldType, $supportedFieldTypes)) { throw new Exception(vtranslate('LBL_WRONG_FIELD_TYPE', 'Settings::LayoutEditor'), 513); } $max_fieldid = $db->getUniqueID("vtiger_field"); $columnName = 'cf_' . $max_fieldid; $custfld_fieldid = $max_fieldid; $moduleName = $this->getName(); $focus = CRMEntity::getInstance($moduleName); if (isset($focus->customFieldTable)) { $tableName = $focus->customFieldTable[0]; } else { $tableName = 'vtiger_' . strtolower($moduleName) . 'cf'; } $details = $this->getTypeDetailsForAddField($fieldType, $params); $uitype = $details['uitype']; $typeofdata = $details['typeofdata']; $dbType = $details['dbType']; $quickCreate = in_array($moduleName, getInventoryModules()) ? 3 : 1; $fieldModel = new Settings_LayoutEditor_Field_Model(); $fieldModel->set('name', $columnName)->set('table', $tableName)->set('generatedtype', 2)->set('uitype', $uitype)->set('label', $label)->set('typeofdata', $typeofdata)->set('quickcreate', $quickCreate)->set('columntype', $dbType); $blockModel = Vtiger_Block_Model::getInstance($blockId, $this); $blockModel->addField($fieldModel); if ($fieldType == 'Picklist' || $fieldType == 'MultiSelectCombo') { $pickListValues = explode(',', $params['pickListValues']); $fieldModel->setPicklistValues($pickListValues); } return $fieldModel; }
public function addField($fieldType, $blockId, $params) { $db = PearDatabase::getInstance(); $label = $params['fieldLabel']; if($this->checkFIeldExists($label)){ throw new Exception(vtranslate('LBL_DUPLICATE_FIELD_EXISTS', 'Settings::LayoutEditor'), 513); } $supportedFieldTypes = $this->getAddSupportedFieldTypes(); if(!in_array($fieldType, $supportedFieldTypes)) { throw new Exception(vtranslate('LBL_WRONG_FIELD_TYPE', 'Settings::LayoutEditor'), 513); } $columnName = $params['ColumnName']; $moduleName = $this->getName(); $focus = CRMEntity::getInstance($moduleName); if ($params['fieldTableName'] !== '') { $tableName= $params['fieldTableName']; } elseif (isset($focus->customFieldTable)) { $tableName=$focus->customFieldTable[0]; } else { $tableName= 'vtiger_'.strtolower($moduleName).'cf'; } $details = $this->getTypeDetailsForAddField($fieldType, $params); $uitype = $details['uitype']; $typeofdata = $details['typeofdata']; $dbType = $details['dbType']; $quickCreate = in_array($moduleName, getInventoryModules()) ? 3 : 1; $fieldModel = new Settings_LayoutEditor_Field_Model(); $fieldModel->set('name', $columnName) ->set('table', $tableName) ->set('generatedtype',2) ->set('uitype', $uitype) ->set('label', $label) ->set('typeofdata',$typeofdata) ->set('quickcreate',$quickCreate) ->set('columntype', $dbType); $blockModel = Vtiger_Block_Model::getInstance($blockId, $this); $blockModel->addField($fieldModel); if($fieldType == 'ModuleLinked') { $moduleListNames = explode(',',$params['pickListValues']); foreach ($moduleListNames as $key => $modname) { // проверяем все имена модулей $rmoduleInstance = Vtiger_Module::getInstance($modname); if (!$rmoduleInstance) unset($moduleListNames[$key]); // И удаляем если такого модуля нет } $fieldModel->setRelatedModules($moduleListNames); } if($fieldType == 'Picklist' || $fieldType == 'MultiSelectCombo') { $pickListValues = explode(',',$params['pickListValues']); // можно присоединиться к готовому списку с таким же columnname if ($pickListValues[0] != 'null') $fieldModel->setPicklistValues($pickListValues); } return $fieldModel; }
public function deleteBlocks($blocks) { global $log; $log->debug("Entering YetiForceUpdate::deleteBlocks() method ..."); foreach ($blocks as $block) { $checkIfFieldsExists = Vtiger_Block_Model::checkFieldsExists($block); if (!$checkIfFieldsExists && $block) { $blockInstance = Vtiger_Block_Model::getInstance((int) $block); try { $blockInstance->delete(false); } catch (Exception $e) { $log->debug("ERROR YetiForceUpdate::deleteBlocks: code " . $e->getCode() . " message " . $e->getMessage()); } } } $log->debug("Exiting YetiForceUpdate::deleteBlocks() method ..."); }