-
Notifications
You must be signed in to change notification settings - Fork 1
/
Module.php
130 lines (114 loc) · 3.97 KB
/
Module.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
<?php
namespace marqu3s\itam;
use Yii;
use yii\base\Module as YiiBaseModule;
use yii\helpers\Html;
/**
* ITAM module definition class
*/
class Module extends YiiBaseModule
{
/**
* @inheritdoc
*/
public $controllerNamespace = 'marqu3s\itam\controllers';
/**
* @inheritdoc
*/
public $defaultRoute = 'dashboard/index';
/**
* @inheritdoc
*/
public $layout = 'main';
/**
* Set to true to use the RBAC Authorization from Yii 2.
* This requires the creation of users and the configuration of access rights.
* @link http://www.yiiframework.com/doc-2.0/guide-security-authorization.html
*
* If set to false, (NOT RECOMMENDED) no authorization will be performed and everybody will have permission to use the module.
* Use at your own risk!
*
* @var bool
*/
public $rbacAuthorization = true; // true is the default and recommended for security reasons!
/**
* The prefix used to create and query the permissions.
* @var string
*/
public $rbacItemPrefix = 'itam';
/**
* The path to the nmap executable
* @var string
*/
public $nmapPath = '/usr/bin/';
/**
* @var array The default configuration for the action column of the GridViews.
*/
public static $defaultGridActionColumn = [];
/**
* @inheritdoc
*/
public function init()
{
parent::init();
$this->registerTranslations();
self::$defaultGridActionColumn = [
'class' => 'yii\grid\ActionColumn',
'template' => '{view} {duplicate} {update} {delete}',
'header' => Module::t('app', 'Actions'),
'headerOptions' => [
'style' => 'width: 100px'
],
'contentOptions' => [
'class' => 'text-center'
],
'buttons' => [
'view' => function ($url, $model, $key) {
return Html::a('<i class="fa fa-eye"></i>', $url, ['title' => Module::t('app', 'View'), 'data-pjax' => 0]);
},
'duplicate' => function ($url, $model, $key) {
return Html::a('<i class="fa fa-copy"></i>', $url, ['title' => Module::t('app', 'Duplicate'), 'data-pjax' => 0]);
},
'update' => function ($url, $model, $key) {
return Html::a('<i class="fa fa-pencil"></i>', $url, ['title' => Module::t('app', 'Update'), 'data-pjax' => 0]);
},
'delete' => function ($url, $model, $key) {
if (!Yii::$app->getModule('itam')->rbacAuthorization || Yii::$app->user->can(Yii::$app->getModule('itam')->rbacItemPrefix . 'AssetManager')) {
return Html::a('<i class="fa fa-trash"></i>', $url, ['title' => Module::t('app', 'Delete'), 'data' => ['pjax' => 0, 'method' => 'post', 'confirm' => Module::t('app', 'Are you sure you want to delete this item?')]]);
} else return '';
},
]
];
}
/**
* Registers translation files
*/
public function registerTranslations()
{
Yii::$app->i18n->translations['modules/itam/*'] = [
'class' => 'yii\i18n\PhpMessageSource',
'sourceLanguage' => 'en-US',
'basePath' => __DIR__ . '/messages',
'fileMap' => [
'modules/itam/alert' => 'alert.php',
'modules/itam/app' => 'app.php',
'modules/itam/menu' => 'menu.php',
'modules/itam/model' => 'model.php',
],
];
}
/**
* Executes the translations.
*
* @param string $category
* @param string $message
* @param array $params
* @param string|null $language
*
* @return string
*/
public static function t($category, $message, $params = [], $language = null)
{
return Yii::t('modules/itam/' . $category, $message, $params, $language);
}
}