1 | <?php |
||
21 | class Setting extends BaseSetting |
||
22 | { |
||
23 | /** |
||
24 | * @param bool $forDropDown if false - return array or validators, true - key=>value for dropDown |
||
25 | * @return array |
||
26 | */ |
||
27 | 24 | public function getTypes($forDropDown = true) |
|
28 | { |
||
29 | $values = [ |
||
30 | 24 | 'string' => ['value', 'string'], |
|
31 | 24 | 'integer' => ['value', 'integer'], |
|
32 | 24 | 'boolean' => ['value', 'boolean', 'trueValue' => "1", 'falseValue' => "0", 'strict' => true], |
|
33 | 24 | 'float' => ['value', 'number'], |
|
34 | 24 | 'email' => ['value', 'email'], |
|
35 | 24 | 'ip' => ['value', 'ip'], |
|
36 | 24 | 'url' => ['value', 'url'], |
|
37 | 'object' => [ |
||
38 | 24 | 'value', |
|
39 | function ($attribute, $params) { |
||
|
|||
40 | $object = null; |
||
41 | try { |
||
42 | Json::decode($this->$attribute); |
||
43 | } catch (InvalidParamException $e) { |
||
44 | $this->addError($attribute, Module::t('settings', '"{attribute}" must be a valid JSON object', [ |
||
45 | 'attribute' => $attribute, |
||
46 | ])); |
||
47 | } |
||
48 | } |
||
49 | 24 | ], |
|
50 | 24 | ]; |
|
51 | |||
52 | 24 | if (!$forDropDown) { |
|
53 | 24 | return $values; |
|
54 | } |
||
55 | |||
56 | 1 | $return = []; |
|
57 | 1 | foreach ($values as $key => $value) { |
|
58 | 1 | $return[$key] = Module::t('settings', $key); |
|
59 | 1 | } |
|
60 | |||
61 | 1 | return $return; |
|
62 | } |
||
63 | |||
64 | /** |
||
65 | * @inheritdoc |
||
66 | */ |
||
67 | 24 | public function rules() |
|
68 | { |
||
69 | return [ |
||
70 | 24 | [['value'], 'string'], |
|
71 | 24 | [['section', 'key'], 'string', 'max' => 255], |
|
72 | [ |
||
73 | 24 | ['key'], |
|
74 | 24 | 'unique', |
|
75 | 24 | 'targetAttribute' => ['section', 'key'], |
|
76 | 'message' => |
||
77 | 24 | Module::t('settings', '{attribute} "{value}" already exists for this section.') |
|
78 | 24 | ], |
|
79 | 24 | ['type', 'in', 'range' => array_keys($this->getTypes(false))], |
|
80 | 24 | [['type', 'created', 'modified'], 'safe'], |
|
81 | 24 | [['active'], 'boolean'], |
|
82 | 24 | ]; |
|
83 | } |
||
84 | |||
85 | 22 | public function beforeSave($insert) |
|
110 | |||
111 | /** |
||
112 | * @inheritdoc |
||
113 | */ |
||
114 | 4 | public function attributeLabels() |
|
127 | } |
||
128 |
This check looks from parameters that have been defined for a function or method, but which are not used in the method body.