1: | <?php
2: | namespace Opencart\Admin\Controller\Marketplace;
3: | /**
4: | * Class Startup
5: | *
6: | * @package Opencart\Admin\Controller\Marketplace
7: | */
8: | class Startup extends \Opencart\System\Engine\Controller {
9: | /**
10: | * Index
11: | *
12: | * @return void
13: | */
14: | public function index(): void {
15: | $this->load->language('marketplace/startup');
16: |
17: | $this->document->setTitle($this->language->get('heading_title'));
18: |
19: | $url = '';
20: |
21: | if (isset($this->request->get['sort'])) {
22: | $url .= '&sort=' . $this->request->get['sort'];
23: | }
24: |
25: | if (isset($this->request->get['order'])) {
26: | $url .= '&order=' . $this->request->get['order'];
27: | }
28: |
29: | if (isset($this->request->get['page'])) {
30: | $url .= '&page=' . $this->request->get['page'];
31: | }
32: |
33: | $data['breadcrumbs'] = [];
34: |
35: | $data['breadcrumbs'][] = [
36: | 'text' => $this->language->get('text_home'),
37: | 'href' => $this->url->link('common/dashboard', 'user_token=' . $this->session->data['user_token'])
38: | ];
39: |
40: | $data['breadcrumbs'][] = [
41: | 'text' => $this->language->get('heading_title'),
42: | 'href' => $this->url->link('marketplace/startup', 'user_token=' . $this->session->data['user_token'] . $url)
43: | ];
44: |
45: | $data['delete'] = $this->url->link('marketplace/startup.delete', 'user_token=' . $this->session->data['user_token']);
46: |
47: | $data['list'] = $this->getList();
48: |
49: | $data['user_token'] = $this->session->data['user_token'];
50: |
51: | $data['header'] = $this->load->controller('common/header');
52: | $data['column_left'] = $this->load->controller('common/column_left');
53: | $data['footer'] = $this->load->controller('common/footer');
54: |
55: | $this->response->setOutput($this->load->view('marketplace/startup', $data));
56: | }
57: |
58: | /**
59: | * List
60: | *
61: | * @return void
62: | */
63: | public function list(): void {
64: | $this->load->language('marketplace/startup');
65: |
66: | $this->response->setOutput($this->getList());
67: | }
68: |
69: | /**
70: | * Get List
71: | *
72: | * @return string
73: | */
74: | public function getList(): string {
75: | if (isset($this->request->get['sort'])) {
76: | $sort = (string)$this->request->get['sort'];
77: | } else {
78: | $sort = 'code';
79: | }
80: |
81: | if (isset($this->request->get['order'])) {
82: | $order = (string)$this->request->get['order'];
83: | } else {
84: | $order = 'ASC';
85: | }
86: |
87: | if (isset($this->request->get['page'])) {
88: | $page = (int)$this->request->get['page'];
89: | } else {
90: | $page = 1;
91: | }
92: |
93: | $url = '';
94: |
95: | if (isset($this->request->get['sort'])) {
96: | $url .= '&sort=' . $this->request->get['sort'];
97: | }
98: |
99: | if (isset($this->request->get['order'])) {
100: | $url .= '&order=' . $this->request->get['order'];
101: | }
102: |
103: | if (isset($this->request->get['page'])) {
104: | $url .= '&page=' . $this->request->get['page'];
105: | }
106: |
107: | $data['action'] = $this->url->link('marketplace/startup.list', 'user_token=' . $this->session->data['user_token'] . $url);
108: |
109: | $data['startups'] = [];
110: |
111: | $filter_data = [
112: | 'sort' => $sort,
113: | 'order' => $order,
114: | 'start' => ($page - 1) * $this->config->get('config_pagination_admin'),
115: | 'limit' => $this->config->get('config_pagination_admin')
116: | ];
117: |
118: | $this->load->model('setting/startup');
119: |
120: | $results = $this->model_setting_startup->getStartups($filter_data);
121: |
122: | foreach ($results as $result) {
123: | $data['startups'][] = [
124: | 'startup_id' => $result['startup_id'],
125: | 'code' => $result['code'],
126: | 'description' => $result['description'],
127: | 'action' => $result['action'],
128: | 'status' => $result['status'],
129: | 'sort_order' => $result['sort_order'],
130: | 'enable' => $this->url->link('marketplace/startup.enable', 'user_token=' . $this->session->data['user_token'] . '&startup_id=' . $result['startup_id']),
131: | 'disable' => $this->url->link('marketplace/startup.disable', 'user_token=' . $this->session->data['user_token'] . '&startup_id=' . $result['startup_id'])
132: | ];
133: | }
134: |
135: | $url = '';
136: |
137: | if ($order == 'ASC') {
138: | $url .= '&order=DESC';
139: | } else {
140: | $url .= '&order=ASC';
141: | }
142: |
143: | $data['sort_code'] = $this->url->link('marketplace/startup.list', 'user_token=' . $this->session->data['user_token'] . '&sort=code' . $url);
144: | $data['sort_action'] = $this->url->link('marketplace/startup.list', 'user_token=' . $this->session->data['user_token'] . '&sort=action' . $url);
145: | $data['sort_sort_order'] = $this->url->link('marketplace/startup.list', 'user_token=' . $this->session->data['user_token'] . '&sort=sort_order' . $url);
146: |
147: | $url = '';
148: |
149: | if (isset($this->request->get['sort'])) {
150: | $url .= '&sort=' . $this->request->get['sort'];
151: | }
152: |
153: | if (isset($this->request->get['order'])) {
154: | $url .= '&order=' . $this->request->get['order'];
155: | }
156: |
157: | $startup_total = $this->model_setting_startup->getTotalStartups();
158: |
159: | $data['pagination'] = $this->load->controller('common/pagination', [
160: | 'total' => $startup_total,
161: | 'page' => $page,
162: | 'limit' => $this->config->get('config_pagination_admin'),
163: | 'url' => $this->url->link('marketplace/startup.list', 'user_token=' . $this->session->data['user_token'] . $url . '&page={page}')
164: | ]);
165: |
166: | $data['results'] = sprintf($this->language->get('text_pagination'), ($startup_total) ? (($page - 1) * $this->config->get('config_pagination_admin')) + 1 : 0, ((($page - 1) * $this->config->get('config_pagination_admin')) > ($startup_total - $this->config->get('config_pagination_admin'))) ? $startup_total : ((($page - 1) * $this->config->get('config_pagination_admin')) + $this->config->get('config_pagination_admin')), $startup_total, ceil($startup_total / $this->config->get('config_pagination_admin')));
167: |
168: | $data['sort'] = $sort;
169: | $data['order'] = $order;
170: |
171: | return $this->load->view('marketplace/startup_list', $data);
172: | }
173: |
174: | /**
175: | * Enable
176: | *
177: | * @return void
178: | */
179: | public function enable(): void {
180: | $this->load->language('marketplace/startup');
181: |
182: | $json = [];
183: |
184: | if (isset($this->request->get['startup_id'])) {
185: | $startup_id = (int)$this->request->get['startup_id'];
186: | } else {
187: | $startup_id = 0;
188: | }
189: |
190: | if (!$this->user->hasPermission('modify', 'marketplace/startup')) {
191: | $json['error'] = $this->language->get('error_permission');
192: | }
193: |
194: | if (!$json) {
195: | $this->load->model('setting/startup');
196: |
197: | $this->model_setting_startup->editStatus($startup_id, true);
198: |
199: | $json['success'] = $this->language->get('text_success');
200: | }
201: |
202: | $this->response->addHeader('Content-Type: application/json');
203: | $this->response->setOutput(json_encode($json));
204: | }
205: |
206: | /**
207: | * Disable
208: | *
209: | * @return void
210: | */
211: | public function disable(): void {
212: | $this->load->language('marketplace/startup');
213: |
214: | $json = [];
215: |
216: | if (isset($this->request->get['startup_id'])) {
217: | $startup_id = (int)$this->request->get['startup_id'];
218: | } else {
219: | $startup_id = 0;
220: | }
221: |
222: | if (!$this->user->hasPermission('modify', 'marketplace/startup')) {
223: | $json['error'] = $this->language->get('error_permission');
224: | }
225: |
226: | if (!$json) {
227: | $this->load->model('setting/startup');
228: |
229: | $this->model_setting_startup->editStatus($startup_id, false);
230: |
231: | $json['success'] = $this->language->get('text_success');
232: | }
233: |
234: | $this->response->addHeader('Content-Type: application/json');
235: | $this->response->setOutput(json_encode($json));
236: | }
237: |
238: | /**
239: | * Delete
240: | *
241: | * @return void
242: | */
243: | public function delete(): void {
244: | $this->load->language('marketplace/startup');
245: |
246: | $json = [];
247: |
248: | if (isset($this->request->post['selected'])) {
249: | $selected = (array)$this->request->post['selected'];
250: | } else {
251: | $selected = [];
252: | }
253: |
254: | if (!$this->user->hasPermission('modify', 'marketplace/startup')) {
255: | $json['error'] = $this->language->get('error_permission');
256: | }
257: |
258: | if (!$json) {
259: | $this->load->model('setting/startup');
260: |
261: | foreach ($selected as $startup_id) {
262: | $this->model_setting_startup->deleteStartup($startup_id);
263: | }
264: |
265: | $json['success'] = $this->language->get('text_success');
266: | }
267: |
268: | $this->response->addHeader('Content-Type: application/json');
269: | $this->response->setOutput(json_encode($json));
270: | }
271: | }
272: |

OpenCart API API documentation generated by ApiGen dev-master