shop.balmet.com

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

return_action.php (3724B)


      1 <?php
      2 class ModelLocalisationReturnAction extends Model {
      3 	public function addReturnAction($data) {
      4 		foreach ($data['return_action'] as $language_id => $value) {
      5 			if (isset($return_action_id)) {
      6 				$this->db->query("INSERT INTO " . DB_PREFIX . "return_action SET return_action_id = '" . (int)$return_action_id . "', language_id = '" . (int)$language_id . "', name = '" . $this->db->escape($value['name']) . "'");
      7 			} else {
      8 				$this->db->query("INSERT INTO " . DB_PREFIX . "return_action SET language_id = '" . (int)$language_id . "', name = '" . $this->db->escape($value['name']) . "'");
      9 
     10 				$return_action_id = $this->db->getLastId();
     11 			}
     12 		}
     13 
     14 		$this->cache->delete('return_action');
     15 		
     16 		return $return_action_id;
     17 	}
     18 
     19 	public function editReturnAction($return_action_id, $data) {
     20 		$this->db->query("DELETE FROM " . DB_PREFIX . "return_action WHERE return_action_id = '" . (int)$return_action_id . "'");
     21 
     22 		foreach ($data['return_action'] as $language_id => $value) {
     23 			$this->db->query("INSERT INTO " . DB_PREFIX . "return_action SET return_action_id = '" . (int)$return_action_id . "', language_id = '" . (int)$language_id . "', name = '" . $this->db->escape($value['name']) . "'");
     24 		}
     25 
     26 		$this->cache->delete('return_action');
     27 	}
     28 
     29 	public function deleteReturnAction($return_action_id) {
     30 		$this->db->query("DELETE FROM " . DB_PREFIX . "return_action WHERE return_action_id = '" . (int)$return_action_id . "'");
     31 
     32 		$this->cache->delete('return_action');
     33 	}
     34 
     35 	public function getReturnAction($return_action_id) {
     36 		$query = $this->db->query("SELECT * FROM " . DB_PREFIX . "return_action WHERE return_action_id = '" . (int)$return_action_id . "' AND language_id = '" . (int)$this->config->get('config_language_id') . "'");
     37 
     38 		return $query->row;
     39 	}
     40 
     41 	public function getReturnActions($data = array()) {
     42 		if ($data) {
     43 			$sql = "SELECT * FROM " . DB_PREFIX . "return_action WHERE language_id = '" . (int)$this->config->get('config_language_id') . "'";
     44 
     45 			$sql .= " ORDER BY name";
     46 
     47 			if (isset($data['order']) && ($data['order'] == 'DESC')) {
     48 				$sql .= " DESC";
     49 			} else {
     50 				$sql .= " ASC";
     51 			}
     52 
     53 			if (isset($data['start']) || isset($data['limit'])) {
     54 				if ($data['start'] < 0) {
     55 					$data['start'] = 0;
     56 				}
     57 
     58 				if ($data['limit'] < 1) {
     59 					$data['limit'] = 20;
     60 				}
     61 
     62 				$sql .= " LIMIT " . (int)$data['start'] . "," . (int)$data['limit'];
     63 			}
     64 
     65 			$query = $this->db->query($sql);
     66 
     67 			return $query->rows;
     68 		} else {
     69 			$return_action_data = $this->cache->get('return_action.' . (int)$this->config->get('config_language_id'));
     70 
     71 			if (!$return_action_data) {
     72 				$query = $this->db->query("SELECT return_action_id, name FROM " . DB_PREFIX . "return_action WHERE language_id = '" . (int)$this->config->get('config_language_id') . "' ORDER BY name");
     73 
     74 				$return_action_data = $query->rows;
     75 
     76 				$this->cache->set('return_action.' . (int)$this->config->get('config_language_id'), $return_action_data);
     77 			}
     78 
     79 			return $return_action_data;
     80 		}
     81 	}
     82 
     83 	public function getReturnActionDescriptions($return_action_id) {
     84 		$return_action_data = array();
     85 
     86 		$query = $this->db->query("SELECT * FROM " . DB_PREFIX . "return_action WHERE return_action_id = '" . (int)$return_action_id . "'");
     87 
     88 		foreach ($query->rows as $result) {
     89 			$return_action_data[$result['language_id']] = array('name' => $result['name']);
     90 		}
     91 
     92 		return $return_action_data;
     93 	}
     94 
     95 	public function getTotalReturnActions() {
     96 		$query = $this->db->query("SELECT COUNT(*) AS total FROM " . DB_PREFIX . "return_action WHERE language_id = '" . (int)$this->config->get('config_language_id') . "'");
     97 
     98 		return $query->row['total'];
     99 	}
    100 }