-
Notifications
You must be signed in to change notification settings - Fork 14
Expand file tree
/
Copy pathmy_module.php
More file actions
158 lines (128 loc) · 5.42 KB
/
my_module.php
File metadata and controls
158 lines (128 loc) · 5.42 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
<?php
################################################################################################
# DIY Module Builder for Opencart 1.5.1.x From HostJars http://opencart.hostjars.com #
################################################################################################
class ControllerModuleMyModule extends Controller {
private $error = array();
public function index() {
//Load the language file for this module
$this->load->language('module/my_module');
//Set the title from the language file $_['heading_title'] string
$this->document->setTitle($this->language->get('heading_title'));
//Load the settings model. You can also add any other models you want to load here.
$this->load->model('setting/setting');
//Save the settings if the user has submitted the admin form (ie if someone has pressed save).
if (($this->request->server['REQUEST_METHOD'] == 'POST') && $this->validate()) {
$this->model_setting_setting->editSetting('my_module', $this->request->post);
$this->session->data['success'] = $this->language->get('text_success');
$this->redirect($this->url->link('extension/module', 'token=' . $this->session->data['token'], 'SSL'));
}
//This is how the language gets pulled through from the language file.
//
// If you want to use any extra language items - ie extra text on your admin page for any reason,
// then just add an extra line to the $text_strings array with the name you want to call the extra text,
// then add the same named item to the $_[] array in the language file.
//
// 'my_module_example' is added here as an example of how to add - see admin/language/english/module/my_module.php for the
// other required part.
$text_strings = array(
'heading_title',
'text_enabled',
'text_disabled',
'text_content_top',
'text_content_bottom',
'text_column_left',
'text_column_right',
'entry_layout',
'entry_limit',
'entry_image',
'entry_position',
'entry_status',
'entry_sort_order',
'button_save',
'button_cancel',
'button_add_module',
'button_remove',
'entry_example' //this is an example extra field added
);
foreach ($text_strings as $text) {
$this->data[$text] = $this->language->get($text);
}
//END LANGUAGE
//The following code pulls in the required data from either config files or user
//submitted data (when the user presses save in admin). Add any extra config data
// you want to store.
//
// NOTE: These must have the same names as the form data in your my_module.tpl file
//
$config_data = array(
'my_module_example' //this becomes available in our view by the foreach loop just below.
);
foreach ($config_data as $conf) {
if (isset($this->request->post[$conf])) {
$this->data[$conf] = $this->request->post[$conf];
} else {
$this->data[$conf] = $this->config->get($conf);
}
}
//This creates an error message. The error['warning'] variable is set by the call to function validate() in this controller (below)
if (isset($this->error['warning'])) {
$this->data['error_warning'] = $this->error['warning'];
} else {
$this->data['error_warning'] = '';
}
//SET UP BREADCRUMB TRAIL. YOU WILL NOT NEED TO MODIFY THIS UNLESS YOU CHANGE YOUR MODULE NAME.
$this->data['breadcrumbs'] = array();
$this->data['breadcrumbs'][] = array(
'text' => $this->language->get('text_home'),
'href' => $this->url->link('common/home', 'token=' . $this->session->data['token'], 'SSL'),
'separator' => false
);
$this->data['breadcrumbs'][] = array(
'text' => $this->language->get('text_module'),
'href' => $this->url->link('extension/module', 'token=' . $this->session->data['token'], 'SSL'),
'separator' => ' :: '
);
$this->data['breadcrumbs'][] = array(
'text' => $this->language->get('heading_title'),
'href' => $this->url->link('module/my_module', 'token=' . $this->session->data['token'], 'SSL'),
'separator' => ' :: '
);
$this->data['action'] = $this->url->link('module/my_module', 'token=' . $this->session->data['token'], 'SSL');
$this->data['cancel'] = $this->url->link('extension/module', 'token=' . $this->session->data['token'], 'SSL');
//This code handles the situation where you have multiple instances of this module, for different layouts.
$this->data['modules'] = array();
if (isset($this->request->post['my_module_module'])) {
$this->data['modules'] = $this->request->post['my_module_module'];
} elseif ($this->config->get('my_module_module')) {
$this->data['modules'] = $this->config->get('my_module_module');
}
$this->load->model('design/layout');
$this->data['layouts'] = $this->model_design_layout->getLayouts();
//Choose which template file will be used to display this request.
$this->template = 'module/my_module.tpl';
$this->children = array(
'common/header',
'common/footer',
);
//Send the output.
$this->response->setOutput($this->render());
}
/*
*
* This function is called to ensure that the settings chosen by the admin user are allowed/valid.
* You can add checks in here of your own.
*
*/
private function validate() {
if (!$this->user->hasPermission('modify', 'module/my_module')) {
$this->error['warning'] = $this->language->get('error_permission');
}
if (!$this->error) {
return TRUE;
} else {
return FALSE;
}
}
}
?>