1: | <?php
2: | namespace Opencart\Admin\Controller\Extension\Opencart\Dashboard;
3: | /**
4: | * Class Online
5: | *
6: | * @package Opencart\Admin\Controller\Extension\Opencart\Dashboard
7: | */
8: | class Online extends \Opencart\System\Engine\Controller {
9: | /**
10: | * Index
11: | *
12: | * @return void
13: | */
14: | public function index(): void {
15: | $this->load->language('extension/opencart/dashboard/online');
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=dashboard')
29: | ];
30: |
31: | $data['breadcrumbs'][] = [
32: | 'text' => $this->language->get('heading_title'),
33: | 'href' => $this->url->link('extension/opencart/dashboard/online', 'user_token=' . $this->session->data['user_token'])
34: | ];
35: |
36: | $data['save'] = $this->url->link('extension/opencart/dashboard/online.save', 'user_token=' . $this->session->data['user_token']);
37: | $data['back'] = $this->url->link('marketplace/extension', 'user_token=' . $this->session->data['user_token'] . '&type=dashboard');
38: |
39: | $data['dashboard_online_width'] = $this->config->get('dashboard_online_width');
40: |
41: | $data['columns'] = [];
42: |
43: | for ($i = 3; $i <= 12; $i++) {
44: | $data['columns'][] = $i;
45: | }
46: |
47: | $data['dashboard_online_status'] = $this->config->get('dashboard_online_status');
48: | $data['dashboard_online_sort_order'] = $this->config->get('dashboard_online_sort_order');
49: |
50: | $data['header'] = $this->load->controller('common/header');
51: | $data['column_left'] = $this->load->controller('common/column_left');
52: | $data['footer'] = $this->load->controller('common/footer');
53: |
54: | $this->response->setOutput($this->load->view('extension/opencart/dashboard/online_form', $data));
55: | }
56: |
57: | /**
58: | * Save
59: | *
60: | * @return void
61: | */
62: | public function save(): void {
63: | $this->load->language('extension/opencart/dashboard/online');
64: |
65: | $json = [];
66: |
67: | if (!$this->user->hasPermission('modify', 'extension/opencart/dashboard/online')) {
68: | $json['error'] = $this->language->get('error_permission');
69: | }
70: |
71: | if (!$json) {
72: | $this->load->model('setting/setting');
73: |
74: | $this->model_setting_setting->editSetting('dashboard_online', $this->request->post);
75: |
76: | $json['success'] = $this->language->get('text_success');
77: | }
78: |
79: | $this->response->addHeader('Content-Type: application/json');
80: | $this->response->setOutput(json_encode($json));
81: | }
82: |
83: | /**
84: | * Dashboard
85: | *
86: | * @return string
87: | */
88: | public function dashboard(): string {
89: | $this->load->language('extension/opencart/dashboard/online');
90: |
91: | $this->load->model('report/online');
92: |
93: | // Customers Online
94: | $online_total = $this->model_report_online->getTotalOnline();
95: |
96: | if ($online_total > 1000000000000) {
97: | $data['total'] = round($online_total / 1000000000000, 1) . 'T';
98: | } elseif ($online_total > 1000000000) {
99: | $data['total'] = round($online_total / 1000000000, 1) . 'B';
100: | } elseif ($online_total > 1000000) {
101: | $data['total'] = round($online_total / 1000000, 1) . 'M';
102: | } elseif ($online_total > 1000) {
103: | $data['total'] = round($online_total / 1000, 1) . 'K';
104: | } else {
105: | $data['total'] = $online_total;
106: | }
107: |
108: | $data['online'] = $this->url->link('report/online', 'user_token=' . $this->session->data['user_token']);
109: |
110: | return $this->load->view('extension/opencart/dashboard/online_info', $data);
111: | }
112: | }
113: |

OpenCart API API documentation generated by ApiGen dev-master