|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
/** |
|
4
|
|
|
* @package Zopim |
|
5
|
|
|
* @author Iurii Makukh <[email protected]> |
|
6
|
|
|
* @copyright Copyright (c) 2017, Iurii Makukh <[email protected]> |
|
7
|
|
|
* @license https://www.gnu.org/licenses/gpl-3.0.en.html GNU General Public License 3.0 |
|
8
|
|
|
*/ |
|
9
|
|
|
|
|
10
|
|
|
namespace gplcart\modules\zopim\controllers; |
|
11
|
|
|
|
|
12
|
|
|
use gplcart\core\controllers\backend\Controller; |
|
13
|
|
|
use gplcart\core\models\Trigger; |
|
14
|
|
|
|
|
15
|
|
|
/** |
|
16
|
|
|
* Handles incoming requests and outputs data related to Zopim module |
|
17
|
|
|
*/ |
|
18
|
|
|
class Settings extends Controller |
|
19
|
|
|
{ |
|
20
|
|
|
|
|
21
|
|
|
/** |
|
22
|
|
|
* Trigger model instance |
|
23
|
|
|
* @var \gplcart\core\models\Trigger $trigger |
|
24
|
|
|
*/ |
|
25
|
|
|
protected $trigger; |
|
26
|
|
|
|
|
27
|
|
|
/** |
|
28
|
|
|
* Settings constructor. |
|
29
|
|
|
* @param Trigger $trigger |
|
30
|
|
|
*/ |
|
31
|
|
|
public function __construct(Trigger $trigger) |
|
32
|
|
|
{ |
|
33
|
|
|
parent::__construct(); |
|
34
|
|
|
|
|
35
|
|
|
$this->trigger = $trigger; |
|
36
|
|
|
} |
|
37
|
|
|
|
|
38
|
|
|
/** |
|
39
|
|
|
* Route page callback to display the module settings page |
|
40
|
|
|
*/ |
|
41
|
|
|
public function editSettings() |
|
42
|
|
|
{ |
|
43
|
|
|
$this->setTitleEditSettings(); |
|
44
|
|
|
$this->setBreadcrumbEditSettings(); |
|
45
|
|
|
|
|
46
|
|
|
$this->setData('triggers', $this->trigger->getList()); |
|
47
|
|
|
$this->setData('settings', $this->module->getSettings('zopim')); |
|
48
|
|
|
|
|
49
|
|
|
$this->submitSettings(); |
|
50
|
|
|
$this->outputEditSettings(); |
|
51
|
|
|
} |
|
52
|
|
|
|
|
53
|
|
|
/** |
|
54
|
|
|
* Set title on the module settings page |
|
55
|
|
|
*/ |
|
56
|
|
|
protected function setTitleEditSettings() |
|
57
|
|
|
{ |
|
58
|
|
|
$title = $this->text('Edit %name settings', array('%name' => $this->text('Zopim'))); |
|
59
|
|
|
$this->setTitle($title); |
|
60
|
|
|
} |
|
61
|
|
|
|
|
62
|
|
|
/** |
|
63
|
|
|
* Set breadcrumbs on the module settings page |
|
64
|
|
|
*/ |
|
65
|
|
|
protected function setBreadcrumbEditSettings() |
|
66
|
|
|
{ |
|
67
|
|
|
$breadcrumbs = array(); |
|
68
|
|
|
|
|
69
|
|
|
$breadcrumbs[] = array( |
|
70
|
|
|
'text' => $this->text('Dashboard'), |
|
71
|
|
|
'url' => $this->url('admin') |
|
72
|
|
|
); |
|
73
|
|
|
|
|
74
|
|
|
$breadcrumbs[] = array( |
|
75
|
|
|
'text' => $this->text('Modules'), |
|
76
|
|
|
'url' => $this->url('admin/module/list') |
|
77
|
|
|
); |
|
78
|
|
|
|
|
79
|
|
|
$this->setBreadcrumbs($breadcrumbs); |
|
80
|
|
|
} |
|
81
|
|
|
|
|
82
|
|
|
/** |
|
83
|
|
|
* Saves the submitted settings |
|
84
|
|
|
*/ |
|
85
|
|
|
protected function submitSettings() |
|
86
|
|
|
{ |
|
87
|
|
|
if ($this->isPosted('save') && $this->validateSettings()) { |
|
88
|
|
|
$this->updateSettings(); |
|
89
|
|
|
} |
|
90
|
|
|
} |
|
91
|
|
|
|
|
92
|
|
|
/** |
|
93
|
|
|
* Validate submitted module settings |
|
94
|
|
|
*/ |
|
95
|
|
|
protected function validateSettings() |
|
96
|
|
|
{ |
|
97
|
|
|
$this->setSubmitted('settings'); |
|
98
|
|
|
return !$this->hasErrors(); |
|
99
|
|
|
} |
|
100
|
|
|
|
|
101
|
|
|
/** |
|
102
|
|
|
* Update module settings |
|
103
|
|
|
*/ |
|
104
|
|
|
protected function updateSettings() |
|
105
|
|
|
{ |
|
106
|
|
|
$this->controlAccess('module_edit'); |
|
107
|
|
|
$this->module->setSettings('zopim', $this->getSubmitted()); |
|
108
|
|
|
$this->redirect('', $this->text('Settings have been updated'), 'success'); |
|
109
|
|
|
} |
|
110
|
|
|
|
|
111
|
|
|
/** |
|
112
|
|
|
* Render and output the module settings page |
|
113
|
|
|
*/ |
|
114
|
|
|
protected function outputEditSettings() |
|
115
|
|
|
{ |
|
116
|
|
|
$this->output('zopim|settings'); |
|
117
|
|
|
} |
|
118
|
|
|
|
|
119
|
|
|
} |
|
120
|
|
|
|