1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace Apps\Model\Admin\Profile; |
4
|
|
|
|
5
|
|
|
use Ffcms\Core\Arch\Model; |
6
|
|
|
|
7
|
|
|
/** |
8
|
|
|
* Class FormSettings. Admin profile settings business logic |
9
|
|
|
* @package Apps\Model\Admin\Profile |
10
|
|
|
*/ |
11
|
|
View Code Duplication |
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
|
|
|
} |
Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.
You can also find more detailed suggestions in the “Code” section of your repository.