shop.balmet.com

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

zone.php (2855B)


      1 <?php
      2 class ModelLocalisationZone extends Model {
      3 	public function addZone($data) {
      4 		$this->db->query("INSERT INTO " . DB_PREFIX . "zone SET status = '" . (int)$data['status'] . "', name = '" . $this->db->escape($data['name']) . "', code = '" . $this->db->escape($data['code']) . "', country_id = '" . (int)$data['country_id'] . "'");
      5 
      6 		$this->cache->delete('zone');
      7 		
      8 		return $this->db->getLastId();
      9 	}
     10 
     11 	public function editZone($zone_id, $data) {
     12 		$this->db->query("UPDATE " . DB_PREFIX . "zone SET status = '" . (int)$data['status'] . "', name = '" . $this->db->escape($data['name']) . "', code = '" . $this->db->escape($data['code']) . "', country_id = '" . (int)$data['country_id'] . "' WHERE zone_id = '" . (int)$zone_id . "'");
     13 
     14 		$this->cache->delete('zone');
     15 	}
     16 
     17 	public function deleteZone($zone_id) {
     18 		$this->db->query("DELETE FROM " . DB_PREFIX . "zone WHERE zone_id = '" . (int)$zone_id . "'");
     19 
     20 		$this->cache->delete('zone');
     21 	}
     22 
     23 	public function getZone($zone_id) {
     24 		$query = $this->db->query("SELECT DISTINCT * FROM " . DB_PREFIX . "zone WHERE zone_id = '" . (int)$zone_id . "'");
     25 
     26 		return $query->row;
     27 	}
     28 
     29 	public function getZones($data = array()) {
     30 		$sql = "SELECT *, z.name, c.name AS country FROM " . DB_PREFIX . "zone z LEFT JOIN " . DB_PREFIX . "country c ON (z.country_id = c.country_id)";
     31 
     32 		$sort_data = array(
     33 			'c.name',
     34 			'z.name',
     35 			'z.code'
     36 		);
     37 
     38 		if (isset($data['sort']) && in_array($data['sort'], $sort_data)) {
     39 			$sql .= " ORDER BY " . $data['sort'];
     40 		} else {
     41 			$sql .= " ORDER BY c.name";
     42 		}
     43 
     44 		if (isset($data['order']) && ($data['order'] == 'DESC')) {
     45 			$sql .= " DESC";
     46 		} else {
     47 			$sql .= " ASC";
     48 		}
     49 
     50 		if (isset($data['start']) || isset($data['limit'])) {
     51 			if ($data['start'] < 0) {
     52 				$data['start'] = 0;
     53 			}
     54 
     55 			if ($data['limit'] < 1) {
     56 				$data['limit'] = 20;
     57 			}
     58 
     59 			$sql .= " LIMIT " . (int)$data['start'] . "," . (int)$data['limit'];
     60 		}
     61 
     62 		$query = $this->db->query($sql);
     63 
     64 		return $query->rows;
     65 	}
     66 
     67 	public function getZonesByCountryId($country_id) {
     68 		$zone_data = $this->cache->get('zone.' . (int)$country_id);
     69 
     70 		if (!$zone_data) {
     71 			$query = $this->db->query("SELECT * FROM " . DB_PREFIX . "zone WHERE country_id = '" . (int)$country_id . "' AND status = '1' ORDER BY name");
     72 
     73 			$zone_data = $query->rows;
     74 
     75 			$this->cache->set('zone.' . (int)$country_id, $zone_data);
     76 		}
     77 
     78 		return $zone_data;
     79 	}
     80 
     81 	public function getTotalZones() {
     82 		$query = $this->db->query("SELECT COUNT(*) AS total FROM " . DB_PREFIX . "zone");
     83 
     84 		return $query->row['total'];
     85 	}
     86 
     87 	public function getTotalZonesByCountryId($country_id) {
     88 		$query = $this->db->query("SELECT COUNT(*) AS total FROM " . DB_PREFIX . "zone WHERE country_id = '" . (int)$country_id . "'");
     89 
     90 		return $query->row['total'];
     91 	}
     92 }