|
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657 |
- <?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' => ['date'],
- '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;
- }
- }
-
- ?>
|