Skip to content

Commit da7b400

Browse files
committedNov 4, 2012
AutoBanner: Allow to delete banners.
1 parent 6a77273 commit da7b400

File tree

5 files changed

+81
-23
lines changed

5 files changed

+81
-23
lines changed
 

‎upload/admin/controller/module/autobanner.php

+59-8
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,8 @@ function _make_static_data() {
4848
$this->session->data['error'] = '';
4949
$this->session->data['success'] = '';
5050

51+
$this->data['entry_name'] = $this->language->get('entry_name');
52+
5153
$this->children = array(
5254
'common/header',
5355
'common/footer'
@@ -89,17 +91,15 @@ public function index() {
8991
function _make_form_data($banner_id=0) {
9092
$this->data['text_enabled'] = $this->language->get('text_enabled');
9193
$this->data['text_disabled'] = $this->language->get('text_disabled');
92-
$this->data['text_default'] = $this->language->get('text_default');
93-
$this->data['text_image_manager'] = $this->language->get('text_image_manager');
94-
$this->data['text_browse'] = $this->language->get('text_browse');
95-
$this->data['text_clear'] = $this->language->get('text_clear');
9694

9795
$this->data['entry_name'] = $this->language->get('entry_name');
98-
$this->data['entry_title'] = $this->language->get('entry_title');
99-
$this->data['entry_link'] = $this->language->get('entry_link');
10096
$this->data['entry_image'] = $this->language->get('entry_image');
10197
$this->data['entry_status'] = $this->language->get('entry_status');
10298

99+
$this->data['column_name'] = $this->language->get('column_name');
100+
$this->data['column_image'] = $this->language->get('column_image');
101+
$this->data['column_model'] = $this->language->get('column_model');
102+
103103

104104
if (isset($this->error['name'])) {
105105
$this->data['error_name'] = $this->error['name'];
@@ -205,6 +205,15 @@ public function update() {
205205
$this->_show_form($id);
206206
}
207207

208+
public function delete() {
209+
if ($this->request->server['REQUEST_METHOD'] == 'POST') {
210+
$this->_process_deletion();
211+
}
212+
/* Redirect to parent page */
213+
$this->redirect($this->url->link('module/autobanner', 'token=' . $this->session->data['token'], 'SSL'));
214+
}
215+
216+
/* Strip some unused info relate to product */
208217
function _reduce_product($prd) {
209218
$img = $prd['image'];
210219
if ($img && file_exists(DIR_IMAGE . $img)) {
@@ -221,6 +230,7 @@ function _reduce_product($prd) {
221230
);
222231
}
223232

233+
/* Banner_image_description in various languages */
224234
function _desc_in_langs($desc, $languages) {
225235
$d = array();
226236
foreach ($languages as $l) {
@@ -229,6 +239,13 @@ function _desc_in_langs($desc, $languages) {
229239
}
230240
return $d;
231241
}
242+
243+
/* Make route for banner item */
244+
function _make_product_route($prd_id) {
245+
$cat = $this->model_catalog_product->getProductCategories($id)[0];
246+
return "index.php?route=product/product&path=$cat&product_id=$prd_id";
247+
}
248+
232249
function _process_submitted_data() {
233250
if (!$this->_validate()) {
234251
return;
@@ -252,8 +269,7 @@ function _process_submitted_data() {
252269
$banner_image_description = $this->_desc_in_langs($product_info['name'],
253270
$languages);
254271
$image = $product_info['image'];
255-
$cat = $this->model_catalog_product->getProductCategories($id)[0];
256-
$link = $this->url->link('product/product', "path=$cat&product_id=$id");
272+
$link = $this->_make_product_route($id);
257273
$banner_image[] = compact('banner_image_description', 'image', 'link');
258274
}
259275
$banner['banner_image'] = $banner_image;
@@ -276,6 +292,23 @@ function _process_submitted_data() {
276292
$this->redirect($this->url->link('module/autobanner', 'token=' . $this->session->data['token'], 'SSL'));
277293
}
278294

295+
function _process_deletion() {
296+
if (!$this->_validate_delete()) {
297+
$this->session->data['error_warning'] = $this->error['warning'];
298+
return;
299+
}
300+
301+
$this->load->model('module/autobanner');
302+
$this->load->model('design/banner');
303+
$this->load->language("module/{$this->MODULENAME}");
304+
$banners = $this->request->post['delete'];
305+
/* Delete on the table of this module */
306+
$this->model_module_autobanner->deleteBanners($banners);
307+
/* Delete in system's banners table */
308+
array_map(array($this->model_design_banner, 'deleteBanner'), $banners);
309+
$this->session->data['success'] = $this->language->get('text_success');
310+
}
311+
279312
function _validate() {
280313
$this->request->post['name'] = trim($this->request->post['name']);
281314
if (!$this->user->hasPermission('modify', 'design/banner')) {
@@ -293,6 +326,21 @@ function _validate() {
293326
}
294327
}
295328

329+
function _validate_delete() {
330+
if (!$this->user->hasPermission('modify', 'design/banner')) {
331+
$this->error['warning'] = $this->language->get('error_permission');
332+
}
333+
$this->request->post['delete'] = array_map('intval',
334+
$this->request->post['delete']);
335+
336+
if (!$this->error) {
337+
return true;
338+
} else {
339+
return false;
340+
}
341+
}
342+
343+
/* This method is called when this module is activated */
296344
public function install() {
297345
$this->load->language('extension/module');
298346

@@ -305,10 +353,12 @@ public function install() {
305353
else {
306354
/*Permisson is OK */
307355
$this->load->model('module/autobanner');
356+
/* Install neccessary table for this module */
308357
$this->model_module_autobanner->install();
309358
}
310359
}
311360

361+
/* This method is called when this module is deactivated */
312362
public function uninstall() {
313363
$this->load->language('extension/module');
314364

@@ -321,6 +371,7 @@ public function uninstall() {
321371
else {
322372
/*Permisson is OK */
323373
$this->load->model('module/autobanner');
374+
/* Remove the table created by this module */
324375
$this->model_module_autobanner->uninstall();
325376
}
326377
}

‎upload/admin/language/english/module/autobanner.php

+5-8
Original file line numberDiff line numberDiff line change
@@ -8,17 +8,14 @@
88

99
// Entry
1010
$_['entry_name'] = 'Banner Name:';
11-
$_['entry_title'] = 'Title:';
12-
$_['entry_link'] = 'Link:';
13-
$_['entry_image'] = 'Image:';
1411
$_['entry_status'] = 'Status:';
1512

13+
// Column
14+
$_['column_name'] = 'Product Name';
15+
$_['column_model'] = 'Model';
16+
$_['column_image'] = 'Image';
17+
1618
// Error
1719
$_['error_permission'] = 'Warning: You do not have permission to modify banners!';
1820
$_['error_name'] = 'Banner Name must be between 3 and 64 characters!';
19-
$_['error_title'] = 'Banner Title must be between 2 and 64 characters!';
20-
$_['error_default'] = 'Warning: This layout cannot be deleted as it is currently assigned as the default store layout!';
21-
$_['error_product'] = 'Warning: This layout cannot be deleted as it is currently assigned to %s products!';
22-
$_['error_category'] = 'Warning: This layout cannot be deleted as it is currently assigned to %s categories!';
23-
$_['error_information'] = 'Warning: This layout cannot be deleted as it is currently assigned to %s information pages!';
2421
?>

‎upload/admin/model/module/autobanner.php

+7
Original file line numberDiff line numberDiff line change
@@ -78,6 +78,13 @@ public function editBanner($banner_id, $product_ids) {
7878
return $this->db->query($sql);
7979
}
8080

81+
public function deleteBanners($banner_ids) {
82+
$idlist = join(', ', $banner_ids);
83+
$sql = "DELETE FROM `".DB_PREFIX.self::TABLE_NAME."`
84+
WHERE `banner_id` IN ($idlist)";
85+
return $this->db->query($sql);
86+
}
87+
8188
function _row_to_id($row) {
8289
return $row['banner_id'];
8390
}

‎upload/admin/view/template/module/autobanner.tpl

+5-2
Original file line numberDiff line numberDiff line change
@@ -24,19 +24,21 @@
2424
</div>
2525
</div>
2626
<div class="content">
27+
<form action="<?php echo $delete; ?>" method="post" enctype="multipart/form-data" id="form">
2728
<table class='list'>
2829
<thead>
2930
<tr>
3031
<td><input type='checkbox' /></td>
31-
<td class='left'>Name</td>
32+
<td class='left'><?php echo $entry_name ?></td>
3233
<td></td>
3334
</tr>
3435
</thead>
3536
<tbody>
3637
<?php
3738
foreach ($own_banners as $b) { ?>
3839
<tr>
39-
<td><input type='checkbox' name='selected[]' /></td>
40+
<td><input type='checkbox' name='delete[]'
41+
value='<?php echo $b['banner_id']?>'/></td>
4042
<td class='left'><?php echo $b['name']?></td>
4143
<td>
4244
<a href='<?php echo $b['edit_link']?>'>Edit</a>
@@ -46,6 +48,7 @@
4648
} ?>
4749
</tbody>
4850
</table>
51+
</form>
4952
</div>
5053
</div>
5154
</div>

‎upload/admin/view/template/module/autobanner_form.tpl

+5-5
Original file line numberDiff line numberDiff line change
@@ -54,8 +54,8 @@
5454
<table id='allproducts' class='list'>
5555
<thead>
5656
<tr>
57-
<td class='left'>Image</td>
58-
<td><?php echo $entry_name; ?></td>
57+
<td class='left'><?php echo $column_image ?></td>
58+
<td><?php echo $column_name; ?></td>
5959
<td>Model</td>
6060
<td></td>
6161
</tr>
@@ -80,9 +80,9 @@
8080
<table id='ownproducts' class='list'>
8181
<thead>
8282
<tr>
83-
<td class='left'>Image</td>
84-
<td><?php echo $entry_name; ?></td>
85-
<td>Model</td>
83+
<td class='left'><?php echo $column_image ?></td>
84+
<td><?php echo $column_name; ?></td>
85+
<td><?php echo $column_model ?></td>
8686
<td></td>
8787
</tr>
8888
</thead>

0 commit comments

Comments
 (0)
Please sign in to comment.