選択できるのは25トピックまでです。 トピックは、先頭が英数字で、英数字とダッシュ('-')を使用した35文字以内のものにしてください。

AdminSettingsForm.php 1.6KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657
  1. <?php
  2. namespace backend\forms;
  3. use domain\Setting\SettingModule;
  4. use yii\base\Model;
  5. class AdminSettingsForm extends Model
  6. {
  7. public function __get($name)
  8. {
  9. return SettingModule::getInstance()->getAdminSettingBag()->get($name);
  10. }
  11. public function __set($name, $value)
  12. {
  13. $this->$name = $value;
  14. }
  15. public function rules()
  16. {
  17. $rulesArray = [];
  18. $typesArray = [
  19. 'string' => ['string', 'text'],
  20. 'date' => ['safe'],
  21. 'boolean' => ['boolean'],
  22. 'integer' => ['integer'],
  23. 'double' => ['double', 'float'],
  24. ];
  25. foreach($typesArray as $rule => $typesSettingArray) {
  26. $rulesArray[] = [$this->getSettingNamesByTypeArray($typesSettingArray), $rule];
  27. }
  28. return $rulesArray;
  29. }
  30. public function attributeLabels()
  31. {
  32. $attributeLabelsArray = [];
  33. foreach(SettingModule::getInstance()->getAdminSettingDefinition()->getSettingDetailsFlat() as $settingDetail) {
  34. $attributeLabelsArray[$settingDetail->getName()] = $settingDetail->getLabel();
  35. }
  36. return $attributeLabelsArray;
  37. }
  38. public function getSettingNamesByTypeArray(array $typesSettingArray): array
  39. {
  40. $settingNamesTypeArray = [];
  41. foreach(SettingModule::getInstance()->getAdminSettingDefinition()->getSettingDetailsFlat() as $settingDetail) {
  42. if(in_array($settingDetail->getType(), $typesSettingArray)) {
  43. $settingNamesTypeArray[] = $settingDetail->getName();
  44. }
  45. }
  46. return $settingNamesTypeArray;
  47. }
  48. }
  49. ?>