aboutsummaryrefslogtreecommitdiffstats
path: root/public/admin/model/setting
diff options
context:
space:
mode:
Diffstat (limited to 'public/admin/model/setting')
-rw-r--r--public/admin/model/setting/event.php88
-rw-r--r--public/admin/model/setting/extension.php77
-rw-r--r--public/admin/model/setting/modification.php80
-rw-r--r--public/admin/model/setting/module.php42
-rw-r--r--public/admin/model/setting/setting.php54
-rw-r--r--public/admin/model/setting/store.php108
6 files changed, 449 insertions, 0 deletions
diff --git a/public/admin/model/setting/event.php b/public/admin/model/setting/event.php
new file mode 100644
index 0000000..6e76425
--- /dev/null
+++ b/public/admin/model/setting/event.php
@@ -0,0 +1,88 @@
+<?php
+class ModelSettingEvent extends Model {
+ public function addEvent($code, $trigger, $action, $status = 1, $sort_order = 0) {
+ $this->db->query("INSERT INTO `" . DB_PREFIX . "event` SET `code` = '" . $this->db->escape($code) . "', `trigger` = '" . $this->db->escape($trigger) . "', `action` = '" . $this->db->escape($action) . "', `sort_order` = '" . (int)$sort_order . "', `status` = '" . (int)$status . "'");
+
+ return $this->db->getLastId();
+ }
+
+ public function deleteEvent($event_id) {
+ $this->db->query("DELETE FROM `" . DB_PREFIX . "event` WHERE `event_id` = '" . (int)$event_id . "'");
+ }
+
+ public function deleteEventByCode($code) {
+ $this->db->query("DELETE FROM `" . DB_PREFIX . "event` WHERE `code` = '" . $this->db->escape($code) . "'");
+ }
+
+ public function enableEvent($event_id) {
+ $this->db->query("UPDATE `" . DB_PREFIX . "event` SET `status` = '1' WHERE event_id = '" . (int)$event_id . "'");
+ }
+
+ public function disableEvent($event_id) {
+ $this->db->query("UPDATE `" . DB_PREFIX . "event` SET `status` = '0' WHERE event_id = '" . (int)$event_id . "'");
+ }
+
+ public function uninstall($type, $code) {
+ $this->db->query("DELETE FROM `" . DB_PREFIX . "extension` WHERE `type` = '" . $this->db->escape($type) . "' AND `code` = '" . $this->db->escape($code) . "'");
+ $this->db->query("DELETE FROM `" . DB_PREFIX . "setting` WHERE `code` = '" . $this->db->escape($code) . "'");
+ }
+
+ public function getEvent($event_id) {
+ $query = $this->db->query("SELECT DISTINCT * FROM `" . DB_PREFIX . "event` WHERE `event_id` = '" . (int)$event_id . "' LIMIT 1");
+
+ return $query->row;
+ }
+
+ public function getEventByCode($code) {
+ $query = $this->db->query("SELECT DISTINCT * FROM `" . DB_PREFIX . "event` WHERE `code` = '" . $this->db->escape($code) . "' LIMIT 1");
+
+ return $query->row;
+ }
+
+ public function getEvents($data = array()) {
+ $sql = "SELECT * FROM `" . DB_PREFIX . "event`";
+
+ $sort_data = array(
+ 'code',
+ 'trigger',
+ 'action',
+ 'sort_order',
+ 'status',
+ 'date_added'
+ );
+
+ if (isset($data['sort']) && in_array($data['sort'], $sort_data)) {
+ $sql .= " ORDER BY `" . $data['sort'] . "`";
+ } else {
+ $sql .= " ORDER BY `sort_order`";
+ }
+
+ 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;
+ }
+
+ public function getTotalEvents() {
+ $query = $this->db->query("SELECT COUNT(*) AS total FROM `" . DB_PREFIX . "event`");
+
+ return $query->row['total'];
+ }
+} \ No newline at end of file
diff --git a/public/admin/model/setting/extension.php b/public/admin/model/setting/extension.php
new file mode 100644
index 0000000..4c42f0e
--- /dev/null
+++ b/public/admin/model/setting/extension.php
@@ -0,0 +1,77 @@
+<?php
+class ModelSettingExtension extends Model {
+ public function getInstalled($type) {
+ $extension_data = array();
+
+ $query = $this->db->query("SELECT * FROM `" . DB_PREFIX . "extension` WHERE `type` = '" . $this->db->escape($type) . "' ORDER BY `code`");
+
+ foreach ($query->rows as $result) {
+ $extension_data[] = $result['code'];
+ }
+
+ return $extension_data;
+ }
+
+ public function install($type, $code) {
+ $extensions = $this->getInstalled($type);
+
+ if (!in_array($code, $extensions)) {
+ $this->db->query("INSERT INTO `" . DB_PREFIX . "extension` SET `type` = '" . $this->db->escape($type) . "', `code` = '" . $this->db->escape($code) . "'");
+ }
+ }
+
+ public function uninstall($type, $code) {
+ $this->db->query("DELETE FROM `" . DB_PREFIX . "extension` WHERE `type` = '" . $this->db->escape($type) . "' AND `code` = '" . $this->db->escape($code) . "'");
+ $this->db->query("DELETE FROM `" . DB_PREFIX . "setting` WHERE `code` = '" . $this->db->escape($type . '_' . $code) . "'");
+ }
+
+ public function addExtensionInstall($filename, $extension_download_id = 0) {
+ $this->db->query("INSERT INTO `" . DB_PREFIX . "extension_install` SET `filename` = '" . $this->db->escape($filename) . "', `extension_download_id` = '" . (int)$extension_download_id . "', `date_added` = NOW()");
+
+ return $this->db->getLastId();
+ }
+
+ public function deleteExtensionInstall($extension_install_id) {
+ $this->db->query("DELETE FROM `" . DB_PREFIX . "extension_install` WHERE `extension_install_id` = '" . (int)$extension_install_id . "'");
+ }
+
+ public function getExtensionInstalls($start = 0, $limit = 10) {
+ if ($start < 0) {
+ $start = 0;
+ }
+
+ if ($limit < 1) {
+ $limit = 10;
+ }
+
+ $query = $this->db->query("SELECT * FROM `" . DB_PREFIX . "extension_install` ORDER BY date_added ASC LIMIT " . (int)$start . "," . (int)$limit);
+
+ return $query->rows;
+ }
+
+ public function getExtensionInstallByExtensionDownloadId($extension_download_id) {
+ $query = $this->db->query("SELECT * FROM `" . DB_PREFIX . "extension_install` WHERE `extension_download_id` = '" . (int)$extension_download_id . "'");
+
+ return $query->row;
+ }
+
+ public function getTotalExtensionInstalls() {
+ $query = $this->db->query("SELECT COUNT(*) AS total FROM `" . DB_PREFIX . "extension_install`");
+
+ return $query->row['total'];
+ }
+
+ public function addExtensionPath($extension_install_id, $path) {
+ $this->db->query("INSERT INTO `" . DB_PREFIX . "extension_path` SET `extension_install_id` = '" . (int)$extension_install_id . "', `path` = '" . $this->db->escape($path) . "', `date_added` = NOW()");
+ }
+
+ public function deleteExtensionPath($extension_path_id) {
+ $this->db->query("DELETE FROM `" . DB_PREFIX . "extension_path` WHERE `extension_path_id` = '" . (int)$extension_path_id . "'");
+ }
+
+ public function getExtensionPathsByExtensionInstallId($extension_install_id) {
+ $query = $this->db->query("SELECT * FROM `" . DB_PREFIX . "extension_path` WHERE `extension_install_id` = '" . (int)$extension_install_id . "' ORDER BY `date_added` ASC");
+
+ return $query->rows;
+ }
+} \ No newline at end of file
diff --git a/public/admin/model/setting/modification.php b/public/admin/model/setting/modification.php
new file mode 100644
index 0000000..28ca33c
--- /dev/null
+++ b/public/admin/model/setting/modification.php
@@ -0,0 +1,80 @@
+<?php
+class ModelSettingModification extends Model {
+ public function addModification($data) {
+ $this->db->query("INSERT INTO `" . DB_PREFIX . "modification` SET `extension_install_id` = '" . (int)$data['extension_install_id'] . "', `name` = '" . $this->db->escape($data['name']) . "', `code` = '" . $this->db->escape($data['code']) . "', `author` = '" . $this->db->escape($data['author']) . "', `version` = '" . $this->db->escape($data['version']) . "', `link` = '" . $this->db->escape($data['link']) . "', `xml` = '" . $this->db->escape($data['xml']) . "', `status` = '" . (int)$data['status'] . "', `date_added` = NOW()");
+ }
+
+ public function deleteModification($modification_id) {
+ $this->db->query("DELETE FROM `" . DB_PREFIX . "modification` WHERE `modification_id` = '" . (int)$modification_id . "'");
+ }
+
+ public function deleteModificationsByExtensionInstallId($extension_install_id) {
+ $this->db->query("DELETE FROM `" . DB_PREFIX . "modification` WHERE `extension_install_id` = '" . (int)$extension_install_id . "'");
+ }
+
+ public function enableModification($modification_id) {
+ $this->db->query("UPDATE `" . DB_PREFIX . "modification` SET `status` = '1' WHERE `modification_id` = '" . (int)$modification_id . "'");
+ }
+
+ public function disableModification($modification_id) {
+ $this->db->query("UPDATE `" . DB_PREFIX . "modification` SET `status` = '0' WHERE `modification_id` = '" . (int)$modification_id . "'");
+ }
+
+ public function getModification($modification_id) {
+ $query = $this->db->query("SELECT * FROM `" . DB_PREFIX . "modification` WHERE `modification_id` = '" . (int)$modification_id . "'");
+
+ return $query->row;
+ }
+
+ public function getModifications($data = array()) {
+ $sql = "SELECT * FROM `" . DB_PREFIX . "modification`";
+
+ $sort_data = array(
+ 'name',
+ 'author',
+ 'version',
+ 'status',
+ '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;
+ }
+
+ public function getTotalModifications() {
+ $query = $this->db->query("SELECT COUNT(*) AS total FROM `" . DB_PREFIX . "modification`");
+
+ return $query->row['total'];
+ }
+
+ public function getModificationByCode($code) {
+ $query = $this->db->query("SELECT * FROM `" . DB_PREFIX . "modification` WHERE `code` = '" . $this->db->escape($code) . "'");
+
+ return $query->row;
+ }
+} \ No newline at end of file
diff --git a/public/admin/model/setting/module.php b/public/admin/model/setting/module.php
new file mode 100644
index 0000000..c05b53a
--- /dev/null
+++ b/public/admin/model/setting/module.php
@@ -0,0 +1,42 @@
+<?php
+class ModelSettingModule extends Model {
+ public function addModule($code, $data) {
+ $this->db->query("INSERT INTO `" . DB_PREFIX . "module` SET `name` = '" . $this->db->escape($data['name']) . "', `code` = '" . $this->db->escape($code) . "', `setting` = '" . $this->db->escape(json_encode($data)) . "'");
+ }
+
+ public function editModule($module_id, $data) {
+ $this->db->query("UPDATE `" . DB_PREFIX . "module` SET `name` = '" . $this->db->escape($data['name']) . "', `setting` = '" . $this->db->escape(json_encode($data)) . "' WHERE `module_id` = '" . (int)$module_id . "'");
+ }
+
+ public function deleteModule($module_id) {
+ $this->db->query("DELETE FROM `" . DB_PREFIX . "module` WHERE `module_id` = '" . (int)$module_id . "'");
+ $this->db->query("DELETE FROM `" . DB_PREFIX . "layout_module` WHERE `code` LIKE '%." . (int)$module_id . "'");
+ }
+
+ public function getModule($module_id) {
+ $query = $this->db->query("SELECT * FROM `" . DB_PREFIX . "module` WHERE `module_id` = '" . (int)$module_id . "'");
+
+ if ($query->row) {
+ return json_decode($query->row['setting'], true);
+ } else {
+ return array();
+ }
+ }
+
+ public function getModules() {
+ $query = $this->db->query("SELECT * FROM `" . DB_PREFIX . "module` ORDER BY `code`");
+
+ return $query->rows;
+ }
+
+ public function getModulesByCode($code) {
+ $query = $this->db->query("SELECT * FROM `" . DB_PREFIX . "module` WHERE `code` = '" . $this->db->escape($code) . "' ORDER BY `name`");
+
+ return $query->rows;
+ }
+
+ public function deleteModulesByCode($code) {
+ $this->db->query("DELETE FROM `" . DB_PREFIX . "module` WHERE `code` = '" . $this->db->escape($code) . "'");
+ $this->db->query("DELETE FROM `" . DB_PREFIX . "layout_module` WHERE `code` LIKE '" . $this->db->escape($code) . "' OR `code` LIKE '" . $this->db->escape($code . '.%') . "'");
+ }
+} \ No newline at end of file
diff --git a/public/admin/model/setting/setting.php b/public/admin/model/setting/setting.php
new file mode 100644
index 0000000..613b621
--- /dev/null
+++ b/public/admin/model/setting/setting.php
@@ -0,0 +1,54 @@
+<?php
+class ModelSettingSetting extends Model {
+ public function getSetting($code, $store_id = 0) {
+ $setting_data = array();
+
+ $query = $this->db->query("SELECT * FROM " . DB_PREFIX . "setting WHERE store_id = '" . (int)$store_id . "' AND `code` = '" . $this->db->escape($code) . "'");
+
+ foreach ($query->rows as $result) {
+ if (!$result['serialized']) {
+ $setting_data[$result['key']] = $result['value'];
+ } else {
+ $setting_data[$result['key']] = json_decode($result['value'], true);
+ }
+ }
+
+ return $setting_data;
+ }
+
+ public function editSetting($code, $data, $store_id = 0) {
+ $this->db->query("DELETE FROM `" . DB_PREFIX . "setting` WHERE store_id = '" . (int)$store_id . "' AND `code` = '" . $this->db->escape($code) . "'");
+
+ foreach ($data as $key => $value) {
+ if (substr($key, 0, strlen($code)) == $code) {
+ if (!is_array($value)) {
+ $this->db->query("INSERT INTO " . DB_PREFIX . "setting SET store_id = '" . (int)$store_id . "', `code` = '" . $this->db->escape($code) . "', `key` = '" . $this->db->escape($key) . "', `value` = '" . $this->db->escape($value) . "'");
+ } else {
+ $this->db->query("INSERT INTO " . DB_PREFIX . "setting SET store_id = '" . (int)$store_id . "', `code` = '" . $this->db->escape($code) . "', `key` = '" . $this->db->escape($key) . "', `value` = '" . $this->db->escape(json_encode($value, true)) . "', serialized = '1'");
+ }
+ }
+ }
+ }
+
+ public function deleteSetting($code, $store_id = 0) {
+ $this->db->query("DELETE FROM " . DB_PREFIX . "setting WHERE store_id = '" . (int)$store_id . "' AND `code` = '" . $this->db->escape($code) . "'");
+ }
+
+ public function getSettingValue($key, $store_id = 0) {
+ $query = $this->db->query("SELECT value FROM " . DB_PREFIX . "setting WHERE store_id = '" . (int)$store_id . "' AND `key` = '" . $this->db->escape($key) . "'");
+
+ if ($query->num_rows) {
+ return $query->row['value'];
+ } else {
+ return null;
+ }
+ }
+
+ public function editSettingValue($code = '', $key = '', $value = '', $store_id = 0) {
+ if (!is_array($value)) {
+ $this->db->query("UPDATE " . DB_PREFIX . "setting SET `value` = '" . $this->db->escape($value) . "', serialized = '0' WHERE `code` = '" . $this->db->escape($code) . "' AND `key` = '" . $this->db->escape($key) . "' AND store_id = '" . (int)$store_id . "'");
+ } else {
+ $this->db->query("UPDATE " . DB_PREFIX . "setting SET `value` = '" . $this->db->escape(json_encode($value)) . "', serialized = '1' WHERE `code` = '" . $this->db->escape($code) . "' AND `key` = '" . $this->db->escape($key) . "' AND store_id = '" . (int)$store_id . "'");
+ }
+ }
+}
diff --git a/public/admin/model/setting/store.php b/public/admin/model/setting/store.php
new file mode 100644
index 0000000..5a12c05
--- /dev/null
+++ b/public/admin/model/setting/store.php
@@ -0,0 +1,108 @@
+<?php
+class ModelSettingStore extends Model {
+ public function addStore($data) {
+ $this->db->query("INSERT INTO " . DB_PREFIX . "store SET name = '" . $this->db->escape($data['config_name']) . "', `url` = '" . $this->db->escape($data['config_url']) . "', `ssl` = '" . $this->db->escape($data['config_ssl']) . "'");
+
+ $store_id = $this->db->getLastId();
+
+ // Layout Route
+ $query = $this->db->query("SELECT * FROM " . DB_PREFIX . "layout_route WHERE store_id = '0'");
+
+ foreach ($query->rows as $layout_route) {
+ $this->db->query("INSERT INTO " . DB_PREFIX . "layout_route SET layout_id = '" . (int)$layout_route['layout_id'] . "', route = '" . $this->db->escape($layout_route['route']) . "', store_id = '" . (int)$store_id . "'");
+ }
+
+ $this->cache->delete('store');
+
+ return $store_id;
+ }
+
+ public function editStore($store_id, $data) {
+ $this->db->query("UPDATE " . DB_PREFIX . "store SET name = '" . $this->db->escape($data['config_name']) . "', `url` = '" . $this->db->escape($data['config_url']) . "', `ssl` = '" . $this->db->escape($data['config_ssl']) . "' WHERE store_id = '" . (int)$store_id . "'");
+
+ $this->cache->delete('store');
+ }
+
+ public function deleteStore($store_id) {
+ $this->db->query("DELETE FROM " . DB_PREFIX . "store WHERE store_id = '" . (int)$store_id . "'");
+ $this->db->query("DELETE FROM " . DB_PREFIX . "layout_route WHERE store_id = '" . (int)$store_id . "'");
+
+ $this->cache->delete('store');
+ }
+
+ public function getStore($store_id) {
+ $query = $this->db->query("SELECT DISTINCT * FROM " . DB_PREFIX . "store WHERE store_id = '" . (int)$store_id . "'");
+
+ return $query->row;
+ }
+
+ public function getStores($data = array()) {
+ $store_data = $this->cache->get('store');
+
+ if (!$store_data) {
+ $query = $this->db->query("SELECT * FROM " . DB_PREFIX . "store ORDER BY url");
+
+ $store_data = $query->rows;
+
+ $this->cache->set('store', $store_data);
+ }
+
+ return $store_data;
+ }
+
+ public function getTotalStores() {
+ $query = $this->db->query("SELECT COUNT(*) AS total FROM " . DB_PREFIX . "store");
+
+ return $query->row['total'];
+ }
+
+ public function getTotalStoresByLayoutId($layout_id) {
+ $query = $this->db->query("SELECT COUNT(*) AS total FROM " . DB_PREFIX . "setting WHERE `key` = 'config_layout_id' AND `value` = '" . (int)$layout_id . "' AND store_id != '0'");
+
+ return $query->row['total'];
+ }
+
+ public function getTotalStoresByLanguage($language) {
+ $query = $this->db->query("SELECT COUNT(*) AS total FROM " . DB_PREFIX . "setting WHERE `key` = 'config_language' AND `value` = '" . $this->db->escape($language) . "' AND store_id != '0'");
+
+ return $query->row['total'];
+ }
+
+ public function getTotalStoresByCurrency($currency) {
+ $query = $this->db->query("SELECT COUNT(*) AS total FROM " . DB_PREFIX . "setting WHERE `key` = 'config_currency' AND `value` = '" . $this->db->escape($currency) . "' AND store_id != '0'");
+
+ return $query->row['total'];
+ }
+
+ public function getTotalStoresByCountryId($country_id) {
+ $query = $this->db->query("SELECT COUNT(*) AS total FROM " . DB_PREFIX . "setting WHERE `key` = 'config_country_id' AND `value` = '" . (int)$country_id . "' AND store_id != '0'");
+
+ return $query->row['total'];
+ }
+
+ public function getTotalStoresByZoneId($zone_id) {
+ $query = $this->db->query("SELECT COUNT(*) AS total FROM " . DB_PREFIX . "setting WHERE `key` = 'config_zone_id' AND `value` = '" . (int)$zone_id . "' AND store_id != '0'");
+
+ return $query->row['total'];
+ }
+
+ public function getTotalStoresByCustomerGroupId($customer_group_id) {
+ $query = $this->db->query("SELECT COUNT(*) AS total FROM " . DB_PREFIX . "setting WHERE `key` = 'config_customer_group_id' AND `value` = '" . (int)$customer_group_id . "' AND store_id != '0'");
+
+ return $query->row['total'];
+ }
+
+ public function getTotalStoresByInformationId($information_id) {
+ $account_query = $this->db->query("SELECT COUNT(*) AS total FROM " . DB_PREFIX . "setting WHERE `key` = 'config_account_id' AND `value` = '" . (int)$information_id . "' AND store_id != '0'");
+
+ $checkout_query = $this->db->query("SELECT COUNT(*) AS total FROM " . DB_PREFIX . "setting WHERE `key` = 'config_checkout_id' AND `value` = '" . (int)$information_id . "' AND store_id != '0'");
+
+ return ($account_query->row['total'] + $checkout_query->row['total']);
+ }
+
+ public function getTotalStoresByOrderStatusId($order_status_id) {
+ $query = $this->db->query("SELECT COUNT(*) AS total FROM " . DB_PREFIX . "setting WHERE `key` = 'config_order_status_id' AND `value` = '" . (int)$order_status_id . "' AND store_id != '0'");
+
+ return $query->row['total'];
+ }
+} \ No newline at end of file