layout.php (4459B)
1 <?php 2 class ModelDesignLayout extends Model { 3 public function addLayout($data) { 4 $this->db->query("INSERT INTO " . DB_PREFIX . "layout SET name = '" . $this->db->escape($data['name']) . "'"); 5 6 $layout_id = $this->db->getLastId(); 7 8 if (isset($data['layout_route'])) { 9 foreach ($data['layout_route'] as $layout_route) { 10 $this->db->query("INSERT INTO " . DB_PREFIX . "layout_route SET layout_id = '" . (int)$layout_id . "', store_id = '" . (int)$layout_route['store_id'] . "', route = '" . $this->db->escape($layout_route['route']) . "'"); 11 } 12 } 13 14 if (isset($data['layout_module'])) { 15 foreach ($data['layout_module'] as $layout_module) { 16 $this->db->query("INSERT INTO " . DB_PREFIX . "layout_module SET layout_id = '" . (int)$layout_id . "', code = '" . $this->db->escape($layout_module['code']) . "', position = '" . $this->db->escape($layout_module['position']) . "', sort_order = '" . (int)$layout_module['sort_order'] . "'"); 17 } 18 } 19 20 return $layout_id; 21 } 22 23 public function editLayout($layout_id, $data) { 24 $this->db->query("UPDATE " . DB_PREFIX . "layout SET name = '" . $this->db->escape($data['name']) . "' WHERE layout_id = '" . (int)$layout_id . "'"); 25 26 $this->db->query("DELETE FROM " . DB_PREFIX . "layout_route WHERE layout_id = '" . (int)$layout_id . "'"); 27 28 if (isset($data['layout_route'])) { 29 foreach ($data['layout_route'] as $layout_route) { 30 $this->db->query("INSERT INTO " . DB_PREFIX . "layout_route SET layout_id = '" . (int)$layout_id . "', store_id = '" . (int)$layout_route['store_id'] . "', route = '" . $this->db->escape($layout_route['route']) . "'"); 31 } 32 } 33 34 $this->db->query("DELETE FROM " . DB_PREFIX . "layout_module WHERE layout_id = '" . (int)$layout_id . "'"); 35 36 if (isset($data['layout_module'])) { 37 foreach ($data['layout_module'] as $layout_module) { 38 $this->db->query("INSERT INTO " . DB_PREFIX . "layout_module SET layout_id = '" . (int)$layout_id . "', code = '" . $this->db->escape($layout_module['code']) . "', position = '" . $this->db->escape($layout_module['position']) . "', sort_order = '" . (int)$layout_module['sort_order'] . "'"); 39 } 40 } 41 } 42 43 public function deleteLayout($layout_id) { 44 $this->db->query("DELETE FROM " . DB_PREFIX . "layout WHERE layout_id = '" . (int)$layout_id . "'"); 45 $this->db->query("DELETE FROM " . DB_PREFIX . "layout_route WHERE layout_id = '" . (int)$layout_id . "'"); 46 $this->db->query("DELETE FROM " . DB_PREFIX . "layout_module WHERE layout_id = '" . (int)$layout_id . "'"); 47 $this->db->query("DELETE FROM " . DB_PREFIX . "category_to_layout WHERE layout_id = '" . (int)$layout_id . "'"); 48 $this->db->query("DELETE FROM " . DB_PREFIX . "product_to_layout WHERE layout_id = '" . (int)$layout_id . "'"); 49 $this->db->query("DELETE FROM " . DB_PREFIX . "information_to_layout WHERE layout_id = '" . (int)$layout_id . "'"); 50 } 51 52 public function getLayout($layout_id) { 53 $query = $this->db->query("SELECT DISTINCT * FROM " . DB_PREFIX . "layout WHERE layout_id = '" . (int)$layout_id . "'"); 54 55 return $query->row; 56 } 57 58 public function getLayouts($data = array()) { 59 $sql = "SELECT * FROM " . DB_PREFIX . "layout"; 60 61 $sort_data = array('name'); 62 63 if (isset($data['sort']) && in_array($data['sort'], $sort_data)) { 64 $sql .= " ORDER BY " . $data['sort']; 65 } else { 66 $sql .= " ORDER BY name"; 67 } 68 69 if (isset($data['order']) && ($data['order'] == 'DESC')) { 70 $sql .= " DESC"; 71 } else { 72 $sql .= " ASC"; 73 } 74 75 if (isset($data['start']) || isset($data['limit'])) { 76 if ($data['start'] < 0) { 77 $data['start'] = 0; 78 } 79 80 if ($data['limit'] < 1) { 81 $data['limit'] = 20; 82 } 83 84 $sql .= " LIMIT " . (int)$data['start'] . "," . (int)$data['limit']; 85 } 86 87 $query = $this->db->query($sql); 88 89 return $query->rows; 90 } 91 92 public function getLayoutRoutes($layout_id) { 93 $query = $this->db->query("SELECT * FROM " . DB_PREFIX . "layout_route WHERE layout_id = '" . (int)$layout_id . "'"); 94 95 return $query->rows; 96 } 97 98 public function getLayoutModules($layout_id) { 99 $query = $this->db->query("SELECT * FROM " . DB_PREFIX . "layout_module WHERE layout_id = '" . (int)$layout_id . "' ORDER BY position ASC, sort_order ASC"); 100 101 return $query->rows; 102 } 103 104 public function getTotalLayouts() { 105 $query = $this->db->query("SELECT COUNT(*) AS total FROM " . DB_PREFIX . "layout"); 106 107 return $query->row['total']; 108 } 109 }