shop.balmet.com

Unnamed repository; edit this file 'description' to name the repository.
Log | Files | Refs | README

information.php (9624B)


      1 <?php
      2 class ModelCatalogInformation extends Model {
      3 	public function addInformation($data) {
      4 		$this->db->query("INSERT INTO " . DB_PREFIX . "information SET sort_order = '" . (int)$data['sort_order'] . "', bottom = '" . (isset($data['bottom']) ? (int)$data['bottom'] : 0) . "', status = '" . (int)$data['status'] . "'");
      5 
      6 		$information_id = $this->db->getLastId();
      7 
      8 		foreach ($data['information_description'] as $language_id => $value) {
      9 			$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_title = '" . $this->db->escape($value['meta_title']) . "', meta_description = '" . $this->db->escape($value['meta_description']) . "', meta_keyword = '" . $this->db->escape($value['meta_keyword']) . "'");
     10 		}
     11 
     12 		if (isset($data['information_store'])) {
     13 			foreach ($data['information_store'] as $store_id) {
     14 				$this->db->query("INSERT INTO " . DB_PREFIX . "information_to_store SET information_id = '" . (int)$information_id . "', store_id = '" . (int)$store_id . "'");
     15 			}
     16 		}
     17 
     18 		// SEO URL
     19 		if (isset($data['information_seo_url'])) {
     20 			foreach ($data['information_seo_url'] as $store_id => $language) {
     21 				foreach ($language as $language_id => $keyword) {
     22 					if (!empty($keyword)) {
     23 						$this->db->query("INSERT INTO " . DB_PREFIX . "seo_url SET store_id = '" . (int)$store_id . "', language_id = '" . (int)$language_id . "', query = 'information_id=" . (int)$information_id . "', keyword = '" . $this->db->escape($keyword) . "'");
     24 					}
     25 				}
     26 			}
     27 		}
     28 		
     29 		if (isset($data['information_layout'])) {
     30 			foreach ($data['information_layout'] as $store_id => $layout_id) {
     31 				$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_id . "'");
     32 			}
     33 		}
     34 
     35 		$this->cache->delete('information');
     36 
     37 		return $information_id;
     38 	}
     39 
     40 	public function editInformation($information_id, $data) {
     41 		$this->db->query("UPDATE " . DB_PREFIX . "information SET sort_order = '" . (int)$data['sort_order'] . "', bottom = '" . (isset($data['bottom']) ? (int)$data['bottom'] : 0) . "', status = '" . (int)$data['status'] . "' WHERE information_id = '" . (int)$information_id . "'");
     42 
     43 		$this->db->query("DELETE FROM " . DB_PREFIX . "information_description WHERE information_id = '" . (int)$information_id . "'");
     44 
     45 		foreach ($data['information_description'] as $language_id => $value) {
     46 			$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_title = '" . $this->db->escape($value['meta_title']) . "', meta_description = '" . $this->db->escape($value['meta_description']) . "', meta_keyword = '" . $this->db->escape($value['meta_keyword']) . "'");
     47 		}
     48 
     49 		$this->db->query("DELETE FROM " . DB_PREFIX . "information_to_store WHERE information_id = '" . (int)$information_id . "'");
     50 
     51 		if (isset($data['information_store'])) {
     52 			foreach ($data['information_store'] as $store_id) {
     53 				$this->db->query("INSERT INTO " . DB_PREFIX . "information_to_store SET information_id = '" . (int)$information_id . "', store_id = '" . (int)$store_id . "'");
     54 			}
     55 		}
     56 
     57 		$this->db->query("DELETE FROM " . DB_PREFIX . "seo_url WHERE query = 'information_id=" . (int)$information_id . "'");
     58 
     59 		if (isset($data['information_seo_url'])) {
     60 			foreach ($data['information_seo_url'] as $store_id => $language) {
     61 				foreach ($language as $language_id => $keyword) {
     62 					if (trim($keyword)) {
     63 						$this->db->query("INSERT INTO `" . DB_PREFIX . "seo_url` SET store_id = '" . (int)$store_id . "', language_id = '" . (int)$language_id . "', query = 'information_id=" . (int)$information_id . "', keyword = '" . $this->db->escape($keyword) . "'");
     64 					}
     65 				}
     66 			}
     67 		}
     68 
     69 		$this->db->query("DELETE FROM `" . DB_PREFIX . "information_to_layout` WHERE information_id = '" . (int)$information_id . "'");
     70 
     71 		if (isset($data['information_layout'])) {
     72 			foreach ($data['information_layout'] as $store_id => $layout_id) {
     73 				$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_id . "'");
     74 			}
     75 		}
     76 
     77 		$this->cache->delete('information');
     78 	}
     79 
     80 	public function deleteInformation($information_id) {
     81 		$this->db->query("DELETE FROM `" . DB_PREFIX . "information` WHERE information_id = '" . (int)$information_id . "'");
     82 		$this->db->query("DELETE FROM `" . DB_PREFIX . "information_description` WHERE information_id = '" . (int)$information_id . "'");
     83 		$this->db->query("DELETE FROM `" . DB_PREFIX . "information_to_store` WHERE information_id = '" . (int)$information_id . "'");
     84 		$this->db->query("DELETE FROM `" . DB_PREFIX . "information_to_layout` WHERE information_id = '" . (int)$information_id . "'");
     85 		$this->db->query("DELETE FROM `" . DB_PREFIX . "seo_url` WHERE query = 'information_id=" . (int)$information_id . "'");
     86 
     87 		$this->cache->delete('information');
     88 	}
     89 
     90 	public function getInformation($information_id) {
     91 		$query = $this->db->query("SELECT DISTINCT * FROM " . DB_PREFIX . "information WHERE information_id = '" . (int)$information_id . "'");
     92 
     93 		return $query->row;
     94 	}
     95 
     96 	public function getInformations($data = array()) {
     97 		if ($data) {
     98 			$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') . "'";
     99 
    100 			$sort_data = array(
    101 				'id.title',
    102 				'i.sort_order'
    103 			);
    104 
    105 			if (isset($data['sort']) && in_array($data['sort'], $sort_data)) {
    106 				$sql .= " ORDER BY " . $data['sort'];
    107 			} else {
    108 				$sql .= " ORDER BY id.title";
    109 			}
    110 
    111 			if (isset($data['order']) && ($data['order'] == 'DESC')) {
    112 				$sql .= " DESC";
    113 			} else {
    114 				$sql .= " ASC";
    115 			}
    116 
    117 			if (isset($data['start']) || isset($data['limit'])) {
    118 				if ($data['start'] < 0) {
    119 					$data['start'] = 0;
    120 				}
    121 
    122 				if ($data['limit'] < 1) {
    123 					$data['limit'] = 20;
    124 				}
    125 
    126 				$sql .= " LIMIT " . (int)$data['start'] . "," . (int)$data['limit'];
    127 			}
    128 
    129 			$query = $this->db->query($sql);
    130 
    131 			return $query->rows;
    132 		} else {
    133 			$information_data = $this->cache->get('information.' . (int)$this->config->get('config_language_id'));
    134 
    135 			if (!$information_data) {
    136 				$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");
    137 
    138 				$information_data = $query->rows;
    139 
    140 				$this->cache->set('information.' . (int)$this->config->get('config_language_id'), $information_data);
    141 			}
    142 
    143 			return $information_data;
    144 		}
    145 	}
    146 
    147 	public function getInformationDescriptions($information_id) {
    148 		$information_description_data = array();
    149 
    150 		$query = $this->db->query("SELECT * FROM " . DB_PREFIX . "information_description WHERE information_id = '" . (int)$information_id . "'");
    151 
    152 		foreach ($query->rows as $result) {
    153 			$information_description_data[$result['language_id']] = array(
    154 				'title'            => $result['title'],
    155 				'description'      => $result['description'],
    156 				'meta_title'       => $result['meta_title'],
    157 				'meta_description' => $result['meta_description'],
    158 				'meta_keyword'     => $result['meta_keyword']
    159 			);
    160 		}
    161 
    162 		return $information_description_data;
    163 	}
    164 
    165 	public function getInformationStores($information_id) {
    166 		$information_store_data = array();
    167 
    168 		$query = $this->db->query("SELECT * FROM " . DB_PREFIX . "information_to_store WHERE information_id = '" . (int)$information_id . "'");
    169 
    170 		foreach ($query->rows as $result) {
    171 			$information_store_data[] = $result['store_id'];
    172 		}
    173 
    174 		return $information_store_data;
    175 	}
    176 
    177 	public function getInformationSeoUrls($information_id) {
    178 		$information_seo_url_data = array();
    179 		
    180 		$query = $this->db->query("SELECT * FROM " . DB_PREFIX . "seo_url WHERE query = 'information_id=" . (int)$information_id . "'");
    181 
    182 		foreach ($query->rows as $result) {
    183 			$information_seo_url_data[$result['store_id']][$result['language_id']] = $result['keyword'];
    184 		}
    185 
    186 		return $information_seo_url_data;
    187 	}
    188 
    189 	public function getInformationLayouts($information_id) {
    190 		$information_layout_data = array();
    191 
    192 		$query = $this->db->query("SELECT * FROM " . DB_PREFIX . "information_to_layout WHERE information_id = '" . (int)$information_id . "'");
    193 
    194 		foreach ($query->rows as $result) {
    195 			$information_layout_data[$result['store_id']] = $result['layout_id'];
    196 		}
    197 
    198 		return $information_layout_data;
    199 	}
    200 
    201 	public function getTotalInformations() {
    202 		$query = $this->db->query("SELECT COUNT(*) AS total FROM " . DB_PREFIX . "information");
    203 
    204 		return $query->row['total'];
    205 	}
    206 
    207 	public function getTotalInformationsByLayoutId($layout_id) {
    208 		$query = $this->db->query("SELECT COUNT(*) AS total FROM " . DB_PREFIX . "information_to_layout WHERE layout_id = '" . (int)$layout_id . "'");
    209 
    210 		return $query->row['total'];
    211 	}
    212 }