module.php (2884B)
1 <?php 2 class ModelExtensionDOpencartPatchModule extends Model { 3 public function addModule($code, $data) { 4 if(VERSION >= '2.1.0.0'){ 5 $this->db->query("INSERT INTO `" . DB_PREFIX . "module` SET `name` = '" . $this->db->escape($data['name']) . "', `code` = '" . $this->db->escape($code) . "', `setting` = '" . $this->db->escape(json_encode($data)) . "'"); 6 }else{ 7 $this->db->query("INSERT INTO `" . DB_PREFIX . "module` SET `name` = '" . $this->db->escape($data['name']) . "', `code` = '" . $this->db->escape($code) . "', `setting` = '" . $this->db->escape(serialize($data)) . "'"); 8 } 9 return $this->db->getLastId(); 10 } 11 12 public function editModule($module_id, $data) { 13 if(VERSION >= '2.1.0.0'){ 14 $this->db->query("UPDATE `" . DB_PREFIX . "module` SET `name` = '" . $this->db->escape($data['name']) . "', `setting` = '" . $this->db->escape(json_encode($data)) . "' WHERE `module_id` = '" . (int)$module_id . "'"); 15 }else{ 16 $this->db->query("UPDATE `" . DB_PREFIX . "module` SET `name` = '" . $this->db->escape($data['name']) . "', `setting` = '" . $this->db->escape(serialize($data)) . "' WHERE `module_id` = '" . (int)$module_id . "'"); 17 } 18 } 19 20 public function deleteModule($module_id) { 21 $this->db->query("DELETE FROM `" . DB_PREFIX . "module` WHERE `module_id` = '" . (int)$module_id . "'"); 22 $this->db->query("DELETE FROM `" . DB_PREFIX . "layout_module` WHERE `code` LIKE '%." . (int)$module_id . "'"); 23 } 24 25 public function getModule($module_id) { 26 $query = $this->db->query("SELECT * FROM `" . DB_PREFIX . "module` WHERE `module_id` = '" . (int)$module_id . "'"); 27 28 if(VERSION >= '2.1.0.0'){ 29 if ($query->row) { 30 return json_decode($query->row['setting'], true); 31 } else { 32 return array(); 33 } 34 }else{ 35 if ($query->row) { 36 return unserialize($query->row['setting']); 37 } else { 38 return array(); 39 } 40 } 41 } 42 43 public function getModules() { 44 $query = $this->db->query("SELECT * FROM `" . DB_PREFIX . "module` ORDER BY `code`"); 45 46 return $query->rows; 47 } 48 49 public function getModulesByCode($code) { 50 $query = $this->db->query("SELECT * FROM `" . DB_PREFIX . "module` WHERE `code` = '" . $this->db->escape($code) . "' ORDER BY `name`"); 51 52 return $query->rows; 53 } 54 55 public function deleteModulesByCode($code) { 56 $this->db->query("DELETE FROM `" . DB_PREFIX . "module` WHERE `code` = '" . $this->db->escape($code) . "'"); 57 $this->db->query("DELETE FROM `" . DB_PREFIX . "layout_module` WHERE `code` LIKE '" . $this->db->escape($code) . "' OR `code` LIKE '" . $this->db->escape($code . '.%') . "'"); 58 } 59 }