|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
namespace humhub\modules\privacybox\models\forms; |
|
4
|
|
|
|
|
5
|
|
|
use Yii; |
|
6
|
|
|
|
|
7
|
|
|
class EditForm extends \yii\base\Model |
|
8
|
|
|
{ |
|
9
|
|
|
|
|
10
|
|
|
public $active; |
|
11
|
|
|
public $title; |
|
12
|
|
|
public $content; |
|
13
|
|
|
public $reset; |
|
14
|
|
|
public $statement; |
|
15
|
|
|
|
|
16
|
|
|
/** |
|
17
|
|
|
* @inheritdocs |
|
18
|
|
|
*/ |
|
19
|
|
|
public function rules() |
|
20
|
|
|
{ |
|
21
|
|
|
return array( |
|
22
|
|
|
array(['title', 'content', 'statement'], 'required'), |
|
23
|
|
|
array(['reset', 'active'], 'safe') |
|
24
|
|
|
); |
|
25
|
|
|
} |
|
26
|
|
|
|
|
27
|
|
|
/** |
|
28
|
|
|
* @inheritdocs |
|
29
|
|
|
*/ |
|
30
|
|
|
public function init() |
|
31
|
|
|
{ |
|
32
|
|
|
$settings = Yii::$app->getModule('privacybox')->settings; |
|
33
|
|
|
$this->title = $settings->get('title', Yii::t('PrivacyboxModule.models_forms_EditForm', 'Privacy Policy')); |
|
34
|
|
|
$this->statement = $settings->get('statement', Yii::t('PrivacyboxModule.models_forms_EditForm', 'Please Read and Agree to our Privacy Policy')); |
|
35
|
|
|
$this->content = $settings->get('content'); |
|
36
|
|
|
$this->active = $settings->get('active', false); |
|
37
|
|
|
} |
|
38
|
|
|
|
|
39
|
|
|
/** |
|
40
|
|
|
* Declares customized attribute labels. |
|
41
|
|
|
* If not declared here, an attribute would have a label that is |
|
42
|
|
|
* the same as its name with the first letter in upper case. |
|
43
|
|
|
*/ |
|
44
|
|
|
public function attributeLabels() |
|
45
|
|
|
{ |
|
46
|
|
|
return array( |
|
47
|
|
|
'active' => Yii::t('PrivacyboxModule.models_forms_EditForm', 'Active'), |
|
48
|
|
|
'title' => Yii::t('PrivacyboxModule.models_forms_EditForm', 'Title'), |
|
49
|
|
|
'statement' => Yii::t('PrivacyboxModule.models_forms_EditForm', 'Statement'), |
|
50
|
|
|
'content' => Yii::t('PrivacyboxModule.models_forms_EditForm', 'Content'), |
|
51
|
|
|
'reset' => Yii::t('PrivacyboxModule.models_forms_EditForm', 'Mark as unseen for all users'), |
|
52
|
|
|
); |
|
53
|
|
|
} |
|
54
|
|
|
|
|
55
|
|
|
/** |
|
56
|
|
|
* Saves the given form settings. |
|
57
|
|
|
*/ |
|
58
|
|
|
public function save() |
|
59
|
|
|
{ |
|
60
|
|
|
$settings = Yii::$app->getModule('privacybox')->settings; |
|
61
|
|
|
$settings->set('title', $this->title); |
|
62
|
|
|
$settings->set('statement', $this->statement); |
|
63
|
|
|
$settings->set('content', $this->content); |
|
64
|
|
|
|
|
65
|
|
|
if ($this->active) { |
|
66
|
|
|
$settings->set('active', true); |
|
67
|
|
|
} else { |
|
68
|
|
|
$settings->set('active', false); |
|
69
|
|
|
} |
|
70
|
|
|
|
|
71
|
|
|
// Note the reset flag only affects the timestamp if the conditionas are active |
|
72
|
|
|
$lastTimeStamp = $settings->get('timestamp'); |
|
73
|
|
|
if ($this->active && ($this->reset || $lastTimeStamp == null)) { |
|
74
|
|
|
$settings->set('timestamp', time()); |
|
75
|
|
|
} |
|
76
|
|
|
|
|
77
|
|
|
return true; |
|
78
|
|
|
} |
|
79
|
|
|
|
|
80
|
|
|
} |
|
81
|
|
|
|