first commit
This commit is contained in:
76
admininistrator/model/report/online.php
Normal file
76
admininistrator/model/report/online.php
Normal file
@ -0,0 +1,76 @@
|
||||
<?php
|
||||
namespace Opencart\Admin\Model\Report;
|
||||
/**
|
||||
* Class Online
|
||||
*
|
||||
* @package Opencart\Admin\Model\Report
|
||||
*/
|
||||
class Online extends \Opencart\System\Engine\Model {
|
||||
/**
|
||||
* @param array $data
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function getOnline(array $data = []): array {
|
||||
$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`)";
|
||||
|
||||
$implode = [];
|
||||
|
||||
if (!empty($data['filter_ip'])) {
|
||||
$implode[] = "`co`.`ip` LIKE '" . $this->db->escape((string)$data['filter_ip']) . "'";
|
||||
}
|
||||
|
||||
if (!empty($data['filter_customer'])) {
|
||||
$implode[] = "`co`.`customer_id` > '0' AND CONCAT(`c`.`firstname`, ' ', `c`.`lastname`) LIKE '" . $this->db->escape((string)$data['filter_customer']) . "'";
|
||||
}
|
||||
|
||||
if ($implode) {
|
||||
$sql .= " WHERE " . implode(" AND ", $implode);
|
||||
}
|
||||
|
||||
$sql .= " ORDER BY `co`.`date_added` DESC";
|
||||
|
||||
if (isset($data['start']) || isset($data['limit'])) {
|
||||
if ($data['start'] < 0) {
|
||||
$data['start'] = 0;
|
||||
}
|
||||
|
||||
if ($data['limit'] < 1) {
|
||||
$data['limit'] = 20;
|
||||
}
|
||||
|
||||
$sql .= " LIMIT " . (int)$data['start'] . "," . (int)$data['limit'];
|
||||
}
|
||||
|
||||
$query = $this->db->query($sql);
|
||||
|
||||
return $query->rows;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param array $data
|
||||
*
|
||||
* @return int
|
||||
*/
|
||||
public function getTotalOnline(array $data = []): int {
|
||||
$sql = "SELECT COUNT(*) AS `total` FROM `" . DB_PREFIX . "customer_online` `co` LEFT JOIN `" . DB_PREFIX . "customer` `c` ON (`co`.`customer_id` = `c`.`customer_id`)";
|
||||
|
||||
$implode = [];
|
||||
|
||||
if (!empty($data['filter_ip'])) {
|
||||
$implode[] = "`co`.`ip` LIKE '" . $this->db->escape((string)$data['filter_ip']) . "'";
|
||||
}
|
||||
|
||||
if (!empty($data['filter_customer'])) {
|
||||
$implode[] = "`co`.`customer_id` > '0' AND CONCAT(`c`.`firstname`, ' ', `c`.`lastname`) LIKE '" . $this->db->escape((string)$data['filter_customer']) . "'";
|
||||
}
|
||||
|
||||
if ($implode) {
|
||||
$sql .= " WHERE " . implode(" AND ", $implode);
|
||||
}
|
||||
|
||||
$query = $this->db->query($sql);
|
||||
|
||||
return (int)$query->row['total'];
|
||||
}
|
||||
}
|
62
admininistrator/model/report/statistics.php
Normal file
62
admininistrator/model/report/statistics.php
Normal file
@ -0,0 +1,62 @@
|
||||
<?php
|
||||
namespace Opencart\Admin\Model\Report;
|
||||
/**
|
||||
* Class Statistics
|
||||
*
|
||||
* @package Opencart\Admin\Model\Report
|
||||
*/
|
||||
class Statistics extends \Opencart\System\Engine\Model {
|
||||
/**
|
||||
* @return array
|
||||
*/
|
||||
public function getStatistics(): array {
|
||||
$query = $this->db->query("SELECT * FROM `" . DB_PREFIX . "statistics`");
|
||||
|
||||
return $query->rows;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param string $code
|
||||
*
|
||||
* @return float
|
||||
*/
|
||||
public function getValue(string $code): float {
|
||||
$query = $this->db->query("SELECT `value` FROM `" . DB_PREFIX . "statistics` WHERE `code` = '" . $this->db->escape($code) . "'");
|
||||
|
||||
if ($query->num_rows) {
|
||||
return $query->row['value'];
|
||||
} else {
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @param string $code
|
||||
* @param float $value
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function addValue(string $code, float $value): void {
|
||||
$this->db->query("UPDATE `" . DB_PREFIX . "statistics` SET `value` = (`value` + '" . (float)$value . "') WHERE `code` = '" . $this->db->escape($code) . "'");
|
||||
}
|
||||
|
||||
/**
|
||||
* @param string $code
|
||||
* @param float $value
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function removeValue(string $code, float $value): void {
|
||||
$this->db->query("UPDATE `" . DB_PREFIX . "statistics` SET `value` = (`value` - '" . (float)$value . "') WHERE `code` = '" . $this->db->escape($code) . "'");
|
||||
}
|
||||
|
||||
/**
|
||||
* @param string $code
|
||||
* @param float $value
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function editValue(string $code, float $value): void {
|
||||
$this->db->query("UPDATE `" . DB_PREFIX . "statistics` SET `value` = '" . (float)$value . "' WHERE `code` = '" . $this->db->escape($code) . "'");
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user