/admin/model/catalog/information.php
https://gitlab.com/AndreyLes/top-tap · PHP · 290 lines · 223 code · 67 blank · 0 comment · 37 complexity · 5fd3ffea8bdd6a5f5fe70386149ad490 MD5 · raw file
- <?php
- class ModelCatalogInformation extends Model {
- public function addInformation($data) {
- $this->db->query("INSERT INTO " . DB_PREFIX . "information SET sort_order = '" . (int)$data['sort_order'] . "', top = '" . (isset($data['top']) ? (int)$data['top'] : 0) . "', bottom = '" . (isset($data['bottom']) ? (int)$data['bottom'] : 0) . "', status = '" . (int)$data['status'] . "'");
- $information_id = $this->db->getLastId();
-
- $informationTitle = '';
- foreach ($data['information_description'] as $language_id => $value) {
- if ($language_id == $this->config->get('config_language_id')){
- $informationTitle = $value['title'];
- }
- $this->db->query("INSERT INTO " . DB_PREFIX . "information_description SET information_id = '" . (int)$information_id . "', language_id = '" . (int)$language_id . "', title = '" . $this->db->escape($value['title']) . "', description = '" . $this->db->escape($value['description']) . "', meta_keyword = '" . $this->db->escape($value['meta_keyword']) . "', meta_description = '" . $this->db->escape($value['meta_description']) . "', seo_title = '" . $this->db->escape($value['seo_title']) . "', seo_h1 = '" . $this->db->escape($value['seo_h1']) . "'");
- }
-
- if (isset($data['information_store'])) {
- foreach ($data['information_store'] as $store_id) {
- $this->db->query("INSERT INTO " . DB_PREFIX . "information_to_store SET information_id = '" . (int)$information_id . "', store_id = '" . (int)$store_id . "'");
- }
- }
- if (isset($data['information_layout'])) {
- foreach ($data['information_layout'] as $store_id => $layout) {
- if ($layout) {
- $this->db->query("INSERT INTO " . DB_PREFIX . "information_to_layout SET information_id = '" . (int)$information_id . "', store_id = '" . (int)$store_id . "', layout_id = '" . (int)$layout['layout_id'] . "'");
- }
- }
- }
-
- if ($data['keyword']) {
- $this->db->query("INSERT INTO " . DB_PREFIX . "url_alias SET query = 'information_id=" . (int)$information_id . "', keyword = '" . $this->db->escape($data['keyword']) . "'");
- } else {
- $this->load->model('tool/seo_manager');
- if ($informationTitle) {
- $this->model_tool_seo_manager->generateInformation($information_id, $informationTitle, $this->config->get('config_template_seo_url_informations'), $this->config->get('config_language'));
- }
- }
-
- $this->cache->delete('information');
- $this->cache->delete('seo_pro');
- $this->cache->delete('seo_url');
- return $information_id;
- }
-
- public function editInformation($information_id, $data) {
- $this->db->query("UPDATE " . DB_PREFIX . "information SET sort_order = '" . (int)$data['sort_order'] . "', top = '" . (isset($data['top']) ? (int)$data['top'] : 0) . "', bottom = '" . (isset($data['bottom']) ? (int)$data['bottom'] : 0) . "', status = '" . (int)$data['status'] . "' WHERE information_id = '" . (int)$information_id . "'");
-
- $this->db->query("DELETE FROM " . DB_PREFIX . "information_description WHERE information_id = '" . (int)$information_id . "'");
-
- $informationTitle = '';
- foreach ($data['information_description'] as $language_id => $value) {
- if ($language_id == $this->config->get('config_language_id')){
- $informationTitle = $value['title'];
- }
- $this->db->query("INSERT INTO " . DB_PREFIX . "information_description SET information_id = '" . (int)$information_id . "', language_id = '" . (int)$language_id . "', title = '" . $this->db->escape($value['title']) . "', description = '" . $this->db->escape($value['description']) . "', meta_keyword = '" . $this->db->escape($value['meta_keyword']) . "', meta_description = '" . $this->db->escape($value['meta_description']) . "', seo_title = '" . $this->db->escape($value['seo_title']) . "', seo_h1 = '" . $this->db->escape($value['seo_h1']) . "'");
- }
- $this->db->query("DELETE FROM " . DB_PREFIX . "information_to_store WHERE information_id = '" . (int)$information_id . "'");
-
- if (isset($data['information_store'])) {
- foreach ($data['information_store'] as $store_id) {
- $this->db->query("INSERT INTO " . DB_PREFIX . "information_to_store SET information_id = '" . (int)$information_id . "', store_id = '" . (int)$store_id . "'");
- }
- }
-
- $this->db->query("DELETE FROM " . DB_PREFIX . "information_to_layout WHERE information_id = '" . (int)$information_id . "'");
- if (isset($data['information_layout'])) {
- foreach ($data['information_layout'] as $store_id => $layout) {
- if ($layout['layout_id']) {
- $this->db->query("INSERT INTO " . DB_PREFIX . "information_to_layout SET information_id = '" . (int)$information_id . "', store_id = '" . (int)$store_id . "', layout_id = '" . (int)$layout['layout_id'] . "'");
- }
- }
- }
-
- $this->db->query("DELETE FROM " . DB_PREFIX . "url_alias WHERE query = 'information_id=" . (int)$information_id. "'");
-
- if ($data['keyword']) {
- $this->db->query("INSERT INTO " . DB_PREFIX . "url_alias SET query = 'information_id=" . (int)$information_id . "', keyword = '" . $this->db->escape($data['keyword']) . "'");
- } else {
- $this->load->model('tool/seo_manager');
- if ($informationTitle) {
- $this->model_tool_seo_manager->generateInformation($information_id, $informationTitle, $this->config->get('config_template_seo_url_informations'), $this->config->get('config_language'));
- }
- }
-
- $this->cache->delete('information');
- $this->cache->delete('seo_pro');
- $this->cache->delete('seo_url');
- return $information_id;
- }
-
- public function deleteInformation($information_id) {
- $this->db->query("DELETE FROM " . DB_PREFIX . "information WHERE information_id = '" . (int)$information_id . "'");
- $this->db->query("DELETE FROM " . DB_PREFIX . "information_description WHERE information_id = '" . (int)$information_id . "'");
- $this->db->query("DELETE FROM " . DB_PREFIX . "information_to_store WHERE information_id = '" . (int)$information_id . "'");
- $this->db->query("DELETE FROM " . DB_PREFIX . "information_to_layout WHERE information_id = '" . (int)$information_id . "'");
- $this->db->query("DELETE FROM " . DB_PREFIX . "url_alias WHERE query = 'information_id=" . (int)$information_id . "'");
- $this->cache->delete('information');
- }
- public function getInformation($information_id) {
- $query = $this->db->query("SELECT DISTINCT *, (SELECT keyword FROM " . DB_PREFIX . "url_alias WHERE query = 'information_id=" . (int)$information_id . "') AS keyword FROM " . DB_PREFIX . "information WHERE information_id = '" . (int)$information_id . "'");
-
- return $query->row;
- }
-
- public function getInformations($data = array()) {
- if ($data) {
- $sql = "SELECT * FROM " . DB_PREFIX . "information i LEFT JOIN " . DB_PREFIX . "information_description id ON (i.information_id = id.information_id) WHERE id.language_id = '" . (int)$this->config->get('config_language_id') . "'";
-
- $sort_data = array(
- 'id.title',
- 'i.sort_order'
- );
-
- if (isset($data['sort']) && in_array($data['sort'], $sort_data)) {
- $sql .= " ORDER BY " . $data['sort'];
- } else {
- $sql .= " ORDER BY id.title";
- }
-
- 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;
- } else {
- $information_data = $this->cache->get('information.' . (int)$this->config->get('config_language_id'));
-
- if (!$information_data) {
- $query = $this->db->query("SELECT * FROM " . DB_PREFIX . "information i LEFT JOIN " . DB_PREFIX . "information_description id ON (i.information_id = id.information_id) WHERE id.language_id = '" . (int)$this->config->get('config_language_id') . "' ORDER BY id.title");
-
- $information_data = $query->rows;
-
- $this->cache->set('information.' . (int)$this->config->get('config_language_id'), $information_data);
- }
-
- return $information_data;
- }
- }
-
- public function getInformationDescriptions($information_id) {
- $information_description_data = array();
-
- $query = $this->db->query("SELECT * FROM " . DB_PREFIX . "information_description WHERE information_id = '" . (int)$information_id . "'");
- foreach ($query->rows as $result) {
- $information_description_data[$result['language_id']] = array(
- 'title' => $result['title'],
- 'seo_title' => $result['seo_title'],
- 'seo_h1' => $result['seo_h1'],
- 'meta_keyword' => $result['meta_keyword'],
- 'meta_description' => $result['meta_description'],
- 'description' => $result['description']
- );
- }
-
- return $information_description_data;
- }
-
- public function getInformationStores($information_id) {
- $information_store_data = array();
-
- $query = $this->db->query("SELECT * FROM " . DB_PREFIX . "information_to_store WHERE information_id = '" . (int)$information_id . "'");
- foreach ($query->rows as $result) {
- $information_store_data[] = $result['store_id'];
- }
-
- return $information_store_data;
- }
- public function getInformationLayouts($information_id) {
- $information_layout_data = array();
-
- $query = $this->db->query("SELECT * FROM " . DB_PREFIX . "information_to_layout WHERE information_id = '" . (int)$information_id . "'");
-
- foreach ($query->rows as $result) {
- $information_layout_data[$result['store_id']] = $result['layout_id'];
- }
-
- return $information_layout_data;
- }
-
- public function getTotalInformations() {
- $query = $this->db->query("SELECT COUNT(*) AS total FROM " . DB_PREFIX . "information");
-
- return $query->row['total'];
- }
-
- public function getTotalInformationsByLayoutId($layout_id) {
- $query = $this->db->query("SELECT COUNT(*) AS total FROM " . DB_PREFIX . "information_to_layout WHERE layout_id = '" . (int)$layout_id . "'");
- return $query->row['total'];
- }
-
- public function getInformationTitle($information_id) {
- $selected_language = (int)$this->config->get('config_language_id');
- $row = $this->db->query("SELECT title FROM " . DB_PREFIX . "information_description WHERE information_id = '" . (int) $information_id . "' AND language_id = '" . $selected_language . "'");
- if(isset($row->row['title'])){
- return $row->row['title'];
- }
- }
- public function changeTitle($information_id, $title){
- $selected_language = (int)$this->config->get('config_language_id');
- if ($this->user->hasPermission('modify', 'catalog/information_quick')) {
- $query = $this->db->query("UPDATE " . DB_PREFIX . "information_description SET title= '" .$this->db->escape($title) . "' WHERE information_id = '" . (int)$information_id . "' AND language_id='" . $selected_language . "'");
- }
- $query = $this->db->query("SELECT title FROM " . DB_PREFIX . "information_description WHERE information_id = '" . (int)$information_id . "' AND language_id= '" . $selected_language . "'");
-
- $this->cache->delete('information');
- return $query->row['title'];
- }
-
- public function changeSortOrder($information_id, $sort_order) {
- if ($this->user->hasPermission('modify', 'catalog/information_quick')) {
- $this->db->query("UPDATE " . DB_PREFIX . "information SET sort_order = '" . (int)$sort_order . "' WHERE information_id = '" . (int)$information_id . "'");
- }
-
- $query = $this->db->query("SELECT sort_order FROM " . DB_PREFIX . "information WHERE information_id = '". $information_id . "'");
- $row = $query->row;
-
- $this->cache->delete('information');
- return $row['sort_order'];
- }
-
- public function changeStatus($information_id, $column_name, $value){
- $this->db->query("UPDATE " . DB_PREFIX . "information SET " . $column_name . " = '" . (int)$value . "' WHERE information_id = '" . (int)$information_id . "'");
- }
-
- public function changeDescriptions($information_id, $data){
- $this->db->query("DELETE FROM " . DB_PREFIX . "information_description WHERE information_id = '" . (int)$information_id . "'");
- $this->db->query("DELETE FROM " . DB_PREFIX . "url_alias WHERE query = 'information_id=" . (int)$information_id. "'");
- foreach ($data['information_description'] as $language_id => $value) {
- $this->db->query("INSERT INTO " . DB_PREFIX . "information_description SET information_id = '" . (int)$information_id . "', language_id = '" . (int)$language_id . "', title = '" . $this->db->escape($value['title']) . "', description = '" . $this->db->escape($value['description']) . "', meta_keyword = '" . $this->db->escape($value['meta_keyword']) . "', meta_description = '" . $this->db->escape($value['meta_description']) . "', seo_title = '" . $this->db->escape($value['seo_title']) . "', seo_h1 = '" . $this->db->escape($value['seo_h1']) . "'");
- }
-
- if ($data['keyword']) {
- $this->db->query("INSERT INTO " . DB_PREFIX . "url_alias SET query = 'information_id=" . (int)$information_id . "', keyword = '" . $this->db->escape($data['keyword']) . "'");
- }
-
- $this->cache->delete('information');
- }
-
- public function changeInformationData($information_id, $data){
- $this->db->query("UPDATE " . DB_PREFIX . "information SET top = '" . (isset($data['top']) ? (int)$data['top'] : 0) . "', bottom = '" . (isset($data['bottom']) ? (int)$data['bottom'] : 0) . "' WHERE information_id = '" . (int)$information_id . "'");
-
- $this->db->query("DELETE FROM " . DB_PREFIX . "information_to_store WHERE information_id = '" . (int)$information_id . "'");
-
- if (isset($data['information_store'])) {
- foreach ($data['information_store'] as $store_id) {
- $this->db->query("INSERT INTO " . DB_PREFIX . "information_to_store SET information_id = '" . (int)$information_id . "', store_id = '" . (int)$store_id . "'");
- }
- }
-
- $this->db->query("DELETE FROM " . DB_PREFIX . "information_to_layout WHERE information_id = '" . (int)$information_id . "'");
- if (isset($data['information_layout'])) {
- foreach ($data['information_layout'] as $store_id => $layout) {
- if ($layout['layout_id']) {
- $this->db->query("INSERT INTO " . DB_PREFIX . "information_to_layout SET information_id = '" . (int)$information_id . "', store_id = '" . (int)$store_id . "', layout_id = '" . (int)$layout['layout_id'] . "'");
- }
- }
- }
-
- $this->cache->delete('information');
- }
- }
- ?>