public function getStructureSettings() { /** @var StructureSetting[] $aStructureSettings */ $aStructureSettings = $this->findRelationCache($this->getPrimaryKeyName(), StructureSetting::cls()); if (empty($aStructureSettings)) { $oStructureSettings = DataSource::factory(StructureSetting::cls()); $oStructureSettings->builder()->where("structure_id={$this->getPrimaryKey()}"); $aStructureSettings = $oStructureSettings->findAll(); foreach ($aStructureSettings as $oStructureSetting) { $this->addRelationCache('id', $oStructureSetting); $oStructureSetting->addRelationCache('structure_id', $this); } } return $aStructureSettings; }
protected function getModuleConfigView(Structure $oStructure, Module $oModule) { $moduleConfigView = new ViewModuleConfiguration(); $settings = []; if ($oModule->getPrimaryKey()) { $aModulesSettings = $oModule->getModuleSettings(); foreach ($aModulesSettings as $oModuleSetting) { $type = Module::TYPE_LIST; if (!is_null($oModuleSetting->entity)) { $oEntities = DataSource::factory($oModuleSetting->entity); $oEntities->builder()->where('deleted=0'); $list = $oEntities->findAll(); $type = Module::TYPE_ENTITY; } elseif (!is_null($oModuleSetting->list)) { $list = json_decode($oModuleSetting->list, true); } else { $list = []; } $oStructureSetting = null; if ($oStructure->id) { $oStructureSettings = DataSource::factory(StructureSetting::cls()); $oStructureSettings->builder()->where("structure_id={$oStructure->getPrimaryKey()}")->whereAnd()->where("module_setting_id={$oModuleSetting->getPrimaryKey()}"); /** @var StructureSetting[] $aStructureSettings */ $aStructureSettings = $oStructureSettings->findAll(); if (!empty($aStructureSettings)) { $oStructureSetting = $aStructureSettings[0]; } } $settings[] = ['type' => $type, 'setting' => $oModuleSetting, 'list' => $list, 'value' => is_null($oStructureSetting) ? null : $oStructureSetting->value]; } } $moduleConfigView->settings = $settings; return $moduleConfigView; }
protected function saveStructureSettings(Structure $oStructure) { /** @var Module $oModule */ $oModule = $oStructure->getModule(); /** @var ModuleSetting[] $aModuleSettings */ $aModuleSettings = $oModule->getModuleSettings(); foreach ($aModuleSettings as $oModuleSetting) { /** @var StructureSetting $oStructureSettings */ $oStructureSettings = DataSource::factory(StructureSetting::cls()); $oStructureSettings->builder()->where("module_setting_id={$oModuleSetting->id}")->whereAnd()->where("structure_id={$oStructure->id}"); /** @var StructureSetting[] $aStructureSettings */ $aStructureSettings = $oStructureSettings->findAll(); if (!empty($aStructureSettings)) { $oStructureSetting = $aStructureSettings[0]; $oStructureSetting->value = is_null($oModuleSetting->entity) ? (string) Param::post($oModuleSetting->parameter, false)->asString() : (string) Param::post($oModuleSetting->parameter, false)->asInteger(); $oStructureSetting->commit(); } else { /** @var StructureSetting $oNewStructureSetting */ $oNewStructureSetting = DataSource::factory(StructureSetting::cls()); $oNewStructureSetting->structure_id = $oStructure->id; $oNewStructureSetting->module_setting_id = $oModuleSetting->id; $oNewStructureSetting->value = is_null($oModuleSetting->entity) ? Param::post($oModuleSetting->parameter)->asString() : Param::post($oModuleSetting->parameter)->asInteger(); $oNewStructureSetting->commit(); } } }