Commit 10eacd2dbd0cb3d41e10a08df6ad6e588f5723a5
1 parent
2acc1d15
- add partners
Showing
3 changed files
with
200 additions
and
0 deletions
Show diff stats
1 | +<?php | ||
2 | + /** | ||
3 | + * Created by PhpStorm. | ||
4 | + * User: stes | ||
5 | + * Date: 09.07.18 | ||
6 | + * Time: 14:36 | ||
7 | + */ | ||
8 | + | ||
9 | + namespace backend\controllers; | ||
10 | + | ||
11 | + use artbox\core\admin\actions\Create; | ||
12 | + use artbox\core\admin\actions\Delete; | ||
13 | + use artbox\core\admin\actions\Index; | ||
14 | + use artbox\core\admin\actions\Update; | ||
15 | + use artbox\core\admin\widgets\Form; | ||
16 | + use common\models\Partner; | ||
17 | + use yii\filters\AccessControl; | ||
18 | + use yii\filters\VerbFilter; | ||
19 | + use yii\web\Controller; | ||
20 | + use yii\web\NotFoundHttpException; | ||
21 | + use yii\web\View; | ||
22 | + | ||
23 | + class PartnerController extends Controller | ||
24 | + { | ||
25 | + public function behaviors() | ||
26 | + { | ||
27 | + return [ | ||
28 | + 'verbs' => [ | ||
29 | + 'class' => VerbFilter::className(), | ||
30 | + 'actions' => [ | ||
31 | + 'delete' => [ 'POST' ], | ||
32 | + ], | ||
33 | + ], | ||
34 | + 'access' => [ | ||
35 | + 'class' => AccessControl::className(), | ||
36 | + 'rules' => [ | ||
37 | + [ | ||
38 | + 'allow' => true, | ||
39 | + 'roles' => [ '@' ], | ||
40 | + ], | ||
41 | + ], | ||
42 | + ], | ||
43 | + ]; | ||
44 | + } | ||
45 | + public function actions() | ||
46 | + { | ||
47 | + return [ | ||
48 | + 'index' => [ | ||
49 | + 'class' => Index::className(), | ||
50 | + 'columns' => [ | ||
51 | + 'link' => [ | ||
52 | + 'type' => Index::ACTION_COL, | ||
53 | + ], | ||
54 | + 'sort' => [ | ||
55 | + 'type' => Index::POSITION_COL, | ||
56 | + ], | ||
57 | + 'status' => [ | ||
58 | + 'type' => Index::STATUS_COL, | ||
59 | + ], | ||
60 | + ], | ||
61 | + 'model' => Partner::className(), | ||
62 | + 'hasLanguage' => false, | ||
63 | + 'enableMassDelete' => true, | ||
64 | + 'modelPrimaryKey' => 'id', | ||
65 | + ], | ||
66 | + 'create' => array_merge([ 'class' => Create::className() ], self::fieldsConfig()), | ||
67 | + 'update' => array_merge([ 'class' => Update::className() ], self::fieldsConfig()), | ||
68 | + 'view' => [ | ||
69 | + 'class' => View::className(), | ||
70 | + 'model' => Partner::className(), | ||
71 | + 'hasAlias' => false, | ||
72 | + 'fields' => [ | ||
73 | + [ | ||
74 | + 'name' => 'image_id', | ||
75 | + 'type' => Form::IMAGE, | ||
76 | + ], | ||
77 | + [ | ||
78 | + 'name' => 'link', | ||
79 | + 'type' => Form::STRING, | ||
80 | + ], | ||
81 | + ], | ||
82 | + ], | ||
83 | + 'delete' => [ | ||
84 | + 'class' => Delete::className(), | ||
85 | + ], | ||
86 | + ]; | ||
87 | + } | ||
88 | + public function findModel($id) | ||
89 | + { | ||
90 | + $model = Partner::find() | ||
91 | + ->where([ 'id' => $id ]) | ||
92 | + ->one(); | ||
93 | + if ($model !== null) { | ||
94 | + return $model; | ||
95 | + } else { | ||
96 | + throw new NotFoundHttpException('The requested page does not exist.'); | ||
97 | + } | ||
98 | + } | ||
99 | + | ||
100 | + public function newModel() | ||
101 | + { | ||
102 | + return new Partner(); | ||
103 | + } | ||
104 | + | ||
105 | + public function deleteModel($id) | ||
106 | + { | ||
107 | + $page = Partner::find() | ||
108 | + ->where( | ||
109 | + [ | ||
110 | + 'id' => $id, | ||
111 | + ] | ||
112 | + ) | ||
113 | + ->one(); | ||
114 | + return $page->delete(); | ||
115 | + } | ||
116 | + | ||
117 | + protected static function fieldsConfig() | ||
118 | + { | ||
119 | + return [ | ||
120 | + 'model' => Partner::className(), | ||
121 | + 'hasAlias' => false, | ||
122 | + 'fields' => [ | ||
123 | + | ||
124 | + [ | ||
125 | + 'name' => 'image_id', | ||
126 | + 'type' => Form::IMAGE, | ||
127 | + ], | ||
128 | + [ | ||
129 | + 'name' => 'link', | ||
130 | + 'type' => Form::STRING, | ||
131 | + ], | ||
132 | + [ | ||
133 | + 'name' => 'status', | ||
134 | + 'type' => Form::BOOL, | ||
135 | + ], | ||
136 | + [ | ||
137 | + 'name' => 'sort', | ||
138 | + 'type' => Form::NUMBER, | ||
139 | + ], | ||
140 | + ], | ||
141 | + ]; | ||
142 | + } | ||
143 | + } | ||
0 | \ No newline at end of file | 144 | \ No newline at end of file |
backend/views/layouts/menu_items.php
1 | +<?php | ||
2 | + | ||
3 | +namespace common\models; | ||
4 | + | ||
5 | +use Yii; | ||
6 | + | ||
7 | +/** | ||
8 | + * This is the model class for table "partner". | ||
9 | + * | ||
10 | + * @property int $id | ||
11 | + * @property int $image_id | ||
12 | + * @property bool $status | ||
13 | + * @property int $sort | ||
14 | + * @property string $link | ||
15 | + */ | ||
16 | +class Partner extends \yii\db\ActiveRecord | ||
17 | +{ | ||
18 | + /** | ||
19 | + * {@inheritdoc} | ||
20 | + */ | ||
21 | + public static function tableName() | ||
22 | + { | ||
23 | + return 'partner'; | ||
24 | + } | ||
25 | + | ||
26 | + /** | ||
27 | + * {@inheritdoc} | ||
28 | + */ | ||
29 | + public function rules() | ||
30 | + { | ||
31 | + return [ | ||
32 | + [['image_id', 'sort'], 'default', 'value' => null], | ||
33 | + [['image_id', 'sort'], 'integer'], | ||
34 | + [['status'], 'boolean'], | ||
35 | + [['link'], 'string', 'max' => 255], | ||
36 | + ]; | ||
37 | + } | ||
38 | + | ||
39 | + /** | ||
40 | + * {@inheritdoc} | ||
41 | + */ | ||
42 | + public function attributeLabels() | ||
43 | + { | ||
44 | + return [ | ||
45 | + 'id' => Yii::t('app', 'ID'), | ||
46 | + 'image_id' => Yii::t('app', 'Image ID'), | ||
47 | + 'status' => Yii::t('app', 'Status'), | ||
48 | + 'sort' => Yii::t('app', 'Sort'), | ||
49 | + 'link' => Yii::t('app', 'Link'), | ||
50 | + ]; | ||
51 | + } | ||
52 | +} |