shop.balmet.com

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

event.php (2875B)


      1 <?php
      2 class ModelSettingEvent extends Model {
      3 	public function addEvent($code, $trigger, $action, $status = 1, $sort_order = 0) {
      4 		$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 . "'");
      5 	
      6 		return $this->db->getLastId();
      7 	}
      8 
      9 	public function deleteEvent($event_id) {
     10 		$this->db->query("DELETE FROM `" . DB_PREFIX . "event` WHERE `event_id` = '" . (int)$event_id . "'");
     11 	}
     12 	
     13 	public function deleteEventByCode($code) {
     14 		$this->db->query("DELETE FROM `" . DB_PREFIX . "event` WHERE `code` = '" . $this->db->escape($code) . "'");
     15 	}
     16 
     17 	public function enableEvent($event_id) {
     18 		$this->db->query("UPDATE `" . DB_PREFIX . "event` SET `status` = '1' WHERE event_id = '" . (int)$event_id . "'");
     19 	}
     20 	
     21 	public function disableEvent($event_id) {
     22 		$this->db->query("UPDATE `" . DB_PREFIX . "event` SET `status` = '0' WHERE event_id = '" . (int)$event_id . "'");
     23 	}
     24 	
     25 	public function uninstall($type, $code) {
     26 		$this->db->query("DELETE FROM `" . DB_PREFIX . "extension` WHERE `type` = '" . $this->db->escape($type) . "' AND `code` = '" . $this->db->escape($code) . "'");
     27 		$this->db->query("DELETE FROM `" . DB_PREFIX . "setting` WHERE `code` = '" . $this->db->escape($code) . "'");
     28 	}
     29 
     30 	public function getEvent($event_id) {
     31 		$query = $this->db->query("SELECT DISTINCT * FROM `" . DB_PREFIX . "event` WHERE `event_id` = '" . (int)$event_id . "' LIMIT 1");
     32 
     33 		return $query->row;
     34 	}
     35 
     36 	public function getEventByCode($code) {
     37 		$query = $this->db->query("SELECT DISTINCT * FROM `" . DB_PREFIX . "event` WHERE `code` = '" . $this->db->escape($code) . "' LIMIT 1");
     38 
     39 		return $query->row;
     40 	}
     41 		
     42 	public function getEvents($data = array()) {
     43 		$sql = "SELECT * FROM `" . DB_PREFIX . "event`";
     44 
     45 		$sort_data = array(
     46 			'code',
     47 			'trigger',
     48 			'action',
     49 			'sort_order',
     50 			'status',
     51 			'date_added'
     52 		);
     53 
     54 		if (isset($data['sort']) && in_array($data['sort'], $sort_data)) {
     55 			$sql .= " ORDER BY `" . $data['sort'] . "`";
     56 		} else {
     57 			$sql .= " ORDER BY `sort_order`";
     58 		}
     59 
     60 		if (isset($data['order']) && ($data['order'] == 'DESC')) {
     61 			$sql .= " DESC";
     62 		} else {
     63 			$sql .= " ASC";
     64 		}
     65 
     66 		if (isset($data['start']) || isset($data['limit'])) {
     67 			if ($data['start'] < 0) {
     68 				$data['start'] = 0;
     69 			}
     70 
     71 			if ($data['limit'] < 1) {
     72 				$data['limit'] = 20;
     73 			}
     74 
     75 			$sql .= " LIMIT " . (int)$data['start'] . "," . (int)$data['limit'];
     76 		}
     77 
     78 		$query = $this->db->query($sql);
     79 
     80 		return $query->rows;
     81 	}
     82 
     83 	public function getTotalEvents() {
     84 		$query = $this->db->query("SELECT COUNT(*) AS total FROM `" . DB_PREFIX . "event`");
     85 
     86 		return $query->row['total'];
     87 	}
     88 }