shop.balmet.com

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

setting.php (2660B)


      1 <?php
      2 class ModelSettingSetting extends Model {
      3 	public function getSetting($code, $store_id = 0) {
      4 		$setting_data = array();
      5 
      6 		$query = $this->db->query("SELECT * FROM " . DB_PREFIX . "setting WHERE store_id = '" . (int)$store_id . "' AND `code` = '" . $this->db->escape($code) . "'");
      7 
      8 		foreach ($query->rows as $result) {
      9 			if (!$result['serialized']) {
     10 				$setting_data[$result['key']] = $result['value'];
     11 			} else {
     12 				$setting_data[$result['key']] = json_decode($result['value'], true);
     13 			}
     14 		}
     15 
     16 		return $setting_data;
     17 	}
     18 
     19 	public function editSetting($code, $data, $store_id = 0) {
     20 		$this->db->query("DELETE FROM `" . DB_PREFIX . "setting` WHERE store_id = '" . (int)$store_id . "' AND `code` = '" . $this->db->escape($code) . "'");
     21 
     22 		foreach ($data as $key => $value) {
     23 			if (substr($key, 0, strlen($code)) == $code) {
     24 				if (!is_array($value)) {
     25 					$this->db->query("INSERT INTO " . DB_PREFIX . "setting SET store_id = '" . (int)$store_id . "', `code` = '" . $this->db->escape($code) . "', `key` = '" . $this->db->escape($key) . "', `value` = '" . $this->db->escape($value) . "'");
     26 				} else {
     27 					$this->db->query("INSERT INTO " . DB_PREFIX . "setting SET store_id = '" . (int)$store_id . "', `code` = '" . $this->db->escape($code) . "', `key` = '" . $this->db->escape($key) . "', `value` = '" . $this->db->escape(json_encode($value, true)) . "', serialized = '1'");
     28 				}
     29 			}
     30 		}
     31 	}
     32 
     33 	public function deleteSetting($code, $store_id = 0) {
     34 		$this->db->query("DELETE FROM " . DB_PREFIX . "setting WHERE store_id = '" . (int)$store_id . "' AND `code` = '" . $this->db->escape($code) . "'");
     35 	}
     36 	
     37 	public function getSettingValue($key, $store_id = 0) {
     38 		$query = $this->db->query("SELECT value FROM " . DB_PREFIX . "setting WHERE store_id = '" . (int)$store_id . "' AND `key` = '" . $this->db->escape($key) . "'");
     39 
     40 		if ($query->num_rows) {
     41 			return $query->row['value'];
     42 		} else {
     43 			return null;	
     44 		}
     45 	}
     46 	
     47 	public function editSettingValue($code = '', $key = '', $value = '', $store_id = 0) {
     48 		if (!is_array($value)) {
     49 			$this->db->query("UPDATE " . DB_PREFIX . "setting SET `value` = '" . $this->db->escape($value) . "', serialized = '0'  WHERE `code` = '" . $this->db->escape($code) . "' AND `key` = '" . $this->db->escape($key) . "' AND store_id = '" . (int)$store_id . "'");
     50 		} else {
     51 			$this->db->query("UPDATE " . DB_PREFIX . "setting SET `value` = '" . $this->db->escape(json_encode($value)) . "', serialized = '1' WHERE `code` = '" . $this->db->escape($code) . "' AND `key` = '" . $this->db->escape($key) . "' AND store_id = '" . (int)$store_id . "'");
     52 		}
     53 	}
     54 }