d1f8bd40
Alexey Boroda
first commit
|
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
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
|
<?php
namespace backend\modules\menu\controllers;
use Yii;
use yii\helpers\{
ArrayHelper, Url
};
//
use thread\actions\{
EditableAttributeSave, EditableAttributeSaveLang
};
use thread\app\base\controllers\BackendController;
//
use backend\modules\menu\models\{
MenuItem, MenuItemLang, Menu, search\MenuItem as filterMenuItemModel
};
/**
* Class ItemController
*
* @package backend\modules\menu\controllers
* @author FilamentV <vortex.filament@gmail.com>
* @copyright (c), Thread
*/
class ItemController extends BackendController
{
public $model = MenuItem::class;
public $modelLang = MenuItemLang::class;
public $filterModel = filterMenuItemModel::class;
public $group = null;
public $parent = null;
public $title = 'Items';
public $name = 'item';
/**
* Actions
*
* @return array
*/
public function actions()
{
$link = function () {
return Url::to(
[
'list',
'group_id' => ($this->group !== null) ? $this->group->id : 0,
'parent_id' => ($this->parent !== null) ? $this->parent->id : 0
]
);
};
return ArrayHelper::merge(
parent::actions(),
[
'list' => [
'layout' => 'list-item',
],
'trash' => [
'layout' => 'list-item-trash',
],
'delete' => [
'redirect' => function () {
return [
'trash',
'group_id' => $this->group->id
];
}
],
'create' => [
'layout' => 'create',
'redirect' => function () {
return ($_POST['save_and_exit']) ? $this->actionListLinkStatus : [
'update',
'id' => $this->action->getModel()->id,
'group_id' => $this->group->id
];
}
],
'update' => [
'layout' => 'update',
'redirect' => function () {
return ($_POST['save_and_exit']) ? $this->actionListLinkStatus : [
'update',
'id' => $this->action->getModel()->id,
'group_id' => $this->group->id
];
}
],
'published' => [
'redirect' => $link
],
'intrash' => [
'redirect' => $link
],
'outtrash' => [
'redirect' => $link
],
'attribute-save' => [
'class' => EditableAttributeSaveLang::class,
'modelClass' => $this->modelLang,
'attribute' => 'title',
],
'attribute-save-position' => [
'class' => EditableAttributeSave::class,
'modelClass' => $this->model,
'attribute' => 'position',
'returnValue' => function ($model) {
return $model['position']??0;
}
]
]
);
}
/**
* Before actions
*
* @param $action
* @return bool
* @throws \yii\web\NotFoundHttpException
*/
public function beforeAction($action)
{
$groupId = Yii::$app->request->get('group_id', null);
$parentId = Yii::$app->request->get('parent_id', null);
if (in_array($action->id, ['list', 'create', 'update', 'trash'])) {
if ($groupId === null) {
throw new \yii\web\NotFoundHttpException;
}
}
if ($groupId !== null) {
$this->group = Menu::getById($groupId);
}
if ($parentId !== null) {
$this->parent = MenuItem::getById($parentId);
}
return parent::beforeAction($action);
}
}
|