generated from aljawaid/KanboardSkeletonPlugin
-
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathPlugin.php
131 lines (112 loc) · 6.24 KB
/
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
118
119
120
121
122
123
124
125
126
127
128
129
130
131
<?php
namespace Kanboard\Plugin\CostControl;
use Kanboard\Core\Plugin\Base;
use Kanboard\Core\Translator;
use Kanboard\Core\Security\Role;
use Kanboard\Plugin\CostControl\Model\ExtendedCurrencyModel;
use Kanboard\Model\CurrencyModel;
use Kanboard\Plugin\CostControl\Helper\CostControlLayoutHelper;
use Kanboard\Helper;
class Plugin extends Base
{
public function initialize()
{
// CSS - Asset Hook
// - Keep filename lowercase
$this->hook->on('template:layout:css', array('template' => 'plugins/CostControl/Assets/css/cost-control.css'));
$this->hook->on('template:layout:css', array('template' => 'plugins/CostControl/Assets/css/cost-control-icons.css'));
// JS - Asset Hook
// - Keep filename lowercase
$this->hook->on('template:layout:js', array('template' => 'plugins/CostControl/Assets/js/cost-control.js'));
if (!file_exists('plugins/PluginManager')) {
$this->hook->on('template:layout:js', array('template' => 'plugins/CostControl/Assets/js/cost-control-top-btn.js'));
}
// Template Override
// - Override name should be camelCase e.g. pluginNameExampleCamelCase
$this->template->setTemplateOverride('currency/change', 'costControl:currency/change');
$this->template->setTemplateOverride('currency/create', 'costControl:currency/create');
$this->template->setTemplateOverride('currency/show', 'costControl:currency/show');
// Views - Add Menu Item - Template Hook
// - Override name should start lowercase e.g. pluginNameExampleCamelCase
$this->template->hook->attach('template:project:dropdown', 'costControl:project/dropdown');
$this->template->hook->attach('template:user:sidebar:actions', 'costControl:user/sidebar');
$this->template->hook->attach('template:config:application', 'costControl:config/settings');
// TOP RIGHT MENU FOR ALL USERS TO ACCESS
$this->template->hook->attach('template:header:dropdown', 'costControl:header/user_dropdown');
// TOP DASHBOARD MENU FOR ALL USERS TO ACCESS
$this->template->hook->attach('template:dashboard:page-header:menu', 'costControl:dashboard/layout');
// Extra Page - Routes
// - Example: $this->route->addRoute('/my/custom/route', 'MyController', 'show', 'PluginNameExampleStudlyCaps');
// - Must have the corresponding action in the matching controller
$this->route->addRoute('/project/:project_id/budget', 'BudgetController', 'show', 'CostControl');
$this->route->addRoute('/project/:project_id/budget/lines', 'BudgetLineController', 'show', 'CostControl');
$this->route->addRoute('/project/:project_id/budget/lines/add', 'BudgetLineController', 'create', 'CostControl');
$this->route->addRoute('/project/:project_id/budget/breakdown', 'BudgetController', 'breakdown', 'CostControl');
$this->route->addRoute('/user/:user_id/rate', 'HourlyRateController', 'show', 'CostControl');
$this->route->addRoute('/user/:user_id/rate/add', 'HourlyRateController', 'create', 'CostControl');
$this->route->addRoute('/user/:user_id/rate/delete/:rate_id', 'HourlyRateController', 'confirm', 'CostControl');
$this->route->addRoute('/settings/currencies/rates', 'CurrencyController', 'show');
$this->route->addRoute('/cost-control/currencies/rates', 'CostController', 'showEveryone', 'CostControl');
$this->route->addRoute('/cost-control/currencies/rates/manual/add', 'CostController', 'create', 'CostControl');
$this->route->addRoute('/cost-control/currencies/base/change', 'CostController', 'change', 'CostControl');
$this->route->addRoute('/cost-control/currencies/:currency/:comment', 'CostController', 'editComment', 'CostControl');
// Helper
// - Example: $this->helper->register('helperClassNameCamelCase', '\Kanboard\Plugin\PluginNameExampleStudlyCaps\Helper\HelperNameExampleStudlyCaps');
// - Add each Helper in the 'use' section at the top of this file
$this->helper->register('costControlLayoutHelper', '\Kanboard\Plugin\CostControl\Helper\CostControlLayoutHelper');
$this->applicationAccessMap->add('HourlyRateController', '*', Role::APP_ADMIN);
$this->projectAccessMap->add('BudgetController', '*', Role::PROJECT_MANAGER);
// Replace Model
$this->container['currencyModel'] = $this->container->factory(function ($c) {
return new ExtendedCurrencyModel($c);
});
// CHECK FOR LIVE RATES ONE MIN AFTER NEXT SCHEDULED UPDATE FROM THE JSON
if (time() - $this->configModel->get('cost_control_next_update', time() - 61) > 60) {
// SAVE DATE WHEN CHECKED
$this->configModel->save(['cost_control_last_checked_live_rates' => time()]);
// CHECK JSON API
$this->currencyModel->getLiveRates();
}
}
public function onStartup()
{
Translator::load($this->languageModel->getCurrentLanguage(), __DIR__ . '/Locale');
}
public function getClasses()
{
return array(
'Plugin\CostControl\Model' => array(
'HourlyRate',
'Budget',
)
);
}
public function getPluginName()
{
// Plugin Name MUST be identical to namespace for Plugin Directory to detect updated versions
// Do not translate the plugin name here
return 'CostControl';
}
public function getPluginDescription()
{
return t('Use the new Cost Control section to enable currencies and budgeting in Kanboard. Get live currency rates automatically for over 120 currencies allowing users to compare with manually saved rates. This plugin replaces and extends the features from the original Budget plugin enabling projects to have an associated cost element.');
}
public function getPluginAuthor()
{
return 'aljawaid';
}
public function getPluginVersion()
{
return '1.2.0';
}
public function getCompatibleVersion()
{
// Examples: '>=1.0.37' '<1.0.37' '<=1.0.37'
// Tested on KB v1.2.20 upto plugin v1.1.0, then KB v1.2.32+
return '>=1.2.20';
}
public function getPluginHomepage()
{
return 'https://github.com/aljawaid/CostControl';
}
}