attribute_group.php (12540B)
1 <?php 2 class ControllerCatalogAttributeGroup extends Controller { 3 private $error = array(); 4 5 public function index() { 6 $this->load->language('catalog/attribute_group'); 7 8 $this->document->setTitle($this->language->get('heading_title')); 9 10 $this->load->model('catalog/attribute_group'); 11 12 $this->getList(); 13 } 14 15 public function add() { 16 $this->load->language('catalog/attribute_group'); 17 18 $this->document->setTitle($this->language->get('heading_title')); 19 20 $this->load->model('catalog/attribute_group'); 21 22 if (($this->request->server['REQUEST_METHOD'] == 'POST') && $this->validateForm()) { 23 $this->model_catalog_attribute_group->addAttributeGroup($this->request->post); 24 25 $this->session->data['success'] = $this->language->get('text_success'); 26 27 $url = ''; 28 29 if (isset($this->request->get['sort'])) { 30 $url .= '&sort=' . $this->request->get['sort']; 31 } 32 33 if (isset($this->request->get['order'])) { 34 $url .= '&order=' . $this->request->get['order']; 35 } 36 37 if (isset($this->request->get['page'])) { 38 $url .= '&page=' . $this->request->get['page']; 39 } 40 41 $this->response->redirect($this->url->link('catalog/attribute_group', 'user_token=' . $this->session->data['user_token'] . $url, true)); 42 } 43 44 $this->getForm(); 45 } 46 47 public function edit() { 48 $this->load->language('catalog/attribute_group'); 49 50 $this->document->setTitle($this->language->get('heading_title')); 51 52 $this->load->model('catalog/attribute_group'); 53 54 if (($this->request->server['REQUEST_METHOD'] == 'POST') && $this->validateForm()) { 55 $this->model_catalog_attribute_group->editAttributeGroup($this->request->get['attribute_group_id'], $this->request->post); 56 57 $this->session->data['success'] = $this->language->get('text_success'); 58 59 $url = ''; 60 61 if (isset($this->request->get['sort'])) { 62 $url .= '&sort=' . $this->request->get['sort']; 63 } 64 65 if (isset($this->request->get['order'])) { 66 $url .= '&order=' . $this->request->get['order']; 67 } 68 69 if (isset($this->request->get['page'])) { 70 $url .= '&page=' . $this->request->get['page']; 71 } 72 73 $this->response->redirect($this->url->link('catalog/attribute_group', 'user_token=' . $this->session->data['user_token'] . $url, true)); 74 } 75 76 $this->getForm(); 77 } 78 79 public function delete() { 80 $this->load->language('catalog/attribute_group'); 81 82 $this->document->setTitle($this->language->get('heading_title')); 83 84 $this->load->model('catalog/attribute_group'); 85 86 if (isset($this->request->post['selected']) && $this->validateDelete()) { 87 foreach ($this->request->post['selected'] as $attribute_group_id) { 88 $this->model_catalog_attribute_group->deleteAttributeGroup($attribute_group_id); 89 } 90 91 $this->session->data['success'] = $this->language->get('text_success'); 92 93 $url = ''; 94 95 if (isset($this->request->get['sort'])) { 96 $url .= '&sort=' . $this->request->get['sort']; 97 } 98 99 if (isset($this->request->get['order'])) { 100 $url .= '&order=' . $this->request->get['order']; 101 } 102 103 if (isset($this->request->get['page'])) { 104 $url .= '&page=' . $this->request->get['page']; 105 } 106 107 $this->response->redirect($this->url->link('catalog/attribute_group', 'user_token=' . $this->session->data['user_token'] . $url, true)); 108 } 109 110 $this->getList(); 111 } 112 113 protected function getList() { 114 if (isset($this->request->get['sort'])) { 115 $sort = $this->request->get['sort']; 116 } else { 117 $sort = 'agd.name'; 118 } 119 120 if (isset($this->request->get['order'])) { 121 $order = $this->request->get['order']; 122 } else { 123 $order = 'ASC'; 124 } 125 126 if (isset($this->request->get['page'])) { 127 $page = $this->request->get['page']; 128 } else { 129 $page = 1; 130 } 131 132 $url = ''; 133 134 if (isset($this->request->get['sort'])) { 135 $url .= '&sort=' . $this->request->get['sort']; 136 } 137 138 if (isset($this->request->get['order'])) { 139 $url .= '&order=' . $this->request->get['order']; 140 } 141 142 if (isset($this->request->get['page'])) { 143 $url .= '&page=' . $this->request->get['page']; 144 } 145 146 $data['breadcrumbs'] = array(); 147 148 $data['breadcrumbs'][] = array( 149 'text' => $this->language->get('text_home'), 150 'href' => $this->url->link('common/dashboard', 'user_token=' . $this->session->data['user_token'], true) 151 ); 152 153 $data['breadcrumbs'][] = array( 154 'text' => $this->language->get('heading_title'), 155 'href' => $this->url->link('catalog/attribute_group', 'user_token=' . $this->session->data['user_token'] . $url, true) 156 ); 157 158 $data['add'] = $this->url->link('catalog/attribute_group/add', 'user_token=' . $this->session->data['user_token'] . $url, true); 159 $data['delete'] = $this->url->link('catalog/attribute_group/delete', 'user_token=' . $this->session->data['user_token'] . $url, true); 160 161 $data['attribute_groups'] = array(); 162 163 $filter_data = array( 164 'sort' => $sort, 165 'order' => $order, 166 'start' => ($page - 1) * $this->config->get('config_limit_admin'), 167 'limit' => $this->config->get('config_limit_admin') 168 ); 169 170 $attribute_group_total = $this->model_catalog_attribute_group->getTotalAttributeGroups(); 171 172 $results = $this->model_catalog_attribute_group->getAttributeGroups($filter_data); 173 174 foreach ($results as $result) { 175 $data['attribute_groups'][] = array( 176 'attribute_group_id' => $result['attribute_group_id'], 177 'name' => $result['name'], 178 'sort_order' => $result['sort_order'], 179 'edit' => $this->url->link('catalog/attribute_group/edit', 'user_token=' . $this->session->data['user_token'] . '&attribute_group_id=' . $result['attribute_group_id'] . $url, true) 180 ); 181 } 182 183 if (isset($this->error['warning'])) { 184 $data['error_warning'] = $this->error['warning']; 185 } else { 186 $data['error_warning'] = ''; 187 } 188 189 if (isset($this->session->data['success'])) { 190 $data['success'] = $this->session->data['success']; 191 192 unset($this->session->data['success']); 193 } else { 194 $data['success'] = ''; 195 } 196 197 if (isset($this->request->post['selected'])) { 198 $data['selected'] = (array)$this->request->post['selected']; 199 } else { 200 $data['selected'] = array(); 201 } 202 203 $url = ''; 204 205 if ($order == 'ASC') { 206 $url .= '&order=DESC'; 207 } else { 208 $url .= '&order=ASC'; 209 } 210 211 if (isset($this->request->get['page'])) { 212 $url .= '&page=' . $this->request->get['page']; 213 } 214 215 $data['sort_name'] = $this->url->link('catalog/attribute_group', 'user_token=' . $this->session->data['user_token'] . '&sort=agd.name' . $url, true); 216 $data['sort_sort_order'] = $this->url->link('catalog/attribute_group', 'user_token=' . $this->session->data['user_token'] . '&sort=ag.sort_order' . $url, true); 217 218 $url = ''; 219 220 if (isset($this->request->get['sort'])) { 221 $url .= '&sort=' . $this->request->get['sort']; 222 } 223 224 if (isset($this->request->get['order'])) { 225 $url .= '&order=' . $this->request->get['order']; 226 } 227 228 $pagination = new Pagination(); 229 $pagination->total = $attribute_group_total; 230 $pagination->page = $page; 231 $pagination->limit = $this->config->get('config_limit_admin'); 232 $pagination->url = $this->url->link('catalog/attribute_group', 'user_token=' . $this->session->data['user_token'] . $url . '&page={page}', true); 233 234 $data['pagination'] = $pagination->render(); 235 236 $data['results'] = sprintf($this->language->get('text_pagination'), ($attribute_group_total) ? (($page - 1) * $this->config->get('config_limit_admin')) + 1 : 0, ((($page - 1) * $this->config->get('config_limit_admin')) > ($attribute_group_total - $this->config->get('config_limit_admin'))) ? $attribute_group_total : ((($page - 1) * $this->config->get('config_limit_admin')) + $this->config->get('config_limit_admin')), $attribute_group_total, ceil($attribute_group_total / $this->config->get('config_limit_admin'))); 237 238 $data['sort'] = $sort; 239 $data['order'] = $order; 240 241 $data['header'] = $this->load->controller('common/header'); 242 $data['column_left'] = $this->load->controller('common/column_left'); 243 $data['footer'] = $this->load->controller('common/footer'); 244 245 $this->response->setOutput($this->load->view('catalog/attribute_group_list', $data)); 246 } 247 248 protected function getForm() { 249 $data['text_form'] = !isset($this->request->get['attribute_group_id']) ? $this->language->get('text_add') : $this->language->get('text_edit'); 250 251 if (isset($this->error['warning'])) { 252 $data['error_warning'] = $this->error['warning']; 253 } else { 254 $data['error_warning'] = ''; 255 } 256 257 if (isset($this->error['name'])) { 258 $data['error_name'] = $this->error['name']; 259 } else { 260 $data['error_name'] = array(); 261 } 262 263 $url = ''; 264 265 if (isset($this->request->get['sort'])) { 266 $url .= '&sort=' . $this->request->get['sort']; 267 } 268 269 if (isset($this->request->get['order'])) { 270 $url .= '&order=' . $this->request->get['order']; 271 } 272 273 if (isset($this->request->get['page'])) { 274 $url .= '&page=' . $this->request->get['page']; 275 } 276 277 $data['breadcrumbs'] = array(); 278 279 $data['breadcrumbs'][] = array( 280 'text' => $this->language->get('text_home'), 281 'href' => $this->url->link('common/dashboard', 'user_token=' . $this->session->data['user_token'], true) 282 ); 283 284 $data['breadcrumbs'][] = array( 285 'text' => $this->language->get('heading_title'), 286 'href' => $this->url->link('catalog/attribute_group', 'user_token=' . $this->session->data['user_token'] . $url, true) 287 ); 288 289 if (!isset($this->request->get['attribute_group_id'])) { 290 $data['action'] = $this->url->link('catalog/attribute_group/add', 'user_token=' . $this->session->data['user_token'] . $url, true); 291 } else { 292 $data['action'] = $this->url->link('catalog/attribute_group/edit', 'user_token=' . $this->session->data['user_token'] . '&attribute_group_id=' . $this->request->get['attribute_group_id'] . $url, true); 293 } 294 295 $data['cancel'] = $this->url->link('catalog/attribute_group', 'user_token=' . $this->session->data['user_token'] . $url, true); 296 297 if (isset($this->request->get['attribute_group_id']) && ($this->request->server['REQUEST_METHOD'] != 'POST')) { 298 $attribute_group_info = $this->model_catalog_attribute_group->getAttributeGroup($this->request->get['attribute_group_id']); 299 } 300 301 $this->load->model('localisation/language'); 302 303 $data['languages'] = $this->model_localisation_language->getLanguages(); 304 305 if (isset($this->request->post['attribute_group_description'])) { 306 $data['attribute_group_description'] = $this->request->post['attribute_group_description']; 307 } elseif (isset($this->request->get['attribute_group_id'])) { 308 $data['attribute_group_description'] = $this->model_catalog_attribute_group->getAttributeGroupDescriptions($this->request->get['attribute_group_id']); 309 } else { 310 $data['attribute_group_description'] = array(); 311 } 312 313 if (isset($this->request->post['sort_order'])) { 314 $data['sort_order'] = $this->request->post['sort_order']; 315 } elseif (!empty($attribute_group_info)) { 316 $data['sort_order'] = $attribute_group_info['sort_order']; 317 } else { 318 $data['sort_order'] = ''; 319 } 320 321 $data['header'] = $this->load->controller('common/header'); 322 $data['column_left'] = $this->load->controller('common/column_left'); 323 $data['footer'] = $this->load->controller('common/footer'); 324 325 $this->response->setOutput($this->load->view('catalog/attribute_group_form', $data)); 326 } 327 328 protected function validateForm() { 329 if (!$this->user->hasPermission('modify', 'catalog/attribute_group')) { 330 $this->error['warning'] = $this->language->get('error_permission'); 331 } 332 333 foreach ($this->request->post['attribute_group_description'] as $language_id => $value) { 334 if ((utf8_strlen($value['name']) < 1) || (utf8_strlen($value['name']) > 64)) { 335 $this->error['name'][$language_id] = $this->language->get('error_name'); 336 } 337 } 338 339 return !$this->error; 340 } 341 342 protected function validateDelete() { 343 if (!$this->user->hasPermission('modify', 'catalog/attribute_group')) { 344 $this->error['warning'] = $this->language->get('error_permission'); 345 } 346 347 $this->load->model('catalog/attribute'); 348 349 foreach ($this->request->post['selected'] as $attribute_group_id) { 350 $attribute_total = $this->model_catalog_attribute->getTotalAttributesByAttributeGroupId($attribute_group_id); 351 352 if ($attribute_total) { 353 $this->error['warning'] = sprintf($this->language->get('error_attribute'), $attribute_total); 354 } 355 } 356 357 return !$this->error; 358 } 359 }