1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
/** |
4
|
|
|
* @package Authorize.Net |
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\authorize\controllers; |
11
|
|
|
|
12
|
|
|
use gplcart\core\controllers\backend\Controller; |
13
|
|
|
use gplcart\core\models\Order; |
14
|
|
|
|
15
|
|
|
/** |
16
|
|
|
* Handles incoming requests and outputs data related to Authorize.Net module |
17
|
|
|
*/ |
18
|
|
|
class Settings extends Controller |
19
|
|
|
{ |
20
|
|
|
|
21
|
|
|
/** |
22
|
|
|
* Order model instance |
23
|
|
|
* @var \gplcart\core\models\Order $order |
24
|
|
|
*/ |
25
|
|
|
protected $order; |
26
|
|
|
|
27
|
|
|
/** |
28
|
|
|
* @param Order $order |
29
|
|
|
*/ |
30
|
|
|
public function __construct(Order $order) |
31
|
|
|
{ |
32
|
|
|
parent::__construct(); |
33
|
|
|
|
34
|
|
|
$this->order = $order; |
35
|
|
|
} |
36
|
|
|
|
37
|
|
|
/** |
38
|
|
|
* Route page callback to display module settings form |
39
|
|
|
*/ |
40
|
|
|
public function editSettings() |
41
|
|
|
{ |
42
|
|
|
$this->setTitleEditSettings(); |
43
|
|
|
$this->setBreadcrumbEditSettings(); |
44
|
|
|
|
45
|
|
|
$this->setData('statuses', $this->order->getStatuses()); |
46
|
|
|
$this->setData('settings', $this->module->getSettings('authorize')); |
47
|
|
|
|
48
|
|
|
$this->submitSettings(); |
49
|
|
|
$this->outputEditSettings(); |
50
|
|
|
} |
51
|
|
|
|
52
|
|
|
/** |
53
|
|
|
* Saves the submitted settings |
54
|
|
|
*/ |
55
|
|
|
protected function submitSettings() |
56
|
|
|
{ |
57
|
|
|
if ($this->isPosted('save') && $this->validateSettings()) { |
58
|
|
|
$this->updateSettings(); |
59
|
|
|
} |
60
|
|
|
} |
61
|
|
|
|
62
|
|
|
/** |
63
|
|
|
* Updates module settings |
64
|
|
|
*/ |
65
|
|
|
protected function updateSettings() |
66
|
|
|
{ |
67
|
|
|
$this->controlAccess('module_edit'); |
68
|
|
|
$this->module->setSettings('authorize', $this->getSubmitted()); |
69
|
|
|
$this->redirect('admin/module/list', $this->text('Settings have been updated'), 'success'); |
70
|
|
|
} |
71
|
|
|
|
72
|
|
|
/** |
73
|
|
|
* Validates module settings |
74
|
|
|
* @return bool |
75
|
|
|
*/ |
76
|
|
|
protected function validateSettings() |
77
|
|
|
{ |
78
|
|
|
$this->setSubmitted('settings'); |
79
|
|
|
$this->setSubmittedBool('status'); |
80
|
|
|
|
81
|
|
|
return !$this->hasErrors('settings'); |
82
|
|
|
} |
83
|
|
|
|
84
|
|
|
/** |
85
|
|
|
* Set title on the edit module settings page |
86
|
|
|
*/ |
87
|
|
|
protected function setTitleEditSettings() |
88
|
|
|
{ |
89
|
|
|
$title = $this->text('Edit %name settings', array('%name' => $this->text('Authorize'))); |
90
|
|
|
$this->setTitle($title); |
91
|
|
|
} |
92
|
|
|
|
93
|
|
|
/** |
94
|
|
|
* Set breadcrumbs on the edit module settings page |
95
|
|
|
*/ |
96
|
|
|
protected function setBreadcrumbEditSettings() |
97
|
|
|
{ |
98
|
|
|
$breadcrumbs = array(); |
99
|
|
|
|
100
|
|
|
$breadcrumbs[] = array( |
101
|
|
|
'text' => $this->text('Dashboard'), |
102
|
|
|
'url' => $this->url('admin') |
103
|
|
|
); |
104
|
|
|
|
105
|
|
|
$breadcrumbs[] = array( |
106
|
|
|
'text' => $this->text('Modules'), |
107
|
|
|
'url' => $this->url('admin/module/list') |
108
|
|
|
); |
109
|
|
|
|
110
|
|
|
$this->setBreadcrumbs($breadcrumbs); |
111
|
|
|
} |
112
|
|
|
|
113
|
|
|
/** |
114
|
|
|
* Render and output the edit module settings page |
115
|
|
|
*/ |
116
|
|
|
protected function outputEditSettings() |
117
|
|
|
{ |
118
|
|
|
$this->output('authorize|settings'); |
119
|
|
|
} |
120
|
|
|
|
121
|
|
|
} |
122
|
|
|
|