1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace Apps\Model\Admin\Comments; |
4
|
|
|
|
5
|
|
|
use Ffcms\Core\Arch\Model; |
6
|
|
|
|
7
|
|
|
/** |
8
|
|
|
* Class FormSettings. Model for settings of comments |
9
|
|
|
* @package Apps\Model\Admin\Comments |
10
|
|
|
*/ |
11
|
|
|
class FormSettings extends Model |
12
|
|
|
{ |
13
|
|
|
public $perPage; |
14
|
|
|
public $delay; |
15
|
|
|
public $minLength; |
16
|
|
|
public $maxLength; |
17
|
|
|
public $guestAdd; |
18
|
|
|
public $editTime; |
19
|
|
|
|
20
|
|
|
private $_configs; |
21
|
|
|
|
22
|
|
|
/** |
23
|
|
|
* FormSettings constructor. Pass array configs from controller. |
24
|
|
|
* @param array $configs |
25
|
|
|
*/ |
26
|
|
|
public function __construct(array $configs) |
27
|
|
|
{ |
28
|
|
|
$this->_configs = $configs; |
29
|
|
|
parent::__construct(); |
30
|
|
|
} |
31
|
|
|
|
32
|
|
|
/** |
33
|
|
|
* Set model properties based on defaults config values |
34
|
|
|
*/ |
35
|
|
|
public function before() |
36
|
|
|
{ |
37
|
|
|
foreach ($this->_configs as $property => $value) { |
38
|
|
|
if (property_exists($this, $property)) { |
39
|
|
|
$this->$property = $value; |
40
|
|
|
} |
41
|
|
|
} |
42
|
|
|
} |
43
|
|
|
|
44
|
|
|
/** |
45
|
|
|
* Labels for form |
46
|
|
|
*/ |
47
|
|
|
public function labels() |
48
|
|
|
{ |
49
|
|
|
return [ |
50
|
|
|
'perPage' => __('Comments count'), |
51
|
|
|
'delay' => __('Delay'), |
52
|
|
|
'minLength' => __('Minimal length'), |
53
|
|
|
'maxLength' => __('Maximum length'), |
54
|
|
|
'guestAdd' => __('Guest add'), |
55
|
|
|
'editTime' => __('Edit time') |
56
|
|
|
]; |
57
|
|
|
} |
58
|
|
|
|
59
|
|
|
/** |
60
|
|
|
* Validation rules for comments settings |
61
|
|
|
*/ |
62
|
|
|
public function rules() |
63
|
|
|
{ |
64
|
|
|
return [ |
65
|
|
|
[['perPage', 'delay', 'minLength', 'maxLength', 'guestAdd', 'editTime'], 'required'], |
66
|
|
|
[['minLength', 'maxLength', 'delay', 'perPage', 'editTime'], 'int'], |
67
|
|
|
['guestAdd', 'in', ['0', '1']] |
68
|
|
|
]; |
69
|
|
|
} |
70
|
|
|
} |