Commit c882dc756ae56b48eb9139ddbe079a6db3229ffc
0 parents
first commit
Showing
19 changed files
with
2018 additions
and
0 deletions
Show diff stats
1 | +++ a/composer.json | ||
1 | +{ | ||
2 | + "name": "artweb/artbox-seo", | ||
3 | + "description": "Yii2 light-weight CMS", | ||
4 | + "license": "BSD-3-Clause", | ||
5 | + "require": { | ||
6 | + "php": ">=7.0", | ||
7 | + "yiisoft/yii2": "*", | ||
8 | + "developeruz/yii2-db-rbac": "*" | ||
9 | + }, | ||
10 | + "autoload": { | ||
11 | + "psr-4": { | ||
12 | + "artweb\\artbox\\seo\\": "" | ||
13 | + } | ||
14 | + } | ||
15 | +} | ||
0 | \ No newline at end of file | 16 | \ No newline at end of file |
1 | +++ a/controllers/BannerController.php | ||
1 | +<?php | ||
2 | + | ||
3 | + namespace backend\controllers; | ||
4 | + | ||
5 | + use Yii; | ||
6 | + use common\models\Banner; | ||
7 | + use common\models\BannerSearch; | ||
8 | + use yii\web\Controller; | ||
9 | + use yii\web\NotFoundHttpException; | ||
10 | + use yii\filters\VerbFilter; | ||
11 | + use developeruz\db_rbac\behaviors\AccessBehavior; | ||
12 | + | ||
13 | + /** | ||
14 | + * BannerController implements the CRUD actions for Banner model. | ||
15 | + */ | ||
16 | + class BannerController extends Controller | ||
17 | + { | ||
18 | + | ||
19 | + /** | ||
20 | + * @inheritdoc | ||
21 | + */ | ||
22 | + public function behaviors() | ||
23 | + { | ||
24 | + return [ | ||
25 | + 'access' => [ | ||
26 | + 'class' => AccessBehavior::className(), | ||
27 | + 'rules' => [ | ||
28 | + 'site' => [ | ||
29 | + [ | ||
30 | + 'actions' => [ | ||
31 | + 'login', | ||
32 | + 'error', | ||
33 | + ], | ||
34 | + 'allow' => true, | ||
35 | + ], | ||
36 | + ], | ||
37 | + ], | ||
38 | + ], | ||
39 | + 'verbs' => [ | ||
40 | + 'class' => VerbFilter::className(), | ||
41 | + 'actions' => [ | ||
42 | + 'delete' => [ 'POST' ], | ||
43 | + ], | ||
44 | + ], | ||
45 | + ]; | ||
46 | + } | ||
47 | + | ||
48 | + /** | ||
49 | + * Lists all Banner models. | ||
50 | + * @return mixed | ||
51 | + */ | ||
52 | + public function actionIndex() | ||
53 | + { | ||
54 | + $searchModel = new BannerSearch(); | ||
55 | + $dataProvider = $searchModel->search(Yii::$app->request->queryParams); | ||
56 | + | ||
57 | + return $this->render('index', [ | ||
58 | + 'searchModel' => $searchModel, | ||
59 | + 'dataProvider' => $dataProvider, | ||
60 | + ]); | ||
61 | + } | ||
62 | + | ||
63 | + /** | ||
64 | + * Displays a single Banner model. | ||
65 | + * | ||
66 | + * @param integer $id | ||
67 | + * | ||
68 | + * @return mixed | ||
69 | + */ | ||
70 | + public function actionView($id) | ||
71 | + { | ||
72 | + return $this->render('view', [ | ||
73 | + 'model' => $this->findModel($id), | ||
74 | + ]); | ||
75 | + } | ||
76 | + | ||
77 | + /** | ||
78 | + * Creates a new Banner model. | ||
79 | + * If creation is successful, the browser will be redirected to the 'view' page. | ||
80 | + * @return mixed | ||
81 | + */ | ||
82 | + public function actionCreate() | ||
83 | + { | ||
84 | + $model = new Banner(); | ||
85 | + $model->generateLangs(); | ||
86 | + | ||
87 | + if($model->load(Yii::$app->request->post())) { | ||
88 | + $model->loadLangs(\Yii::$app->request); | ||
89 | + if($model->save() && $model->transactionStatus) { | ||
90 | + return $this->redirect([ | ||
91 | + 'view', | ||
92 | + 'id' => $model->id, | ||
93 | + ]); | ||
94 | + } | ||
95 | + } | ||
96 | + return $this->render('create', [ | ||
97 | + 'model' => $model, | ||
98 | + 'modelLangs' => $model->modelLangs, | ||
99 | + ]); | ||
100 | + } | ||
101 | + | ||
102 | + /** | ||
103 | + * Updates an existing Banner model. | ||
104 | + * If update is successful, the browser will be redirected to the 'view' page. | ||
105 | + * | ||
106 | + * @param integer $id | ||
107 | + * | ||
108 | + * @return mixed | ||
109 | + */ | ||
110 | + public function actionUpdate($id) | ||
111 | + { | ||
112 | + $model = $this->findModel($id); | ||
113 | + $model->generateLangs(); | ||
114 | + if($model->load(Yii::$app->request->post())) { | ||
115 | + $model->loadLangs(\Yii::$app->request); | ||
116 | + if($model->save() && $model->transactionStatus) { | ||
117 | + return $this->redirect([ | ||
118 | + 'view', | ||
119 | + 'id' => $model->id, | ||
120 | + ]); | ||
121 | + } | ||
122 | + } | ||
123 | + return $this->render('update', [ | ||
124 | + 'model' => $model, | ||
125 | + 'modelLangs' => $model->modelLangs, | ||
126 | + ]); | ||
127 | + } | ||
128 | + | ||
129 | + /** | ||
130 | + * Deletes an existing Banner model. | ||
131 | + * If deletion is successful, the browser will be redirected to the 'index' page. | ||
132 | + * | ||
133 | + * @param integer $id | ||
134 | + * | ||
135 | + * @return mixed | ||
136 | + */ | ||
137 | + public function actionDelete($id) | ||
138 | + { | ||
139 | + $this->findModel($id) | ||
140 | + ->delete(); | ||
141 | + | ||
142 | + return $this->redirect([ 'index' ]); | ||
143 | + } | ||
144 | + | ||
145 | + /** | ||
146 | + * Finds the Banner model based on its primary key value. | ||
147 | + * If the model is not found, a 404 HTTP exception will be thrown. | ||
148 | + * | ||
149 | + * @param integer $id | ||
150 | + * | ||
151 | + * @return Banner the loaded model | ||
152 | + * @throws NotFoundHttpException if the model cannot be found | ||
153 | + */ | ||
154 | + protected function findModel($id) | ||
155 | + { | ||
156 | + if(( $model = Banner::findOne($id) ) !== NULL) { | ||
157 | + return $model; | ||
158 | + } else { | ||
159 | + throw new NotFoundHttpException('The requested page does not exist.'); | ||
160 | + } | ||
161 | + } | ||
162 | + } |
1 | +++ a/controllers/BgController.php | ||
1 | +<?php | ||
2 | + | ||
3 | + namespace backend\controllers; | ||
4 | + | ||
5 | + use Yii; | ||
6 | + use common\models\Bg; | ||
7 | + use common\models\BgSearch; | ||
8 | + use yii\web\Controller; | ||
9 | + use yii\web\NotFoundHttpException; | ||
10 | + use yii\filters\VerbFilter; | ||
11 | + use developeruz\db_rbac\behaviors\AccessBehavior; | ||
12 | + | ||
13 | + /** | ||
14 | + * BgController implements the CRUD actions for Bg model. | ||
15 | + */ | ||
16 | + class BgController extends Controller | ||
17 | + { | ||
18 | + | ||
19 | + /** | ||
20 | + * @inheritdoc | ||
21 | + */ | ||
22 | + public function behaviors() | ||
23 | + { | ||
24 | + return [ | ||
25 | + 'access' => [ | ||
26 | + 'class' => AccessBehavior::className(), | ||
27 | + 'rules' => [ | ||
28 | + 'site' => [ | ||
29 | + [ | ||
30 | + 'actions' => [ | ||
31 | + 'login', | ||
32 | + 'error', | ||
33 | + ], | ||
34 | + 'allow' => true, | ||
35 | + ], | ||
36 | + ], | ||
37 | + ], | ||
38 | + ], | ||
39 | + 'verbs' => [ | ||
40 | + 'class' => VerbFilter::className(), | ||
41 | + 'actions' => [ | ||
42 | + 'delete' => [ 'POST' ], | ||
43 | + ], | ||
44 | + ], | ||
45 | + ]; | ||
46 | + } | ||
47 | + | ||
48 | + /** | ||
49 | + * Lists all Bg models. | ||
50 | + * @return mixed | ||
51 | + */ | ||
52 | + public function actionIndex() | ||
53 | + { | ||
54 | + $searchModel = new BgSearch(); | ||
55 | + $dataProvider = $searchModel->search(Yii::$app->request->queryParams); | ||
56 | + | ||
57 | + return $this->render('index', [ | ||
58 | + 'searchModel' => $searchModel, | ||
59 | + 'dataProvider' => $dataProvider, | ||
60 | + ]); | ||
61 | + } | ||
62 | + | ||
63 | + /** | ||
64 | + * Displays a single Bg model. | ||
65 | + * | ||
66 | + * @param integer $id | ||
67 | + * | ||
68 | + * @return mixed | ||
69 | + */ | ||
70 | + public function actionView($id) | ||
71 | + { | ||
72 | + return $this->render('view', [ | ||
73 | + 'model' => $this->findModel($id), | ||
74 | + ]); | ||
75 | + } | ||
76 | + | ||
77 | + /** | ||
78 | + * Creates a new Bg model. | ||
79 | + * If creation is successful, the browser will be redirected to the 'view' page. | ||
80 | + * @return mixed | ||
81 | + */ | ||
82 | + public function actionCreate() | ||
83 | + { | ||
84 | + $model = new Bg(); | ||
85 | + $model->generateLangs(); | ||
86 | + | ||
87 | + if($model->load(Yii::$app->request->post())) { | ||
88 | + $model->loadLangs(\Yii::$app->request); | ||
89 | + if($model->save() && $model->transactionStatus) { | ||
90 | + return $this->redirect([ | ||
91 | + 'view', | ||
92 | + 'id' => $model->id, | ||
93 | + ]); | ||
94 | + } | ||
95 | + } | ||
96 | + return $this->render('create', [ | ||
97 | + 'model' => $model, | ||
98 | + 'modelLangs' => $model->modelLangs, | ||
99 | + ]); | ||
100 | + } | ||
101 | + | ||
102 | + /** | ||
103 | + * Updates an existing Bg model. | ||
104 | + * If update is successful, the browser will be redirected to the 'view' page. | ||
105 | + * | ||
106 | + * @param integer $id | ||
107 | + * | ||
108 | + * @return mixed | ||
109 | + */ | ||
110 | + public function actionUpdate($id) | ||
111 | + { | ||
112 | + $model = $this->findModel($id); | ||
113 | + $model->generateLangs(); | ||
114 | + | ||
115 | + if($model->load(Yii::$app->request->post())) { | ||
116 | + $model->loadLangs(\Yii::$app->request); | ||
117 | + if($model->save() && $model->transactionStatus) { | ||
118 | + return $this->redirect([ | ||
119 | + 'view', | ||
120 | + 'id' => $model->id, | ||
121 | + ]); | ||
122 | + } | ||
123 | + } | ||
124 | + return $this->render('update', [ | ||
125 | + 'model' => $model, | ||
126 | + 'modelLangs' => $model->modelLangs, | ||
127 | + ]); | ||
128 | + } | ||
129 | + | ||
130 | + /** | ||
131 | + * Deletes an existing Bg model. | ||
132 | + * If deletion is successful, the browser will be redirected to the 'index' page. | ||
133 | + * | ||
134 | + * @param integer $id | ||
135 | + * | ||
136 | + * @return mixed | ||
137 | + */ | ||
138 | + public function actionDelete($id) | ||
139 | + { | ||
140 | + $this->findModel($id) | ||
141 | + ->delete(); | ||
142 | + | ||
143 | + return $this->redirect([ 'index' ]); | ||
144 | + } | ||
145 | + | ||
146 | + /** | ||
147 | + * Finds the Bg model based on its primary key value. | ||
148 | + * If the model is not found, a 404 HTTP exception will be thrown. | ||
149 | + * | ||
150 | + * @param integer $id | ||
151 | + * | ||
152 | + * @return Bg the loaded model | ||
153 | + * @throws NotFoundHttpException if the model cannot be found | ||
154 | + */ | ||
155 | + protected function findModel($id) | ||
156 | + { | ||
157 | + if(( $model = Bg::find() | ||
158 | + ->where([ 'id' => $id ]) | ||
159 | + ->with('lang') | ||
160 | + ->one() ) !== NULL | ||
161 | + ) { | ||
162 | + return $model; | ||
163 | + } else { | ||
164 | + throw new NotFoundHttpException('The requested page does not exist.'); | ||
165 | + } | ||
166 | + } | ||
167 | + } |
1 | +++ a/controllers/SliderController.php | ||
1 | +<?php | ||
2 | + | ||
3 | + namespace backend\controllers; | ||
4 | + | ||
5 | + use Yii; | ||
6 | + use common\models\Slider; | ||
7 | + use common\models\SliderSearch; | ||
8 | + use yii\db\ActiveQuery; | ||
9 | + use yii\web\Controller; | ||
10 | + use yii\web\NotFoundHttpException; | ||
11 | + use yii\filters\VerbFilter; | ||
12 | + use developeruz\db_rbac\behaviors\AccessBehavior; | ||
13 | + | ||
14 | + /** | ||
15 | + * SliderController implements the CRUD actions for Slider model. | ||
16 | + */ | ||
17 | + class SliderController extends Controller | ||
18 | + { | ||
19 | + /** | ||
20 | + * @inheritdoc | ||
21 | + */ | ||
22 | + public function behaviors() | ||
23 | + { | ||
24 | + return [ | ||
25 | + 'access' => [ | ||
26 | + 'class' => AccessBehavior::className(), | ||
27 | + 'rules' => [ | ||
28 | + 'site' => [ | ||
29 | + [ | ||
30 | + 'actions' => [ | ||
31 | + 'login', | ||
32 | + 'error', | ||
33 | + ], | ||
34 | + 'allow' => true, | ||
35 | + ], | ||
36 | + ], | ||
37 | + ], | ||
38 | + ], | ||
39 | + 'verbs' => [ | ||
40 | + 'class' => VerbFilter::className(), | ||
41 | + 'actions' => [ | ||
42 | + 'delete' => [ 'POST' ], | ||
43 | + ], | ||
44 | + ], | ||
45 | + ]; | ||
46 | + } | ||
47 | + | ||
48 | + /** | ||
49 | + * Lists all Slider models. | ||
50 | + * | ||
51 | + * @return mixed | ||
52 | + */ | ||
53 | + public function actionIndex() | ||
54 | + { | ||
55 | + $searchModel = new SliderSearch(); | ||
56 | + $dataProvider = $searchModel->search(Yii::$app->request->queryParams); | ||
57 | + /** | ||
58 | + * @var ActiveQuery $query | ||
59 | + */ | ||
60 | + $query = $dataProvider->query; | ||
61 | + $query->with('sliderImages'); | ||
62 | + | ||
63 | + return $this->render( | ||
64 | + 'index', | ||
65 | + [ | ||
66 | + 'searchModel' => $searchModel, | ||
67 | + 'dataProvider' => $dataProvider, | ||
68 | + ] | ||
69 | + ); | ||
70 | + } | ||
71 | + | ||
72 | + /** | ||
73 | + * Creates a new Slider model. | ||
74 | + * If creation is successful, the browser will be redirected to the 'view' page. | ||
75 | + * | ||
76 | + * @return mixed | ||
77 | + */ | ||
78 | + public function actionCreate() | ||
79 | + { | ||
80 | + $model = new Slider(); | ||
81 | + | ||
82 | + if ($model->load(Yii::$app->request->post()) && $model->save()) { | ||
83 | + return $this->redirect( | ||
84 | + [ | ||
85 | + 'index', | ||
86 | + ] | ||
87 | + ); | ||
88 | + } else { | ||
89 | + | ||
90 | + return $this->render( | ||
91 | + 'create', | ||
92 | + [ | ||
93 | + 'model' => $model, | ||
94 | + ] | ||
95 | + ); | ||
96 | + } | ||
97 | + } | ||
98 | + | ||
99 | + /** | ||
100 | + * Updates an existing Slider model. | ||
101 | + * If update is successful, the browser will be redirected to the 'view' page. | ||
102 | + * | ||
103 | + * @param integer $id | ||
104 | + * | ||
105 | + * @return mixed | ||
106 | + */ | ||
107 | + public function actionUpdate($id) | ||
108 | + { | ||
109 | + $model = $this->findModel($id); | ||
110 | + | ||
111 | + if ($model->load(Yii::$app->request->post()) && $model->save()) { | ||
112 | + return $this->redirect( | ||
113 | + [ | ||
114 | + 'index', | ||
115 | + ] | ||
116 | + ); | ||
117 | + } else { | ||
118 | + return $this->render( | ||
119 | + 'update', | ||
120 | + [ | ||
121 | + 'model' => $model, | ||
122 | + ] | ||
123 | + ); | ||
124 | + } | ||
125 | + } | ||
126 | + | ||
127 | + /** | ||
128 | + * Deletes an existing Slider model. | ||
129 | + * If deletion is successful, the browser will be redirected to the 'index' page. | ||
130 | + * | ||
131 | + * @param integer $id | ||
132 | + * | ||
133 | + * @return mixed | ||
134 | + */ | ||
135 | + public function actionDelete($id) | ||
136 | + { | ||
137 | + $this->findModel($id) | ||
138 | + ->delete(); | ||
139 | + | ||
140 | + return $this->redirect([ 'index' ]); | ||
141 | + } | ||
142 | + | ||
143 | + /** | ||
144 | + * Finds the Slider model based on its primary key value. | ||
145 | + * If the model is not found, a 404 HTTP exception will be thrown. | ||
146 | + * | ||
147 | + * @param integer $id | ||
148 | + * | ||
149 | + * @return Slider the loaded model | ||
150 | + * @throws NotFoundHttpException if the model cannot be found | ||
151 | + */ | ||
152 | + protected function findModel($id) | ||
153 | + { | ||
154 | + if (( $model = Slider::findOne($id) ) !== null) { | ||
155 | + return $model; | ||
156 | + } else { | ||
157 | + throw new NotFoundHttpException('The requested page does not exist.'); | ||
158 | + } | ||
159 | + } | ||
160 | + } |
1 | +++ a/controllers/SliderImageController.php | ||
1 | +<?php | ||
2 | + | ||
3 | + namespace backend\controllers; | ||
4 | + | ||
5 | + use developeruz\db_rbac\behaviors\AccessBehavior; | ||
6 | + use common\models\Slider; | ||
7 | + use Yii; | ||
8 | + use common\models\SliderImage; | ||
9 | + use common\models\SliderImageSearch; | ||
10 | + use yii\web\Controller; | ||
11 | + use yii\web\NotFoundHttpException; | ||
12 | + use yii\filters\VerbFilter; | ||
13 | + | ||
14 | + /** | ||
15 | + * SliderImageController implements the CRUD actions for SliderImage model. | ||
16 | + */ | ||
17 | + class SliderImageController extends Controller | ||
18 | + { | ||
19 | + | ||
20 | + /** | ||
21 | + * @inheritdoc | ||
22 | + */ | ||
23 | + public function behaviors() | ||
24 | + { | ||
25 | + return [ | ||
26 | + 'access' => [ | ||
27 | + 'class' => AccessBehavior::className(), | ||
28 | + 'rules' => [ | ||
29 | + 'site' => [ | ||
30 | + [ | ||
31 | + 'actions' => [ | ||
32 | + 'login', | ||
33 | + 'error', | ||
34 | + ], | ||
35 | + 'allow' => true, | ||
36 | + ], | ||
37 | + ], | ||
38 | + ], | ||
39 | + ], | ||
40 | + 'verbs' => [ | ||
41 | + 'class' => VerbFilter::className(), | ||
42 | + 'actions' => [ | ||
43 | + 'delete' => [ 'POST' ], | ||
44 | + ], | ||
45 | + ], | ||
46 | + ]; | ||
47 | + } | ||
48 | + | ||
49 | + /** | ||
50 | + * Lists all SliderImage models. | ||
51 | + * | ||
52 | + * @param $slider_id Slider id | ||
53 | + * | ||
54 | + * @return mixed | ||
55 | + */ | ||
56 | + public function actionIndex($slider_id) | ||
57 | + { | ||
58 | + $searchModel = new SliderImageSearch(); | ||
59 | + $dataProvider = $searchModel->search($slider_id, Yii::$app->request->queryParams); | ||
60 | + | ||
61 | + return $this->render( | ||
62 | + 'index', | ||
63 | + [ | ||
64 | + 'slider_id' => $slider_id, | ||
65 | + 'searchModel' => $searchModel, | ||
66 | + 'dataProvider' => $dataProvider, | ||
67 | + ] | ||
68 | + ); | ||
69 | + } | ||
70 | + | ||
71 | + /** | ||
72 | + * Displays a single SliderImage model. | ||
73 | + * | ||
74 | + * @param integer $id | ||
75 | + * @param $slider_id Slider id | ||
76 | + * | ||
77 | + * @return mixed | ||
78 | + */ | ||
79 | + public function actionView($slider_id, $id) | ||
80 | + { | ||
81 | + return $this->render( | ||
82 | + 'view', | ||
83 | + [ | ||
84 | + 'slider_id' => $slider_id, | ||
85 | + 'model' => $this->findModel($slider_id, $id), | ||
86 | + ] | ||
87 | + ); | ||
88 | + } | ||
89 | + | ||
90 | + /** | ||
91 | + * Creates a new SliderImage model. | ||
92 | + * If creation is successful, the browser will be redirected to the 'view' page. | ||
93 | + * | ||
94 | + * @param $slider_id Slider id | ||
95 | + * | ||
96 | + * @return mixed | ||
97 | + */ | ||
98 | + public function actionCreate($slider_id) | ||
99 | + { | ||
100 | + $model = new SliderImage(); | ||
101 | + $model->generateLangs(); | ||
102 | + if ($model->load(Yii::$app->request->post())) { | ||
103 | + $model->loadLangs(\Yii::$app->request); | ||
104 | + $model->slider_id = $slider_id; | ||
105 | + if ($model->save() && $model->transactionStatus) { | ||
106 | + return $this->redirect( | ||
107 | + [ | ||
108 | + 'view', | ||
109 | + 'slider_id' => $slider_id, | ||
110 | + 'id' => $model->id, | ||
111 | + ] | ||
112 | + ); | ||
113 | + } | ||
114 | + } | ||
115 | + $slider = Slider::findOne($slider_id); | ||
116 | + return $this->render( | ||
117 | + 'create', | ||
118 | + [ | ||
119 | + 'slider_id' => $slider_id, | ||
120 | + 'model' => $model, | ||
121 | + 'modelLangs' => $model->modelLangs, | ||
122 | + 'slider' => $slider, | ||
123 | + ] | ||
124 | + ); | ||
125 | + } | ||
126 | + | ||
127 | + /** | ||
128 | + * Updates an existing SliderImage model. | ||
129 | + * If update is successful, the browser will be redirected to the 'view' page. | ||
130 | + * | ||
131 | + * @param $slider_id Slider id | ||
132 | + * @param integer $id | ||
133 | + * | ||
134 | + * @return mixed | ||
135 | + */ | ||
136 | + public function actionUpdate($slider_id, $id) | ||
137 | + { | ||
138 | + $model = $this->findModel($slider_id, $id); | ||
139 | + $model->generateLangs(); | ||
140 | + if ($model->load(Yii::$app->request->post())) { | ||
141 | + $model->loadLangs(\Yii::$app->request); | ||
142 | + if ($model->save() && $model->transactionStatus) { | ||
143 | + return $this->redirect( | ||
144 | + [ | ||
145 | + 'view', | ||
146 | + 'slider_id' => $slider_id, | ||
147 | + 'id' => $model->id, | ||
148 | + ] | ||
149 | + ); | ||
150 | + } | ||
151 | + } | ||
152 | + $slider = Slider::findOne($slider_id); | ||
153 | + return $this->render( | ||
154 | + 'update', | ||
155 | + [ | ||
156 | + 'model' => $model, | ||
157 | + 'modelLangs' => $model->modelLangs, | ||
158 | + 'slider_id' => $slider_id, | ||
159 | + 'slider' => $slider, | ||
160 | + ] | ||
161 | + ); | ||
162 | + } | ||
163 | + | ||
164 | + /** | ||
165 | + * Deletes an existing SliderImage model. | ||
166 | + * If deletion is successful, the browser will be redirected to the 'index' page. | ||
167 | + * | ||
168 | + * @param $slider_id Slider id | ||
169 | + * @param integer $id | ||
170 | + * | ||
171 | + * @return mixed | ||
172 | + */ | ||
173 | + public function actionDelete($slider_id, $id) | ||
174 | + { | ||
175 | + $this->findModel($slider_id, $id) | ||
176 | + ->delete(); | ||
177 | + | ||
178 | + return $this->redirect( | ||
179 | + [ | ||
180 | + 'index', | ||
181 | + 'slider_id' => $slider_id, | ||
182 | + ] | ||
183 | + ); | ||
184 | + } | ||
185 | + | ||
186 | + /** | ||
187 | + * Finds the SliderImage model based on its primary key value. | ||
188 | + * If the model is not found, a 404 HTTP exception will be thrown. | ||
189 | + * | ||
190 | + * @param $slider_id Slider id | ||
191 | + * @param integer $id | ||
192 | + * | ||
193 | + * @return SliderImage the loaded model | ||
194 | + * @throws NotFoundHttpException if the model cannot be found | ||
195 | + */ | ||
196 | + protected function findModel($slider_id, $id) | ||
197 | + { | ||
198 | + /** | ||
199 | + * @var SliderImage $model | ||
200 | + */ | ||
201 | + if (( $model = SliderImage::find() | ||
202 | + ->where( | ||
203 | + [ | ||
204 | + 'id' => $id, | ||
205 | + 'slider_id' => $slider_id, | ||
206 | + ] | ||
207 | + ) | ||
208 | + ->one() ) !== null | ||
209 | + ) { | ||
210 | + return $model; | ||
211 | + } else { | ||
212 | + throw new NotFoundHttpException('The requested page does not exist.'); | ||
213 | + } | ||
214 | + } | ||
215 | + } |
1 | +++ a/models/Banner.php | ||
1 | +<?php | ||
2 | + | ||
3 | + namespace common\models; | ||
4 | + | ||
5 | + use common\modules\language\behaviors\LanguageBehavior; | ||
6 | + use Yii; | ||
7 | + use yii\db\ActiveQuery; | ||
8 | + use yii\db\ActiveRecord; | ||
9 | + use yii\web\Request; | ||
10 | + | ||
11 | + /** | ||
12 | + * This is the model class for table "banner". | ||
13 | + * | ||
14 | + * @property integer $id | ||
15 | + * @property string $url | ||
16 | + * @property integer $status | ||
17 | + * * From language behavior * | ||
18 | + * @property BannerLang $lang | ||
19 | + * @property BannerLang[] $langs | ||
20 | + * @property BannerLang $objectLang | ||
21 | + * @property string $ownerKey | ||
22 | + * @property string $langKey | ||
23 | + * @property BannerLang[] $modelLangs | ||
24 | + * @property bool $transactionStatus | ||
25 | + * @method string getOwnerKey() | ||
26 | + * @method void setOwnerKey( string $value ) | ||
27 | + * @method string getLangKey() | ||
28 | + * @method void setLangKey( string $value ) | ||
29 | + * @method ActiveQuery getLangs() | ||
30 | + * @method ActiveQuery getLang( integer $language_id ) | ||
31 | + * @method BannerLang[] generateLangs() | ||
32 | + * @method void loadLangs( Request $request ) | ||
33 | + * @method bool linkLangs() | ||
34 | + * @method bool saveLangs() | ||
35 | + * @method bool getTransactionStatus() | ||
36 | + * * End language behavior * | ||
37 | + */ | ||
38 | + class Banner extends ActiveRecord | ||
39 | + { | ||
40 | + | ||
41 | + /** | ||
42 | + * @inheritdoc | ||
43 | + */ | ||
44 | + public static function tableName() | ||
45 | + { | ||
46 | + return 'banner'; | ||
47 | + } | ||
48 | + | ||
49 | + public function behaviors() | ||
50 | + { | ||
51 | + return [ | ||
52 | + 'language' => [ | ||
53 | + 'class' => LanguageBehavior::className(), | ||
54 | + ], | ||
55 | + ]; | ||
56 | + } | ||
57 | + | ||
58 | + /** | ||
59 | + * @inheritdoc | ||
60 | + */ | ||
61 | + public function rules() | ||
62 | + { | ||
63 | + return [ | ||
64 | + [ | ||
65 | + [ 'status' ], | ||
66 | + 'integer', | ||
67 | + ], | ||
68 | + [ | ||
69 | + [ 'url' ], | ||
70 | + 'string', | ||
71 | + 'max' => 255, | ||
72 | + ], | ||
73 | + ]; | ||
74 | + } | ||
75 | + | ||
76 | + /** | ||
77 | + * @inheritdoc | ||
78 | + */ | ||
79 | + public function attributeLabels() | ||
80 | + { | ||
81 | + return [ | ||
82 | + 'id' => Yii::t('app', 'id'), | ||
83 | + 'url' => Yii::t('app', 'url'), | ||
84 | + 'status' => Yii::t('app', 'status'), | ||
85 | + ]; | ||
86 | + } | ||
87 | + } |
1 | +++ a/models/BannerLang.php | ||
1 | +<?php | ||
2 | + | ||
3 | + namespace common\models; | ||
4 | + | ||
5 | + use common\behaviors\SaveImgBehavior; | ||
6 | + use common\modules\language\models\Language; | ||
7 | + use Yii; | ||
8 | + use yii\db\ActiveRecord; | ||
9 | + | ||
10 | + /** | ||
11 | + * This is the model class for table "banner_lang". | ||
12 | + * | ||
13 | + * @property integer $banner_id | ||
14 | + * @property integer $language_id | ||
15 | + * @property string $alt | ||
16 | + * @property string $title | ||
17 | + * @property string $image | ||
18 | + * @property Banner $banner | ||
19 | + * @property Language $language | ||
20 | + * * From SaveImgBehavior | ||
21 | + * @property string|null $imageFile | ||
22 | + * @property string|null $imageUrl | ||
23 | + * @method string|null getImageFile( int $field ) | ||
24 | + * @method string|null getImageUrl( int $field ) | ||
25 | + * * End SaveImgBehavior | ||
26 | + */ | ||
27 | + class BannerLang extends ActiveRecord | ||
28 | + { | ||
29 | + | ||
30 | + public static function primaryKey() | ||
31 | + { | ||
32 | + return [ | ||
33 | + 'banner_id', | ||
34 | + 'language_id', | ||
35 | + ]; | ||
36 | + } | ||
37 | + | ||
38 | + /** | ||
39 | + * @inheritdoc | ||
40 | + */ | ||
41 | + public static function tableName() | ||
42 | + { | ||
43 | + return 'banner_lang'; | ||
44 | + } | ||
45 | + | ||
46 | + public function behaviors() | ||
47 | + { | ||
48 | + return [ | ||
49 | + [ | ||
50 | + 'class' => SaveImgBehavior::className(), | ||
51 | + 'isLanguage' => true, | ||
52 | + 'fields' => [ | ||
53 | + [ | ||
54 | + 'name' => 'image', | ||
55 | + 'directory' => 'banner', | ||
56 | + ], | ||
57 | + ], | ||
58 | + ], | ||
59 | + ]; | ||
60 | + } | ||
61 | + | ||
62 | + /** | ||
63 | + * @inheritdoc | ||
64 | + */ | ||
65 | + public function rules() | ||
66 | + { | ||
67 | + return [ | ||
68 | + [ | ||
69 | + [ | ||
70 | + 'alt', | ||
71 | + 'title', | ||
72 | + 'image', | ||
73 | + ], | ||
74 | + 'string', | ||
75 | + 'max' => 255, | ||
76 | + ], | ||
77 | + [ | ||
78 | + [ | ||
79 | + 'banner_id', | ||
80 | + 'language_id', | ||
81 | + ], | ||
82 | + 'unique', | ||
83 | + 'targetAttribute' => [ | ||
84 | + 'banner_id', | ||
85 | + 'language_id', | ||
86 | + ], | ||
87 | + 'message' => 'The combination of Banner ID and Language ID has already been taken.', | ||
88 | + ], | ||
89 | + [ | ||
90 | + [ 'banner_id' ], | ||
91 | + 'exist', | ||
92 | + 'skipOnError' => true, | ||
93 | + 'targetClass' => Banner::className(), | ||
94 | + 'targetAttribute' => [ 'banner_id' => 'id' ], | ||
95 | + ], | ||
96 | + [ | ||
97 | + [ 'language_id' ], | ||
98 | + 'exist', | ||
99 | + 'skipOnError' => true, | ||
100 | + 'targetClass' => Language::className(), | ||
101 | + 'targetAttribute' => [ 'language_id' => 'id' ], | ||
102 | + ], | ||
103 | + ]; | ||
104 | + } | ||
105 | + | ||
106 | + /** | ||
107 | + * @inheritdoc | ||
108 | + */ | ||
109 | + public function attributeLabels() | ||
110 | + { | ||
111 | + return [ | ||
112 | + 'banner_id' => Yii::t('app', 'banner_id'), | ||
113 | + 'language_id' => Yii::t('app', 'language_id'), | ||
114 | + 'alt' => Yii::t('app', 'alt'), | ||
115 | + 'title' => Yii::t('app', 'title'), | ||
116 | + ]; | ||
117 | + } | ||
118 | + | ||
119 | + /** | ||
120 | + * @return \yii\db\ActiveQuery | ||
121 | + */ | ||
122 | + public function getBanner() | ||
123 | + { | ||
124 | + return $this->hasOne(Banner::className(), [ 'id' => 'banner_id' ]); | ||
125 | + } | ||
126 | + | ||
127 | + /** | ||
128 | + * @return \yii\db\ActiveQuery | ||
129 | + */ | ||
130 | + public function getLanguage() | ||
131 | + { | ||
132 | + return $this->hasOne(Language::className(), [ 'id' => 'language_id' ]); | ||
133 | + } | ||
134 | + } |
1 | +++ a/models/BannerSearch.php | ||
1 | +<?php | ||
2 | + | ||
3 | + namespace common\models; | ||
4 | + | ||
5 | + use yii\base\Model; | ||
6 | + use yii\data\ActiveDataProvider; | ||
7 | + | ||
8 | + /** | ||
9 | + * BannerSearch represents the model behind the search form about `common\models\Banner`. | ||
10 | + */ | ||
11 | + class BannerSearch extends Banner | ||
12 | + { | ||
13 | + | ||
14 | + public $title; | ||
15 | + | ||
16 | + /** | ||
17 | + * @inheritdoc | ||
18 | + */ | ||
19 | + public function rules() | ||
20 | + { | ||
21 | + return [ | ||
22 | + [ | ||
23 | + [ | ||
24 | + 'id', | ||
25 | + 'status', | ||
26 | + ], | ||
27 | + 'integer', | ||
28 | + ], | ||
29 | + [ | ||
30 | + [ | ||
31 | + 'url', | ||
32 | + 'title', | ||
33 | + ], | ||
34 | + 'safe', | ||
35 | + ], | ||
36 | + ]; | ||
37 | + } | ||
38 | + | ||
39 | + public function behaviors() | ||
40 | + { | ||
41 | + return []; | ||
42 | + } | ||
43 | + | ||
44 | + /** | ||
45 | + * @inheritdoc | ||
46 | + */ | ||
47 | + public function scenarios() | ||
48 | + { | ||
49 | + // bypass scenarios() implementation in the parent class | ||
50 | + return Model::scenarios(); | ||
51 | + } | ||
52 | + | ||
53 | + /** | ||
54 | + * Creates data provider instance with search query applied | ||
55 | + * | ||
56 | + * @param array $params | ||
57 | + * | ||
58 | + * @return ActiveDataProvider | ||
59 | + */ | ||
60 | + public function search($params) | ||
61 | + { | ||
62 | + $query = Banner::find() | ||
63 | + ->joinWith('lang'); | ||
64 | + | ||
65 | + // add conditions that should always apply here | ||
66 | + | ||
67 | + $dataProvider = new ActiveDataProvider( | ||
68 | + [ | ||
69 | + 'query' => $query, | ||
70 | + 'sort' => [ | ||
71 | + 'attributes' => [ | ||
72 | + 'id', | ||
73 | + 'url', | ||
74 | + 'status', | ||
75 | + 'title' => [ | ||
76 | + 'asc' => [ 'banner_lang.title' => SORT_ASC ], | ||
77 | + 'desc' => [ 'banner_lang.title' => SORT_DESC ], | ||
78 | + ], | ||
79 | + ], | ||
80 | + ], | ||
81 | + ] | ||
82 | + ); | ||
83 | + | ||
84 | + $this->load($params); | ||
85 | + | ||
86 | + if (!$this->validate()) { | ||
87 | + // uncomment the following line if you do not want to return any records when validation fails | ||
88 | + // $query->where('0=1'); | ||
89 | + return $dataProvider; | ||
90 | + } | ||
91 | + | ||
92 | + // grid filtering conditions | ||
93 | + $query->andFilterWhere( | ||
94 | + [ | ||
95 | + 'id' => $this->id, | ||
96 | + 'status' => $this->status, | ||
97 | + ] | ||
98 | + ); | ||
99 | + | ||
100 | + $query->andFilterWhere( | ||
101 | + [ | ||
102 | + 'like', | ||
103 | + 'url', | ||
104 | + $this->url, | ||
105 | + ] | ||
106 | + ) | ||
107 | + ->andFilterWhere( | ||
108 | + [ | ||
109 | + 'like', | ||
110 | + 'banner_lang.title', | ||
111 | + $this->title, | ||
112 | + ] | ||
113 | + ); | ||
114 | + | ||
115 | + return $dataProvider; | ||
116 | + } | ||
117 | + } |
1 | +++ a/models/Bg.php | ||
1 | +<?php | ||
2 | + | ||
3 | + namespace common\models; | ||
4 | + | ||
5 | + use common\behaviors\SaveImgBehavior; | ||
6 | + use common\modules\language\behaviors\LanguageBehavior; | ||
7 | + use yii\db\ActiveQuery; | ||
8 | + use yii\db\ActiveRecord; | ||
9 | + use yii\web\Request; | ||
10 | + use Yii; | ||
11 | + | ||
12 | + /** | ||
13 | + * Class Bg | ||
14 | + * | ||
15 | + * @property int $id | ||
16 | + * @property string $url | ||
17 | + * @property string $image | ||
18 | + * * From language behavior * | ||
19 | + * @property BgLang $lang | ||
20 | + * @property BgLang[] $langs | ||
21 | + * @property BgLang $objectLang | ||
22 | + * @property string $ownerKey | ||
23 | + * @property string $langKey | ||
24 | + * @property BgLang[] $modelLangs | ||
25 | + * @property bool $transactionStatus | ||
26 | + * @method string getOwnerKey() | ||
27 | + * @method void setOwnerKey( string $value ) | ||
28 | + * @method string getLangKey() | ||
29 | + * @method void setLangKey( string $value ) | ||
30 | + * @method ActiveQuery getLangs() | ||
31 | + * @method ActiveQuery getLang( integer $language_id ) | ||
32 | + * @method BgLang[] generateLangs() | ||
33 | + * @method void loadLangs( Request $request ) | ||
34 | + * @method bool linkLangs() | ||
35 | + * @method bool saveLangs() | ||
36 | + * @method bool getTransactionStatus() | ||
37 | + * * End language behavior * | ||
38 | + * * From SaveImgBehavior | ||
39 | + * @property string|null $imageFile | ||
40 | + * @property string|null $imageUrl | ||
41 | + * @method string|null getImageFile( int $field ) | ||
42 | + * @method string|null getImageUrl( int $field ) | ||
43 | + * * End SaveImgBehavior | ||
44 | + */ | ||
45 | + class Bg extends ActiveRecord | ||
46 | + { | ||
47 | + | ||
48 | + public static function tableName() | ||
49 | + { | ||
50 | + return 'bg'; | ||
51 | + } | ||
52 | + | ||
53 | + public function behaviors() | ||
54 | + { | ||
55 | + return [ | ||
56 | + [ | ||
57 | + 'class' => SaveImgBehavior::className(), | ||
58 | + 'fields' => [ | ||
59 | + [ | ||
60 | + 'name' => 'image', | ||
61 | + 'directory' => 'bg', | ||
62 | + ], | ||
63 | + ], | ||
64 | + ], | ||
65 | + 'language' => [ | ||
66 | + 'class' => LanguageBehavior::className(), | ||
67 | + ], | ||
68 | + ]; | ||
69 | + } | ||
70 | + | ||
71 | + public function rules() | ||
72 | + { | ||
73 | + return [ | ||
74 | + [ | ||
75 | + [ 'url' ], | ||
76 | + 'string', | ||
77 | + ], | ||
78 | + ]; | ||
79 | + } | ||
80 | + | ||
81 | + public function attributeLabels() | ||
82 | + { | ||
83 | + return [ | ||
84 | + 'image' => Yii::t('app', 'image'), | ||
85 | + 'url' => Yii::t('app', 'url'), | ||
86 | + ]; | ||
87 | + } | ||
88 | + } |
1 | +++ a/models/BgLang.php | ||
1 | +<?php | ||
2 | + | ||
3 | + namespace common\models; | ||
4 | + | ||
5 | + use common\modules\language\models\Language; | ||
6 | + use Yii; | ||
7 | + use yii\db\ActiveRecord; | ||
8 | + | ||
9 | + /** | ||
10 | + * This is the model class for table "bg_lang". | ||
11 | + * @property integer $bg_id | ||
12 | + * @property integer $language_id | ||
13 | + * @property string $title | ||
14 | + * @property Bg $bg | ||
15 | + * @property Language $language | ||
16 | + */ | ||
17 | + class BgLang extends ActiveRecord | ||
18 | + { | ||
19 | + | ||
20 | + public static function primaryKey() | ||
21 | + { | ||
22 | + return [ | ||
23 | + 'bg_id', | ||
24 | + 'language_id', | ||
25 | + ]; | ||
26 | + } | ||
27 | + | ||
28 | + /** | ||
29 | + * @inheritdoc | ||
30 | + */ | ||
31 | + public static function tableName() | ||
32 | + { | ||
33 | + return 'bg_lang'; | ||
34 | + } | ||
35 | + | ||
36 | + /** | ||
37 | + * @inheritdoc | ||
38 | + */ | ||
39 | + public function rules() | ||
40 | + { | ||
41 | + return [ | ||
42 | + [ | ||
43 | + [ 'title' ], | ||
44 | + 'required', | ||
45 | + ], | ||
46 | + [ | ||
47 | + [ 'title' ], | ||
48 | + 'string', | ||
49 | + 'max' => 255, | ||
50 | + ], | ||
51 | + [ | ||
52 | + [ | ||
53 | + 'bg_id', | ||
54 | + 'language_id', | ||
55 | + ], | ||
56 | + 'unique', | ||
57 | + 'targetAttribute' => [ | ||
58 | + 'bg_id', | ||
59 | + 'language_id', | ||
60 | + ], | ||
61 | + 'message' => 'The combination of Bg ID and Language ID has already been taken.', | ||
62 | + ], | ||
63 | + [ | ||
64 | + [ 'bg_id' ], | ||
65 | + 'exist', | ||
66 | + 'skipOnError' => true, | ||
67 | + 'targetClass' => Bg::className(), | ||
68 | + 'targetAttribute' => [ 'bg_id' => 'id' ], | ||
69 | + ], | ||
70 | + [ | ||
71 | + [ 'language_id' ], | ||
72 | + 'exist', | ||
73 | + 'skipOnError' => true, | ||
74 | + 'targetClass' => Language::className(), | ||
75 | + 'targetAttribute' => [ 'language_id' => 'id' ], | ||
76 | + ], | ||
77 | + ]; | ||
78 | + } | ||
79 | + | ||
80 | + /** | ||
81 | + * @inheritdoc | ||
82 | + */ | ||
83 | + public function attributeLabels() | ||
84 | + { | ||
85 | + return [ | ||
86 | + 'bg_id' => Yii::t('app', 'bg_id'), | ||
87 | + 'language_id' => Yii::t('app', 'language_id'), | ||
88 | + 'title' => Yii::t('app', 'title'), | ||
89 | + ]; | ||
90 | + } | ||
91 | + | ||
92 | + /** | ||
93 | + * @return \yii\db\ActiveQuery | ||
94 | + */ | ||
95 | + public function getBg() | ||
96 | + { | ||
97 | + return $this->hasOne(Bg::className(), [ 'id' => 'bg_id' ]); | ||
98 | + } | ||
99 | + | ||
100 | + /** | ||
101 | + * @return \yii\db\ActiveQuery | ||
102 | + */ | ||
103 | + public function getLanguage() | ||
104 | + { | ||
105 | + return $this->hasOne(Language::className(), [ 'id' => 'language_id' ]); | ||
106 | + } | ||
107 | + } |
1 | +++ a/models/BgSearch.php | ||
1 | +<?php | ||
2 | + | ||
3 | + namespace common\models; | ||
4 | + | ||
5 | + use yii\base\Model; | ||
6 | + use yii\data\ActiveDataProvider; | ||
7 | + | ||
8 | + /** | ||
9 | + * BgSearch represents the model behind the search form about `common\models\Bg`. | ||
10 | + */ | ||
11 | + class BgSearch extends Bg | ||
12 | + { | ||
13 | + | ||
14 | + public $title; | ||
15 | + | ||
16 | + /** | ||
17 | + * @inheritdoc | ||
18 | + */ | ||
19 | + public function rules() | ||
20 | + { | ||
21 | + return [ | ||
22 | + [ | ||
23 | + [ 'id' ], | ||
24 | + 'integer', | ||
25 | + ], | ||
26 | + [ | ||
27 | + [ | ||
28 | + 'url', | ||
29 | + 'title', | ||
30 | + ], | ||
31 | + 'safe', | ||
32 | + ], | ||
33 | + ]; | ||
34 | + } | ||
35 | + | ||
36 | + public function behaviors() | ||
37 | + { | ||
38 | + return []; | ||
39 | + } | ||
40 | + | ||
41 | + /** | ||
42 | + * @inheritdoc | ||
43 | + */ | ||
44 | + public function scenarios() | ||
45 | + { | ||
46 | + // bypass scenarios() implementation in the parent class | ||
47 | + return Model::scenarios(); | ||
48 | + } | ||
49 | + | ||
50 | + /** | ||
51 | + * Creates data provider instance with search query applied | ||
52 | + * | ||
53 | + * @param array $params | ||
54 | + * | ||
55 | + * @return ActiveDataProvider | ||
56 | + */ | ||
57 | + public function search($params) | ||
58 | + { | ||
59 | + $query = Bg::find() | ||
60 | + ->joinWith('lang'); | ||
61 | + | ||
62 | + // add conditions that should always apply here | ||
63 | + | ||
64 | + $dataProvider = new ActiveDataProvider( | ||
65 | + [ | ||
66 | + 'query' => $query, | ||
67 | + 'sort' => [ | ||
68 | + 'attributes' => [ | ||
69 | + 'id', | ||
70 | + 'url', | ||
71 | + 'title' => [ | ||
72 | + 'asc' => [ 'bg_lang.title' => SORT_ASC ], | ||
73 | + 'desc' => [ 'bg_lang.title' => SORT_DESC ], | ||
74 | + ], | ||
75 | + ], | ||
76 | + ], | ||
77 | + ] | ||
78 | + ); | ||
79 | + | ||
80 | + $this->load($params); | ||
81 | + | ||
82 | + if (!$this->validate()) { | ||
83 | + // uncomment the following line if you do not want to return any records when validation fails | ||
84 | + // $query->where('0=1'); | ||
85 | + return $dataProvider; | ||
86 | + } | ||
87 | + | ||
88 | + // grid filtering conditions | ||
89 | + $query->andFilterWhere( | ||
90 | + [ | ||
91 | + 'id' => $this->id, | ||
92 | + ] | ||
93 | + ); | ||
94 | + | ||
95 | + $query->andFilterWhere( | ||
96 | + [ | ||
97 | + 'like', | ||
98 | + 'url', | ||
99 | + $this->url, | ||
100 | + ] | ||
101 | + ) | ||
102 | + ->andFilterWhere( | ||
103 | + [ | ||
104 | + 'ilike', | ||
105 | + 'bg_lang.title', | ||
106 | + $this->title, | ||
107 | + ] | ||
108 | + ); | ||
109 | + | ||
110 | + return $dataProvider; | ||
111 | + } | ||
112 | + } |
1 | +++ a/models/Slider.php | ||
1 | +<?php | ||
2 | + | ||
3 | + namespace common\models; | ||
4 | + | ||
5 | + use Yii; | ||
6 | + use yii\db\ActiveRecord; | ||
7 | + | ||
8 | + /** | ||
9 | + * This is the model class for table "slider". | ||
10 | + * | ||
11 | + * @property integer $id | ||
12 | + * @property integer $speed | ||
13 | + * @property integer $duration | ||
14 | + * @property string $title | ||
15 | + * @property integer $status | ||
16 | + * @property integer $width | ||
17 | + * @property integer $height | ||
18 | + * @property SliderImage[] $sliderImages | ||
19 | + */ | ||
20 | + class Slider extends ActiveRecord | ||
21 | + { | ||
22 | + | ||
23 | + /** | ||
24 | + * @inheritdoc | ||
25 | + */ | ||
26 | + public static function tableName() | ||
27 | + { | ||
28 | + return 'slider'; | ||
29 | + } | ||
30 | + | ||
31 | + /** | ||
32 | + * @inheritdoc | ||
33 | + */ | ||
34 | + public function rules() | ||
35 | + { | ||
36 | + return [ | ||
37 | + [ | ||
38 | + [ | ||
39 | + 'speed', | ||
40 | + 'duration', | ||
41 | + 'status', | ||
42 | + 'width', | ||
43 | + 'height', | ||
44 | + ], | ||
45 | + 'integer', | ||
46 | + ], | ||
47 | + [ | ||
48 | + [ 'title' ], | ||
49 | + 'string', | ||
50 | + 'max' => 200, | ||
51 | + ], | ||
52 | + [ | ||
53 | + [ | ||
54 | + 'width', | ||
55 | + 'height', | ||
56 | + 'title', | ||
57 | + ], | ||
58 | + 'required', | ||
59 | + ], | ||
60 | + [ | ||
61 | + 'title', | ||
62 | + 'unique', | ||
63 | + 'targetClass' => '\common\models\Slider', | ||
64 | + 'message' => Yii::t( | ||
65 | + 'app', | ||
66 | + 'message', | ||
67 | + [ | ||
68 | + 'field' => 'Title', | ||
69 | + ] | ||
70 | + ), | ||
71 | + ], | ||
72 | + ]; | ||
73 | + } | ||
74 | + | ||
75 | + /** | ||
76 | + * @inheritdoc | ||
77 | + */ | ||
78 | + public function attributeLabels() | ||
79 | + { | ||
80 | + return [ | ||
81 | + 'id' => Yii::t('app', 'slider_id'), | ||
82 | + 'speed' => Yii::t('app', 'speed'), | ||
83 | + 'duration' => Yii::t('app', 'duration'), | ||
84 | + 'title' => Yii::t('app', 'title'), | ||
85 | + 'status' => Yii::t('app', 'status'), | ||
86 | + 'width' => Yii::t('app', 'width'), | ||
87 | + 'height' => Yii::t('app', 'height'), | ||
88 | + ]; | ||
89 | + } | ||
90 | + | ||
91 | + /** | ||
92 | + * @return \yii\db\ActiveQuery | ||
93 | + */ | ||
94 | + public function getSliderImages() | ||
95 | + { | ||
96 | + return $this->hasMany(SliderImage::className(), [ 'slider_id' => 'id' ]) | ||
97 | + ->where([ SliderImage::tableName() . '.status' => 1 ]); | ||
98 | + } | ||
99 | + | ||
100 | + } |
1 | +++ a/models/SliderImage.php | ||
1 | +<?php | ||
2 | + | ||
3 | + namespace common\models; | ||
4 | + | ||
5 | + use common\behaviors\SaveImgBehavior; | ||
6 | + use common\modules\language\behaviors\LanguageBehavior; | ||
7 | + use Yii; | ||
8 | + use yii\db\ActiveQuery; | ||
9 | + use yii\db\ActiveRecord; | ||
10 | + use yii\web\Request; | ||
11 | + | ||
12 | + /** | ||
13 | + * This is the model class for table "slider_image". | ||
14 | + * | ||
15 | + * @property integer $id | ||
16 | + * @property integer $slider_id | ||
17 | + * @property string $image | ||
18 | + * @property string $url | ||
19 | + * @property integer $status | ||
20 | + * @property integer $sort | ||
21 | + * @property Slider $slider | ||
22 | + * * From language behavior * | ||
23 | + * @property SliderImageLang $lang | ||
24 | + * @property SliderImageLang[] $langs | ||
25 | + * @property SliderImageLang $objectLang | ||
26 | + * @property string $ownerKey | ||
27 | + * @property string $langKey | ||
28 | + * @property SliderImageLang[] $modelLangs | ||
29 | + * @property bool $transactionStatus | ||
30 | + * @method string getOwnerKey() | ||
31 | + * @method void setOwnerKey( string $value ) | ||
32 | + * @method string getLangKey() | ||
33 | + * @method void setLangKey( string $value ) | ||
34 | + * @method ActiveQuery getLangs() | ||
35 | + * @method ActiveQuery getLang( integer $language_id ) | ||
36 | + * @method SliderImageLang[] generateLangs() | ||
37 | + * @method void loadLangs( Request $request ) | ||
38 | + * @method bool linkLangs() | ||
39 | + * @method bool saveLangs() | ||
40 | + * @method bool getTransactionStatus() | ||
41 | + * * End language behavior * | ||
42 | + * * From SaveImgBehavior | ||
43 | + * @property string|null $imageFile | ||
44 | + * @property string|null $imageUrl | ||
45 | + * @method string|null getImageFile( int $field ) | ||
46 | + * @method string|null getImageUrl( int $field ) | ||
47 | + * * End SaveImgBehavior | ||
48 | + */ | ||
49 | + class SliderImage extends ActiveRecord | ||
50 | + { | ||
51 | + | ||
52 | + /** | ||
53 | + * @inheritdoc | ||
54 | + */ | ||
55 | + public static function tableName() | ||
56 | + { | ||
57 | + return 'slider_image'; | ||
58 | + } | ||
59 | + | ||
60 | + /** | ||
61 | + * @inheritdoc | ||
62 | + */ | ||
63 | + public function rules() | ||
64 | + { | ||
65 | + return [ | ||
66 | + [ | ||
67 | + [ | ||
68 | + 'slider_id', | ||
69 | + 'status', | ||
70 | + 'sort', | ||
71 | + ], | ||
72 | + 'integer', | ||
73 | + ], | ||
74 | + [ | ||
75 | + [ | ||
76 | + 'url', | ||
77 | + ], | ||
78 | + 'string', | ||
79 | + 'max' => 255, | ||
80 | + ], | ||
81 | + [ | ||
82 | + [ 'slider_id' ], | ||
83 | + 'exist', | ||
84 | + 'skipOnError' => true, | ||
85 | + 'targetClass' => Slider::className(), | ||
86 | + 'targetAttribute' => [ 'slider_id' => 'id' ], | ||
87 | + ], | ||
88 | + ]; | ||
89 | + } | ||
90 | + | ||
91 | + public function behaviors() | ||
92 | + { | ||
93 | + return [ | ||
94 | + 'language' => [ | ||
95 | + 'class' => LanguageBehavior::className(), | ||
96 | + ], | ||
97 | + [ | ||
98 | + 'class' => SaveImgBehavior::className(), | ||
99 | + 'fields' => [ | ||
100 | + [ | ||
101 | + 'name' => 'image', | ||
102 | + 'directory' => 'slider', | ||
103 | + ], | ||
104 | + ], | ||
105 | + ], | ||
106 | + ]; | ||
107 | + } | ||
108 | + | ||
109 | + /** | ||
110 | + * @inheritdoc | ||
111 | + */ | ||
112 | + public function attributeLabels() | ||
113 | + { | ||
114 | + return [ | ||
115 | + 'id' => Yii::t('app', 'slider_image_id'), | ||
116 | + 'slider_id' => Yii::t('app', 'slider_id'), | ||
117 | + 'image' => Yii::t('app', 'image'), | ||
118 | + 'url' => Yii::t('app', 'url'), | ||
119 | + 'status' => Yii::t('app', 'status'), | ||
120 | + 'sort' => Yii::t('app', 'sort'), | ||
121 | + ]; | ||
122 | + } | ||
123 | + | ||
124 | + /** | ||
125 | + * @return \yii\db\ActiveQuery | ||
126 | + */ | ||
127 | + public function getSlider() | ||
128 | + { | ||
129 | + return $this->hasOne(Slider::className(), [ 'id' => 'slider_id' ]); | ||
130 | + } | ||
131 | + } |
1 | +++ a/models/SliderImageLang.php | ||
1 | +<?php | ||
2 | + | ||
3 | + namespace common\models; | ||
4 | + | ||
5 | + use common\modules\language\models\Language; | ||
6 | + use Yii; | ||
7 | + use yii\db\ActiveRecord; | ||
8 | + | ||
9 | + /** | ||
10 | + * This is the model class for table "slider_image_lang". | ||
11 | + * | ||
12 | + * @property integer $slider_image_id | ||
13 | + * @property integer $language_id | ||
14 | + * @property string $title | ||
15 | + * @property string $alt | ||
16 | + * @property Language $language | ||
17 | + * @property SliderImage $sliderImage | ||
18 | + */ | ||
19 | + class SliderImageLang extends ActiveRecord | ||
20 | + { | ||
21 | + | ||
22 | + public static function primaryKey() | ||
23 | + { | ||
24 | + return [ | ||
25 | + 'slider_image_id', | ||
26 | + 'language_id', | ||
27 | + ]; | ||
28 | + } | ||
29 | + | ||
30 | + /** | ||
31 | + * @inheritdoc | ||
32 | + */ | ||
33 | + public static function tableName() | ||
34 | + { | ||
35 | + return 'slider_image_lang'; | ||
36 | + } | ||
37 | + | ||
38 | + /** | ||
39 | + * @inheritdoc | ||
40 | + */ | ||
41 | + public function rules() | ||
42 | + { | ||
43 | + return [ | ||
44 | + [ | ||
45 | + [ | ||
46 | + 'title', | ||
47 | + 'alt', | ||
48 | + ], | ||
49 | + 'string', | ||
50 | + 'max' => 255, | ||
51 | + ], | ||
52 | + [ | ||
53 | + [ | ||
54 | + 'slider_image_id', | ||
55 | + 'language_id', | ||
56 | + ], | ||
57 | + 'unique', | ||
58 | + 'targetAttribute' => [ | ||
59 | + 'slider_image_id', | ||
60 | + 'language_id', | ||
61 | + ], | ||
62 | + 'message' => 'The combination of Slider Image ID and Language ID has already been taken.', | ||
63 | + ], | ||
64 | + [ | ||
65 | + [ 'language_id' ], | ||
66 | + 'exist', | ||
67 | + 'skipOnError' => true, | ||
68 | + 'targetClass' => Language::className(), | ||
69 | + 'targetAttribute' => [ 'language_id' => 'id' ], | ||
70 | + ], | ||
71 | + [ | ||
72 | + [ 'slider_image_id' ], | ||
73 | + 'exist', | ||
74 | + 'skipOnError' => true, | ||
75 | + 'targetClass' => SliderImage::className(), | ||
76 | + 'targetAttribute' => [ 'slider_image_id' => 'id' ], | ||
77 | + ], | ||
78 | + ]; | ||
79 | + } | ||
80 | + | ||
81 | + /** | ||
82 | + * @inheritdoc | ||
83 | + */ | ||
84 | + public function attributeLabels() | ||
85 | + { | ||
86 | + return [ | ||
87 | + 'slider_image_id' => Yii::t('app', 'slider_image_id'), | ||
88 | + 'language_id' => Yii::t('app', 'language_id'), | ||
89 | + 'title' => Yii::t('app', 'title'), | ||
90 | + 'alt' => Yii::t('app', 'alt'), | ||
91 | + ]; | ||
92 | + } | ||
93 | + | ||
94 | + /** | ||
95 | + * @return \yii\db\ActiveQuery | ||
96 | + */ | ||
97 | + public function getLanguage() | ||
98 | + { | ||
99 | + return $this->hasOne(Language::className(), [ 'id' => 'language_id' ]); | ||
100 | + } | ||
101 | + | ||
102 | + /** | ||
103 | + * @return \yii\db\ActiveQuery | ||
104 | + */ | ||
105 | + public function getSliderImage() | ||
106 | + { | ||
107 | + return $this->hasOne(SliderImage::className(), [ 'id' => 'slider_image_id' ]); | ||
108 | + } | ||
109 | + } |
1 | +++ a/models/SliderImageSearch.php | ||
1 | +<?php | ||
2 | + | ||
3 | + namespace common\models; | ||
4 | + | ||
5 | + use yii\base\Model; | ||
6 | + use yii\data\ActiveDataProvider; | ||
7 | + | ||
8 | + /** | ||
9 | + * SliderImageSearch represents the model behind the search form about | ||
10 | + * `common\models\SliderImage`. | ||
11 | + */ | ||
12 | + class SliderImageSearch extends SliderImage | ||
13 | + { | ||
14 | + | ||
15 | + public function behaviors() | ||
16 | + { | ||
17 | + return []; | ||
18 | + } | ||
19 | + | ||
20 | + /** | ||
21 | + * @inheritdoc | ||
22 | + */ | ||
23 | + public function rules() | ||
24 | + { | ||
25 | + return [ | ||
26 | + [ | ||
27 | + [ | ||
28 | + 'id', | ||
29 | + 'slider_id', | ||
30 | + 'status', | ||
31 | + 'sort', | ||
32 | + ], | ||
33 | + 'integer', | ||
34 | + ], | ||
35 | + [ | ||
36 | + [ | ||
37 | + 'url', | ||
38 | + ], | ||
39 | + 'safe', | ||
40 | + ], | ||
41 | + ]; | ||
42 | + } | ||
43 | + | ||
44 | + /** | ||
45 | + * @inheritdoc | ||
46 | + */ | ||
47 | + public function scenarios() | ||
48 | + { | ||
49 | + // bypass scenarios() implementation in the parent class | ||
50 | + return Model::scenarios(); | ||
51 | + } | ||
52 | + | ||
53 | + /** | ||
54 | + * Creates data provider instance with search query applied | ||
55 | + * | ||
56 | + * @param array $params | ||
57 | + * @param $slider_id Slider id | ||
58 | + * | ||
59 | + * @return ActiveDataProvider | ||
60 | + */ | ||
61 | + public function search($slider_id, $params) | ||
62 | + { | ||
63 | + $query = SliderImage::find(); | ||
64 | + | ||
65 | + // add conditions that should always apply here | ||
66 | + | ||
67 | + $dataProvider = new ActiveDataProvider( | ||
68 | + [ | ||
69 | + 'query' => $query, | ||
70 | + ] | ||
71 | + ); | ||
72 | + | ||
73 | + $this->load($params); | ||
74 | + | ||
75 | + if (!$this->validate()) { | ||
76 | + // uncomment the following line if you do not want to return any records when validation fails | ||
77 | + // $query->where('0=1'); | ||
78 | + return $dataProvider; | ||
79 | + } | ||
80 | + | ||
81 | + // grid filtering conditions | ||
82 | + $query->andFilterWhere( | ||
83 | + [ | ||
84 | + 'id' => $this->id, | ||
85 | + 'slider_id' => $slider_id, | ||
86 | + 'status' => $this->status, | ||
87 | + 'sort' => $this->sort, | ||
88 | + ] | ||
89 | + ); | ||
90 | + | ||
91 | + $query->andFilterWhere( | ||
92 | + [ | ||
93 | + 'like', | ||
94 | + 'url', | ||
95 | + $this->url, | ||
96 | + ] | ||
97 | + ); | ||
98 | + | ||
99 | + return $dataProvider; | ||
100 | + } | ||
101 | + } |
1 | +++ a/models/SliderSearch.php | ||
1 | +<?php | ||
2 | + | ||
3 | + namespace common\models; | ||
4 | + | ||
5 | + use yii\base\Model; | ||
6 | + use yii\data\ActiveDataProvider; | ||
7 | + | ||
8 | + /** | ||
9 | + * SliderSearch represents the model behind the search form about `common\models\Slider`. | ||
10 | + */ | ||
11 | + class SliderSearch extends Slider | ||
12 | + { | ||
13 | + | ||
14 | + public $location; | ||
15 | + | ||
16 | + /** | ||
17 | + * @inheritdoc | ||
18 | + */ | ||
19 | + public function rules() | ||
20 | + { | ||
21 | + return [ | ||
22 | + [ | ||
23 | + [ | ||
24 | + 'id', | ||
25 | + 'status', | ||
26 | + ], | ||
27 | + 'integer', | ||
28 | + ], | ||
29 | + [ | ||
30 | + [ 'title' ], | ||
31 | + 'safe', | ||
32 | + ], | ||
33 | + ]; | ||
34 | + } | ||
35 | + | ||
36 | + /** | ||
37 | + * @inheritdoc | ||
38 | + */ | ||
39 | + public function scenarios() | ||
40 | + { | ||
41 | + // bypass scenarios() implementation in the parent class | ||
42 | + return Model::scenarios(); | ||
43 | + } | ||
44 | + | ||
45 | + /** | ||
46 | + * Creates data provider instance with search query applied | ||
47 | + * | ||
48 | + * @param array $params | ||
49 | + * | ||
50 | + * @return ActiveDataProvider | ||
51 | + */ | ||
52 | + public function search($params) | ||
53 | + { | ||
54 | + $query = Slider::find(); | ||
55 | + | ||
56 | + // add conditions that should always apply here | ||
57 | + | ||
58 | + $dataProvider = new ActiveDataProvider( | ||
59 | + [ | ||
60 | + 'query' => $query, | ||
61 | + ] | ||
62 | + ); | ||
63 | + | ||
64 | + $this->load($params); | ||
65 | + | ||
66 | + if (!$this->validate()) { | ||
67 | + // uncomment the following line if you do not want to return any records when validation fails | ||
68 | + // $query->where('0=1'); | ||
69 | + return $dataProvider; | ||
70 | + } | ||
71 | + | ||
72 | + // grid filtering conditions | ||
73 | + $query->andFilterWhere( | ||
74 | + [ | ||
75 | + 'id' => $this->id, | ||
76 | + 'status' => $this->status, | ||
77 | + ] | ||
78 | + ); | ||
79 | + | ||
80 | + $query->andFilterWhere( | ||
81 | + [ | ||
82 | + 'like', | ||
83 | + 'title', | ||
84 | + $this->title, | ||
85 | + ] | ||
86 | + ); | ||
87 | + | ||
88 | + return $dataProvider; | ||
89 | + } | ||
90 | + } |
1 | +++ a/widgets/Slider.php | ||
1 | +<?php | ||
2 | +namespace frontend\widgets; | ||
3 | + | ||
4 | +use yii\base\Widget; | ||
5 | + | ||
6 | +class Slider extends Widget | ||
7 | +{ | ||
8 | + public $title; | ||
9 | + | ||
10 | + public function init(){ | ||
11 | + | ||
12 | + parent::init(); | ||
13 | + | ||
14 | + } | ||
15 | + | ||
16 | + | ||
17 | + public function run() | ||
18 | + { | ||
19 | + | ||
20 | + | ||
21 | + $slider = \common\models\Slider::find()->where([\common\models\Slider::tableName().'.title'=>$this->title])->joinWith("sliderImage")->one(); | ||
22 | + if($slider instanceof \common\models\Slider){ | ||
23 | + return $this->render('slider',[ | ||
24 | + 'slider'=>$slider, | ||
25 | + 'title'=>$this->title | ||
26 | + ]); | ||
27 | + | ||
28 | + } | ||
29 | + | ||
30 | + | ||
31 | + } | ||
32 | + | ||
33 | +} | ||
0 | \ No newline at end of file | 34 | \ No newline at end of file |
1 | +++ a/widgets/views/slider.php | ||
1 | +<?php | ||
2 | +/* @var $slider Slider*/ | ||
3 | +use common\components\artboximage\ArtboxImageHelper; | ||
4 | +use common\models\Slider; | ||
5 | +use yii\helpers\Html; | ||
6 | +use yii\web\View; | ||
7 | +use frontend\assets\FlipclockAsset; | ||
8 | +FlipclockAsset::register($this); | ||
9 | + | ||
10 | +?> | ||
11 | + | ||
12 | + | ||
13 | +<div id="<?=$title?>" class="owl-carousel owl-theme"> | ||
14 | + <?php if($slider instanceof Slider){ foreach($slider->sliderImage as $image): | ||
15 | + | ||
16 | + | ||
17 | + ?> | ||
18 | + <div class="item"> | ||
19 | +<?php | ||
20 | + if(!empty($image->end_at) && strtotime($image->end_at) > strtotime(date("Y-m-d"))){ | ||
21 | + ?> | ||
22 | + <div class="clock_centered"><div class="clock_style clock_<?= $image->primaryKey ?>"></div></div> | ||
23 | + <?php $js = "var clock; | ||
24 | + clock = new FlipClock($('.clock_". $image->primaryKey ."'), { | ||
25 | + clockFace: 'DailyCounter', | ||
26 | + language: 'ru', | ||
27 | + classes: { | ||
28 | + active: 'flip-clock-active', | ||
29 | + before: 'flip-clock-before', | ||
30 | + divider: 'flip-clock-divider', | ||
31 | + dot: 'flip-clock-dot', | ||
32 | + label: 'flip-clock-label', | ||
33 | + flip: 'flip', | ||
34 | + play: 'play', | ||
35 | + wrapper: 'flip-clock-wrapper' | ||
36 | + }, | ||
37 | + }); | ||
38 | + | ||
39 | + clock.setTime(".(strtotime($image->end_at) - strtotime(date('Y-m-d H:i:s')))."); | ||
40 | + clock.setCountdown(true); | ||
41 | + clock.start();"; | ||
42 | + $this->registerJs($js,View::POS_LOAD) ?> | ||
43 | + | ||
44 | + | ||
45 | + <?php | ||
46 | + }?> | ||
47 | + <?= Html::a(Html::img(ArtboxImageHelper::getImageSrc($image->imageUrl,'slider')), $image->url)?> | ||
48 | + </div> | ||
49 | + | ||
50 | + | ||
51 | + | ||
52 | +<?php endforeach; } | ||
53 | + ?> | ||
54 | +</div> | ||
55 | +<?php | ||
56 | +$dur = $slider->duration ? $slider->duration : 5000; | ||
57 | +$speed = $slider->speed ? $slider->speed : 500; | ||
58 | +$js=" $(\"#$title\").owlCarousel({ | ||
59 | + navigation : true, // Show next and prev buttons | ||
60 | + slideSpeed : 500, | ||
61 | + autoplayTimeout:$dur, | ||
62 | + paginationSpeed : $speed, | ||
63 | + singleItem:true, | ||
64 | + autoPlay:true | ||
65 | + | ||
66 | + }); | ||
67 | + var owl = $(\"#$title\"); | ||
68 | + $('#next_slide').click(function() { | ||
69 | + owl.trigger('owl.next'); | ||
70 | + }) | ||
71 | + $('#prev_slide').click(function() { | ||
72 | + owl.trigger('owl.prev'); | ||
73 | + }) | ||
74 | + "; | ||
75 | + | ||
76 | +$this->registerJs($js,View::POS_READY); | ||
77 | + | ||
78 | +?> |