| @@ 11-77 (lines=67) @@ | ||
| 8 | * Class FormSettings. Business logic of content app settings |
|
| 9 | * @package Apps\Model\Admin\Content |
|
| 10 | */ |
|
| 11 | class FormSettings extends Model |
|
| 12 | { |
|
| 13 | public $itemPerCategory; |
|
| 14 | public $userAdd; |
|
| 15 | public $multiCategories; |
|
| 16 | public $galleryResize; |
|
| 17 | public $gallerySize; |
|
| 18 | public $rss; |
|
| 19 | public $rssFull; |
|
| 20 | ||
| 21 | private $_configs; |
|
| 22 | ||
| 23 | /** |
|
| 24 | * FormSettings constructor. Pass config values from controller |
|
| 25 | * @param array|null $configs |
|
| 26 | */ |
|
| 27 | public function __construct(array $configs = null) |
|
| 28 | { |
|
| 29 | $this->_configs = $configs; |
|
| 30 | parent::__construct(); |
|
| 31 | } |
|
| 32 | ||
| 33 | /** |
|
| 34 | * Set model properties based on defaults config values |
|
| 35 | */ |
|
| 36 | public function before() |
|
| 37 | { |
|
| 38 | if ($this->_configs === null) { |
|
| 39 | return; |
|
| 40 | } |
|
| 41 | ||
| 42 | foreach ($this->_configs as $property => $value) { |
|
| 43 | if (property_exists($this, $property)) { |
|
| 44 | $this->$property = $value; |
|
| 45 | } |
|
| 46 | } |
|
| 47 | } |
|
| 48 | ||
| 49 | /** |
|
| 50 | * Form display labels |
|
| 51 | * @return array |
|
| 52 | */ |
|
| 53 | public function labels() |
|
| 54 | { |
|
| 55 | return [ |
|
| 56 | 'itemPerCategory' => __('Content per page'), |
|
| 57 | 'userAdd' => __('User add'), |
|
| 58 | 'multiCategories' => __('Multi categories'), |
|
| 59 | 'galleryResize' => __('Gallery resize'), |
|
| 60 | 'gallerySize' => __('Image size'), |
|
| 61 | 'rss' => __('Rss feed') |
|
| 62 | ]; |
|
| 63 | } |
|
| 64 | ||
| 65 | /** |
|
| 66 | * Validation rules |
|
| 67 | * @return array |
|
| 68 | */ |
|
| 69 | public function rules() |
|
| 70 | { |
|
| 71 | return [ |
|
| 72 | [['itemPerCategory', 'userAdd', 'multiCategories', 'galleryResize', 'rss', 'gallerySize'], 'required'], |
|
| 73 | [['itemPerCategory', 'userAdd', 'multiCategories', 'galleryResize', 'rss', 'gallerySize'], 'int'], |
|
| 74 | [['userAdd', 'multiCategories', 'rss', 'rssFull'], 'in', ['0', '1']] |
|
| 75 | ]; |
|
| 76 | } |
|
| 77 | } |
|
| @@ 11-73 (lines=63) @@ | ||
| 8 | * Class FormSettings. Admin profile settings business logic |
|
| 9 | * @package Apps\Model\Admin\Profile |
|
| 10 | */ |
|
| 11 | class FormSettings extends Model |
|
| 12 | { |
|
| 13 | public $guestView; |
|
| 14 | public $wallPostOnPage; |
|
| 15 | public $delayBetweenPost; |
|
| 16 | public $rating; |
|
| 17 | public $usersOnPage; |
|
| 18 | public $ratingDelay; |
|
| 19 | ||
| 20 | private $_configs; |
|
| 21 | ||
| 22 | /** |
|
| 23 | * Construct model with default values |
|
| 24 | * @param array|null $configs |
|
| 25 | */ |
|
| 26 | public function __construct(array $configs = null) |
|
| 27 | { |
|
| 28 | $this->_configs = $configs; |
|
| 29 | parent::__construct(); |
|
| 30 | } |
|
| 31 | ||
| 32 | public function before() |
|
| 33 | { |
|
| 34 | if ($this->_configs === null) { |
|
| 35 | return; |
|
| 36 | } |
|
| 37 | ||
| 38 | foreach ($this->_configs as $property => $value) { |
|
| 39 | if (property_exists($this, $property)) { |
|
| 40 | $this->{$property} = $value; |
|
| 41 | } |
|
| 42 | } |
|
| 43 | } |
|
| 44 | ||
| 45 | /** |
|
| 46 | * Form display labels |
|
| 47 | * @return array |
|
| 48 | */ |
|
| 49 | public function labels() |
|
| 50 | { |
|
| 51 | return [ |
|
| 52 | 'guestView' => __('Guest view'), |
|
| 53 | 'wallPostOnPage' => __('Post on page'), |
|
| 54 | 'delayBetweenPost' => __('Post delay'), |
|
| 55 | 'rating' => __('Rating'), |
|
| 56 | 'usersOnPage' => __('User per page'), |
|
| 57 | 'ratingDelay' => __('Rating delay') |
|
| 58 | ]; |
|
| 59 | } |
|
| 60 | ||
| 61 | /** |
|
| 62 | * Validation rules |
|
| 63 | * @return array |
|
| 64 | */ |
|
| 65 | public function rules() |
|
| 66 | { |
|
| 67 | return [ |
|
| 68 | [['guestView', 'wallPostOnPage', 'delayBetweenPost', 'rating', 'usersOnPage', 'ratingDelay'], 'required'], |
|
| 69 | [['guestView', 'wallPostOnPage', 'delayBetweenPost', 'rating', 'usersOnPage', 'ratingDelay'], 'int'], |
|
| 70 | [['guestView', 'rating'], 'in', ['0', '1']] |
|
| 71 | ]; |
|
| 72 | } |
|
| 73 | } |
|