shop.balmet.com

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

location.php (2581B)


      1 <?php
      2 class ModelLocalisationLocation extends Model {
      3 	public function addLocation($data) {
      4 		$this->db->query("INSERT INTO " . DB_PREFIX . "location SET name = '" . $this->db->escape($data['name']) . "', address = '" . $this->db->escape($data['address']) . "', geocode = '" . $this->db->escape($data['geocode']) . "', telephone = '" . $this->db->escape($data['telephone']) . "', fax = '" . $this->db->escape($data['fax']) . "', image = '" . $this->db->escape($data['image']) . "', open = '" . $this->db->escape($data['open']) . "', comment = '" . $this->db->escape($data['comment']) . "'");
      5 	
      6 		return $this->db->getLastId();
      7 	}
      8 
      9 	public function editLocation($location_id, $data) {
     10 		$this->db->query("UPDATE " . DB_PREFIX . "location SET name = '" . $this->db->escape($data['name']) . "', address = '" . $this->db->escape($data['address']) . "', geocode = '" . $this->db->escape($data['geocode']) . "', telephone = '" . $this->db->escape($data['telephone']) . "', fax = '" . $this->db->escape($data['fax']) . "', image = '" . $this->db->escape($data['image']) . "', open = '" . $this->db->escape($data['open']) . "', comment = '" . $this->db->escape($data['comment']) . "' WHERE location_id = '" . (int)$location_id . "'");
     11 	}
     12 
     13 	public function deleteLocation($location_id) {
     14 		$this->db->query("DELETE FROM " . DB_PREFIX . "location WHERE location_id = " . (int)$location_id);
     15 	}
     16 
     17 	public function getLocation($location_id) {
     18 		$query = $this->db->query("SELECT DISTINCT * FROM " . DB_PREFIX . "location WHERE location_id = '" . (int)$location_id . "'");
     19 
     20 		return $query->row;
     21 	}
     22 
     23 	public function getLocations($data = array()) {
     24 		$sql = "SELECT location_id, name, address FROM " . DB_PREFIX . "location";
     25 
     26 		$sort_data = array(
     27 			'name',
     28 			'address',
     29 		);
     30 
     31 		if (isset($data['sort']) && in_array($data['sort'], $sort_data)) {
     32 			$sql .= " ORDER BY " . $data['sort'];
     33 		} else {
     34 			$sql .= " ORDER BY name";
     35 		}
     36 
     37 		if (isset($data['order']) && ($data['order'] == 'DESC')) {
     38 			$sql .= " DESC";
     39 		} else {
     40 			$sql .= " ASC";
     41 		}
     42 
     43 		if (isset($data['start']) || isset($data['limit'])) {
     44 			if ($data['start'] < 0) {
     45 				$data['start'] = 0;
     46 			}
     47 
     48 			if ($data['limit'] < 1) {
     49 				$data['limit'] = 20;
     50 			}
     51 
     52 			$sql .= " LIMIT " . (int)$data['start'] . "," . (int)$data['limit'];
     53 		}
     54 
     55 		$query = $this->db->query($sql);
     56 
     57 		return $query->rows;
     58 	}
     59 
     60 	public function getTotalLocations() {
     61 		$query = $this->db->query("SELECT COUNT(*) AS total FROM " . DB_PREFIX . "location");
     62 
     63 		return $query->row['total'];
     64 	}
     65 }