|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
namespace app\traits; |
|
4
|
|
|
|
|
5
|
|
|
use Yii; |
|
6
|
|
|
use yii\helpers\ArrayHelper; |
|
7
|
|
|
use app\helpers\BaseHelper; |
|
8
|
|
|
use Itstructure\AdminModule\models\Language; |
|
9
|
|
|
use Itstructure\AdminModule\components\AdminView; |
|
10
|
|
|
|
|
11
|
|
|
/** |
|
12
|
|
|
* Class AdminBeforeActionTrait |
|
13
|
|
|
* |
|
14
|
|
|
* @property AdminView $view |
|
15
|
|
|
* @property string $shortLanguage |
|
16
|
|
|
* @property Language[] $languages |
|
17
|
|
|
* |
|
18
|
|
|
* @package app\traits |
|
19
|
|
|
*/ |
|
20
|
|
|
trait AdminBeforeActionTrait |
|
21
|
|
|
{ |
|
22
|
|
|
/** |
|
23
|
|
|
* @var array |
|
24
|
|
|
*/ |
|
25
|
|
|
private $neighborControllers = [ |
|
26
|
|
|
'profiles' => 'roles', |
|
27
|
|
|
'roles' => 'permissions', |
|
28
|
|
|
]; |
|
29
|
|
|
|
|
30
|
|
|
/** |
|
31
|
|
|
* @param \yii\base\Action $action |
|
32
|
|
|
* |
|
33
|
|
|
* @return bool |
|
34
|
|
|
*/ |
|
35
|
|
|
public function beforeAction($action) |
|
36
|
|
|
{ |
|
37
|
|
|
$this->view->mainMenuConfig = require __DIR__ . '/../config/admin/main-menu.php'; |
|
38
|
|
|
|
|
39
|
|
|
$this->view->homeUrl = '/' . $this->shortLanguage . '/admin'; |
|
40
|
|
|
|
|
41
|
|
|
$this->view->signOutLink = '/' . $this->shortLanguage . '/logout'; |
|
42
|
|
|
|
|
43
|
|
|
$this->view->profileLink = '/' . $this->shortLanguage . '/admin/users/view?id='.Yii::$app->getUser()->id; |
|
44
|
|
|
|
|
45
|
|
|
Yii::$app->getUser()->loginUrl = '/' . $this->shortLanguage . '/login'; |
|
46
|
|
|
|
|
47
|
|
|
$this->urlPrefix = '/' . $this->shortLanguage . '/' . $this->module->id . '/' . $action->controller->id . '/'; |
|
|
|
|
|
|
48
|
|
|
|
|
49
|
|
|
if (array_key_exists($action->controller->id, $this->neighborControllers)) { |
|
50
|
|
|
$this->urlPrefixNeighbor = '/' . $this->shortLanguage . '/' . $this->module->id . '/' . |
|
|
|
|
|
|
51
|
|
|
$this->neighborControllers[$action->controller->id] . '/'; |
|
52
|
|
|
} |
|
53
|
|
|
|
|
54
|
|
|
$this->view->userBody = ArrayHelper::map($this->languages, 'name', function ($item) { |
|
55
|
|
|
/* @var Language $item */ |
|
56
|
|
|
return BaseHelper::getSwitchLanguageLink($item->getShortName(), Yii::$app->request); |
|
|
|
|
|
|
57
|
|
|
}); |
|
58
|
|
|
|
|
59
|
|
|
return parent::beforeAction($action); |
|
60
|
|
|
} |
|
61
|
|
|
} |