|
- <?php
-
- namespace backend\forms;
-
- use domain\Setting\SettingModule;
- use yii\base\Model;
-
- class AdminSettingsForm extends Model
- {
- public function __get($name)
- {
- return SettingModule::getInstance()->getAdminSettingBag()->get($name);
- }
-
- public function __set($name, $value)
- {
- $this->$name = $value;
- }
-
- public function rules()
- {
- $rulesArray = [];
- $typesArray = [
- 'string' => ['string', 'text'],
- 'date' => ['safe'],
- 'boolean' => ['boolean'],
- 'integer' => ['integer'],
- 'double' => ['double', 'float'],
- ];
- foreach($typesArray as $rule => $typesSettingArray) {
- $rulesArray[] = [$this->getSettingNamesByTypeArray($typesSettingArray), $rule];
- }
- return $rulesArray;
- }
-
- public function attributeLabels()
- {
- $attributeLabelsArray = [];
- foreach(SettingModule::getInstance()->getAdminSettingDefinition()->getSettingDetailsFlat() as $settingDetail) {
- $attributeLabelsArray[$settingDetail->getName()] = $settingDetail->getLabel();
- }
- return $attributeLabelsArray;
- }
-
- public function getSettingNamesByTypeArray(array $typesSettingArray): array
- {
- $settingNamesTypeArray = [];
- foreach(SettingModule::getInstance()->getAdminSettingDefinition()->getSettingDetailsFlat() as $settingDetail) {
- if(in_array($settingDetail->getType(), $typesSettingArray)) {
- $settingNamesTypeArray[] = $settingDetail->getName();
- }
- }
- return $settingNamesTypeArray;
- }
- }
-
- ?>
|