-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcustomerpetlist.php
More file actions
103 lines (83 loc) · 2.88 KB
/
customerpetlist.php
File metadata and controls
103 lines (83 loc) · 2.88 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
<?php
declare(strict_types=1);
if (!defined('_PS_VERSION_')) {
exit;
}
// Needed for install process
require_once __DIR__ . '/vendor/autoload.php';
use Preston\CustomerPetList\Controller\Admin\PetController;
class CustomerPetList extends Module
{
const INSTALL_SQL_FILE = 'install.sql';
const UNINSTALL_SQL_FILE = 'uninstall.sql';
public function __construct()
{
$this->name = 'customerpetlist';
$this->tab = 'front_office_features';
$this->version = '1.0.0';
$this->author = 'Thomas NARES';
$this->need_instance = 0;
$this->ps_versions_compliancy = [
'min' => '1.6.0',
'max' => '8.1.0',
];
$this->bootstrap = true;
parent::__construct();
$this->displayName = $this->l('Customer Pet List');
$this->description = $this->l('This module allows you to store the Pet list of a Customer');
$this->confirmUninstall = $this->l('Are you sure you want to uninstall and delete all pets from database ?');
// See https://devdocs.prestashop.com/1.7/modules/concepts/controllers/admin-controllers/tabs/
$tabNames = [];
foreach (Language::getLanguages(true) as $lang) {
$tabNames[$lang['locale']] = 'Pet list';
}
$this->tabs = [
[
'route_name' => 'preston_customerpetlist_controller_index',
'class_name' => PetController::TAB_CLASS_NAME,
'visible' => true,
'name' => $tabNames,
'icon' => 'school',
'parent_class_name' => 'IMPROVE',
],
];
}
public function install()
{
if (Shop::isFeatureActive()) {
Shop::setContext(Shop::CONTEXT_ALL);
}
if (!file_exists(dirname(__FILE__) . '/' . self::INSTALL_SQL_FILE)) {
return false;
} elseif (!$sql = file_get_contents(dirname(__FILE__) . '/' . self::INSTALL_SQL_FILE)) {
return false;
}
$sql = preg_split("/;\s*[\r\n]+/", trim($sql));
foreach ($sql as $query) {
if (!Db::getInstance()->execute(trim($query))) {
return false;
}
}
return (
parent::install()
);
}
public function uninstall()
{
if (!file_exists(dirname(__FILE__) . '/' . self::UNINSTALL_SQL_FILE)) {
return false;
} elseif (!$sql = file_get_contents(dirname(__FILE__) . '/' . self::UNINSTALL_SQL_FILE)) {
return false;
}
$sql = str_replace(['ENGINE_TYPE'], [_MYSQL_ENGINE_], $sql);
$sql = preg_split("/;\s*[\r\n]+/", trim($sql));
foreach ($sql as $query) {
if (!Db::getInstance()->execute(trim($query))) {
return false;
}
}
return (
parent::uninstall()
);
}
}