first commit

This commit is contained in:
sujan
2024-08-06 18:06:00 +05:45
commit a2fa49071a
2745 changed files with 391199 additions and 0 deletions

View File

@ -0,0 +1,276 @@
<?php
namespace Opencart\Admin\Model\Customer;
/**
* Class Custom Field
*
* @package Opencart\Admin\Model\Customer
*/
class CustomField extends \Opencart\System\Engine\Model {
/**
* @param array $data
*
* @return int
*/
public function addCustomField(array $data): int {
$this->db->query("INSERT INTO `" . DB_PREFIX . "custom_field` SET `type` = '" . $this->db->escape((string)$data['type']) . "', `value` = '" . $this->db->escape((string)$data['value']) . "', `validation` = '" . $this->db->escape((string)$data['validation']) . "', `location` = '" . $this->db->escape((string)$data['location']) . "', `status` = '" . (bool)(isset($data['status']) ? $data['status'] : 0) . "', `sort_order` = '" . (int)$data['sort_order'] . "'");
$custom_field_id = $this->db->getLastId();
foreach ($data['custom_field_description'] as $language_id => $value) {
$this->db->query("INSERT INTO `" . DB_PREFIX . "custom_field_description` SET `custom_field_id` = '" . (int)$custom_field_id . "', `language_id` = '" . (int)$language_id . "', `name` = '" . $this->db->escape($value['name']) . "'");
}
if (isset($data['custom_field_customer_group'])) {
foreach ($data['custom_field_customer_group'] as $custom_field_customer_group) {
if (isset($custom_field_customer_group['customer_group_id'])) {
$this->db->query("INSERT INTO `" . DB_PREFIX . "custom_field_customer_group` SET `custom_field_id` = '" . (int)$custom_field_id . "', `customer_group_id` = '" . (int)$custom_field_customer_group['customer_group_id'] . "', `required` = '" . (int)(isset($custom_field_customer_group['required']) ? 1 : 0) . "'");
}
}
}
if (isset($data['custom_field_value'])) {
foreach ($data['custom_field_value'] as $custom_field_value) {
$this->db->query("INSERT INTO `" . DB_PREFIX . "custom_field_value` SET `custom_field_id` = '" . (int)$custom_field_id . "', `sort_order` = '" . (int)$custom_field_value['sort_order'] . "'");
$custom_field_value_id = $this->db->getLastId();
foreach ($custom_field_value['custom_field_value_description'] as $language_id => $custom_field_value_description) {
$this->db->query("INSERT INTO `" . DB_PREFIX . "custom_field_value_description` SET `custom_field_value_id` = '" . (int)$custom_field_value_id . "', `language_id` = '" . (int)$language_id . "', `custom_field_id` = '" . (int)$custom_field_id . "', `name` = '" . $this->db->escape($custom_field_value_description['name']) . "'");
}
}
}
return $custom_field_id;
}
/**
* @param int $custom_field_id
* @param array $data
*
* @return void
*/
public function editCustomField(int $custom_field_id, array $data): void {
$this->db->query("UPDATE `" . DB_PREFIX . "custom_field` SET `type` = '" . $this->db->escape((string)$data['type']) . "', `value` = '" . $this->db->escape((string)$data['value']) . "', `validation` = '" . $this->db->escape((string)$data['validation']) . "', `location` = '" . $this->db->escape((string)$data['location']) . "', `status` = '" . (bool)(isset($data['status']) ? $data['status'] : 0) . "', `sort_order` = '" . (int)$data['sort_order'] . "' WHERE `custom_field_id` = '" . (int)$custom_field_id . "'");
$this->db->query("DELETE FROM `" . DB_PREFIX . "custom_field_description` WHERE `custom_field_id` = '" . (int)$custom_field_id . "'");
foreach ($data['custom_field_description'] as $language_id => $value) {
$this->db->query("INSERT INTO `" . DB_PREFIX . "custom_field_description` SET `custom_field_id` = '" . (int)$custom_field_id . "', `language_id` = '" . (int)$language_id . "', `name` = '" . $this->db->escape($value['name']) . "'");
}
$this->db->query("DELETE FROM `" . DB_PREFIX . "custom_field_customer_group` WHERE `custom_field_id` = '" . (int)$custom_field_id . "'");
if (isset($data['custom_field_customer_group'])) {
foreach ($data['custom_field_customer_group'] as $custom_field_customer_group) {
if (isset($custom_field_customer_group['customer_group_id'])) {
$this->db->query("INSERT INTO `" . DB_PREFIX . "custom_field_customer_group` SET `custom_field_id` = '" . (int)$custom_field_id . "', `customer_group_id` = '" . (int)$custom_field_customer_group['customer_group_id'] . "', `required` = '" . (int)(isset($custom_field_customer_group['required']) ? 1 : 0) . "'");
}
}
}
$this->db->query("DELETE FROM `" . DB_PREFIX . "custom_field_value` WHERE `custom_field_id` = '" . (int)$custom_field_id . "'");
$this->db->query("DELETE FROM `" . DB_PREFIX . "custom_field_value_description` WHERE `custom_field_id` = '" . (int)$custom_field_id . "'");
if (isset($data['custom_field_value'])) {
foreach ($data['custom_field_value'] as $custom_field_value) {
if ($custom_field_value['custom_field_value_id']) {
$this->db->query("INSERT INTO `" . DB_PREFIX . "custom_field_value` SET `custom_field_value_id` = '" . (int)$custom_field_value['custom_field_value_id'] . "', `custom_field_id` = '" . (int)$custom_field_id . "', `sort_order` = '" . (int)$custom_field_value['sort_order'] . "'");
} else {
$this->db->query("INSERT INTO `" . DB_PREFIX . "custom_field_value` SET `custom_field_id` = '" . (int)$custom_field_id . "', `sort_order` = '" . (int)$custom_field_value['sort_order'] . "'");
}
$custom_field_value_id = $this->db->getLastId();
foreach ($custom_field_value['custom_field_value_description'] as $language_id => $custom_field_value_description) {
$this->db->query("INSERT INTO `" . DB_PREFIX . "custom_field_value_description` SET `custom_field_value_id` = '" . (int)$custom_field_value_id . "', `language_id` = '" . (int)$language_id . "', `custom_field_id` = '" . (int)$custom_field_id . "', `name` = '" . $this->db->escape($custom_field_value_description['name']) . "'");
}
}
}
}
/**
* @param int $custom_field_id
*
* @return void
*/
public function deleteCustomField(int $custom_field_id): void {
$this->db->query("DELETE FROM `" . DB_PREFIX . "custom_field` WHERE `custom_field_id` = '" . (int)$custom_field_id . "'");
$this->db->query("DELETE FROM `" . DB_PREFIX . "custom_field_description` WHERE `custom_field_id` = '" . (int)$custom_field_id . "'");
$this->db->query("DELETE FROM `" . DB_PREFIX . "custom_field_customer_group` WHERE `custom_field_id` = '" . (int)$custom_field_id . "'");
$this->db->query("DELETE FROM `" . DB_PREFIX . "custom_field_value` WHERE `custom_field_id` = '" . (int)$custom_field_id . "'");
$this->db->query("DELETE FROM `" . DB_PREFIX . "custom_field_value_description` WHERE `custom_field_id` = '" . (int)$custom_field_id . "'");
}
/**
* @param int $custom_field_id
*
* @return array
*/
public function getCustomField(int $custom_field_id): array {
$query = $this->db->query("SELECT * FROM `" . DB_PREFIX . "custom_field` cf LEFT JOIN `" . DB_PREFIX . "custom_field_description` cfd ON (cf.`custom_field_id` = cfd.`custom_field_id`) WHERE cf.`custom_field_id` = '" . (int)$custom_field_id . "' AND cfd.`language_id` = '" . (int)$this->config->get('config_language_id') . "'");
return $query->row;
}
/**
* @param array $data
*
* @return array
*/
public function getCustomFields(array $data = []): array {
if (empty($data['filter_customer_group_id'])) {
$sql = "SELECT * FROM `" . DB_PREFIX . "custom_field` cf LEFT JOIN `" . DB_PREFIX . "custom_field_description` cfd ON (cf.`custom_field_id` = cfd.`custom_field_id`) WHERE cfd.`language_id` = '" . (int)$this->config->get('config_language_id') . "'";
} else {
$sql = "SELECT * FROM `" . DB_PREFIX . "custom_field_customer_group` cfcg LEFT JOIN `" . DB_PREFIX . "custom_field` cf ON (cfcg.`custom_field_id` = cf.`custom_field_id`) LEFT JOIN `" . DB_PREFIX . "custom_field_description` cfd ON (cf.`custom_field_id` = cfd.`custom_field_id`) WHERE cfd.`language_id` = '" . (int)$this->config->get('config_language_id') . "'";
}
if (!empty($data['filter_name'])) {
$sql .= " AND cfd.`name` LIKE '" . $this->db->escape((string)$data['filter_name'] . '%') . "'";
}
if (isset($data['filter_status'])) {
$sql .= " AND cf.`status` = '" . (int)$data['filter_status'] . "'";
}
if (isset($data['filter_location'])) {
$sql .= " AND cf.`location` = '" . $this->db->escape((string)$data['filter_location']) . "'";
}
if (!empty($data['filter_customer_group_id'])) {
$sql .= " AND cfcg.`customer_group_id` = '" . (int)$data['filter_customer_group_id'] . "'";
}
$sort_data = [
'cfd.name',
'cf.type',
'cf.location',
'cf.status',
'cf.sort_order'
];
if (isset($data['sort']) && in_array($data['sort'], $sort_data)) {
$sql .= " ORDER BY " . $data['sort'];
} else {
$sql .= " ORDER BY cfd.`name`";
}
if (isset($data['order']) && ($data['order'] == 'DESC')) {
$sql .= " DESC";
} else {
$sql .= " ASC";
}
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 int $custom_field_id
*
* @return array
*/
public function getDescriptions(int $custom_field_id): array {
$custom_field_data = [];
$query = $this->db->query("SELECT * FROM `" . DB_PREFIX . "custom_field_description` WHERE `custom_field_id` = '" . (int)$custom_field_id . "'");
foreach ($query->rows as $result) {
$custom_field_data[$result['language_id']] = ['name' => $result['name']];
}
return $custom_field_data;
}
/**
* @param int $custom_field_value_id
*
* @return array
*/
public function getValue(int $custom_field_value_id): array {
$query = $this->db->query("SELECT * FROM `" . DB_PREFIX . "custom_field_value` cfv LEFT JOIN `" . DB_PREFIX . "custom_field_value_description` cfvd ON (cfv.`custom_field_value_id` = cfvd.`custom_field_value_id`) WHERE cfv.`custom_field_value_id` = '" . (int)$custom_field_value_id . "' AND cfvd.`language_id` = '" . (int)$this->config->get('config_language_id') . "'");
return $query->row;
}
/**
* @param int $custom_field_id
*
* @return array
*/
public function getValues(int $custom_field_id): array {
$custom_field_value_data = [];
$custom_field_value_query = $this->db->query("SELECT * FROM `" . DB_PREFIX . "custom_field_value` cfv LEFT JOIN `" . DB_PREFIX . "custom_field_value_description` cfvd ON (cfv.`custom_field_value_id` = cfvd.`custom_field_value_id`) WHERE cfv.`custom_field_id` = '" . (int)$custom_field_id . "' AND cfvd.`language_id` = '" . (int)$this->config->get('config_language_id') . "' ORDER BY cfv.`sort_order` ASC");
foreach ($custom_field_value_query->rows as $custom_field_value) {
$custom_field_value_data[$custom_field_value['custom_field_value_id']] = [
'custom_field_value_id' => $custom_field_value['custom_field_value_id'],
'name' => $custom_field_value['name']
];
}
return $custom_field_value_data;
}
/**
* @param int $custom_field_id
*
* @return array
*/
public function getCustomerGroups(int $custom_field_id): array {
$query = $this->db->query("SELECT * FROM `" . DB_PREFIX . "custom_field_customer_group` WHERE `custom_field_id` = '" . (int)$custom_field_id . "'");
return $query->rows;
}
/**
* @param int $custom_field_id
*
* @return array
*/
public function getValueDescriptions(int $custom_field_id): array {
$custom_field_value_data = [];
$custom_field_value_query = $this->db->query("SELECT * FROM `" . DB_PREFIX . "custom_field_value` WHERE `custom_field_id` = '" . (int)$custom_field_id . "'");
foreach ($custom_field_value_query->rows as $custom_field_value) {
$custom_field_value_description_data = [];
$custom_field_value_description_query = $this->db->query("SELECT * FROM `" . DB_PREFIX . "custom_field_value_description` WHERE `custom_field_value_id` = '" . (int)$custom_field_value['custom_field_value_id'] . "'");
foreach ($custom_field_value_description_query->rows as $custom_field_value_description) {
$custom_field_value_description_data[$custom_field_value_description['language_id']] = ['name' => $custom_field_value_description['name']];
}
$custom_field_value_data[] = [
'custom_field_value_id' => $custom_field_value['custom_field_value_id'],
'custom_field_value_description' => $custom_field_value_description_data,
'sort_order' => $custom_field_value['sort_order']
];
}
return $custom_field_value_data;
}
/**
* @return int
*/
public function getTotalCustomFields(): int {
$query = $this->db->query("SELECT COUNT(*) AS `total` FROM `" . DB_PREFIX . "custom_field`");
return (int)$query->row['total'];
}
}

View File

@ -0,0 +1,613 @@
<?php
namespace Opencart\Admin\Model\Customer;
/**
* Class Customer
*
* @package Opencart\Admin\Model\Customer
*/
class Customer extends \Opencart\System\Engine\Model {
/**
* @param array $data
*
* @return int
*/
public function addCustomer(array $data): int {
$this->db->query("INSERT INTO `" . DB_PREFIX . "customer` SET `store_id` = '" . (int)$data['store_id'] . "', `customer_group_id` = '" . (int)$data['customer_group_id'] . "', `firstname` = '" . $this->db->escape((string)$data['firstname']) . "', `lastname` = '" . $this->db->escape((string)$data['lastname']) . "', `email` = '" . $this->db->escape((string)$data['email']) . "', `telephone` = '" . $this->db->escape((string)$data['telephone']) . "', `custom_field` = '" . $this->db->escape(isset($data['custom_field']) ? json_encode($data['custom_field']) : json_encode([])) . "', `newsletter` = '" . (isset($data['newsletter']) ? (bool)$data['newsletter'] : 0) . "', `password` = '" . $this->db->escape(password_hash(html_entity_decode($data['password'], ENT_QUOTES, 'UTF-8'), PASSWORD_DEFAULT)) . "', `status` = '" . (isset($data['status']) ? (bool)$data['status'] : 0) . "', `safe` = '" . (isset($data['safe']) ? (bool)$data['safe'] : 0) . "', `date_added` = NOW()");
$customer_id = $this->db->getLastId();
if (isset($data['address'])) {
foreach ($data['address'] as $address) {
$this->db->query("INSERT INTO `" . DB_PREFIX . "address` SET `customer_id` = '" . (int)$customer_id . "', `firstname` = '" . $this->db->escape($address['firstname']) . "', `lastname` = '" . $this->db->escape($address['lastname']) . "', `company` = '" . $this->db->escape($address['company']) . "', `address_1` = '" . $this->db->escape($address['address_1']) . "', `address_2` = '" . $this->db->escape($address['address_2']) . "', `city` = '" . $this->db->escape($address['city']) . "', `postcode` = '" . $this->db->escape($address['postcode']) . "', `country_id` = '" . (int)$address['country_id'] . "', `zone_id` = '" . (int)$address['zone_id'] . "', `custom_field` = '" . $this->db->escape(isset($address['custom_field']) ? json_encode($address['custom_field']) : json_encode([])) . "', `default` = '" . (isset($address['default']) ? (int)$address['default'] : 0) . "'");
}
}
return $customer_id;
}
/**
* @param int $customer_id
* @param array $data
*
* @return void
*/
public function editCustomer(int $customer_id, array $data): void {
$this->db->query("UPDATE `" . DB_PREFIX . "customer` SET `store_id` = '" . (int)$data['store_id'] . "', `customer_group_id` = '" . (int)$data['customer_group_id'] . "', `firstname` = '" . $this->db->escape((string)$data['firstname']) . "', `lastname` = '" . $this->db->escape((string)$data['lastname']) . "', `email` = '" . $this->db->escape((string)$data['email']) . "', `telephone` = '" . $this->db->escape((string)$data['telephone']) . "', `custom_field` = '" . $this->db->escape(isset($data['custom_field']) ? json_encode($data['custom_field']) : json_encode([])) . "', `newsletter` = '" . (isset($data['newsletter']) ? (bool)$data['newsletter'] : 0) . "', `status` = '" . (isset($data['status']) ? (bool)$data['status'] : 0) . "', `safe` = '" . (isset($data['safe']) ? (bool)$data['safe'] : 0) . "' WHERE `customer_id` = '" . (int)$customer_id . "'");
if ($data['password']) {
$this->db->query("UPDATE `" . DB_PREFIX . "customer` SET `password` = '" . $this->db->escape(password_hash(html_entity_decode($data['password'], ENT_QUOTES, 'UTF-8'), PASSWORD_DEFAULT)) . "' WHERE `customer_id` = '" . (int)$customer_id . "'");
}
$this->db->query("DELETE FROM `" . DB_PREFIX . "address` WHERE `customer_id` = '" . (int)$customer_id . "'");
if (isset($data['address'])) {
foreach ($data['address'] as $address) {
$this->db->query("INSERT INTO `" . DB_PREFIX . "address` SET `address_id` = '" . (int)$address['address_id'] . "', `customer_id` = '" . (int)$customer_id . "', `firstname` = '" . $this->db->escape($address['firstname']) . "', `lastname` = '" . $this->db->escape($address['lastname']) . "', `company` = '" . $this->db->escape($address['company']) . "', `address_1` = '" . $this->db->escape($address['address_1']) . "', `address_2` = '" . $this->db->escape($address['address_2']) . "', `city` = '" . $this->db->escape($address['city']) . "', `postcode` = '" . $this->db->escape($address['postcode']) . "', `country_id` = '" . (int)$address['country_id'] . "', `zone_id` = '" . (int)$address['zone_id'] . "', `custom_field` = '" . $this->db->escape(isset($address['custom_field']) ? json_encode($address['custom_field']) : json_encode([])) . "', `default` = '" . (isset($address['default']) ? (int)$address['default'] : 0) . "'");
}
}
}
/**
* @param int $customer_id
* @param string $token
*
* @return void
*/
public function editToken(int $customer_id, string $token): void {
$this->db->query("UPDATE `" . DB_PREFIX . "customer` SET `token` = '" . $this->db->escape($token) . "' WHERE `customer_id` = '" . (int)$customer_id . "'");
}
/**
* @param int $customer_id
*
* @return void
*/
public function deleteCustomer(int $customer_id): void {
$this->db->query("DELETE FROM `" . DB_PREFIX . "customer` WHERE `customer_id` = '" . (int)$customer_id . "'");
$this->db->query("DELETE FROM `" . DB_PREFIX . "customer_activity` WHERE `customer_id` = '" . (int)$customer_id . "'");
$this->db->query("DELETE FROM `" . DB_PREFIX . "customer_affiliate` WHERE `customer_id` = '" . (int)$customer_id . "'");
$this->db->query("DELETE FROM `" . DB_PREFIX . "customer_affiliate_report` WHERE `customer_id` = '" . (int)$customer_id . "'");
$this->db->query("DELETE FROM `" . DB_PREFIX . "customer_approval` WHERE `customer_id` = '" . (int)$customer_id . "'");
$this->db->query("DELETE FROM `" . DB_PREFIX . "customer_history` WHERE `customer_id` = '" . (int)$customer_id . "'");
$this->db->query("DELETE FROM `" . DB_PREFIX . "customer_reward` WHERE `customer_id` = '" . (int)$customer_id . "'");
$this->db->query("DELETE FROM `" . DB_PREFIX . "customer_transaction` WHERE `customer_id` = '" . (int)$customer_id . "'");
$this->db->query("DELETE FROM `" . DB_PREFIX . "customer_wishlist` WHERE `customer_id` = '" . (int)$customer_id . "'");
$this->db->query("DELETE FROM `" . DB_PREFIX . "customer_ip` WHERE `customer_id` = '" . (int)$customer_id . "'");
$this->db->query("DELETE FROM `" . DB_PREFIX . "address` WHERE `customer_id` = '" . (int)$customer_id . "'");
}
/**
* @param int $customer_id
*
* @return array
*/
public function getCustomer(int $customer_id): array {
$query = $this->db->query("SELECT DISTINCT * FROM `" . DB_PREFIX . "customer` WHERE `customer_id` = '" . (int)$customer_id . "'");
return $query->row;
}
/**
* @param string $email
*
* @return array
*/
public function getCustomerByEmail(string $email): array {
$query = $this->db->query("SELECT DISTINCT * FROM `" . DB_PREFIX . "customer` WHERE LCASE(`email`) = '" . $this->db->escape(oc_strtolower($email)) . "'");
return $query->row;
}
/**
* @param array $data
*
* @return array
*/
public function getCustomers(array $data = []): array {
$sql = "SELECT *, CONCAT(c.`firstname`, ' ', c.`lastname`) AS `name`, cgd.`name` AS `customer_group` FROM `" . DB_PREFIX . "customer` c LEFT JOIN `" . DB_PREFIX . "customer_group_description` cgd ON (c.`customer_group_id` = cgd.`customer_group_id`)";
$sql .= " WHERE cgd.`language_id` = '" . (int)$this->config->get('config_language_id') . "'";
if (!empty($data['filter_name'])) {
$sql .= " AND CONCAT(c.`firstname`, ' ', c.`lastname`) LIKE '" . $this->db->escape('%' . (string)$data['filter_name'] . '%') . "'";
}
if (!empty($data['filter_email'])) {
$sql .= " AND c.`email` LIKE '" . $this->db->escape((string)$data['filter_email'] . '%') . "'";
}
if (isset($data['filter_newsletter']) && $data['filter_newsletter'] !== '') {
$sql .= " AND c.`newsletter` = '" . (int)$data['filter_newsletter'] . "'";
}
if (!empty($data['filter_customer_group_id'])) {
$sql .= " AND c.`customer_group_id` = '" . (int)$data['filter_customer_group_id'] . "'";
}
if (!empty($data['filter_ip'])) {
$sql .= " AND c.`customer_id` IN (SELECT `customer_id` FROM `" . DB_PREFIX . "customer_ip` WHERE `ip` = '" . $this->db->escape((string)$data['filter_ip']) . "')";
}
if (isset($data['filter_status']) && $data['filter_status'] !== '') {
$sql .= " AND c.`status` = '" . (int)$data['filter_status'] . "'";
}
if (!empty($data['filter_date_from'])) {
$sql .= " AND DATE(c.`date_added`) >= DATE('" . $this->db->escape((string)$data['filter_date_from']) . "')";
}
if (!empty($data['filter_date_to'])) {
$sql .= " AND DATE(c.`date_added`) <= DATE('" . $this->db->escape((string)$data['filter_date_to']) . "')";
}
$sort_data = [
'name',
'c.email',
'customer_group',
'c.status',
'c.ip',
'c.date_added'
];
if (isset($data['sort']) && in_array($data['sort'], $sort_data)) {
$sql .= " ORDER BY " . $data['sort'];
} else {
$sql .= " ORDER BY name";
}
if (isset($data['order']) && ($data['order'] == 'DESC')) {
$sql .= " DESC";
} else {
$sql .= " ASC";
}
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 getTotalCustomers(array $data = []): int {
$sql = "SELECT COUNT(*) AS `total` FROM `" . DB_PREFIX . "customer` c";
$implode = [];
if (!empty($data['filter_name'])) {
$implode[] = "CONCAT(c.`firstname`, ' ', c.`lastname`) LIKE '" . $this->db->escape('%' . (string)$data['filter_name'] . '%') . "'";
}
if (!empty($data['filter_email'])) {
$implode[] = "c.`email` LIKE '" . $this->db->escape((string)$data['filter_email'] . '%') . "'";
}
if (isset($data['filter_newsletter']) && $data['filter_newsletter'] !== '') {
$implode[] = "c.`newsletter` = '" . (int)$data['filter_newsletter'] . "'";
}
if (!empty($data['filter_customer_group_id'])) {
$implode[] = "c.`customer_group_id` = '" . (int)$data['filter_customer_group_id'] . "'";
}
if (!empty($data['filter_ip'])) {
$implode[] = "c.`customer_id` IN (SELECT `customer_id` FROM " . DB_PREFIX . "customer_ip WHERE `ip` = '" . $this->db->escape((string)$data['filter_ip']) . "')";
}
if (isset($data['filter_status']) && $data['filter_status'] !== '') {
$implode[] = "c.`status` = '" . (int)$data['filter_status'] . "'";
}
if (!empty($data['filter_date_from'])) {
$implode[] = "DATE(c.`date_added`) >= DATE('" . $this->db->escape((string)$data['filter_date_from']) . "')";
}
if (!empty($data['filter_date_to'])) {
$implode[] = "DATE(c.`date_added`) <= DATE('" . $this->db->escape((string)$data['filter_date_to']) . "')";
}
if ($implode) {
$sql .= " WHERE " . implode(" AND ", $implode);
}
$query = $this->db->query($sql);
return (int)$query->row['total'];
}
/**
* @param int $address_id
*
* @return array
*/
public function getAddress(int $address_id): array {
$address_query = $this->db->query("SELECT * FROM `" . DB_PREFIX . "address` WHERE `address_id` = '" . (int)$address_id . "'");
if ($address_query->num_rows) {
$country_query = $this->db->query("SELECT *, c.name FROM `" . DB_PREFIX . "country` c LEFT JOIN `" . DB_PREFIX . "address_format` af ON (c.`address_format_id` = af.`address_format_id`) WHERE `country_id` = '" . (int)$address_query->row['country_id'] . "'");
if ($country_query->num_rows) {
$country = $country_query->row['name'];
$iso_code_2 = $country_query->row['iso_code_2'];
$iso_code_3 = $country_query->row['iso_code_3'];
$address_format = $country_query->row['address_format'];
} else {
$country = '';
$iso_code_2 = '';
$iso_code_3 = '';
$address_format = '';
}
$zone_query = $this->db->query("SELECT * FROM `" . DB_PREFIX . "zone` WHERE `zone_id` = '" . (int)$address_query->row['zone_id'] . "'");
if ($zone_query->num_rows) {
$zone = $zone_query->row['name'];
$zone_code = $zone_query->row['code'];
} else {
$zone = '';
$zone_code = '';
}
return [
'address_id' => $address_query->row['address_id'],
'customer_id' => $address_query->row['customer_id'],
'firstname' => $address_query->row['firstname'],
'lastname' => $address_query->row['lastname'],
'company' => $address_query->row['company'],
'address_1' => $address_query->row['address_1'],
'address_2' => $address_query->row['address_2'],
'postcode' => $address_query->row['postcode'],
'city' => $address_query->row['city'],
'zone_id' => $address_query->row['zone_id'],
'zone' => $zone,
'zone_code' => $zone_code,
'country_id' => $address_query->row['country_id'],
'country' => $country,
'iso_code_2' => $iso_code_2,
'iso_code_3' => $iso_code_3,
'address_format' => $address_format,
'custom_field' => json_decode($address_query->row['custom_field'], true),
'default' => $address_query->row['default']
];
}
return [];
}
/**
* @param int $customer_id
*
* @return array
*/
public function getAddresses(int $customer_id): array {
$address_data = [];
$query = $this->db->query("SELECT `address_id` FROM `" . DB_PREFIX . "address` WHERE `customer_id` = '" . (int)$customer_id . "'");
foreach ($query->rows as $result) {
$address_info = $this->getAddress($result['address_id']);
if ($address_info) {
$address_data[] = $address_info;
}
}
return $address_data;
}
/**
* @param int $customer_id
*
* @return int
*/
public function getTotalAddressesByCustomerId(int $customer_id): int {
$query = $this->db->query("SELECT COUNT(*) AS `total` FROM `" . DB_PREFIX . "address` WHERE `customer_id` = '" . (int)$customer_id . "'");
return (int)$query->row['total'];
}
/**
* @param int $country_id
*
* @return int
*/
public function getTotalAddressesByCountryId(int $country_id): int {
$query = $this->db->query("SELECT COUNT(*) AS `total` FROM `" . DB_PREFIX . "address` WHERE `country_id` = '" . (int)$country_id . "'");
return (int)$query->row['total'];
}
/**
* @param int $zone_id
*
* @return int
*/
public function getTotalAddressesByZoneId(int $zone_id): int {
$query = $this->db->query("SELECT COUNT(*) AS `total` FROM `" . DB_PREFIX . "address` WHERE `zone_id` = '" . (int)$zone_id . "'");
return (int)$query->row['total'];
}
/**
* @param int $customer_group_id
*
* @return int
*/
public function getTotalCustomersByCustomerGroupId(int $customer_group_id): int {
$query = $this->db->query("SELECT COUNT(*) AS `total` FROM `" . DB_PREFIX . "customer` WHERE `customer_group_id` = '" . (int)$customer_group_id . "'");
if ($query->num_rows) {
return (int)$query->row['total'];
} else {
return 0;
}
}
/**
* @param int $customer_id
* @param string $comment
*
* @return void
*/
public function addHistory(int $customer_id, string $comment): void {
$this->db->query("INSERT INTO `" . DB_PREFIX . "customer_history` SET `customer_id` = '" . (int)$customer_id . "', `comment` = '" . $this->db->escape(strip_tags($comment)) . "', `date_added` = NOW()");
}
/**
* @param int $customer_id
* @param int $start
* @param int $limit
*
* @return array
*/
public function getHistories(int $customer_id, int $start = 0, int $limit = 10): array {
if ($start < 0) {
$start = 0;
}
if ($limit < 1) {
$limit = 10;
}
$query = $this->db->query("SELECT `comment`, `date_added` FROM `" . DB_PREFIX . "customer_history` WHERE `customer_id` = '" . (int)$customer_id . "' ORDER BY `date_added` DESC LIMIT " . (int)$start . "," . (int)$limit);
return $query->rows;
}
/**
* @param int $customer_id
*
* @return int
*/
public function getTotalHistories(int $customer_id): int {
$query = $this->db->query("SELECT COUNT(*) AS `total` FROM `" . DB_PREFIX . "customer_history` WHERE `customer_id` = '" . (int)$customer_id . "'");
return (int)$query->row['total'];
}
/**
* @param int $customer_id
* @param string $description
* @param float $amount
* @param int $order_id
*
* @return void
*/
public function addTransaction(int $customer_id, string $description = '', float $amount = 0, int $order_id = 0): void {
$this->db->query("INSERT INTO `" . DB_PREFIX . "customer_transaction` SET `customer_id` = '" . (int)$customer_id . "', `order_id` = '" . (int)$order_id . "', `description` = '" . $this->db->escape($description) . "', `amount` = '" . (float)$amount . "', `date_added` = NOW()");
}
/**
* @param int $order_id
*
* @return void
*/
public function deleteTransactionByOrderId(int $order_id): void {
$this->db->query("DELETE FROM `" . DB_PREFIX . "customer_transaction` WHERE `order_id` = '" . (int)$order_id . "'");
}
/**
* @param int $customer_id
* @param int $start
* @param int $limit
*
* @return array
*/
public function getTransactions(int $customer_id, int $start = 0, int $limit = 10): array {
if ($start < 0) {
$start = 0;
}
if ($limit < 1) {
$limit = 10;
}
$query = $this->db->query("SELECT * FROM `" . DB_PREFIX . "customer_transaction` WHERE `customer_id` = '" . (int)$customer_id . "' ORDER BY `date_added` DESC LIMIT " . (int)$start . "," . (int)$limit);
return $query->rows;
}
/**
* @param int $customer_id
*
* @return int
*/
public function getTotalTransactions(int $customer_id): int {
$query = $this->db->query("SELECT COUNT(*) AS `total` FROM `" . DB_PREFIX . "customer_transaction` WHERE `customer_id` = '" . (int)$customer_id . "'");
return (int)$query->row['total'];
}
/**
* @param int $customer_id
*
* @return float
*/
public function getTransactionTotal(int $customer_id): float {
$query = $this->db->query("SELECT SUM(`amount`) AS `total` FROM `" . DB_PREFIX . "customer_transaction` WHERE `customer_id` = '" . (int)$customer_id . "'");
return (float)$query->row['total'];
}
/**
* @param int $order_id
*
* @return int
*/
public function getTotalTransactionsByOrderId(int $order_id): int {
$query = $this->db->query("SELECT COUNT(*) AS `total` FROM `" . DB_PREFIX . "customer_transaction` WHERE `order_id` = '" . (int)$order_id . "'");
return (int)$query->row['total'];
}
/**
* @param int $customer_id
* @param string $description
* @param int $points
* @param int $order_id
*
* @return void
*/
public function addReward(int $customer_id, string $description = '', int $points = 0, int $order_id = 0): void {
$this->db->query("INSERT INTO `" . DB_PREFIX . "customer_reward` SET `customer_id` = '" . (int)$customer_id . "', `order_id` = '" . (int)$order_id . "', `points` = '" . (int)$points . "', `description` = '" . $this->db->escape($description) . "', `date_added` = NOW()");
}
/**
* @param int $order_id
*
* @return void
*/
public function deleteReward(int $order_id): void {
$this->db->query("DELETE FROM `" . DB_PREFIX . "customer_reward` WHERE `order_id` = '" . (int)$order_id . "' AND `points` > '0'");
}
/**
* @param int $customer_id
* @param int $start
* @param int $limit
*
* @return array
*/
public function getRewards(int $customer_id, int $start = 0, int $limit = 10): array {
if ($start < 0) {
$start = 0;
}
if ($limit < 1) {
$limit = 10;
}
$query = $this->db->query("SELECT * FROM `" . DB_PREFIX . "customer_reward` WHERE `customer_id` = '" . (int)$customer_id . "' ORDER BY `date_added` DESC LIMIT " . (int)$start . "," . (int)$limit);
return $query->rows;
}
/**
* @param int $customer_id
*
* @return int
*/
public function getTotalRewards(int $customer_id): int {
$query = $this->db->query("SELECT COUNT(*) AS `total` FROM `" . DB_PREFIX . "customer_reward` WHERE `customer_id` = '" . (int)$customer_id . "'");
return (int)$query->row['total'];
}
/**
* @param int $customer_id
*
* @return int
*/
public function getRewardTotal(int $customer_id): int {
$query = $this->db->query("SELECT SUM(points) AS `total` FROM `" . DB_PREFIX . "customer_reward` WHERE `customer_id` = '" . (int)$customer_id . "'");
return (int)$query->row['total'];
}
/**
* @param int $order_id
*
* @return int
*/
public function getTotalRewardsByOrderId(int $order_id): int {
$query = $this->db->query("SELECT COUNT(*) AS `total` FROM `" . DB_PREFIX . "customer_reward` WHERE `order_id` = '" . (int)$order_id . "' AND `points` > '0'");
return (int)$query->row['total'];
}
/**
* @param int $customer_id
* @param int $start
* @param int $limit
*
* @return array
*/
public function getIps(int $customer_id, int $start = 0, int $limit = 10): array {
if ($start < 0) {
$start = 0;
}
if ($limit < 1) {
$limit = 10;
}
$query = $this->db->query("SELECT `ip`, `store_id`, `country`, `date_added` FROM `" . DB_PREFIX . "customer_ip` WHERE `customer_id` = '" . (int)$customer_id . "' ORDER BY `date_added` DESC LIMIT " . (int)$start . "," . (int)$limit);
return $query->rows;
}
/**
* @param int $customer_id
*
* @return int
*/
public function getTotalIps(int $customer_id): int {
$query = $this->db->query("SELECT COUNT(*) AS `total` FROM `" . DB_PREFIX . "customer_ip` WHERE `customer_id` = '" . (int)$customer_id . "'");
return (int)$query->row['total'];
}
/**
* @param string $ip
*
* @return int
*/
public function getTotalCustomersByIp(string $ip): int {
$query = $this->db->query("SELECT COUNT(DISTINCT `customer_id`) AS `total` FROM `" . DB_PREFIX . "customer_ip` WHERE `ip` = '" . $this->db->escape($ip) . "'");
return (int)$query->row['total'];
}
/**
* @param string $email
*
* @return array
*/
public function getTotalLoginAttempts(string $email): array {
$query = $this->db->query("SELECT * FROM `" . DB_PREFIX . "customer_login` WHERE `email` = '" . $this->db->escape(oc_strtolower($email)) . "'");
return $query->row;
}
/**
* @param string $email
*
* @return void
*/
public function deleteLoginAttempts(string $email): void {
$this->db->query("DELETE FROM `" . DB_PREFIX . "customer_login` WHERE `email` = '" . $this->db->escape(oc_strtolower($email)) . "'");
}
}

View File

@ -0,0 +1,151 @@
<?php
namespace Opencart\Admin\Model\Customer;
/**
* Class Customer Approval
*
* @package Opencart\Admin\Model\Customer
*/
class CustomerApproval extends \Opencart\System\Engine\Model {
/**
* @param array $data
*
* @return array
*/
public function getCustomerApprovals(array $data = []): array {
$sql = "SELECT *, CONCAT(c.`firstname`, ' ', c.`lastname`) AS customer, cgd.`name` AS customer_group, ca.`type` FROM `" . DB_PREFIX . "customer_approval` ca LEFT JOIN `" . DB_PREFIX . "customer` c ON (ca.`customer_id` = c.`customer_id`) LEFT JOIN `" . DB_PREFIX . "customer_group_description` cgd ON (c.`customer_group_id` = cgd.`customer_group_id`) WHERE cgd.`language_id` = '" . (int)$this->config->get('config_language_id') . "'";
if (!empty($data['filter_customer'])) {
$sql .= " AND CONCAT(c.`firstname`, ' ', c.`lastname`) LIKE '" . $this->db->escape('%' . (string)$data['filter_customer'] . '%') . "'";
}
if (!empty($data['filter_email'])) {
$sql .= " AND c.`email` LIKE '" . $this->db->escape((string)$data['filter_email'] . '%') . "'";
}
if (!empty($data['filter_customer_group_id'])) {
$sql .= " AND c.`customer_group_id` = '" . (int)$data['filter_customer_group_id'] . "'";
}
if (!empty($data['filter_type'])) {
$sql .= " AND ca.`type` = '" . $this->db->escape((string)$data['filter_type']) . "'";
}
if (!empty($data['filter_date_from'])) {
$sql .= " AND DATE(c.`date_added`) >= DATE('" . $this->db->escape((string)$data['filter_date_from']) . "')";
}
if (!empty($data['filter_date_to'])) {
$sql .= " AND DATE(c.`date_added`) <= DATE('" . $this->db->escape((string)$data['filter_date_to']) . "')";
}
$sql .= " ORDER BY c.`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 int $customer_approval_id
*
* @return array
*/
public function getCustomerApproval(int $customer_approval_id): array {
$query = $this->db->query("SELECT * FROM `" . DB_PREFIX . "customer_approval` WHERE `customer_approval_id` = '" . (int)$customer_approval_id . "'");
return $query->row;
}
/**
* @param array $data
*
* @return int
*/
public function getTotalCustomerApprovals(array $data = []): int {
$sql = "SELECT COUNT(*) AS `total` FROM `" . DB_PREFIX . "customer_approval` ca LEFT JOIN `" . DB_PREFIX . "customer` c ON (ca.`customer_id` = c.`customer_id`)";
$implode = [];
if (!empty($data['filter_customer'])) {
$implode[] = "CONCAT(c.`firstname`, ' ', c.`lastname`) LIKE '" . $this->db->escape('%' . (string)$data['filter_customer'] . '%') . "'";
}
if (!empty($data['filter_email'])) {
$implode[] = "c.`email` LIKE '" . $this->db->escape((string)$data['filter_email'] . '%') . "'";
}
if (!empty($data['filter_customer_group_id'])) {
$implode[] = "c.`customer_group_id` = '" . (int)$data['filter_customer_group_id'] . "'";
}
if (!empty($data['filter_type'])) {
$implode[] = "ca.`type` = '" . $this->db->escape((string)$data['filter_type']) . "'";
}
if (!empty($data['filter_date_from'])) {
$implode[] = "DATE(c.`date_added`) >= DATE('" . $this->db->escape((string)$data['filter_date_from']) . "')";
}
if (!empty($data['filter_date_to'])) {
$implode[] = "DATE(c.`date_added`) <= DATE('" . $this->db->escape((string)$data['filter_date_to']) . "')";
}
if ($implode) {
$sql .= " WHERE " . implode(" AND ", $implode);
}
$query = $this->db->query($sql);
return (int)$query->row['total'];
}
/**
* @param int $customer_id
*
* @return void
*/
public function approveCustomer(int $customer_id): void {
$this->db->query("UPDATE `" . DB_PREFIX . "customer` SET `status` = '1' WHERE `customer_id` = '" . (int)$customer_id . "'");
$this->db->query("DELETE FROM `" . DB_PREFIX . "customer_approval` WHERE `customer_id` = '" . (int)$customer_id . "' AND `type` = 'customer'");
}
/**
* @param int $customer_id
*
* @return void
*/
public function denyCustomer(int $customer_id): void {
$this->db->query("DELETE FROM `" . DB_PREFIX . "customer_approval` WHERE `customer_id` = '" . (int)$customer_id . "' AND `type` = 'customer'");
}
/**
* @param int $customer_id
*
* @return void
*/
public function approveAffiliate(int $customer_id): void {
$this->db->query("UPDATE `" . DB_PREFIX . "customer_affiliate` SET `status` = '1' WHERE `customer_id` = '" . (int)$customer_id . "'");
$this->db->query("DELETE FROM `" . DB_PREFIX . "customer_approval` WHERE `customer_id` = '" . (int)$customer_id . "' AND `type` = 'affiliate'");
}
/**
* @param int $customer_id
*
* @return void
*/
public function denyAffiliate(int $customer_id): void {
$this->db->query("DELETE FROM `" . DB_PREFIX . "customer_approval` WHERE `customer_id` = '" . (int)$customer_id . "' AND `type` = 'affiliate'");
}
}

View File

@ -0,0 +1,137 @@
<?php
namespace Opencart\Admin\Model\Customer;
/**
* Class Customer Group
*
* @package Opencart\Admin\Model\Customer
*/
class CustomerGroup extends \Opencart\System\Engine\Model {
/**
* @param array $data
*
* @return int
*/
public function addCustomerGroup(array $data): int {
$this->db->query("INSERT INTO `" . DB_PREFIX . "customer_group` SET `approval` = '" . (isset($data['approval']) ? (bool)$data['approval'] : 0) . "', `sort_order` = '" . (int)$data['sort_order'] . "'");
$customer_group_id = $this->db->getLastId();
foreach ($data['customer_group_description'] as $language_id => $value) {
$this->db->query("INSERT INTO `" . DB_PREFIX . "customer_group_description` SET `customer_group_id` = '" . (int)$customer_group_id . "', `language_id` = '" . (int)$language_id . "', `name` = '" . $this->db->escape($value['name']) . "', `description` = '" . $this->db->escape($value['description']) . "'");
}
return $customer_group_id;
}
/**
* @param int $customer_group_id
* @param array $data
*
* @return void
*/
public function editCustomerGroup(int $customer_group_id, array $data): void {
$this->db->query("UPDATE `" . DB_PREFIX . "customer_group` SET `approval` = '" . (isset($data['approval']) ? (bool)$data['approval'] : 0) . "', `sort_order` = '" . (int)$data['sort_order'] . "' WHERE `customer_group_id` = '" . (int)$customer_group_id . "'");
$this->db->query("DELETE FROM `" . DB_PREFIX . "customer_group_description` WHERE `customer_group_id` = '" . (int)$customer_group_id . "'");
foreach ($data['customer_group_description'] as $language_id => $value) {
$this->db->query("INSERT INTO `" . DB_PREFIX . "customer_group_description` SET `customer_group_id` = '" . (int)$customer_group_id . "', `language_id` = '" . (int)$language_id . "', `name` = '" . $this->db->escape($value['name']) . "', `description` = '" . $this->db->escape($value['description']) . "'");
}
}
/**
* @param int $customer_group_id
*
* @return void
*/
public function deleteCustomerGroup(int $customer_group_id): void {
$this->db->query("DELETE FROM `" . DB_PREFIX . "customer_group` WHERE `customer_group_id` = '" . (int)$customer_group_id . "'");
$this->db->query("DELETE FROM `" . DB_PREFIX . "customer_group_description` WHERE `customer_group_id` = '" . (int)$customer_group_id . "'");
$this->db->query("DELETE FROM `" . DB_PREFIX . "product_discount` WHERE `customer_group_id` = '" . (int)$customer_group_id . "'");
$this->db->query("DELETE FROM `" . DB_PREFIX . "product_special` WHERE `customer_group_id` = '" . (int)$customer_group_id . "'");
$this->db->query("DELETE FROM `" . DB_PREFIX . "product_reward` WHERE `customer_group_id` = '" . (int)$customer_group_id . "'");
$this->db->query("DELETE FROM `" . DB_PREFIX . "tax_rate_to_customer_group` WHERE `customer_group_id` = '" . (int)$customer_group_id . "'");
}
/**
* @param int $customer_group_id
*
* @return array
*/
public function getCustomerGroup(int $customer_group_id): array {
$query = $this->db->query("SELECT DISTINCT * FROM `" . DB_PREFIX . "customer_group` cg LEFT JOIN `" . DB_PREFIX . "customer_group_description` cgd ON (cg.`customer_group_id` = cgd.`customer_group_id`) WHERE cg.`customer_group_id` = '" . (int)$customer_group_id . "' AND cgd.`language_id` = '" . (int)$this->config->get('config_language_id') . "'");
return $query->row;
}
/**
* @param array $data
*
* @return array
*/
public function getCustomerGroups(array $data = []): array {
$sql = "SELECT * FROM `" . DB_PREFIX . "customer_group` cg LEFT JOIN `" . DB_PREFIX . "customer_group_description` cgd ON (cg.`customer_group_id` = cgd.`customer_group_id`) WHERE cgd.`language_id` = '" . (int)$this->config->get('config_language_id') . "'";
$sort_data = [
'cgd.name',
'cg.sort_order'
];
if (isset($data['sort']) && in_array($data['sort'], $sort_data)) {
$sql .= " ORDER BY " . $data['sort'];
} else {
$sql .= " ORDER BY cgd.`name`";
}
if (isset($data['order']) && ($data['order'] == 'DESC')) {
$sql .= " DESC";
} else {
$sql .= " ASC";
}
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 int $customer_group_id
*
* @return array
*/
public function getDescriptions(int $customer_group_id): array {
$customer_group_data = [];
$query = $this->db->query("SELECT * FROM `" . DB_PREFIX . "customer_group_description` WHERE `customer_group_id` = '" . (int)$customer_group_id . "'");
foreach ($query->rows as $result) {
$customer_group_data[$result['language_id']] = [
'name' => $result['name'],
'description' => $result['description']
];
}
return $customer_group_data;
}
/**
* @return int
*/
public function getTotalCustomerGroups(): int {
$query = $this->db->query("SELECT COUNT(*) AS `total` FROM `" . DB_PREFIX . "customer_group`");
return (int)$query->row['total'];
}
}

View File

@ -0,0 +1,139 @@
<?php
namespace Opencart\Admin\Model\Customer;
/**
* Class GDPR
*
* @package Opencart\Admin\Model\Customer
*/
class Gdpr extends \Opencart\System\Engine\Model {
/**
* @param int $gdpr_id
* @param int $status
*
* @return void
*/
public function editStatus(int $gdpr_id, int $status): void {
$this->db->query("UPDATE `" . DB_PREFIX . "gdpr` SET `status` = '" . (int)$status . "' WHERE `gdpr_id` = '" . (int)$gdpr_id . "'");
}
/**
* @param int $gdpr_id
*
* @return void
*/
public function deleteGdpr(int $gdpr_id): void {
$this->db->query("DELETE FROM `" . DB_PREFIX . "gdpr` WHERE `gdpr_id` = '" . (int)$gdpr_id . "'");
}
/**
* @param array $data
*
* @return array
*/
public function getGdprs(array $data = []): array {
$sql = "SELECT * FROM `" . DB_PREFIX . "gdpr`";
$implode = [];
if (!empty($data['filter_email'])) {
$implode[] = "`email` LIKE '" . $this->db->escape((string)$data['filter_email']) . "'";
}
if (!empty($data['filter_action'])) {
$implode[] = "`action` = '" . $this->db->escape((string)$data['filter_action']) . "'";
}
if (isset($data['filter_status']) && $data['filter_status'] !== '') {
$implode[] = "`status` = '" . (int)$data['filter_status'] . "'";
}
if (!empty($data['filter_date_from'])) {
$implode[] = "DATE(`date_added`) >= DATE('" . $this->db->escape((string)$data['filter_date_from']) . "')";
}
if (!empty($data['filter_date_to'])) {
$implode[] = "DATE(`date_added`) <= DATE('" . $this->db->escape((string)$data['filter_date_to']) . "')";
}
if ($implode) {
$sql .= " WHERE " . implode(" AND ", $implode);
}
$sql .= " ORDER BY `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 int $gdpr_id
*
* @return array
*/
public function getGdpr(int $gdpr_id): array {
$query = $this->db->query("SELECT * FROM `" . DB_PREFIX . "gdpr` WHERE `gdpr_id` = '" . (int)$gdpr_id . "'");
return $query->row;
}
/**
* @param array $data
*
* @return int
*/
public function getTotalGdprs(array $data = []): int {
$sql = "SELECT COUNT(*) AS `total` FROM `" . DB_PREFIX . "gdpr`";
$implode = [];
if (!empty($data['filter_email'])) {
$implode[] = "`email` LIKE '" . $this->db->escape((string)$data['filter_email']) . "'";
}
if (!empty($data['filter_action'])) {
$implode[] = "`action` = '" . $this->db->escape((string)$data['filter_action']) . "'";
}
if (isset($data['filter_status']) && $data['filter_status'] !== '') {
$implode[] = "`status` = '" . (int)$data['filter_status'] . "'";
}
if (!empty($data['filter_date_from'])) {
$implode[] = "DATE(`date_added`) >= DATE('" . $this->db->escape((string)$data['filter_date_from']) . "')";
}
if (!empty($data['filter_date_to'])) {
$implode[] = "DATE(`date_added`) <= DATE('" . $this->db->escape((string)$data['filter_date_to']) . "')";
}
if ($implode) {
$sql .= " WHERE " . implode(" AND ", $implode);
}
$query = $this->db->query($sql);
return (int)$query->row['total'];
}
/**
* @return array
*/
public function getExpires(): array {
$query = $this->db->query("SELECT * FROM `" . DB_PREFIX . "gdpr` WHERE `status` = '2' AND DATE(`date_added`) <= DATE('" . $this->db->escape(date('Y-m-d', strtotime('+' . (int)$this->config->get('config_gdpr_limit') . ' days'))) . "') ORDER BY `date_added` DESC");
return $query->rows;
}
}