1: <?php
2: namespace Opencart\Admin\Controller\Extension\Opencart\Module;
3: /**
4: * Class Banner
5: *
6: * @package Opencart\Admin\Controller\Extension\Opencart\Module
7: */
8: class Banner extends \Opencart\System\Engine\Controller {
9: /**
10: * Index
11: *
12: * @return void
13: */
14: public function index(): void {
15: $this->load->language('extension/opencart/module/banner');
16:
17: $this->document->setTitle($this->language->get('heading_title'));
18:
19: $data['breadcrumbs'] = [];
20:
21: $data['breadcrumbs'][] = [
22: 'text' => $this->language->get('text_home'),
23: 'href' => $this->url->link('common/dashboard', 'user_token=' . $this->session->data['user_token'])
24: ];
25:
26: $data['breadcrumbs'][] = [
27: 'text' => $this->language->get('text_extension'),
28: 'href' => $this->url->link('marketplace/extension', 'user_token=' . $this->session->data['user_token'] . '&type=module')
29: ];
30:
31: if (!isset($this->request->get['module_id'])) {
32: $data['breadcrumbs'][] = [
33: 'text' => $this->language->get('heading_title'),
34: 'href' => $this->url->link('extension/opencart/module/banner', 'user_token=' . $this->session->data['user_token'])
35: ];
36: } else {
37: $data['breadcrumbs'][] = [
38: 'text' => $this->language->get('heading_title'),
39: 'href' => $this->url->link('extension/opencart/module/banner', 'user_token=' . $this->session->data['user_token'] . '&module_id=' . $this->request->get['module_id'])
40: ];
41: }
42:
43: if (!isset($this->request->get['module_id'])) {
44: $data['save'] = $this->url->link('extension/opencart/module/banner.save', 'user_token=' . $this->session->data['user_token']);
45: } else {
46: $data['save'] = $this->url->link('extension/opencart/module/banner.save', 'user_token=' . $this->session->data['user_token'] . '&module_id=' . $this->request->get['module_id']);
47: }
48:
49: $data['back'] = $this->url->link('marketplace/extension', 'user_token=' . $this->session->data['user_token'] . '&type=module');
50:
51: if (isset($this->request->get['module_id'])) {
52: $this->load->model('setting/module');
53:
54: $module_info = $this->model_setting_module->getModule($this->request->get['module_id']);
55: }
56:
57: if (isset($module_info['name'])) {
58: $data['name'] = $module_info['name'];
59: } else {
60: $data['name'] = '';
61: }
62:
63: if (isset($module_info['banner_id'])) {
64: $data['banner_id'] = $module_info['banner_id'];
65: } else {
66: $data['banner_id'] = '';
67: }
68:
69: $this->load->model('design/banner');
70:
71: $data['banners'] = $this->model_design_banner->getBanners();
72:
73: if (isset($module_info['effect'])) {
74: $data['effect'] = $module_info['effect'];
75: } else {
76: $data['effect'] = '';
77: }
78:
79: if (isset($module_info['items'])) {
80: $data['items'] = $module_info['items'];
81: } else {
82: $data['items'] = 4;
83: }
84:
85: if (isset($module_info['controls'])) {
86: $data['controls'] = $module_info['controls'];
87: } else {
88: $data['controls'] = '';
89: }
90:
91: if (isset($module_info['indicators'])) {
92: $data['indicators'] = $module_info['indicators'];
93: } else {
94: $data['indicators'] = '';
95: }
96:
97: if (isset($module_info['interval'])) {
98: $data['interval'] = $module_info['interval'];
99: } else {
100: $data['interval'] = 5000;
101: }
102:
103: if (isset($module_info['width'])) {
104: $data['width'] = $module_info['width'];
105: } else {
106: $data['width'] = '';
107: }
108:
109: if (isset($module_info['height'])) {
110: $data['height'] = $module_info['height'];
111: } else {
112: $data['height'] = '';
113: }
114:
115: if (isset($module_info['status'])) {
116: $data['status'] = $module_info['status'];
117: } else {
118: $data['status'] = '';
119: }
120:
121: if (isset($this->request->get['module_id'])) {
122: $data['module_id'] = (int)$this->request->get['module_id'];
123: } else {
124: $data['module_id'] = 0;
125: }
126:
127: $data['header'] = $this->load->controller('common/header');
128: $data['column_left'] = $this->load->controller('common/column_left');
129: $data['footer'] = $this->load->controller('common/footer');
130:
131: $this->response->setOutput($this->load->view('extension/opencart/module/banner', $data));
132: }
133:
134: /**
135: * Save
136: *
137: * @return void
138: */
139: public function save(): void {
140: $this->load->language('extension/opencart/module/banner');
141:
142: $json = [];
143:
144: if (!$this->user->hasPermission('modify', 'extension/opencart/module/banner')) {
145: $json['error']['warning'] = $this->language->get('error_permission');
146: }
147:
148: if ((oc_strlen($this->request->post['name']) < 3) || (oc_strlen($this->request->post['name']) > 64)) {
149: $json['error']['name'] = $this->language->get('error_name');
150: }
151:
152: if (!$this->request->post['interval']) {
153: $json['error']['interval'] = $this->language->get('error_interval');
154: }
155:
156: if (!$this->request->post['width']) {
157: $json['error']['width'] = $this->language->get('error_width');
158: }
159:
160: if (!$this->request->post['height']) {
161: $json['error']['height'] = $this->language->get('error_height');
162: }
163:
164: if (!$json) {
165: $this->load->model('setting/module');
166:
167: if (!$this->request->post['module_id']) {
168: $json['module_id'] = $this->model_setting_module->addModule('opencart.banner', $this->request->post);
169: } else {
170: $this->model_setting_module->editModule($this->request->post['module_id'], $this->request->post);
171: }
172:
173: $json['success'] = $this->language->get('text_success');
174: }
175:
176: $this->response->addHeader('Content-Type: application/json');
177: $this->response->setOutput(json_encode($json));
178: }
179: }
180: