| @@ 12-70 (lines=59) @@ | ||
| 9 | * Class FormSettings. Feedback app settings business logic |
|
| 10 | * @package Apps\Model\Admin\Feedback |
|
| 11 | */ |
|
| 12 | class FormSettings extends Model |
|
| 13 | { |
|
| 14 | public $guestAdd; |
|
| 15 | public $useCaptcha; |
|
| 16 | ||
| 17 | /** @var array|null $_configs */ |
|
| 18 | private $_configs; |
|
| 19 | ||
| 20 | /** |
|
| 21 | * FormSettings constructor. Pass array of configs inside the model |
|
| 22 | * @param array|null $configs |
|
| 23 | */ |
|
| 24 | public function __construct(array $configs = null) |
|
| 25 | { |
|
| 26 | $this->_configs = $configs; |
|
| 27 | parent::__construct(); |
|
| 28 | } |
|
| 29 | ||
| 30 | /** |
|
| 31 | * Set default model values by passed config array |
|
| 32 | */ |
|
| 33 | public function before() |
|
| 34 | { |
|
| 35 | if ($this->_configs === null) { |
|
| 36 | return; |
|
| 37 | } |
|
| 38 | ||
| 39 | foreach ($this->_configs as $property => $value) { |
|
| 40 | if (property_exists($this, $property)) { |
|
| 41 | $this->{$property} = $value; |
|
| 42 | } |
|
| 43 | } |
|
| 44 | } |
|
| 45 | ||
| 46 | /** |
|
| 47 | * Validation rules |
|
| 48 | * @return array |
|
| 49 | */ |
|
| 50 | public function rules() |
|
| 51 | { |
|
| 52 | return [ |
|
| 53 | [['guestAdd', 'useCaptcha'], 'required'], |
|
| 54 | [['guestAdd', 'useCaptcha'], 'int'], |
|
| 55 | ]; |
|
| 56 | } |
|
| 57 | ||
| 58 | /** |
|
| 59 | * Labels to display in form |
|
| 60 | * @return array |
|
| 61 | */ |
|
| 62 | public function labels() |
|
| 63 | { |
|
| 64 | return [ |
|
| 65 | 'guestAdd' => __('Guest add'), |
|
| 66 | 'useCaptcha' => __('Use captcha') |
|
| 67 | ]; |
|
| 68 | } |
|
| 69 | ||
| 70 | } |
|
| @@ 11-63 (lines=53) @@ | ||
| 8 | * Class FormSettings. Model to transfer and validate input data & attributes for search admin configs. |
|
| 9 | * @package Apps\Model\Admin\Search |
|
| 10 | */ |
|
| 11 | class FormSettings extends Model |
|
| 12 | { |
|
| 13 | public $itemPerApp; |
|
| 14 | public $minLength; |
|
| 15 | ||
| 16 | private $_configs; |
|
| 17 | ||
| 18 | /** |
|
| 19 | * ForumSettings constructor. Construct model with default values |
|
| 20 | * @param array|null $configs |
|
| 21 | */ |
|
| 22 | public function __construct(array $configs = null) |
|
| 23 | { |
|
| 24 | $this->_configs = $configs; |
|
| 25 | parent::__construct(); |
|
| 26 | } |
|
| 27 | ||
| 28 | public function before() |
|
| 29 | { |
|
| 30 | if ($this->_configs === null) { |
|
| 31 | return; |
|
| 32 | } |
|
| 33 | foreach ($this->_configs as $property => $value) { |
|
| 34 | if (property_exists($this, $property)) { |
|
| 35 | $this->$property = $value; |
|
| 36 | } |
|
| 37 | } |
|
| 38 | } |
|
| 39 | ||
| 40 | /** |
|
| 41 | * Labels for admin settings form |
|
| 42 | * @return array |
|
| 43 | */ |
|
| 44 | public function labels() |
|
| 45 | { |
|
| 46 | return [ |
|
| 47 | 'itemPerApp' => __('Search count'), |
|
| 48 | 'minLength' => __('Min length') |
|
| 49 | ]; |
|
| 50 | } |
|
| 51 | ||
| 52 | /** |
|
| 53 | * Validation rules |
|
| 54 | * @return @array |
|
| 55 | */ |
|
| 56 | public function rules() |
|
| 57 | { |
|
| 58 | return [ |
|
| 59 | [['itemPerApp', 'minLength'], 'required'], |
|
| 60 | [['itemPerApp', 'minLength'], 'int'] |
|
| 61 | ]; |
|
| 62 | } |
|
| 63 | } |
|