@@ -48,6 +48,8 @@ function _make_static_data() {
48
48
$ this ->session ->data ['error ' ] = '' ;
49
49
$ this ->session ->data ['success ' ] = '' ;
50
50
51
+ $ this ->data ['entry_name ' ] = $ this ->language ->get ('entry_name ' );
52
+
51
53
$ this ->children = array (
52
54
'common/header ' ,
53
55
'common/footer '
@@ -89,17 +91,15 @@ public function index() {
89
91
function _make_form_data ($ banner_id =0 ) {
90
92
$ this ->data ['text_enabled ' ] = $ this ->language ->get ('text_enabled ' );
91
93
$ 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 ' );
96
94
97
95
$ 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 ' );
100
96
$ this ->data ['entry_image ' ] = $ this ->language ->get ('entry_image ' );
101
97
$ this ->data ['entry_status ' ] = $ this ->language ->get ('entry_status ' );
102
98
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
+
103
103
104
104
if (isset ($ this ->error ['name ' ])) {
105
105
$ this ->data ['error_name ' ] = $ this ->error ['name ' ];
@@ -205,6 +205,15 @@ public function update() {
205
205
$ this ->_show_form ($ id );
206
206
}
207
207
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 */
208
217
function _reduce_product ($ prd ) {
209
218
$ img = $ prd ['image ' ];
210
219
if ($ img && file_exists (DIR_IMAGE . $ img )) {
@@ -221,6 +230,7 @@ function _reduce_product($prd) {
221
230
);
222
231
}
223
232
233
+ /* Banner_image_description in various languages */
224
234
function _desc_in_langs ($ desc , $ languages ) {
225
235
$ d = array ();
226
236
foreach ($ languages as $ l ) {
@@ -229,6 +239,13 @@ function _desc_in_langs($desc, $languages) {
229
239
}
230
240
return $ d ;
231
241
}
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
+
232
249
function _process_submitted_data () {
233
250
if (!$ this ->_validate ()) {
234
251
return ;
@@ -252,8 +269,7 @@ function _process_submitted_data() {
252
269
$ banner_image_description = $ this ->_desc_in_langs ($ product_info ['name ' ],
253
270
$ languages );
254
271
$ 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 );
257
273
$ banner_image [] = compact ('banner_image_description ' , 'image ' , 'link ' );
258
274
}
259
275
$ banner ['banner_image ' ] = $ banner_image ;
@@ -276,6 +292,23 @@ function _process_submitted_data() {
276
292
$ this ->redirect ($ this ->url ->link ('module/autobanner ' , 'token= ' . $ this ->session ->data ['token ' ], 'SSL ' ));
277
293
}
278
294
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
+
279
312
function _validate () {
280
313
$ this ->request ->post ['name ' ] = trim ($ this ->request ->post ['name ' ]);
281
314
if (!$ this ->user ->hasPermission ('modify ' , 'design/banner ' )) {
@@ -293,6 +326,21 @@ function _validate() {
293
326
}
294
327
}
295
328
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 */
296
344
public function install () {
297
345
$ this ->load ->language ('extension/module ' );
298
346
@@ -305,10 +353,12 @@ public function install() {
305
353
else {
306
354
/*Permisson is OK */
307
355
$ this ->load ->model ('module/autobanner ' );
356
+ /* Install neccessary table for this module */
308
357
$ this ->model_module_autobanner ->install ();
309
358
}
310
359
}
311
360
361
+ /* This method is called when this module is deactivated */
312
362
public function uninstall () {
313
363
$ this ->load ->language ('extension/module ' );
314
364
@@ -321,6 +371,7 @@ public function uninstall() {
321
371
else {
322
372
/*Permisson is OK */
323
373
$ this ->load ->model ('module/autobanner ' );
374
+ /* Remove the table created by this module */
324
375
$ this ->model_module_autobanner ->uninstall ();
325
376
}
326
377
}
0 commit comments