1 | <?php |
||
18 | class Settings extends BackendController |
||
19 | { |
||
20 | |||
21 | /** |
||
22 | * Google Analytics Report Report model instance |
||
23 | * @var \gplcart\modules\ga_report\models\Report $ga_report_model |
||
24 | */ |
||
25 | protected $ga_report_model; |
||
26 | |||
27 | /** |
||
28 | * @param GaReportModuleReportModel $ga_report_model |
||
29 | */ |
||
30 | public function __construct(GaReportModuleReportModel $ga_report_model) |
||
31 | { |
||
32 | parent::__construct(); |
||
33 | |||
34 | $this->ga_report_model = $ga_report_model; |
||
35 | } |
||
36 | |||
37 | /** |
||
38 | * Route page callback |
||
39 | * Displays the module settings page |
||
40 | */ |
||
41 | public function editSettings() |
||
42 | { |
||
43 | $this->setTitleEditSettings(); |
||
44 | $this->setBreadcrumbEditSettings(); |
||
45 | |||
46 | $this->setData('stores', $this->store->getList()); |
||
47 | $this->setData('credentials', $this->getCredentialSettings()); |
||
48 | $this->setData('handlers', $this->ga_report_model->getHandlers()); |
||
49 | $this->setData('settings', $this->module->getSettings('ga_report')); |
||
50 | |||
51 | $this->submitSettings(); |
||
52 | $this->outputEditSettings(); |
||
53 | } |
||
54 | |||
55 | /** |
||
56 | * Returns an array of Google API credentials |
||
57 | * @return array |
||
58 | */ |
||
59 | protected function getCredentialSettings() |
||
60 | { |
||
61 | /** @var \gplcart\modules\gapi\Main $instance */ |
||
62 | $instance = $this->module->getInstance('gapi'); |
||
63 | return $instance->getCredentials(array('type' => 'service')); |
||
64 | } |
||
65 | |||
66 | /** |
||
67 | * Set title on the module settings page |
||
68 | */ |
||
69 | protected function setTitleEditSettings() |
||
70 | { |
||
71 | $title = $this->text('Edit %name settings', array( |
||
72 | '%name' => $this->text('Google Analytics Report'))); |
||
73 | |||
74 | $this->setTitle($title); |
||
75 | } |
||
76 | |||
77 | /** |
||
78 | * Set breadcrumbs on the module settings page |
||
79 | */ |
||
80 | protected function setBreadcrumbEditSettings() |
||
81 | { |
||
82 | $breadcrumbs = array(); |
||
83 | |||
84 | $breadcrumbs[] = array( |
||
85 | 'url' => $this->url('admin'), |
||
86 | 'text' => $this->text('Dashboard') |
||
87 | ); |
||
88 | |||
89 | $breadcrumbs[] = array( |
||
90 | 'text' => $this->text('Modules'), |
||
91 | 'url' => $this->url('admin/module/list') |
||
92 | ); |
||
93 | |||
94 | $this->setBreadcrumbs($breadcrumbs); |
||
95 | } |
||
96 | |||
97 | /** |
||
98 | * Saves the submitted settings |
||
99 | */ |
||
100 | protected function submitSettings() |
||
101 | { |
||
102 | if ($this->isPosted('clear_cache')) { |
||
103 | $this->deleteCacheSettings(); |
||
104 | } else if ($this->isPosted('save') && $this->validateSettings()) { |
||
105 | $this->updateSettings(); |
||
106 | } |
||
107 | } |
||
108 | |||
109 | /** |
||
110 | * Deletes all Google Analytics cached data |
||
111 | */ |
||
112 | protected function deleteCacheSettings() |
||
117 | |||
118 | /** |
||
119 | * Validate submitted module settings |
||
120 | */ |
||
121 | protected function validateSettings() |
||
122 | { |
||
123 | $this->setSubmitted('settings'); |
||
133 | |||
134 | /** |
||
135 | * Validates Google Analytics profiles |
||
136 | */ |
||
137 | protected function validateGaProfileSettings() |
||
163 | |||
164 | /** |
||
165 | * Update module settings |
||
166 | */ |
||
167 | protected function updateSettings() |
||
174 | |||
175 | /** |
||
176 | * Render and output the module settings page |
||
177 | */ |
||
178 | protected function outputEditSettings() |
||
182 | |||
183 | } |
||
184 |