-
Notifications
You must be signed in to change notification settings - Fork 2
/
states_countries_plugin.php
117 lines (103 loc) · 3.7 KB
/
states_countries_plugin.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
<?php
/**
* States/Countries plugin handler
*
* @package states_countries
* @copyright Copyright (c) 2015, tysonphillips
* @license http://www.gnu.org/licenses/gpl-3.0.txt GNU General Public License v3
*/
class StatesCountriesPlugin extends Plugin
{
/**
* Construct
*/
public function __construct()
{
Language::loadLang("states_countries_plugin", null, dirname(__FILE__) . DS . "language" . DS);
// Load components required by this plugin
Loader::loadComponents($this, ["Input", "Record"]);
$this->loadConfig(dirname(__FILE__) . DS . "config.json");
}
/**
* Performs any necessary bootstraping actions
*
* @param int $plugin_id The ID of the plugin being installed
*/
public function install($plugin_id)
{
Loader::loadModels($this, ["Permissions"]);
// Add a new permission to [Tools]
$group = $this->Permissions->getGroupByAlias("admin_tools");
$perm = [
'plugin_id' => $plugin_id,
'group_id' => $group->id,
'name' => Language::_("StatesCountriesPlugin.admin_main.name", true),
'alias' => "states_countries.admin_main",
'action' => "*"
];
// Add permission to view
$this->Permissions->add($perm);
$errors = $this->Permissions->errors();
// Manage countries
if (empty($errors)) {
$perm = array_merge($perm, [
'name' => Language::_("StatesCountriesPlugin.admin_countries.name", true),
'alias' => "states_countries.admin_countries"
]);
$this->Permissions->add($perm);
$errors = $this->Permissions->errors();
}
// Manage states
if (empty($errors)) {
$perm = array_merge($perm, [
'name' => Language::_("StatesCountriesPlugin.admin_states.name", true),
'alias' => "states_countries.admin_states"
]);
$this->Permissions->add($perm);
$errors = $this->Permissions->errors();
}
if ($errors) {
$this->Input->setErrors($errors);
return;
}
}
/**
* Performs any necessary cleanup actions
*
* @param int $plugin_id The ID of the plugin being uninstalled
* @param boolean $last_instance True if $plugin_id is the last instance across all
* companies for this plugin, false otherwise
*/
public function uninstall($plugin_id, $last_instance)
{
Loader::loadModels($this, ["Permissions"]);
$permissions = [
$this->Permissions->getByAlias("states_countries.admin_main", $plugin_id),
$this->Permissions->getByAlias("states_countries.admin_countries", $plugin_id),
$this->Permissions->getByAlias("states_countries.admin_states", $plugin_id)
];
foreach ($permissions as $permission) {
$this->Permissions->delete($permission->id);
}
}
/**
* Returns all actions to be configured for this widget
* (invoked after install() or upgrade(), overwrites all existing actions)
*
* @return array A numerically indexed array containing:
* - action The action to register for
* - uri The URI to be invoked for the given action
* - name The name to represent the action (can be language definition)
*/
public function getActions()
{
return [
[
'action' => "nav_secondary_staff",
'uri' => "plugin/states_countries/admin_main/",
'name' => Language::_("StatesCountriesPlugin.admin_main.name", true),
'options' => ['parent' => "tools/"]
]
];
}
}