-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathExtend.php
121 lines (108 loc) · 3.37 KB
/
Extend.php
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
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
<?php
namespace SoosyzeExtension\Starterkit;
use Psr\Container\ContainerInterface;
use Queryflatfile\TableBuilder;
class Extend extends \SoosyzeCore\System\ExtendModule
{
public function boot()
{
$this->loadTranslation('fr', __DIR__ . '/Lang/fr/main.json');
}
public function getDir()
{
return __DIR__ . '/composer.json';
}
public function hookInstall(ContainerInterface $ci)
{
if ($ci->module()->has('Menu')) {
$this->hookInstallMenu($ci);
}
if ($ci->module()->has('User')) {
$this->hookInstallUser($ci);
}
}
public function hookInstallMenu(ContainerInterface $ci)
{
$ci->query()
->insertInto('menu_link', [
'key', 'icon', 'title_link', 'link', 'menu', 'weight', 'parent'
])
->values([
'starterkit.admin', 'fa fa-puzzle-piece', 'Starterkit', 'admin/starterkit',
'menu-admin', 50, -1
])
->values([
'starterkit.index', null, 'Starterkit', 'starterkit/index', 'menu-main',
50, -1
])
->execute();
}
public function hookInstallUser(ContainerInterface $ci)
{
$ci->query()
->insertInto('role_permission', [ 'role_id', 'permission_id' ])
->values([ 3, 'starterkit.admin' ])
->values([ 3, 'starterkit.show' ])
->values([ 2, 'starterkit.show' ])
->values([ 1, 'starterkit.show' ])
->execute();
}
public function hookUninstall(ContainerInterface $ci)
{
if ($ci->module()->has('Menu')) {
$this->hookUninstallMenu($ci);
}
if ($ci->module()->has('User')) {
$this->hookUninstallUser($ci);
}
}
public function hookUninstallMenu(ContainerInterface $ci)
{
$ci->menu()->deleteLinks(static function () use ($ci) {
return $ci->query()
->from('menu_link')
->where('key', 'like', 'starterkit%')
->fetchAll();
});
}
public function hookUninstallUser(ContainerInterface $ci)
{
$ci->query()
->from('role_permission')
->delete()
->where('permission_id', 'like', 'starterkit%')
->execute();
}
public function install(ContainerInterface $ci)
{
/* Ajoute une table et insert des données.
$ci->schema()
->createTableIfNotExists('starterkit', static function (TableBuilder $table) {
$table->increments('id')
->string('field_1')
->integer('field_2')->nullable()
->boolean('field_3')->valueDefault(false);
});
// */
$ci->config()
->set('settings.start_check', '')
->set('settings.start_text', '');
}
public function seeders(ContainerInterface $ci)
{
/* Ajout des données
$ci->query()
->insertInto('starterkit', [ 'field_1', 'field_2' ])
->values([ 'value_1', 1 ])
->values([ 'value_1', 2 ])
->values([ 'value_1', null ])
->execute();
// */
}
public function uninstall(ContainerInterface $ci)
{
/* Supprime une table et ses données.
$container->schema()->dropTable('starterkit');
// */
}
}