Back to Opencart

File admin\model\report\online.php

docs/api/source-admin.model.report.online.html

4.1.0.35.5 KB
Original Source

Namespaces

Classes

| 1: | <?php | | 2: | namespace Opencart\Admin\Model\Report; | | 3: | /** | | 4: | * Class Online | | 5: | * | | 6: | * @package Opencart\Admin\Model\Report | | 7: | */ | | 8: | class Online extends \Opencart\System\Engine\Model { | | 9: | /** | | 10: | * Get Online | | 11: | * | | 12: | * @param array<string, mixed> $data | | 13: | * | | 14: | * @return array<int, array<string, mixed>> | | 15: | */ | | 16: | public function getOnline(array $data = []): array { | | 17: | $sql = "SELECT co.ip, co.customer_id, co.url, co.referer, co.date_added FROM " . DB\_PREFIX . "customer\_online co LEFT JOIN " . DB\_PREFIX . "customer c ON (co.customer\_id = c.customer\_id)"; | | 18: | | | 19: | $implode = []; | | 20: | | | 21: | if (!empty($data['filter_ip'])) { | | 22: | $implode[] = "co.ip LIKE '" . $this->db->escape((string)$data['filter_ip']) . "'"; | | 23: | } | | 24: | | | 25: | if (!empty($data['filter_customer'])) { | | 26: | $implode[] = "co.customer_id > '0' AND LCASE(CONCAT(c.firstname, ' ', c.lastname)) LIKE '" . $this->db->escape(oc_strtolower($data['filter_customer'])) . "'"; | | 27: | } | | 28: | | | 29: | if ($implode) { | | 30: | $sql .= " WHERE " . implode(" AND ", $implode); | | 31: | } | | 32: | | | 33: | $sql .= " ORDER BY co.date_added DESC"; | | 34: | | | 35: | if (isset($data['start']) || isset($data['limit'])) { | | 36: | if ($data['start'] < 0) { | | 37: | $data['start'] = 0; | | 38: | } | | 39: | | | 40: | if ($data['limit'] < 1) { | | 41: | $data['limit'] = 20; | | 42: | } | | 43: | | | 44: | $sql .= " LIMIT " . (int)$data['start'] . "," . (int)$data['limit']; | | 45: | } | | 46: | | | 47: | $query = $this->db->query($sql); | | 48: | | | 49: | return $query->rows; | | 50: | } | | 51: | | | 52: | /** | | 53: | * Get Total Online | | 54: | * | | 55: | * @param array<string, mixed> $data | | 56: | * | | 57: | * @return int | | 58: | */ | | 59: | public function getTotalOnline(array $data = []): int { | | 60: | $sql = "SELECT COUNT(*) AS total FROM " . DB\_PREFIX . "customer\_online co LEFT JOIN " . DB\_PREFIX . "customer c ON (co.customer\_id = c.customer\_id)"; | | 61: | | | 62: | $implode = []; | | 63: | | | 64: | if (!empty($data['filter_ip'])) { | | 65: | $implode[] = "co.ip LIKE '" . $this->db->escape((string)$data['filter_ip']) . "'"; | | 66: | } | | 67: | | | 68: | if (!empty($data['filter_customer'])) { | | 69: | $implode[] = "co.customer_id > '0' AND LCASE(CONCAT(c.firstname, ' ', c.lastname)) LIKE '" . $this->db->escape(oc_strtolower($data['filter_customer'])) . "'"; | | 70: | } | | 71: | | | 72: | if ($implode) { | | 73: | $sql .= " WHERE " . implode(" AND ", $implode); | | 74: | } | | 75: | | | 76: | $query = $this->db->query($sql); | | 77: | | | 78: | return (int)$query->row['total']; | | 79: | } | | 80: | } | | 81: | |

OpenCart API API documentation generated by ApiGen dev-master