diff --git a/backend/assets/AppAsset.php b/backend/assets/AppAsset.php index 3f9bf26..688115e 100755 --- a/backend/assets/AppAsset.php +++ b/backend/assets/AppAsset.php @@ -21,11 +21,10 @@ class AppAsset extends AssetBundle 'css/site.css', ]; public $js = [ - 'js/fieldWidget.js', 'js/site.js', ]; public $depends = [ 'yii\web\YiiAsset', - 'yii\bootstrap\BootstrapAsset', + 'yii\bootstrap\BootstrapPluginAsset', ]; } diff --git a/backend/controllers/ArticlesController.php b/backend/controllers/ArticlesController.php index 04145bc..18d0a67 100644 --- a/backend/controllers/ArticlesController.php +++ b/backend/controllers/ArticlesController.php @@ -1,166 +1,191 @@ [ - 'class' => AccessBehavior::className(), - 'rules' => - ['site' => - [ + + /** + * @inheritdoc + */ + public function behaviors() + { + return [ + 'access' => [ + 'class' => AccessBehavior::className(), + 'rules' => [ + 'site' => [ [ - 'actions' => ['login', 'error'], - 'allow' => true, - ] - ] - ] - ], - 'verbs' => [ - 'class' => VerbFilter::className(), - 'actions' => [ - 'delete' => ['POST'], + 'actions' => [ + 'login', + 'error', + ], + 'allow' => true, + ], + ], + ], ], - ], - ]; - } - - /** - * Lists all Articles models. - * @return mixed - */ - public function actionIndex() - { - $searchModel = new ArticlesSearch(); - $dataProvider = $searchModel->search(Yii::$app->request->queryParams); - - return $this->render('index', [ - 'searchModel' => $searchModel, - 'dataProvider' => $dataProvider, - ]); - } - - /** - * Displays a single Articles model. - * @param integer $id - * @return mixed - */ - public function actionView($id) - { - return $this->render('view', [ - 'model' => $this->findModel($id), - ]); - } - - /** - * Creates a new Articles model. - * If creation is successful, the browser will be redirected to the 'view' page. - * @return mixed - */ - public function actionCreate() - { - $model = new Articles(); - - if ($model->load(Yii::$app->request->post())) { - - if ( ($image = UploadedFile::getInstance($model, 'image')) ) { - $model->image = $image->name; - } - - $imgDir = Yii::getAlias('@storage/articles/'); - - if(!is_dir($imgDir)) { - mkdir($imgDir, 0755, true); - } - if ($model->save() && $image) { - $image->saveAs(Yii::getAlias('@storage/articles/' . $image->name)); + 'verbs' => [ + 'class' => VerbFilter::className(), + 'actions' => [ + 'delete' => [ 'POST' ], + ], + ], + ]; + } + + /** + * Lists all Articles models. + * @return mixed + */ + public function actionIndex() + { + $searchModel = new ArticlesSearch(); + $dataProvider = $searchModel->search(Yii::$app->request->queryParams); + + return $this->render('index', [ + 'searchModel' => $searchModel, + 'dataProvider' => $dataProvider, + ]); + } + + /** + * Displays a single Articles model. + * + * @param integer $id + * + * @return mixed + */ + public function actionView($id) + { + return $this->render('view', [ + 'model' => $this->findModel($id), + ]); + } + + /** + * Creates a new Articles model. + * If creation is successful, the browser will be redirected to the 'view' page. + * @return mixed + */ + public function actionCreate() + { + $model = new Articles(); + $model_langs = $model->generateLangs(); + if($model->load(Yii::$app->request->post())) { + $model->loadLangs(\Yii::$app->request, $model_langs); + if(( $image = UploadedFile::getInstance($model, 'image') )) { + $model->image = $image->name; + } + $imgDir = Yii::getAlias('@storage/articles/'); + if(!is_dir($imgDir)) { + mkdir($imgDir, 0755, true); + } + if($model->save()) { + if($image) { + $image->saveAs(Yii::getAlias('@storage/articles/' . $image->name)); + } + if($model->linkLangs($model_langs) && $model->saveLangs($model_langs)) { + return $this->redirect([ + 'view', + 'id' => $model->id, + ]); + } else { + return $this->redirect([ + 'update', + 'id' => $model->id, + ]); + } + } } - - return $this->redirect(['view', 'id' => $model->id]); - } else { return $this->render('create', [ - 'model' => $model, + 'model' => $model, + 'model_langs' => $model_langs, ]); } - } - - /** - * Updates an existing Articles model. - * If update is successful, the browser will be redirected to the 'view' page. - * @param integer $id - * @return mixed - */ - public function actionUpdate($id) - { - $model = $this->findModel($id); - - if ($model->load(Yii::$app->request->post())) { - if ( ($image = UploadedFile::getInstance($model, 'image')) ) { - $model->image = $image->name; - } - - $imgDir = Yii::getAlias('@storage/articles/'); - - if(!is_dir($imgDir)) { - mkdir($imgDir, 0755, true); - } - if ($model->save() && $image) { - $image->saveAs(Yii::getAlias('@storage/articles/' . $image->name)); + /** + * Updates an existing Articles model. + * If update is successful, the browser will be redirected to the 'view' page. + * + * @param integer $id + * + * @return mixed + */ + public function actionUpdate($id) + { + $model = $this->findModel($id); + $model_langs = $model->generateLangs(); + if($model->load(Yii::$app->request->post())) { + $model->loadLangs(\Yii::$app->request, $model_langs); + if(( $image = UploadedFile::getInstance($model, 'image') )) { + $model->image = $image->name; + } + $imgDir = Yii::getAlias('@storage/articles/'); + if(!is_dir($imgDir)) { + mkdir($imgDir, 0755, true); + } + if($model->save()) { + if($image) { + $image->saveAs(Yii::getAlias('@storage/articles/' . $image->name)); + } + if($model->linkLangs($model_langs) && $model->saveLangs($model_langs)) { + return $this->redirect([ + 'view', + 'id' => $model->id, + ]); + } + } } - - return $this->redirect(['view', 'id' => $model->id]); - } else { return $this->render('update', [ - 'model' => $model, + 'model' => $model, + 'model_langs' => $model_langs, ]); } - } - - /** - * Deletes an existing Articles model. - * If deletion is successful, the browser will be redirected to the 'index' page. - * @param integer $id - * @return mixed - */ - public function actionDelete($id) - { - $this->findModel($id)->delete(); - - return $this->redirect(['index']); - } - - /** - * Finds the Articles model based on its primary key value. - * If the model is not found, a 404 HTTP exception will be thrown. - * @param integer $id - * @return Articles the loaded model - * @throws NotFoundHttpException if the model cannot be found - */ - protected function findModel($id) - { - if (($model = Articles::findOne($id)) !== null) { - return $model; - } else { - throw new NotFoundHttpException('The requested page does not exist.'); + + /** + * Deletes an existing Articles model. + * If deletion is successful, the browser will be redirected to the 'index' page. + * + * @param integer $id + * + * @return mixed + */ + public function actionDelete($id) + { + $this->findModel($id) + ->delete(); + + return $this->redirect([ 'index' ]); + } + + /** + * Finds the Articles model based on its primary key value. + * If the model is not found, a 404 HTTP exception will be thrown. + * + * @param integer $id + * + * @return Articles the loaded model + * @throws NotFoundHttpException if the model cannot be found + */ + protected function findModel($id) + { + if(( $model = Articles::findOne($id) ) !== NULL) { + return $model; + } else { + throw new NotFoundHttpException('The requested page does not exist.'); + } } } -} diff --git a/backend/controllers/BannerController.php b/backend/controllers/BannerController.php index ccf4e70..b20f9ad 100644 --- a/backend/controllers/BannerController.php +++ b/backend/controllers/BannerController.php @@ -1,157 +1,169 @@ [ - 'class' => AccessBehavior::className(), - 'rules' => - ['site' => - [ + + /** + * @inheritdoc + */ + public function behaviors() + { + return [ + 'access' => [ + 'class' => AccessBehavior::className(), + 'rules' => [ + 'site' => [ [ - 'actions' => ['login', 'error'], - 'allow' => true, - ] - ] - ] - ], - 'verbs' => [ - 'class' => VerbFilter::className(), - 'actions' => [ - 'delete' => ['POST'], + 'actions' => [ + 'login', + 'error', + ], + 'allow' => true, + ], + ], + ], ], - ], - ]; - } - - /** - * Lists all Banner models. - * @return mixed - */ - public function actionIndex() - { - $searchModel = new BannerSearch(); - $dataProvider = $searchModel->search(Yii::$app->request->queryParams); - - return $this->render('index', [ - 'searchModel' => $searchModel, - 'dataProvider' => $dataProvider, - ]); - } - - public function actionSaveImageSettings(){ - \Yii::$app->response->format = \yii\web\Response::FORMAT_JSON; - $width = Yii::$app->request->post('width'); - $height = Yii::$app->request->post('height'); - - $html = ImageUploader::widget([ - 'model'=> new Banner(), - 'field'=>'image', - 'size' => [ - [ - 'width'=>$width, - 'height'=>$height, + 'verbs' => [ + 'class' => VerbFilter::className(), + 'actions' => [ + 'delete' => [ 'POST' ], + ], ], - ], - 'name' => "Загрузить баннер" - ]); - - return ['html'=>$html]; - } - - /** - * Displays a single Banner model. - * @param integer $id - * @return mixed - */ - public function actionView($id) - { - return $this->render('view', [ - 'model' => $this->findModel($id), - ]); - } - - /** - * Creates a new Banner model. - * If creation is successful, the browser will be redirected to the 'view' page. - * @return mixed - */ - public function actionCreate() - { - $model = new Banner(); - - if ($model->load(Yii::$app->request->post()) && $model->save()) { - return $this->redirect(['view', 'id' => $model->banner_id]); - } else { - return $this->render('create', [ - 'model' => $model, + ]; + } + + /** + * Lists all Banner models. + * @return mixed + */ + public function actionIndex() + { + $searchModel = new BannerSearch(); + $dataProvider = $searchModel->search(Yii::$app->request->queryParams); + + return $this->render('index', [ + 'searchModel' => $searchModel, + 'dataProvider' => $dataProvider, ]); } - } - - /** - * Updates an existing Banner model. - * If update is successful, the browser will be redirected to the 'view' page. - * @param integer $id - * @return mixed - */ - public function actionUpdate($id) - { - $model = $this->findModel($id); - - if ($model->load(Yii::$app->request->post()) && $model->save()) { - return $this->redirect(['view', 'id' => $model->banner_id]); - } else { + + /** + * Displays a single Banner model. + * + * @param integer $id + * + * @return mixed + */ + public function actionView($id) + { + return $this->render('view', [ + 'model' => $this->findModel($id), + ]); + } + + /** + * Creates a new Banner model. + * If creation is successful, the browser will be redirected to the 'view' page. + * @return mixed + */ + public function actionCreate() + { + $model = new Banner(); + $model_langs = $model->generateLangs(); + + if($model->load(Yii::$app->request->post()) && $model->save()) { + $model->loadLangs(\Yii::$app->request, $model_langs); + if($model->linkLangs($model_langs) && $model->saveLangs($model_langs)) { + return $this->redirect([ + 'view', + 'id' => $model->banner_id, + ]); + } else { + return $this->redirect('update', [ + 'id' => $model->banner_id, + ]); + } + } else { + return $this->render('create', [ + 'model' => $model, + 'model_langs' => $model_langs, + ]); + } + } + + /** + * Updates an existing Banner model. + * If update is successful, the browser will be redirected to the 'view' page. + * + * @param integer $id + * + * @return mixed + */ + public function actionUpdate($id) + { + $model = $this->findModel($id); + $model_langs = $model->generateLangs(); + + if($model->load(Yii::$app->request->post()) && $model->save()) { + $model->loadLangs(\Yii::$app->request, $model_langs); + if($model->linkLangs($model_langs) && $model->saveLangs($model_langs)) { + return $this->redirect([ + 'view', + 'id' => $model->banner_id, + ]); + } + } return $this->render('update', [ - 'model' => $model, + 'model' => $model, + 'model_langs' => $model_langs, ]); } - } - - /** - * Deletes an existing Banner model. - * If deletion is successful, the browser will be redirected to the 'index' page. - * @param integer $id - * @return mixed - */ - public function actionDelete($id) - { - $this->findModel($id)->delete(); - - return $this->redirect(['index']); - } - - /** - * Finds the Banner model based on its primary key value. - * If the model is not found, a 404 HTTP exception will be thrown. - * @param integer $id - * @return Banner the loaded model - * @throws NotFoundHttpException if the model cannot be found - */ - protected function findModel($id) - { - if (($model = Banner::findOne($id)) !== null) { - return $model; - } else { - throw new NotFoundHttpException('The requested page does not exist.'); + + /** + * Deletes an existing Banner model. + * If deletion is successful, the browser will be redirected to the 'index' page. + * + * @param integer $id + * + * @return mixed + */ + public function actionDelete($id) + { + $this->findModel($id) + ->delete(); + + return $this->redirect([ 'index' ]); + } + + /** + * Finds the Banner model based on its primary key value. + * If the model is not found, a 404 HTTP exception will be thrown. + * + * @param integer $id + * + * @return Banner the loaded model + * @throws NotFoundHttpException if the model cannot be found + */ + protected function findModel($id) + { + if(( $model = Banner::findOne($id) ) !== NULL) { + return $model; + } else { + throw new NotFoundHttpException('The requested page does not exist.'); + } } } -} diff --git a/backend/controllers/BgController.php b/backend/controllers/BgController.php index f87fdd6..894d2c4 100644 --- a/backend/controllers/BgController.php +++ b/backend/controllers/BgController.php @@ -1,136 +1,169 @@ [ - 'class' => AccessBehavior::className(), - 'rules' => - ['site' => - [ + + /** + * @inheritdoc + */ + public function behaviors() + { + return [ + 'access' => [ + 'class' => AccessBehavior::className(), + 'rules' => [ + 'site' => [ [ - 'actions' => ['login', 'error'], - 'allow' => true, - ] - ] - ] - ], - 'verbs' => [ - 'class' => VerbFilter::className(), - 'actions' => [ - 'delete' => ['POST'], + 'actions' => [ + 'login', + 'error', + ], + 'allow' => true, + ], + ], + ], ], - ], - ]; - } - - /** - * Lists all Bg models. - * @return mixed - */ - public function actionIndex() - { - $searchModel = new BgSearch(); - $dataProvider = $searchModel->search(Yii::$app->request->queryParams); - - return $this->render('index', [ - 'searchModel' => $searchModel, - 'dataProvider' => $dataProvider, - ]); - } - - /** - * Displays a single Bg model. - * @param integer $id - * @return mixed - */ - public function actionView($id) - { - return $this->render('view', [ - 'model' => $this->findModel($id), - ]); - } - - /** - * Creates a new Bg model. - * If creation is successful, the browser will be redirected to the 'view' page. - * @return mixed - */ - public function actionCreate() - { - $model = new Bg(); - - if ($model->load(Yii::$app->request->post()) && $model->save()) { - return $this->redirect(['view', 'id' => $model->id]); - } else { - return $this->render('create', [ - 'model' => $model, + 'verbs' => [ + 'class' => VerbFilter::className(), + 'actions' => [ + 'delete' => [ 'POST' ], + ], + ], + ]; + } + + /** + * Lists all Bg models. + * @return mixed + */ + public function actionIndex() + { + $searchModel = new BgSearch(); + $dataProvider = $searchModel->search(Yii::$app->request->queryParams); + + return $this->render('index', [ + 'searchModel' => $searchModel, + 'dataProvider' => $dataProvider, ]); } - } - - /** - * Updates an existing Bg model. - * If update is successful, the browser will be redirected to the 'view' page. - * @param integer $id - * @return mixed - */ - public function actionUpdate($id) - { - $model = $this->findModel($id); - - if ($model->load(Yii::$app->request->post()) && $model->save()) { - return $this->redirect(['view', 'id' => $model->id]); - } else { + + /** + * Displays a single Bg model. + * + * @param integer $id + * + * @return mixed + */ + public function actionView($id) + { + return $this->render('view', [ + 'model' => $this->findModel($id), + ]); + } + + /** + * Creates a new Bg model. + * If creation is successful, the browser will be redirected to the 'view' page. + * @return mixed + */ + public function actionCreate() + { + $model = new Bg(); + $model_langs = $model->generateLangs(); + + if($model->load(Yii::$app->request->post()) && $model->save()) { + $model->loadLangs(\Yii::$app->request, $model_langs); + if($model->linkLangs($model_langs) && $model->saveLangs($model_langs)) { + return $this->redirect([ + 'view', + 'id' => $model->id, + ]); + } else { + return $this->redirect([ + 'update', + 'id' => $model->id, + ]); + } + } else { + return $this->render('create', [ + 'model' => $model, + 'model_langs' => $model_langs, + ]); + } + } + + /** + * Updates an existing Bg model. + * If update is successful, the browser will be redirected to the 'view' page. + * + * @param integer $id + * + * @return mixed + */ + public function actionUpdate($id) + { + $model = $this->findModel($id); + $model_langs = $model->generateLangs(); + + if($model->load(Yii::$app->request->post()) && $model->save()) { + $model->loadLangs(\Yii::$app->request); + if($model->linkLangs($model_langs) && $model->saveLangs($model_langs)) { + return $this->redirect([ + 'view', + 'id' => $model->id, + ]); + } + } return $this->render('update', [ - 'model' => $model, + 'model' => $model, + 'model_langs' => $model_langs, ]); } - } - - /** - * Deletes an existing Bg model. - * If deletion is successful, the browser will be redirected to the 'index' page. - * @param integer $id - * @return mixed - */ - public function actionDelete($id) - { - $this->findModel($id)->delete(); - - return $this->redirect(['index']); - } - - /** - * Finds the Bg model based on its primary key value. - * If the model is not found, a 404 HTTP exception will be thrown. - * @param integer $id - * @return Bg the loaded model - * @throws NotFoundHttpException if the model cannot be found - */ - protected function findModel($id) - { - if (($model = Bg::findOne($id)) !== null) { - return $model; - } else { - throw new NotFoundHttpException('The requested page does not exist.'); + + /** + * Deletes an existing Bg model. + * If deletion is successful, the browser will be redirected to the 'index' page. + * + * @param integer $id + * + * @return mixed + */ + public function actionDelete($id) + { + $this->findModel($id) + ->delete(); + + return $this->redirect([ 'index' ]); + } + + /** + * Finds the Bg model based on its primary key value. + * If the model is not found, a 404 HTTP exception will be thrown. + * + * @param integer $id + * + * @return Bg the loaded model + * @throws NotFoundHttpException if the model cannot be found + */ + protected function findModel($id) + { + if(( $model = Bg::findOne($id) ) !== NULL) { + return $model; + } else { + throw new NotFoundHttpException('The requested page does not exist.'); + } } } -} diff --git a/backend/controllers/BrandController.php b/backend/controllers/BrandController.php index c30fd00..1915924 100644 --- a/backend/controllers/BrandController.php +++ b/backend/controllers/BrandController.php @@ -1,167 +1,181 @@ [ - 'class' => AccessControl::className(), - 'rules' => [ - [ - 'actions' => ['login', 'error'], - 'allow' => true, - ], - [ - 'actions' => ['logout', 'index', 'create', 'update', 'view', 'delete'], - 'allow' => true, - 'roles' => ['@'], + + /** + * @inheritdoc + */ + public function behaviors() + { + return [ + 'access' => [ + 'class' => AccessControl::className(), + 'rules' => [ + [ + 'actions' => [ + 'login', + 'error', + ], + 'allow' => true, + ], + [ + 'actions' => [ + 'logout', + 'index', + 'create', + 'update', + 'view', + 'delete', + ], + 'allow' => true, + 'roles' => [ '@' ], + ], ], ], - ], - 'verbs' => [ - 'class' => VerbFilter::className(), - 'actions' => [ - 'logout' => ['post'], + 'verbs' => [ + 'class' => VerbFilter::className(), + 'actions' => [ + 'logout' => [ 'post' ], + ], ], - ], - ]; - } - - /** - * Lists all Brand models. - * @return mixed - */ - public function actionIndex() - { - $searchModel = new BrandSearch(); - $dataProvider = $searchModel->search(Yii::$app->request->queryParams); - - return $this->render('index', [ - 'searchModel' => $searchModel, - 'dataProvider' => $dataProvider, - ]); - } - - /** - * Displays a single Brand model. - * @param integer $id - * @return mixed - */ - public function actionView($id) - { - return $this->render('view', [ - 'model' => $this->findModel($id), - ]); - } - - /** - * Creates a new Brand model. - * If creation is successful, the browser will be redirected to the 'view' page. - * @return mixed - */ - public function actionCreate() - { - $model = new Brand(); - if ($model->load(Yii::$app->request->post())) { - if ( ($image = UploadedFile::getInstance($model, 'image')) ) { - $model->image = $image->name; - } - if ($model->save() && $image) { - - $imgDir = Yii::getAlias('@storage/brand/'); - - if(!is_dir($imgDir)) { - mkdir($imgDir, 0755, true); + ]; + } + + /** + * Lists all Brand models. + * @return mixed + */ + public function actionIndex() + { + $searchModel = new BrandSearch(); + $dataProvider = $searchModel->search(Yii::$app->request->queryParams); + + return $this->render('index', [ + 'searchModel' => $searchModel, + 'dataProvider' => $dataProvider, + ]); + } + + /** + * Displays a single Brand model. + * + * @param integer $id + * + * @return mixed + */ + public function actionView($id) + { + return $this->render('view', [ + 'model' => $this->findModel($id), + ]); + } + + /** + * Creates a new Brand model. + * If creation is successful, the browser will be redirected to the 'view' page. + * @return mixed + */ + public function actionCreate() + { + $model = new Brand(); + $model_langs = $model->generateLangs(); + if($model->load(Yii::$app->request->post())) { + $model->loadLangs(\Yii::$app->request, $model_langs); + if($model->save()) { + if($model->linkLangs($model_langs) && $model->saveLangs($model_langs)) { + return is_null(Yii::$app->request->post('create_and_new')) ? $this->redirect([ + 'view', + 'id' => $model->brand_id, + ]) : $this->redirect(array_merge([ 'create' ], Yii::$app->request->queryParams)); + } + } else { + return $this->redirect('update', [ + 'id' => $model->brand_id, + ]); } - - $image->saveAs(Yii::getAlias('@storage/brand/' . $image->name)); } - - return is_null(Yii::$app->request->post('create_and_new')) ? $this->redirect(['view', 'id' => $model->brand_id]) : $this->redirect(array_merge(['create'], Yii::$app->request->queryParams)); - } else { return $this->render('create', [ - 'model' => $model, + 'model' => $model, + 'model_langs' => $model_langs, ]); } - } - - /** - * Updates an existing Brand model. - * If update is successful, the browser will be redirected to the 'view' page. - * @param integer $id - * @return mixed - */ - public function actionUpdate($id) - { - $model = $this->findModel($id); - - if ($model->load(Yii::$app->request->post())) { - if ( ($image = UploadedFile::getInstance($model, 'image')) ) { - $model->image = $image->name; - } - if ($model->save() && $image) { - - $imgDir = Yii::getAlias('@storage/brands/'); - - if(!is_dir($imgDir)) { - mkdir($imgDir, 0755, true); + + /** + * Updates an existing Brand model. + * If update is successful, the browser will be redirected to the 'view' page. + * + * @param integer $id + * + * @return mixed + */ + public function actionUpdate($id) + { + $model = $this->findModel($id); + $model_langs = $model->generateLangs(); + + if($model->load(Yii::$app->request->post())) { + $model->loadLangs(\Yii::$app->request, $model_langs); + if($model->save()) { + if($model->linkLangs($model_langs) && $model->saveLangs($model_langs)) { + return $this->redirect([ + 'view', + 'id' => $model->brand_id, + ]); + } } - - $image->saveAs(Yii::getAlias('@storage/brands/' . $image->name)); } - - return $this->redirect(['view', 'id' => $model->brand_id]); - } else { return $this->render('update', [ - 'model' => $model, + 'model' => $model, + 'model_langs' => $model_langs, ]); } - } - - /** - * Deletes an existing Brand model. - * If deletion is successful, the browser will be redirected to the 'index' page. - * @param integer $id - * @return mixed - */ - public function actionDelete($id) - { - $this->findModel($id)->delete(); - - return $this->redirect(['index']); - } - - /** - * Finds the Brand model based on its primary key value. - * If the model is not found, a 404 HTTP exception will be thrown. - * @param integer $id - * @return Brand the loaded model - * @throws NotFoundHttpException if the model cannot be found - */ - protected function findModel($id) - { - if (($model = Brand::findOne($id)) !== null) { - return $model; - } else { - throw new NotFoundHttpException('The requested page does not exist.'); + + /** + * Deletes an existing Brand model. + * If deletion is successful, the browser will be redirected to the 'index' page. + * + * @param integer $id + * + * @return mixed + */ + public function actionDelete($id) + { + $this->findModel($id) + ->delete(); + + return $this->redirect([ 'index' ]); + } + + /** + * Finds the Brand model based on its primary key value. + * If the model is not found, a 404 HTTP exception will be thrown. + * + * @param integer $id + * + * @return Brand the loaded model + * @throws NotFoundHttpException if the model cannot be found + */ + protected function findModel($id) + { + if(( $model = Brand::findOne($id) ) !== NULL) { + return $model; + } else { + throw new NotFoundHttpException('The requested page does not exist.'); + } } } -} diff --git a/backend/controllers/CategoryController.php b/backend/controllers/CategoryController.php index 11c2b78..c3dd0ef 100644 --- a/backend/controllers/CategoryController.php +++ b/backend/controllers/CategoryController.php @@ -1,161 +1,196 @@ [ - 'class' => AccessBehavior::className(), - 'rules' => - ['site' => - [ + + /** + * @inheritdoc + */ + public function behaviors() + { + return [ + 'access' => [ + 'class' => AccessBehavior::className(), + 'rules' => [ + 'site' => [ [ - 'actions' => ['login', 'error'], - 'allow' => true, - ] - ] - ] - ], - 'verbs' => [ - 'class' => VerbFilter::className(), - 'actions' => [ - 'logout' => ['post'], + 'actions' => [ + 'login', + 'error', + ], + 'allow' => true, + ], + ], + ], ], - ], - ]; - } - - /** - * Lists all Category models. - * @return mixed - */ - public function actionIndex() - { - $searchModel = new CategorySearch(); - $dataProvider = $searchModel->search(Yii::$app->request->queryParams); - - return $this->render('index', [ - 'searchModel' => $searchModel, - 'dataProvider' => $dataProvider, - ]); - } - - /** - * Displays a single Category model. - * @param integer $id - * @return mixed - */ - public function actionView($id) - { - return $this->render('view', [ - 'model' => $this->findModel($id), - ]); - } - - /** - * Creates a new Category model. - * If creation is successful, the browser will be redirected to the 'view' page. - * @return mixed - */ - public function actionCreate() - { - $model = new Category(); - - if ($model->load(Yii::$app->request->post())) { - if ( ($image = UploadedFile::getInstance($model, 'imageUpload')) ) { - $model->image = $image->name; - } - - if ($model->save() && $image) { - $image->saveAs(Yii::getAlias('@imagesDir/categories/' . $image->name)); + 'verbs' => [ + 'class' => VerbFilter::className(), + 'actions' => [ + 'logout' => [ 'post' ], + ], + ], + ]; + } + + /** + * Lists all Category models. + * @return mixed + */ + public function actionIndex() + { + $searchModel = new CategorySearch(); + $dataProvider = $searchModel->search(Yii::$app->request->queryParams); + + return $this->render('index', [ + 'searchModel' => $searchModel, + 'dataProvider' => $dataProvider, + ]); + } + + /** + * Displays a single Category model. + * + * @param integer $id + * + * @return mixed + */ + public function actionView($id) + { + return $this->render('view', [ + 'model' => $this->findModel($id), + ]); + } + + /** + * Creates a new Category model. + * If creation is successful, the browser will be redirected to the 'view' page. + * @return mixed + */ + public function actionCreate() + { + $model = new Category(); + $model_langs = $model->generateLangs(); + + if($model->load(Yii::$app->request->post())) { + $model->loadLangs(\Yii::$app->request, $model_langs); + if(( $image = UploadedFile::getInstance($model, 'imageUpload') )) { + $model->image = $image->name; + } + + if($model->save()) { + if($image) { + $image->saveAs(Yii::getAlias('@imagesDir/categories/' . $image->name)); + } + + if($model->linkLangs($model_langs) && $model->saveLangs($model_langs)) { + return is_null(Yii::$app->request->post('create_and_new')) ? $this->redirect([ + 'view', + 'id' => $model->category_id, + ]) : $this->redirect(array_merge([ 'create' ], Yii::$app->request->queryParams)); + } else { + return $this->redirect('update', [ + 'id' => $model->category_id, + ]); + } + } + } - - return is_null(Yii::$app->request->post('create_and_new')) ? $this->redirect(['view', 'id' => $model->category_id]) : $this->redirect(array_merge(['create'], Yii::$app->request->queryParams)); - } else { - if (!empty(Yii::$app->request->queryParams['parent'])) { - $model->parent_id = Yii::$app->request->queryParams['parent']; + if(!empty( Yii::$app->request->queryParams[ 'parent' ] )) { + $model->parent_id = Yii::$app->request->queryParams[ 'parent' ]; } return $this->render('create', [ - 'model' => $model, - 'categories' => ArtboxTreeHelper::treeMap(Category::find()->getTree(), 'category_id', 'name', '.') + 'model' => $model, + 'model_langs' => $model_langs, + 'categories' => ArtboxTreeHelper::treeMap(Category::find() + ->getTree(), 'category_id', 'name', '.'), ]); } - } - - /** - * Updates an existing Category model. - * If update is successful, the browser will be redirected to the 'view' page. - * @param integer $id - * @return mixed - */ - public function actionUpdate($id) - { - $model = $this->findModel($id); - - if ($model->load(Yii::$app->request->post())) { - if ( ($image = UploadedFile::getInstance($model, 'imageUpload')) ) { - $model->image = $image->name; - } - - if ($model->save() && $image) { - $image->saveAs(Yii::getAlias('@imagesDir/categories/' . $image->name)); + + /** + * Updates an existing Category model. + * If update is successful, the browser will be redirected to the 'view' page. + * + * @param integer $id + * + * @return mixed + */ + public function actionUpdate($id) + { + $model = $this->findModel($id); + + $model_langs = $model->generateLangs(); + + if($model->load(Yii::$app->request->post())) { + if(( $image = UploadedFile::getInstance($model, 'imageUpload') )) { + $model->image = $image->name; + } + $model->loadLangs(\Yii::$app->request, $model_langs); + if($model->save()) { + if($image) { + $image->saveAs(Yii::getAlias('@imagesDir/categories/' . $image->name)); + } + if($model->linkLangs($model_langs) && $model->saveLangs($model_langs)) { + return $this->redirect([ + 'view', + 'id' => $model->category_id, + ]); + } + } } - - return $this->redirect(['view', 'id' => $model->category_id]); - } else { return $this->render('update', [ - 'model' => $model, - 'categories' => ArtboxTreeHelper::treeMap(Category::find()->getTree(), 'category_id', 'name', '.') + 'model' => $model, + 'model_langs' => $model_langs, + 'categories' => ArtboxTreeHelper::treeMap(Category::find() + ->getTree(), 'category_id', 'name', '.'), ]); } - } - - /** - * Deletes an existing Category model. - * If deletion is successful, the browser will be redirected to the 'index' page. - * @param integer $id - * @return mixed - */ - public function actionDelete($id) - { - $this->findModel($id)->delete(); - - return $this->redirect(['index']); - } - - /** - * Finds the Category model based on its primary key value. - * If the model is not found, a 404 HTTP exception will be thrown. - * @param integer $id - * @return Category the loaded model - * @throws NotFoundHttpException if the model cannot be found - */ - protected function findModel($id) - { - if (($model = Category::findOne($id)) !== null) { - return $model; - } else { - throw new NotFoundHttpException('The requested page does not exist.'); + + /** + * Deletes an existing Category model. + * If deletion is successful, the browser will be redirected to the 'index' page. + * + * @param integer $id + * + * @return mixed + */ + public function actionDelete($id) + { + $this->findModel($id) + ->delete(); + + return $this->redirect([ 'index' ]); + } + + /** + * Finds the Category model based on its primary key value. + * If the model is not found, a 404 HTTP exception will be thrown. + * + * @param integer $id + * + * @return Category the loaded model + * @throws NotFoundHttpException if the model cannot be found + */ + protected function findModel($id) + { + if(( $model = Category::findOne($id) ) !== NULL) { + return $model; + } else { + throw new NotFoundHttpException('The requested page does not exist.'); + } } } -} diff --git a/backend/controllers/EventController.php b/backend/controllers/EventController.php index bf67aab..4e3b0d6 100644 --- a/backend/controllers/EventController.php +++ b/backend/controllers/EventController.php @@ -1,156 +1,191 @@ [ - 'class' => AccessBehavior::className(), - 'rules' => - ['site' => - [ + + /** + * @inheritdoc + */ + public function behaviors() + { + return [ + 'access' => [ + 'class' => AccessBehavior::className(), + 'rules' => [ + 'site' => [ [ - 'actions' => ['login', 'error'], - 'allow' => true, - ] - ] - ] - ], - 'verbs' => [ - 'class' => VerbFilter::className(), - 'actions' => [ - 'delete' => ['POST'], + 'actions' => [ + 'login', + 'error', + ], + 'allow' => true, + ], + ], + ], ], - ], - ]; - } - - /** - * Lists all Event models. - * @return mixed - */ - public function actionIndex() - { - $searchModel = new EventSearch(); - $dataProvider = $searchModel->search(Yii::$app->request->queryParams); - - return $this->render('index', [ - 'searchModel' => $searchModel, - 'dataProvider' => $dataProvider, - ]); - } - - /** - * Displays a single Event model. - * @param integer $id - * @return mixed - */ - public function actionView($id) - { - return $this->render('view', [ - 'model' => $this->findModel($id), - ]); - } - - /** - * Creates a new Event model. - * If creation is successful, the browser will be redirected to the 'view' page. - * @return mixed - */ - public function actionCreate() - { - $model = new Event(); - - if ($model->load(Yii::$app->request->post())) { - - if ( ($image = UploadedFile::getInstance($model, 'imageUpload')) ) { - $model->image = $image->name; - } - - if ($model->save() && $image) { - $image->saveAs(Yii::getAlias('@imagesDir/articles/' . $image->name)); + 'verbs' => [ + 'class' => VerbFilter::className(), + 'actions' => [ + 'delete' => [ 'POST' ], + ], + ], + ]; + } + + /** + * Lists all Event models. + * @return mixed + */ + public function actionIndex() + { + $searchModel = new EventSearch(); + $dataProvider = $searchModel->search(Yii::$app->request->queryParams); + + return $this->render('index', [ + 'searchModel' => $searchModel, + 'dataProvider' => $dataProvider, + ]); + } + + /** + * Displays a single Event model. + * + * @param integer $id + * + * @return mixed + */ + public function actionView($id) + { + return $this->render('view', [ + 'model' => $this->findModel($id), + ]); + } + + /** + * Creates a new Event model. + * If creation is successful, the browser will be redirected to the 'view' page. + * @return mixed + */ + public function actionCreate() + { + $model = new Event(); + $model_langs = $model->generateLangs(); + + if($model->load(Yii::$app->request->post())) { + + $model->loadLangs(\Yii::$app->request, $model_langs); + + if(( $image = UploadedFile::getInstance($model, 'imageUpload') )) { + $model->image = $image->name; + } + + if($model->save()) { + if($image) { + $image->saveAs(Yii::getAlias('@imagesDir/articles/' . $image->name)); + } + if($model->linkLangs($model_langs) && $model->saveLangs($model_langs)) { + return $this->redirect([ + 'view', + 'id' => $model->event_id, + ]); + } else { + return $this->redirect([ + 'update', + 'id' => $model->event_id, + ]); + } + } } - - return $this->redirect(['view', 'id' => $model->event_id]); - } else { return $this->render('create', [ - 'model' => $model, + 'model' => $model, + 'model_langs' => $model_langs, ]); } - } - - /** - * Updates an existing Event model. - * If update is successful, the browser will be redirected to the 'view' page. - * @param integer $id - * @return mixed - */ - public function actionUpdate($id) - { - $model = $this->findModel($id); - - if ($model->load(Yii::$app->request->post())) { - - if ( ($image = UploadedFile::getInstance($model, 'imageUpload')) ) { - $model->image = $image->name; - } - - if ($model->save() && $image) { - $image->saveAs(Yii::getAlias('@imagesDir/articles/' . $image->name)); + + /** + * Updates an existing Event model. + * If update is successful, the browser will be redirected to the 'view' page. + * + * @param integer $id + * + * @return mixed + */ + public function actionUpdate($id) + { + $model = $this->findModel($id); + $model_langs = $model->generateLangs(); + + if($model->load(Yii::$app->request->post())) { + + $model->loadLangs(\Yii::$app->request, $model_langs); + + if(( $image = UploadedFile::getInstance($model, 'imageUpload') )) { + $model->image = $image->name; + } + + if($model->save()) { + if($image) { + $image->saveAs(Yii::getAlias('@imagesDir/articles/' . $image->name)); + } + if($model->linkLangs($model_langs) && $model->saveLangs($model_langs)) { + return $this->redirect([ + 'view', + 'id' => $model->event_id, + ]); + } + } } - - return $this->redirect(['view', 'id' => $model->event_id]); - } else { return $this->render('update', [ - 'model' => $model, + 'model' => $model, + 'model_langs' => $model_langs, ]); } - } - - /** - * Deletes an existing Event model. - * If deletion is successful, the browser will be redirected to the 'index' page. - * @param integer $id - * @return mixed - */ - public function actionDelete($id) - { - $this->findModel($id)->delete(); - - return $this->redirect(['index']); - } - - /** - * Finds the Event model based on its primary key value. - * If the model is not found, a 404 HTTP exception will be thrown. - * @param integer $id - * @return Event the loaded model - * @throws NotFoundHttpException if the model cannot be found - */ - protected function findModel($id) - { - if (($model = Event::findOne($id)) !== null) { - return $model; - } else { - throw new NotFoundHttpException('The requested page does not exist.'); + + /** + * Deletes an existing Event model. + * If deletion is successful, the browser will be redirected to the 'index' page. + * + * @param integer $id + * + * @return mixed + */ + public function actionDelete($id) + { + $this->findModel($id) + ->delete(); + + return $this->redirect([ 'index' ]); + } + + /** + * Finds the Event model based on its primary key value. + * If the model is not found, a 404 HTTP exception will be thrown. + * + * @param integer $id + * + * @return Event the loaded model + * @throws NotFoundHttpException if the model cannot be found + */ + protected function findModel($id) + { + if(( $model = Event::findOne($id) ) !== NULL) { + return $model; + } else { + throw new NotFoundHttpException('The requested page does not exist.'); + } } } -} diff --git a/backend/controllers/PageController.php b/backend/controllers/PageController.php index fbe101f..5400aa4 100644 --- a/backend/controllers/PageController.php +++ b/backend/controllers/PageController.php @@ -1,136 +1,168 @@ [ - 'class' => AccessBehavior::className(), - 'rules' => - ['site' => - [ + + /** + * @inheritdoc + */ + public function behaviors() + { + return [ + 'access' => [ + 'class' => AccessBehavior::className(), + 'rules' => [ + 'site' => [ [ - 'actions' => ['login', 'error'], - 'allow' => true, - ] - ] - ] - ], - 'verbs' => [ - 'class' => VerbFilter::className(), - 'actions' => [ - 'delete' => ['POST'], + 'actions' => [ + 'login', + 'error', + ], + 'allow' => true, + ], + ], + ], ], - ], - ]; - } - - /** - * Lists all Page models. - * @return mixed - */ - public function actionIndex() - { - $searchModel = new PageSearch(); - $dataProvider = $searchModel->search(Yii::$app->request->queryParams); - - return $this->render('index', [ - 'searchModel' => $searchModel, - 'dataProvider' => $dataProvider, - ]); - } - - /** - * Displays a single Page model. - * @param integer $id - * @return mixed - */ - public function actionView($id) - { - return $this->render('view', [ - 'model' => $this->findModel($id), - ]); - } - - /** - * Creates a new Page model. - * If creation is successful, the browser will be redirected to the 'view' page. - * @return mixed - */ - public function actionCreate() - { - $model = new Page(); - - if ($model->load(Yii::$app->request->post()) && $model->save()) { - return $this->redirect(['view', 'id' => $model->id]); - } else { - return $this->render('create', [ - 'model' => $model, + 'verbs' => [ + 'class' => VerbFilter::className(), + 'actions' => [ + 'delete' => [ 'POST' ], + ], + ], + ]; + } + + /** + * Lists all Page models. + * @return mixed + */ + public function actionIndex() + { + $searchModel = new PageSearch(); + $dataProvider = $searchModel->search(Yii::$app->request->queryParams); + + return $this->render('index', [ + 'searchModel' => $searchModel, + 'dataProvider' => $dataProvider, ]); } - } - - /** - * Updates an existing Page model. - * If update is successful, the browser will be redirected to the 'view' page. - * @param integer $id - * @return mixed - */ - public function actionUpdate($id) - { - $model = $this->findModel($id); - - if ($model->load(Yii::$app->request->post()) && $model->save()) { - return $this->redirect(['view', 'id' => $model->id]); - } else { + + /** + * Displays a single Page model. + * + * @param integer $id + * + * @return mixed + */ + public function actionView($id) + { + return $this->render('view', [ + 'model' => $this->findModel($id), + ]); + } + + /** + * Creates a new Page model. + * If creation is successful, the browser will be redirected to the 'view' page. + * @return mixed + */ + public function actionCreate() + { + $model = new Page(); + $model_langs = $model->generateLangs(); + if($model->load(Yii::$app->request->post()) && $model->save()) { + $model->loadLangs(\Yii::$app->request, $model_langs); + if($model->linkLangs($model_langs) && $model->saveLangs($model_langs)) { + return $this->redirect([ + 'view', + 'id' => $model->id, + ]); + } else { + return $this->redirect([ + 'update', + 'id' => $model->id, + ]); + } + } else { + return $this->render('create', [ + 'model' => $model, + 'model_langs' => $model_langs, + ]); + } + } + + /** + * Updates an existing Page model. + * If update is successful, the browser will be redirected to the 'view' page. + * + * @param integer $id + * + * @return mixed + */ + public function actionUpdate($id) + { + $model = $this->findModel($id); + $model_langs = $model->generateLangs(); + + if($model->load(Yii::$app->request->post()) && $model->save()) { + $model->loadLangs(\Yii::$app->request, $model_langs); + if($model->linkLangs($model_langs) && $model->saveLangs($model_langs)) { + return $this->redirect([ + 'view', + 'id' => $model->id, + ]); + } + } return $this->render('update', [ - 'model' => $model, + 'model' => $model, + 'model_langs' => $model_langs, ]); } - } - - /** - * Deletes an existing Page model. - * If deletion is successful, the browser will be redirected to the 'index' page. - * @param integer $id - * @return mixed - */ - public function actionDelete($id) - { - $this->findModel($id)->delete(); - - return $this->redirect(['index']); - } - - /** - * Finds the Page model based on its primary key value. - * If the model is not found, a 404 HTTP exception will be thrown. - * @param integer $id - * @return Page the loaded model - * @throws NotFoundHttpException if the model cannot be found - */ - protected function findModel($id) - { - if (($model = Page::findOne($id)) !== null) { - return $model; - } else { - throw new NotFoundHttpException('The requested page does not exist.'); + + /** + * Deletes an existing Page model. + * If deletion is successful, the browser will be redirected to the 'index' page. + * + * @param integer $id + * + * @return mixed + */ + public function actionDelete($id) + { + $this->findModel($id) + ->delete(); + + return $this->redirect([ 'index' ]); + } + + /** + * Finds the Page model based on its primary key value. + * If the model is not found, a 404 HTTP exception will be thrown. + * + * @param integer $id + * + * @return Page the loaded model + * @throws NotFoundHttpException if the model cannot be found + */ + protected function findModel($id) + { + if(( $model = Page::findOne($id) ) !== NULL) { + return $model; + } else { + throw new NotFoundHttpException('The requested page does not exist.'); + } } } -} diff --git a/backend/controllers/ProjectController.php b/backend/controllers/ProjectController.php index 8623f4c..fc963cb 100644 --- a/backend/controllers/ProjectController.php +++ b/backend/controllers/ProjectController.php @@ -88,7 +88,9 @@ public function actionCreate() { $model = new Project(); + $model_langs = $model->generateLangs(); if($model->load(Yii::$app->request->post())) { + $model->loadLangs(\Yii::$app->request, $model_langs); $model->imagesUpload = UploadedFile::getInstances($model, 'imagesUpload'); if($model->save()) { if($model->imagesUpload && ( ( $images = $model->imagesUpload() ) !== false )) { @@ -99,14 +101,22 @@ $imageModel->save(); } } - return $this->redirect([ - 'view', - 'id' => $model->project_id, - ]); + if($model->linkLangs($model_langs) && $model->saveLangs($model_langs)) { + return $this->redirect([ + 'view', + 'id' => $model->project_id, + ]); + } else { + return $this->redirect([ + 'update', + 'id' => $model->project_id, + ]); + } } } return $this->render('create', [ - 'model' => $model, + 'model' => $model, + 'model_langs' => $model_langs, ]); } @@ -121,7 +131,9 @@ public function actionUpdate($id) { $model = $this->findModel($id); + $model_langs = $model->generateLangs(); if($model->load(Yii::$app->request->post())) { + $model->loadLangs(\Yii::$app->request, $model_langs); $model->imagesUpload = UploadedFile::getInstances($model, 'imagesUpload'); if($model->save()) { if($model->imagesUpload && ( ( $images = $model->imagesUpload() ) !== false )) { @@ -132,14 +144,17 @@ $imageModel->save(); } } - return $this->redirect([ - 'view', - 'id' => $model->project_id, - ]); + if($model->linkLangs($model_langs) && $model->saveLangs($model_langs)) { + return $this->redirect([ + 'view', + 'id' => $model->project_id, + ]); + } } } return $this->render('update', [ - 'model' => $model, + 'model' => $model, + 'model_langs' => $model_langs, ]); } @@ -275,13 +290,18 @@ public function actionProductDelete($product_to_project_id) { - $model = ProductToProject::find()->where(['product_to_project_id' => $product_to_project_id])->one(); - if(empty($model)) { + $model = ProductToProject::find() + ->where([ 'product_to_project_id' => $product_to_project_id ]) + ->one(); + if(empty( $model )) { throw new NotFoundHttpException(); } $project_id = $model->project_id; $model->delete(); - return $this->redirect(['project/product', 'id' => $project_id]); + return $this->redirect([ + 'project/product', + 'id' => $project_id, + ]); } public function actionGetVariants($product_id) diff --git a/backend/controllers/SeoCategoryController.php b/backend/controllers/SeoCategoryController.php index ea9046c..653d3f7 100644 --- a/backend/controllers/SeoCategoryController.php +++ b/backend/controllers/SeoCategoryController.php @@ -1,134 +1,166 @@ [ - 'class' => AccessBehavior::className(), - 'rules' => - ['site' => - [ + + /** + * @inheritdoc + */ + public function behaviors() + { + return [ + 'access' => [ + 'class' => AccessBehavior::className(), + 'rules' => [ + 'site' => [ [ - 'actions' => ['login', 'error'], - 'allow' => true, - ] - ] - ] - ], - 'verbs' => [ - 'class' => VerbFilter::className(), - - ], - ]; - } - - /** - * Lists all SeoCategory models. - * @return mixed - */ - public function actionIndex() - { - $searchModel = new SeoCategorySearch(); - $dataProvider = $searchModel->search(Yii::$app->request->queryParams); - - return $this->render('index', [ - 'searchModel' => $searchModel, - 'dataProvider' => $dataProvider, - ]); - } - - /** - * Displays a single SeoCategory model. - * @param integer $id - * @return mixed - */ - public function actionView($id) - { - return $this->render('view', [ - 'model' => $this->findModel($id), - ]); - } - - /** - * Creates a new SeoCategory model. - * If creation is successful, the browser will be redirected to the 'view' page. - * @return mixed - */ - public function actionCreate() - { - $model = new SeoCategory(); - - if ($model->load(Yii::$app->request->post()) && $model->save()) { - return $this->redirect(['view', 'id' => $model->seo_category_id]); - } else { - return $this->render('create', [ - 'model' => $model, + 'actions' => [ + 'login', + 'error', + ], + 'allow' => true, + ], + ], + ], + ], + 'verbs' => [ + 'class' => VerbFilter::className(), + + ], + ]; + } + + /** + * Lists all SeoCategory models. + * @return mixed + */ + public function actionIndex() + { + $searchModel = new SeoCategorySearch(); + $dataProvider = $searchModel->search(Yii::$app->request->queryParams); + + return $this->render('index', [ + 'searchModel' => $searchModel, + 'dataProvider' => $dataProvider, ]); } - } - - /** - * Updates an existing SeoCategory model. - * If update is successful, the browser will be redirected to the 'view' page. - * @param integer $id - * @return mixed - */ - public function actionUpdate($id) - { - $model = $this->findModel($id); - - if ($model->load(Yii::$app->request->post()) && $model->save()) { - return $this->redirect(['view', 'id' => $model->seo_category_id]); - } else { + + /** + * Displays a single SeoCategory model. + * + * @param integer $id + * + * @return mixed + */ + public function actionView($id) + { + return $this->render('view', [ + 'model' => $this->findModel($id), + ]); + } + + /** + * Creates a new SeoCategory model. + * If creation is successful, the browser will be redirected to the 'view' page. + * @return mixed + */ + public function actionCreate() + { + $model = new SeoCategory(); + $model_langs = $model->generateLangs(); + + if($model->load(Yii::$app->request->post()) && $model->save()) { + $model->loadLangs(\Yii::$app->request, $model_langs); + if($model->linkLangs($model_langs) && $model->saveLangs($model_langs)) { + return $this->redirect([ + 'view', + 'id' => $model->seo_category_id, + ]); + } else { + return $this->redirect([ + 'update', + 'id' => $model->seo_category_id, + ]); + } + } else { + return $this->render('create', [ + 'model' => $model, + 'model_langs' => $model_langs, + ]); + } + } + + /** + * Updates an existing SeoCategory model. + * If update is successful, the browser will be redirected to the 'view' page. + * + * @param integer $id + * + * @return mixed + */ + public function actionUpdate($id) + { + $model = $this->findModel($id); + $model_langs = $model->generateLangs(); + if($model->load(Yii::$app->request->post()) && $model->save()) { + $model->loadLangs(\Yii::$app->request, $model_langs); + if($model->linkLangs($model_langs) && $model->saveLangs($model_langs)) { + return $this->redirect([ + 'view', + 'id' => $model->seo_category_id, + ]); + } + } return $this->render('update', [ - 'model' => $model, + 'model' => $model, + 'model_langs' => $model_langs, ]); } - } - - /** - * Deletes an existing SeoCategory model. - * If deletion is successful, the browser will be redirected to the 'index' page. - * @param integer $id - * @return mixed - */ - public function actionDelete($id) - { - $this->findModel($id)->delete(); - - return $this->redirect(['index']); - } - - /** - * Finds the SeoCategory model based on its primary key value. - * If the model is not found, a 404 HTTP exception will be thrown. - * @param integer $id - * @return SeoCategory the loaded model - * @throws NotFoundHttpException if the model cannot be found - */ - protected function findModel($id) - { - if (($model = SeoCategory::findOne($id)) !== null) { - return $model; - } else { - throw new NotFoundHttpException('The requested page does not exist.'); + + /** + * Deletes an existing SeoCategory model. + * If deletion is successful, the browser will be redirected to the 'index' page. + * + * @param integer $id + * + * @return mixed + */ + public function actionDelete($id) + { + $this->findModel($id) + ->delete(); + + return $this->redirect([ 'index' ]); + } + + /** + * Finds the SeoCategory model based on its primary key value. + * If the model is not found, a 404 HTTP exception will be thrown. + * + * @param integer $id + * + * @return SeoCategory the loaded model + * @throws NotFoundHttpException if the model cannot be found + */ + protected function findModel($id) + { + if(( $model = SeoCategory::findOne($id) ) !== NULL) { + return $model; + } else { + throw new NotFoundHttpException('The requested page does not exist.'); + } } } -} diff --git a/backend/controllers/SeoController.php b/backend/controllers/SeoController.php index e3acfaf..ed5dfc2 100644 --- a/backend/controllers/SeoController.php +++ b/backend/controllers/SeoController.php @@ -1,134 +1,166 @@ [ - 'class' => AccessBehavior::className(), - 'rules' => - ['site' => - [ + + /** + * @inheritdoc + */ + public function behaviors() + { + return [ + 'access' => [ + 'class' => AccessBehavior::className(), + 'rules' => [ + 'site' => [ [ - 'actions' => ['login', 'error'], - 'allow' => true, - ] - ] - ] - ], - 'verbs' => [ - 'class' => VerbFilter::className(), - - ], - ]; - } - - /** - * Lists all Seo models. - * @return mixed - */ - public function actionIndex() - { - $searchModel = new SeoSearch(); - $dataProvider = $searchModel->search(Yii::$app->request->queryParams); - - return $this->render('index', [ - 'searchModel' => $searchModel, - 'dataProvider' => $dataProvider, - ]); - } - - /** - * Displays a single Seo model. - * @param integer $id - * @return mixed - */ - public function actionView($id) - { - return $this->render('view', [ - 'model' => $this->findModel($id), - ]); - } - - /** - * Creates a new Seo model. - * If creation is successful, the browser will be redirected to the 'view' page. - * @return mixed - */ - public function actionCreate() - { - $model = new Seo(); - - if ($model->load(Yii::$app->request->post()) && $model->save()) { - return $this->redirect(['view', 'id' => $model->seo_id]); - } else { - return $this->render('create', [ - 'model' => $model, + 'actions' => [ + 'login', + 'error', + ], + 'allow' => true, + ], + ], + ], + ], + 'verbs' => [ + 'class' => VerbFilter::className(), + + ], + ]; + } + + /** + * Lists all Seo models. + * @return mixed + */ + public function actionIndex() + { + $searchModel = new SeoSearch(); + $dataProvider = $searchModel->search(Yii::$app->request->queryParams); + + return $this->render('index', [ + 'searchModel' => $searchModel, + 'dataProvider' => $dataProvider, ]); } - } - - /** - * Updates an existing Seo model. - * If update is successful, the browser will be redirected to the 'view' page. - * @param integer $id - * @return mixed - */ - public function actionUpdate($id) - { - $model = $this->findModel($id); - - if ($model->load(Yii::$app->request->post()) && $model->save()) { - return $this->redirect(['view', 'id' => $model->seo_id]); - } else { + + /** + * Displays a single Seo model. + * + * @param integer $id + * + * @return mixed + */ + public function actionView($id) + { + return $this->render('view', [ + 'model' => $this->findModel($id), + ]); + } + + /** + * Creates a new Seo model. + * If creation is successful, the browser will be redirected to the 'view' page. + * @return mixed + */ + public function actionCreate() + { + $model = new Seo(); + $model_langs = $model->generateLangs(); + + if($model->load(Yii::$app->request->post()) && $model->save()) { + $model->loadLangs(\Yii::$app->request, $model_langs); + if($model->linkLangs($model_langs) && $model->saveLangs($model_langs)) { + return $this->redirect([ + 'view', + 'id' => $model->seo_id, + ]); + } else { + return $this->redirect([ + 'update', + 'id' => $model->seo_id, + ]); + } + } else { + return $this->render('create', [ + 'model' => $model, + 'model_langs' => $model_langs, + ]); + } + } + + /** + * Updates an existing Seo model. + * If update is successful, the browser will be redirected to the 'view' page. + * + * @param integer $id + * + * @return mixed + */ + public function actionUpdate($id) + { + $model = $this->findModel($id); + $model_langs = $model->generateLangs(); + if($model->load(Yii::$app->request->post()) && $model->save()) { + $model->loadLangs(\Yii::$app->request, $model_langs); + if($model->linkLangs($model_langs) && $model->saveLangs($model_langs)) { + return $this->redirect([ + 'view', + 'id' => $model->seo_id, + ]); + } + } return $this->render('update', [ - 'model' => $model, + 'model' => $model, + 'model_langs' => $model_langs, ]); } - } - - /** - * Deletes an existing Seo model. - * If deletion is successful, the browser will be redirected to the 'index' page. - * @param integer $id - * @return mixed - */ - public function actionDelete($id) - { - $this->findModel($id)->delete(); - - return $this->redirect(['index']); - } - - /** - * Finds the Seo model based on its primary key value. - * If the model is not found, a 404 HTTP exception will be thrown. - * @param integer $id - * @return Seo the loaded model - * @throws NotFoundHttpException if the model cannot be found - */ - protected function findModel($id) - { - if (($model = Seo::findOne($id)) !== null) { - return $model; - } else { - throw new NotFoundHttpException('The requested page does not exist.'); + + /** + * Deletes an existing Seo model. + * If deletion is successful, the browser will be redirected to the 'index' page. + * + * @param integer $id + * + * @return mixed + */ + public function actionDelete($id) + { + $this->findModel($id) + ->delete(); + + return $this->redirect([ 'index' ]); + } + + /** + * Finds the Seo model based on its primary key value. + * If the model is not found, a 404 HTTP exception will be thrown. + * + * @param integer $id + * + * @return Seo the loaded model + * @throws NotFoundHttpException if the model cannot be found + */ + protected function findModel($id) + { + if(( $model = Seo::findOne($id) ) !== NULL) { + return $model; + } else { + throw new NotFoundHttpException('The requested page does not exist.'); + } } } -} diff --git a/backend/controllers/SeoDynamicController.php b/backend/controllers/SeoDynamicController.php index 54c4162..475da29 100644 --- a/backend/controllers/SeoDynamicController.php +++ b/backend/controllers/SeoDynamicController.php @@ -1,140 +1,176 @@ [ - 'class' => AccessBehavior::className(), - 'rules' => - ['site' => - [ + + /** + * @inheritdoc + */ + public function behaviors() + { + return [ + 'access' => [ + 'class' => AccessBehavior::className(), + 'rules' => [ + 'site' => [ [ - 'actions' => ['login', 'error'], - 'allow' => true, - ] - ] - ] - ], - 'verbs' => [ - 'class' => VerbFilter::className(), - - ], - ]; - } - - /** - * Lists all SeoDynamic models. - * @return mixed - */ - public function actionIndex($seo_category_id) - { - $searchModel = new SeoDynamicSearch(); - $dataProvider = $searchModel->search($seo_category_id,Yii::$app->request->queryParams); - - return $this->render('index', [ - 'searchModel' => $searchModel, - 'dataProvider' => $dataProvider, - 'seo_category_id' => $seo_category_id - ]); - } - - /** - * Displays a single SeoDynamic model. - * @param integer $id - * @return mixed - */ - public function actionView($seo_category_id, $id) - { - return $this->render('view', [ - 'model' => $this->findModel($id), - 'seo_category_id' => $seo_category_id - ]); - } - - /** - * Creates a new SeoDynamic model. - * If creation is successful, the browser will be redirected to the 'view' page. - * @return mixed - */ - public function actionCreate($seo_category_id) - { - $model = new SeoDynamic(); - - if ($model->load(Yii::$app->request->post())) { - $model->seo_category_id = $seo_category_id; - $model->save(); - return $this->redirect(['index', 'seo_category_id' => $model->seo_category_id]); - } else { - return $this->render('create', [ - 'model' => $model, - 'seo_category_id' => $seo_category_id + 'actions' => [ + 'login', + 'error', + ], + 'allow' => true, + ], + ], + ], + ], + 'verbs' => [ + 'class' => VerbFilter::className(), + + ], + ]; + } + + /** + * Lists all SeoDynamic models. + * @return mixed + */ + public function actionIndex($seo_category_id) + { + $searchModel = new SeoDynamicSearch(); + $dataProvider = $searchModel->search($seo_category_id, Yii::$app->request->queryParams); + + return $this->render('index', [ + 'searchModel' => $searchModel, + 'dataProvider' => $dataProvider, + 'seo_category_id' => $seo_category_id, ]); } - } - - /** - * Updates an existing SeoDynamic model. - * If update is successful, the browser will be redirected to the 'view' page. - * @param integer $id - * @return mixed - */ - public function actionUpdate($seo_category_id,$id) - { - $model = $this->findModel($id); - - if ($model->load(Yii::$app->request->post()) && $model->save()) { - return $this->redirect(['index', 'seo_category_id' => $model->seo_category_id]); - } else { + + /** + * Displays a single SeoDynamic model. + * + * @param integer $id + * + * @return mixed + */ + public function actionView($seo_category_id, $id) + { + return $this->render('view', [ + 'model' => $this->findModel($id), + 'seo_category_id' => $seo_category_id, + ]); + } + + /** + * Creates a new SeoDynamic model. + * If creation is successful, the browser will be redirected to the 'view' page. + * @return mixed + */ + public function actionCreate($seo_category_id) + { + $model = new SeoDynamic(); + $model_langs = $model->generateLangs(); + + if($model->load(Yii::$app->request->post())) { + $model->loadLangs(\Yii::$app->request, $model_langs); + $model->seo_category_id = $seo_category_id; + $model->save(); + if($model->linkLangs($model_langs) && $model->saveLangs($model_langs)) { + return $this->redirect([ + 'index', + 'seo_category_id' => $model->seo_category_id, + ]); + } else { + return $this->redirect([ + 'update', + 'seo_category_id' => $model->seo_category_id, + 'id' => $model->seo_dynamic_id, + ]); + } + } else { + return $this->render('create', [ + 'model' => $model, + 'model_langs' => $model_langs, + 'seo_category_id' => $seo_category_id, + ]); + } + } + + /** + * Updates an existing SeoDynamic model. + * If update is successful, the browser will be redirected to the 'view' page. + * + * @param integer $id + * + * @return mixed + */ + public function actionUpdate($seo_category_id, $id) + { + $model = $this->findModel($id); + $model_langs = $model->generateLangs(); + if($model->load(Yii::$app->request->post()) && $model->save()) { + $model->loadLangs(\Yii::$app->request, $model_langs); + if($model->linkLangs($model_langs) && $model->saveLangs($model_langs)) { + return $this->redirect([ + 'index', + 'seo_category_id' => $model->seo_category_id, + ]); + } + } return $this->render('update', [ - 'model' => $model, - 'seo_category_id' => $seo_category_id + 'model' => $model, + 'model_langs' => $model_langs, + 'seo_category_id' => $seo_category_id, ]); } - } - - /** - * Deletes an existing SeoDynamic model. - * If deletion is successful, the browser will be redirected to the 'index' page. - * @param integer $id - * @return mixed - */ - public function actionDelete($seo_category_id,$id) - { - $this->findModel($id)->delete(); - - return $this->redirect(['index','seo_category_id'=> $seo_category_id]); - } - - /** - * Finds the SeoDynamic model based on its primary key value. - * If the model is not found, a 404 HTTP exception will be thrown. - * @param integer $id - * @return SeoDynamic the loaded model - * @throws NotFoundHttpException if the model cannot be found - */ - protected function findModel($id) - { - if (($model = SeoDynamic::findOne($id)) !== null) { - return $model; - } else { - throw new NotFoundHttpException('The requested page does not exist.'); + + /** + * Deletes an existing SeoDynamic model. + * If deletion is successful, the browser will be redirected to the 'index' page. + * + * @param integer $id + * + * @return mixed + */ + public function actionDelete($seo_category_id, $id) + { + $this->findModel($id) + ->delete(); + + return $this->redirect([ + 'index', + 'seo_category_id' => $seo_category_id, + ]); + } + + /** + * Finds the SeoDynamic model based on its primary key value. + * If the model is not found, a 404 HTTP exception will be thrown. + * + * @param integer $id + * + * @return SeoDynamic the loaded model + * @throws NotFoundHttpException if the model cannot be found + */ + protected function findModel($id) + { + if(( $model = SeoDynamic::findOne($id) ) !== NULL) { + return $model; + } else { + throw new NotFoundHttpException('The requested page does not exist.'); + } } } -} diff --git a/backend/controllers/ServiceController.php b/backend/controllers/ServiceController.php index 4f199de..64497b7 100644 --- a/backend/controllers/ServiceController.php +++ b/backend/controllers/ServiceController.php @@ -1,136 +1,169 @@ [ - 'class' => AccessBehavior::className(), - 'rules' => - ['site' => - [ + + /** + * @inheritdoc + */ + public function behaviors() + { + return [ + 'access' => [ + 'class' => AccessBehavior::className(), + 'rules' => [ + 'site' => [ [ - 'actions' => ['login', 'error'], - 'allow' => true, - ] - ] - ] - ], - 'verbs' => [ - 'class' => VerbFilter::className(), - 'actions' => [ - 'delete' => ['POST'], + 'actions' => [ + 'login', + 'error', + ], + 'allow' => true, + ], + ], + ], ], - ], - ]; - } - - /** - * Lists all Service models. - * @return mixed - */ - public function actionIndex() - { - $searchModel = new ServiceSearch(); - $dataProvider = $searchModel->search(Yii::$app->request->queryParams); - - return $this->render('index', [ - 'searchModel' => $searchModel, - 'dataProvider' => $dataProvider, - ]); - } - - /** - * Displays a single Service model. - * @param integer $id - * @return mixed - */ - public function actionView($id) - { - return $this->render('view', [ - 'model' => $this->findModel($id), - ]); - } - - /** - * Creates a new Service model. - * If creation is successful, the browser will be redirected to the 'view' page. - * @return mixed - */ - public function actionCreate() - { - $model = new Service(); - - if ($model->load(Yii::$app->request->post()) && $model->save()) { - return $this->redirect(['view', 'id' => $model->service_id]); - } else { - return $this->render('create', [ - 'model' => $model, + 'verbs' => [ + 'class' => VerbFilter::className(), + 'actions' => [ + 'delete' => [ 'POST' ], + ], + ], + ]; + } + + /** + * Lists all Service models. + * @return mixed + */ + public function actionIndex() + { + $searchModel = new ServiceSearch(); + $dataProvider = $searchModel->search(Yii::$app->request->queryParams); + + return $this->render('index', [ + 'searchModel' => $searchModel, + 'dataProvider' => $dataProvider, ]); } - } - - /** - * Updates an existing Service model. - * If update is successful, the browser will be redirected to the 'view' page. - * @param integer $id - * @return mixed - */ - public function actionUpdate($id) - { - $model = $this->findModel($id); - - if ($model->load(Yii::$app->request->post()) && $model->save()) { - return $this->redirect(['view', 'id' => $model->service_id]); - } else { + + /** + * Displays a single Service model. + * + * @param integer $id + * + * @return mixed + */ + public function actionView($id) + { + return $this->render('view', [ + 'model' => $this->findModel($id), + ]); + } + + /** + * Creates a new Service model. + * If creation is successful, the browser will be redirected to the 'view' page. + * @return mixed + */ + public function actionCreate() + { + $model = new Service(); + $model_langs = $model->generateLangs(); + + if($model->load(Yii::$app->request->post()) && $model->save()) { + $model->loadLangs(\Yii::$app->request, $model_langs); + if($model->linkLangs($model_langs) && $model->saveLangs($model_langs)) { + return $this->redirect([ + 'view', + 'id' => $model->service_id, + ]); + } else { + return $this->redirect([ + 'update', + 'id' => $model->service_id, + ]); + } + } else { + return $this->render('create', [ + 'model' => $model, + 'model_langs' => $model_langs, + ]); + } + } + + /** + * Updates an existing Service model. + * If update is successful, the browser will be redirected to the 'view' page. + * + * @param integer $id + * + * @return mixed + */ + public function actionUpdate($id) + { + $model = $this->findModel($id); + $model_langs = $model->generateLangs(); + + if($model->load(Yii::$app->request->post()) && $model->save()) { + $model->loadLangs(\Yii::$app->request, $model_langs); + if($model->linkLangs($model_langs) && $model->saveLangs($model_langs)) { + return $this->redirect([ + 'view', + 'id' => $model->service_id, + ]); + } + } return $this->render('update', [ 'model' => $model, + 'model_langs' => $model_langs, ]); } - } - - /** - * Deletes an existing Service model. - * If deletion is successful, the browser will be redirected to the 'index' page. - * @param integer $id - * @return mixed - */ - public function actionDelete($id) - { - $this->findModel($id)->delete(); - - return $this->redirect(['index']); - } - - /** - * Finds the Service model based on its primary key value. - * If the model is not found, a 404 HTTP exception will be thrown. - * @param integer $id - * @return Service the loaded model - * @throws NotFoundHttpException if the model cannot be found - */ - protected function findModel($id) - { - if (($model = Service::findOne($id)) !== null) { - return $model; - } else { - throw new NotFoundHttpException('The requested page does not exist.'); + + /** + * Deletes an existing Service model. + * If deletion is successful, the browser will be redirected to the 'index' page. + * + * @param integer $id + * + * @return mixed + */ + public function actionDelete($id) + { + $this->findModel($id) + ->delete(); + + return $this->redirect([ 'index' ]); + } + + /** + * Finds the Service model based on its primary key value. + * If the model is not found, a 404 HTTP exception will be thrown. + * + * @param integer $id + * + * @return Service the loaded model + * @throws NotFoundHttpException if the model cannot be found + */ + protected function findModel($id) + { + if(( $model = Service::findOne($id) ) !== NULL) { + return $model; + } else { + throw new NotFoundHttpException('The requested page does not exist.'); + } } } -} diff --git a/backend/controllers/SliderImageController.php b/backend/controllers/SliderImageController.php index 4459f8a..675daa1 100644 --- a/backend/controllers/SliderImageController.php +++ b/backend/controllers/SliderImageController.php @@ -1,173 +1,226 @@ [ - 'class' => AccessBehavior::className(), - 'rules' => - ['site' => - [ + + /** + * @inheritdoc + */ + public function behaviors() + { + return [ + 'access' => [ + 'class' => AccessBehavior::className(), + 'rules' => [ + 'site' => [ [ - 'actions' => ['login', 'error'], - 'allow' => true, - ] - ] - ] - ], - 'verbs' => [ - 'class' => VerbFilter::className(), - 'actions' => [ - 'delete' => ['POST'], + 'actions' => [ + 'login', + 'error', + ], + 'allow' => true, + ], + ], + ], ], - ], - ]; - } - - /** - * Lists all SliderImage models. - * @param $slider_id Slider id - * @return mixed - */ - public function actionIndex($slider_id) - { - $searchModel = new SliderImageSearch(); - $dataProvider = $searchModel->search($slider_id, Yii::$app->request->queryParams); - - return $this->render('index', [ - 'slider_id' => $slider_id, - 'searchModel' => $searchModel, - 'dataProvider' => $dataProvider, - ]); - } - - /** - * Displays a single SliderImage model. - * @param integer $id - * @param $slider_id Slider id - * @return mixed - */ - public function actionView($slider_id, $id) - { - return $this->render('view', [ - 'slider_id' => $slider_id, - 'model' => $this->findModel($slider_id, $id), - ]); - } - - /** - * Creates a new SliderImage model. - * If creation is successful, the browser will be redirected to the 'view' page. - * @param $slider_id Slider id - * @return mixed - */ - public function actionCreate($slider_id) - { - $model = new SliderImage(); - if ($model->load(Yii::$app->request->post())) { - $model->slider_id = $slider_id; - if ( ($image = UploadedFile::getInstance($model, 'image')) ) { - $model->image = $image->name; - } - if ($model->save() && $image) { - $imgDir = Yii::getAlias('@storage/slider/'); - if(!is_dir($imgDir)) { - mkdir($imgDir, 0755, true); - } - $image->saveAs(Yii::getAlias('@storage/slider/' . $image->name)); - } - return $this->redirect(['view', 'slider_id'=>$slider_id, 'id' => $model->slider_image_id]); - } else { - $slider = Slider::findOne($slider_id); - return $this->render('create', [ + 'verbs' => [ + 'class' => VerbFilter::className(), + 'actions' => [ + 'delete' => [ 'POST' ], + ], + ], + ]; + } + + /** + * Lists all SliderImage models. + * + * @param $slider_id Slider id + * + * @return mixed + */ + public function actionIndex($slider_id) + { + $searchModel = new SliderImageSearch(); + $dataProvider = $searchModel->search($slider_id, Yii::$app->request->queryParams); + + return $this->render('index', [ + 'slider_id' => $slider_id, + 'searchModel' => $searchModel, + 'dataProvider' => $dataProvider, + ]); + } + + /** + * Displays a single SliderImage model. + * + * @param integer $id + * @param $slider_id Slider id + * + * @return mixed + */ + public function actionView($slider_id, $id) + { + return $this->render('view', [ 'slider_id' => $slider_id, - 'model' => $model, - 'slider' => $slider, + 'model' => $this->findModel($slider_id, $id), ]); } - } - - /** - * Updates an existing SliderImage model. - * If update is successful, the browser will be redirected to the 'view' page. - * @param $slider_id Slider id - * @param integer $id - * @return mixed - */ - public function actionUpdate($slider_id, $id) - { - $model = $this->findModel($slider_id, $id); - if ($model->load(Yii::$app->request->post())) { - if ( ($image = UploadedFile::getInstance($model, 'image')) ) { - $model->image = $image->name; - } - if(!$model->image){ - $model->image = $model->getOldAttribute('image'); + + /** + * Creates a new SliderImage model. + * If creation is successful, the browser will be redirected to the 'view' page. + * + * @param $slider_id Slider id + * + * @return mixed + */ + public function actionCreate($slider_id) + { + $model = new SliderImage(); + $model_langs = $model->generateLangs(); + if($model->load(Yii::$app->request->post())) { + $model->loadLangs(\Yii::$app->request, $model_langs); + $model->slider_id = $slider_id; + if(( $image = UploadedFile::getInstance($model, 'image') )) { + $model->image = $image->name; + } + if($model->save() && $image) { + $imgDir = Yii::getAlias('@storage/slider/'); + if(!is_dir($imgDir)) { + mkdir($imgDir, 0755, true); + } + $image->saveAs(Yii::getAlias('@storage/slider/' . $image->name)); + } + if($model->linkLangs($model_langs) && $model->saveLangs($model_langs)) { + return $this->redirect([ + 'view', + 'slider_id' => $slider_id, + 'id' => $model->slider_image_id, + ]); + } else { + return $this->redirect([ + 'update', + 'slider_id' => $slider_id, + 'id' => $model->slider_image_id, + ]); + } + } else { + $slider = Slider::findOne($slider_id); + return $this->render('create', [ + 'slider_id' => $slider_id, + 'model' => $model, + 'model_langs' => $model_langs, + 'slider' => $slider, + ]); } - if ($model->save() && $image) { - $imgDir = Yii::getAlias('@storage/slider/'); - if(!is_dir($imgDir)) { - mkdir($imgDir, 0755, true); + } + + /** + * Updates an existing SliderImage model. + * If update is successful, the browser will be redirected to the 'view' page. + * + * @param $slider_id Slider id + * @param integer $id + * + * @return mixed + */ + public function actionUpdate($slider_id, $id) + { + $model = $this->findModel($slider_id, $id); + $model_langs = $model->generateLangs(); + if($model->load(Yii::$app->request->post())) { + $model->loadLangs(\Yii::$app->request, $model_langs); + if(( $image = UploadedFile::getInstance($model, 'image') )) { + $model->image = $image->name; + } + if(!$model->image) { + $model->image = $model->getOldAttribute('image'); + } + if($model->save() && $image) { + $imgDir = Yii::getAlias('@storage/slider/'); + if(!is_dir($imgDir)) { + mkdir($imgDir, 0755, true); + } + $image->saveAs(Yii::getAlias('@storage/slider/' . $image->name)); + } + if($model->linkLangs($model_langs) && $model->saveLangs($model_langs)) { + return $this->redirect([ + 'view', + 'slider_id' => $slider_id, + 'id' => $model->slider_image_id, + ]); } - $image->saveAs(Yii::getAlias('@storage/slider/' . $image->name)); } - return $this->redirect(['view', 'slider_id'=>$slider_id, 'id' => $model->slider_image_id]); - } else { $slider = Slider::findOne($slider_id); return $this->render('update', [ - 'model' => $model, + 'model' => $model, + 'model_langs' => $model_langs, + 'slider_id' => $slider_id, + 'slider' => $slider, + ]); + } + + /** + * Deletes an existing SliderImage model. + * If deletion is successful, the browser will be redirected to the 'index' page. + * + * @param $slider_id Slider id + * @param integer $id + * + * @return mixed + */ + public function actionDelete($slider_id, $id) + { + $this->findModel($slider_id, $id) + ->delete(); + + return $this->redirect([ + 'index', 'slider_id' => $slider_id, - 'slider' => $slider, ]); } - } - - /** - * Deletes an existing SliderImage model. - * If deletion is successful, the browser will be redirected to the 'index' page. - * @param $slider_id Slider id - * @param integer $id - * @return mixed - */ - public function actionDelete($slider_id, $id) - { - $this->findModel($slider_id, $id)->delete(); - - return $this->redirect(['index','slider_id'=>$slider_id]); - } - - /** - * Finds the SliderImage model based on its primary key value. - * If the model is not found, a 404 HTTP exception will be thrown. - * @param $slider_id Slider id - * @param integer $id - * @return SliderImage the loaded model - * @throws NotFoundHttpException if the model cannot be found - */ - protected function findModel($slider_id,$id) - { - if (($model = SliderImage::find()->where(['slider_image_id'=> $id, 'slider_id'=>$slider_id])->one()) !== null) { - return $model; - } else { - throw new NotFoundHttpException('The requested page does not exist.'); + + /** + * Finds the SliderImage model based on its primary key value. + * If the model is not found, a 404 HTTP exception will be thrown. + * + * @param $slider_id Slider id + * @param integer $id + * + * @return SliderImage the loaded model + * @throws NotFoundHttpException if the model cannot be found + */ + protected function findModel($slider_id, $id) + { + /** + * @var SliderImage $model + */ + if(( $model = SliderImage::find() + ->where([ + 'slider_image_id' => $id, + 'slider_id' => $slider_id, + ]) + ->one() ) !== NULL + ) { + return $model; + } else { + throw new NotFoundHttpException('The requested page does not exist.'); + } } } -} diff --git a/backend/models/Label.php b/backend/models/Label.php index 8e75a40..bcf0b24 100644 --- a/backend/models/Label.php +++ b/backend/models/Label.php @@ -2,6 +2,32 @@ namespace backend\models; +use common\modules\language\behaviors\LanguageBehavior; +use yii\db\ActiveQuery; +use yii\db\ActiveRecord; +use yii\web\Request; + +/** + * Class Label + * + * * From language behavior * + * @property {TableLang} $lang + * @property {TableLang}[] $langs + * @property {TableLang} $object_lang + * @property string $ownerKey + * @property string $langKey + * @method string getOwnerKey() + * @method void setOwnerKey(string $value) + * @method string getLangKey() + * @method void setLangKey(string $value) + * @method ActiveQuery getLangs() + * @method ActiveQuery getLang( integer $language_id ) + * @method {TableLang}[] generateLangs() + * @method void loadLangs(Request $request, ActiveRecord[] $model_langs) + * @method bool linkLangs(ActiveRecord[] $model_langs) + * @method bool saveLangs(ActiveRecord[] $model_langs) + * * End language behavior * + */ class Label extends \yii\db\ActiveRecord { @@ -10,7 +36,16 @@ class Label extends \yii\db\ActiveRecord return 'orders_label'; } - public function getNl(){ + public function behaviors() + { + return [ + 'language' => [ + 'class' => LanguageBehavior::className(), + ], + ]; + } + + public function getNl(){ return $this->name; } } diff --git a/backend/models/OrdersLabelLang.php b/backend/models/OrdersLabelLang.php new file mode 100644 index 0000000..afad50f --- /dev/null +++ b/backend/models/OrdersLabelLang.php @@ -0,0 +1,78 @@ + 255], + [['orders_label_id', 'language_id'], 'unique', 'targetAttribute' => ['orders_label_id', 'language_id'], 'message' => 'The combination of Orders Label ID and Language ID has already been taken.'], + [['language_id'], 'exist', 'skipOnError' => true, 'targetClass' => Language::className(), 'targetAttribute' => ['language_id' => 'language_id']], + [['orders_label_id'], 'exist', 'skipOnError' => true, 'targetClass' => OrdersLabel::className(), 'targetAttribute' => ['orders_label_id' => 'id']], + ]; + } + + /** + * @inheritdoc + */ + public function attributeLabels() + { + return [ + 'orders_label_id' => Yii::t('app', 'Orders Label ID'), + 'language_id' => Yii::t('app', 'Language ID'), + 'name' => Yii::t('app', 'Name'), + ]; + } + + /** + * @return \yii\db\ActiveQuery + */ + public function getLanguage() + { + return $this->hasOne(Language::className(), ['language_id' => 'language_id']); + } + + /** + * @return \yii\db\ActiveQuery + */ + public function getLabel() + { + return $this->hasOne(Label::className(), ['id' => 'orders_label_id']); + } +} diff --git a/backend/views/articles/_form.php b/backend/views/articles/_form.php index db5386a..b615fbb 100644 --- a/backend/views/articles/_form.php +++ b/backend/views/articles/_form.php @@ -1,82 +1,108 @@
- + false, - 'options' => ['enctype' => 'multipart/form-data'] + 'options' => [ 'enctype' => 'multipart/form-data' ], ]); ?> - - + + field($model, 'date') - ->widget(DatePicker::className(), [ - 'dateFormat' => 'dd-MM-yyyy', - ]) ?> - field($model, 'title')->textInput(['maxlength' => true]) ?> - - field($model, 'body')->widget(CKEditor::className(), - [ - 'editorOptions' => ElFinder::ckeditorOptions('elfinder',[ - 'preset' => 'full', //разработанны стандартные настройки basic, standard, full данную возможность не обязательно использовать - 'inline' => false, //по умолчанию false]), - 'filebrowserUploadUrl'=>Yii::$app->getUrlManager()->createUrl('file/uploader/images-upload') - ] - ) - ]) ?> - - field($model, 'body_preview')->widget(CKEditor::className(), - [ - 'editorOptions' => ElFinder::ckeditorOptions('elfinder',[ - 'preset' => 'full', //разработанны стандартные настройки basic, standard, full данную возможность не обязательно использовать - 'inline' => false, //по умолчанию false]), - 'filebrowserUploadUrl'=>Yii::$app->getUrlManager()->createUrl('file/uploader/images-upload') - ] - ) - ]) ?> - - field($model, 'image')->widget(\kartik\file\FileInput::classname(), [ - 'language' => 'ru', - 'options' => [ - 'accept' => 'image/*', - 'multiple' => false, - ], - 'pluginOptions' => [ - 'allowedFileExtensions' => ['jpg', 'gif', 'png'], - 'initialPreview' => !empty($model->imageUrl) ? \common\components\artboximage\ArtboxImageHelper::getImage($model->imageUrl, 'list') : '', - 'overwriteInitial' => true, - 'showRemove' => false, - 'showUpload' => false, - 'previewFileType' => 'image', - ], - ]); ?> - - field($model, 'translit')->textInput(['maxlength' => true]) ?> - - field($model, 'meta_title')->textInput(['maxlength' => true]) ?> - - field($model, 'meta_keywords')->textInput(['maxlength' => true]) ?> - - field($model, 'meta_description')->textInput(['maxlength' => true]) ?> - - field($model, 'seo_text')->textarea(['rows' => 6]) ?> - - field($model, 'h1')->textInput(['maxlength' => true]) ?> - + ->widget(DatePicker::className(), [ + 'dateFormat' => 'dd-MM-yyyy', + ]) ?> + field($model, 'title') + ->textInput([ 'maxlength' => true ]) ?> + + field($model, 'body') + ->widget(CKEditor::className(), [ + 'editorOptions' => ElFinder::ckeditorOptions('elfinder', [ + 'preset' => 'full', + 'inline' => false, + 'filebrowserUploadUrl' => Yii::$app->getUrlManager() + ->createUrl('file/uploader/images-upload'), + ]), + ]) ?> + + field($model, 'body_preview') + ->widget(CKEditor::className(), [ + 'editorOptions' => ElFinder::ckeditorOptions('elfinder', [ + 'preset' => 'full', + 'inline' => false, + 'filebrowserUploadUrl' => Yii::$app->getUrlManager() + ->createUrl('file/uploader/images-upload'), + ]), + ]) ?> + + field($model, 'image') + ->widget(\kartik\file\FileInput::classname(), [ + 'language' => 'ru', + 'options' => [ + 'accept' => 'image/*', + 'multiple' => false, + ], + 'pluginOptions' => [ + 'allowedFileExtensions' => [ + 'jpg', + 'gif', + 'png', + ], + 'initialPreview' => !empty( $model->imageUrl ) ? \common\components\artboximage\ArtboxImageHelper::getImage($model->imageUrl, 'list') : '', + 'overwriteInitial' => true, + 'showRemove' => false, + 'showUpload' => false, + 'previewFileType' => 'image', + ], + ]); ?> + + field($model, 'translit') + ->textInput([ 'maxlength' => true ]) ?> + + field($model, 'meta_title') + ->textInput([ 'maxlength' => true ]) ?> + + field($model, 'meta_keywords') + ->textInput([ 'maxlength' => true ]) ?> + + field($model, 'meta_description') + ->textInput([ 'maxlength' => true ]) ?> + + field($model, 'seo_text') + ->textarea([ 'rows' => 6 ]) ?> + + field($model, 'h1') + ->textInput([ 'maxlength' => true ]) ?> + + $model_langs, + 'formView' => '@backend/views/articles/_form_language', + 'form' => $form, + ]); + ?> +
- isNewRecord ? 'Create' : 'Update', ['class' => $model->isNewRecord ? 'btn btn-success' : 'btn btn-primary']) ?> + isNewRecord ? 'Create' : 'Update', [ 'class' => $model->isNewRecord ? 'btn btn-success' : 'btn btn-primary' ]) ?>
- +
diff --git a/backend/views/articles/_form_language.php b/backend/views/articles/_form_language.php new file mode 100644 index 0000000..9f280fa --- /dev/null +++ b/backend/views/articles/_form_language.php @@ -0,0 +1,51 @@ + +field($model_lang, '[' . $language->language_id . ']title') + ->textInput([ 'maxlength' => true ]); ?> +field($model_lang, '[' . $language->language_id . ']body') + ->widget(CKEditor::className(), [ + 'editorOptions' => ElFinder::ckeditorOptions('elfinder', [ + 'preset' => 'full', + 'inline' => false, + 'filebrowserUploadUrl' => Yii::$app->getUrlManager() + ->createUrl('file/uploader/images-upload'), + ]), + ]) ?> + +field($model_lang, '[' . $language->language_id . ']body_preview') + ->widget(CKEditor::className(), [ + 'editorOptions' => ElFinder::ckeditorOptions('elfinder', [ + 'preset' => 'full', + 'inline' => false, + 'filebrowserUploadUrl' => Yii::$app->getUrlManager() + ->createUrl('file/uploader/images-upload'), + ]), + ]) ?> + +field($model_lang, '[' . $language->language_id . ']meta_title') + ->textInput([ 'maxlength' => true ]) ?> + +field($model_lang, '[' . $language->language_id . ']meta_keywords') + ->textInput([ 'maxlength' => true ]) ?> + +field($model_lang, '[' . $language->language_id . ']meta_description') + ->textInput([ 'maxlength' => true ]) ?> + +field($model_lang, '[' . $language->language_id . ']seo_text') + ->textarea([ 'rows' => 6 ]) ?> + +field($model_lang, '[' . $language->language_id . ']h1') + ->textInput([ 'maxlength' => true ]) ?> diff --git a/backend/views/articles/create.php b/backend/views/articles/create.php index 3129639..33777c0 100644 --- a/backend/views/articles/create.php +++ b/backend/views/articles/create.php @@ -1,21 +1,28 @@ title = 'Create Articles'; -$this->params['breadcrumbs'][] = ['label' => 'Articles', 'url' => ['index']]; -$this->params['breadcrumbs'][] = $this->title; + use common\models\Articles; + use common\models\ArticlesLang; + use yii\helpers\Html; + use yii\web\View; + + /** + * @var View $this + * @var Articles $model + * @var ArticlesLang[] $model_langs + */ + $this->title = 'Create Articles'; + $this->params[ 'breadcrumbs' ][] = [ + 'label' => 'Articles', + 'url' => [ 'index' ], + ]; + $this->params[ 'breadcrumbs' ][] = $this->title; ?>
- +

title) ?>

- + render('_form', [ - 'model' => $model, + 'model' => $model, + 'model_langs' => $model_langs, ]) ?>
diff --git a/backend/views/articles/update.php b/backend/views/articles/update.php index a30c97d..5c7a71c 100644 --- a/backend/views/articles/update.php +++ b/backend/views/articles/update.php @@ -1,21 +1,35 @@ title = 'Update Articles: ' . $model->title; -$this->params['breadcrumbs'][] = ['label' => 'Articles', 'url' => ['index']]; -$this->params['breadcrumbs'][] = ['label' => $model->title, 'url' => ['view', 'id' => $model->id]]; -$this->params['breadcrumbs'][] = 'Update'; + use common\models\Articles; + use common\models\ArticlesLang; + use yii\helpers\Html; + use yii\web\View; + + /** + * @var View $this + * @var Articles $model + * @var ArticlesLang[] $model_langs + */ + $this->title = 'Update Articles: ' . $model->title; + $this->params[ 'breadcrumbs' ][] = [ + 'label' => 'Articles', + 'url' => [ 'index' ], + ]; + $this->params[ 'breadcrumbs' ][] = [ + 'label' => $model->title, + 'url' => [ + 'view', + 'id' => $model->id, + ], + ]; + $this->params[ 'breadcrumbs' ][] = 'Update'; ?>
- +

title) ?>

- + render('_form', [ - 'model' => $model, + 'model' => $model, + 'model_langs' => $model_langs, ]) ?>
diff --git a/backend/views/banner/_form.php b/backend/views/banner/_form.php index 0c8868a..1f5aa23 100644 --- a/backend/views/banner/_form.php +++ b/backend/views/banner/_form.php @@ -1,95 +1,63 @@ - diff --git a/backend/views/banner/_form_language.php b/backend/views/banner/_form_language.php new file mode 100644 index 0000000..75ea9d5 --- /dev/null +++ b/backend/views/banner/_form_language.php @@ -0,0 +1,34 @@ + +field($model_lang, '[' . $language->language_id . ']title') + ->textInput([ 'maxlength' => true ]); ?> +field($model_lang, '[' . $language->language_id . ']alt') + ->textInput([ 'maxlength' => true ]); ?> + +field($model_lang, '['.$language->language_id.']image')->widget(\kartik\file\FileInput::className(), [ + 'model' => $model_lang, + 'attribute' => 'image', + 'options' => [ + 'accept' => 'image/*', + 'multiple' => false + ], + 'pluginOptions' => [ + 'allowedFileExtensions' => ['jpg','gif','png'], + 'initialPreview' => $model_lang->imageUrl ? \common\components\artboximage\ArtboxImageHelper::getImage($model_lang->imageUrl, 'slider') : '', + 'showRemove' => false, + 'overwriteInitial' => true, + 'showUpload' => false, + 'showClose' => false, + ], +]); ?> \ No newline at end of file diff --git a/backend/views/banner/create.php b/backend/views/banner/create.php index 8fbe344..3e97c14 100644 --- a/backend/views/banner/create.php +++ b/backend/views/banner/create.php @@ -1,21 +1,30 @@ title = Yii::t('app', 'Create Banner'); -$this->params['breadcrumbs'][] = ['label' => Yii::t('app', 'Banners'), 'url' => ['index']]; -$this->params['breadcrumbs'][] = $this->title; + + use common\models\Banner; + use common\models\BannerLang; + use yii\helpers\Html; + use yii\web\View; + + /** + * @var View $this + * @var Banner $model + * @var BannerLang[] $model_langs + */ + + $this->title = Yii::t('app', 'Create Banner'); + $this->params[ 'breadcrumbs' ][] = [ + 'label' => Yii::t('app', 'Banners'), + 'url' => [ 'index' ], + ]; + $this->params[ 'breadcrumbs' ][] = $this->title; ?> diff --git a/backend/views/banner/update.php b/backend/views/banner/update.php index 44ddca7..5b79eb5 100644 --- a/backend/views/banner/update.php +++ b/backend/views/banner/update.php @@ -1,23 +1,39 @@ title = Yii::t('app', 'Update {modelClass}: ', [ - 'modelClass' => 'Banner', -]) . $model->title; -$this->params['breadcrumbs'][] = ['label' => Yii::t('app', 'Banners'), 'url' => ['index']]; -$this->params['breadcrumbs'][] = ['label' => $model->title, 'url' => ['view', 'id' => $model->banner_id]]; -$this->params['breadcrumbs'][] = Yii::t('app', 'Update'); + + use common\models\Banner; + use common\models\BannerLang; + use yii\helpers\Html; + use yii\web\View; + + /** + * @var View $this + * @var Banner $model + * @var BannerLang[] $model_langs + */ + + $this->title = Yii::t('app', 'Update {modelClass}: ', [ + 'modelClass' => 'Banner', + ]) . $model->title; + $this->params[ 'breadcrumbs' ][] = [ + 'label' => Yii::t('app', 'Banners'), + 'url' => [ 'index' ], + ]; + $this->params[ 'breadcrumbs' ][] = [ + 'label' => $model->title, + 'url' => [ + 'view', + 'id' => $model->banner_id, + ], + ]; + $this->params[ 'breadcrumbs' ][] = Yii::t('app', 'Update'); ?> diff --git a/backend/views/bg/_form.php b/backend/views/bg/_form.php index 30dd166..a3b4080 100644 --- a/backend/views/bg/_form.php +++ b/backend/views/bg/_form.php @@ -1,27 +1,43 @@
- + - - field($model, 'title')->textInput(['maxlength' => true]) ?> - - field($model, 'url')->textInput(['maxlength' => true]) ?> - - field($model, 'image')->textInput(['maxlength' => true]) ?> - + + field($model, 'title') + ->textInput([ 'maxlength' => true ]) ?> + + field($model, 'url') + ->textInput([ 'maxlength' => true ]) ?> + + field($model, 'image') + ->textInput([ 'maxlength' => true ]) ?> + + $model_langs, + 'form' => $form, + 'formView' => '@backend/views/bg/_form_language', + ]) ?> +
- isNewRecord ? 'Create' : 'Update', ['class' => $model->isNewRecord ? 'btn btn-success' : 'btn btn-primary']) ?> + isNewRecord ? 'Create' : 'Update', [ 'class' => $model->isNewRecord ? 'btn btn-success' : 'btn btn-primary' ]) ?>
- +
diff --git a/backend/views/bg/_form_language.php b/backend/views/bg/_form_language.php new file mode 100644 index 0000000..40cbe15 --- /dev/null +++ b/backend/views/bg/_form_language.php @@ -0,0 +1,15 @@ + +field($model_lang, '[' . $language->language_id . ']title') + ->textInput([ 'maxlength' => true ]); ?> \ No newline at end of file diff --git a/backend/views/bg/create.php b/backend/views/bg/create.php index bf0913a..9ffa355 100644 --- a/backend/views/bg/create.php +++ b/backend/views/bg/create.php @@ -1,21 +1,30 @@ title = 'Create Bg'; -$this->params['breadcrumbs'][] = ['label' => 'Bgs', 'url' => ['index']]; -$this->params['breadcrumbs'][] = $this->title; + + use common\models\Bg; + use common\models\BgLang; + use yii\helpers\Html; + use yii\web\View; + + /** + * @var View $this + * @var Bg $model + * @var BgLang[] $model_langs + */ + + $this->title = 'Create Bg'; + $this->params[ 'breadcrumbs' ][] = [ + 'label' => 'Bgs', + 'url' => [ 'index' ], + ]; + $this->params[ 'breadcrumbs' ][] = $this->title; ?>
- +

title) ?>

- + render('_form', [ - 'model' => $model, + 'model' => $model, + 'model_langs' => $model_langs, ]) ?>
diff --git a/backend/views/bg/update.php b/backend/views/bg/update.php index a996870..e0ac501 100644 --- a/backend/views/bg/update.php +++ b/backend/views/bg/update.php @@ -1,21 +1,37 @@ title = 'Update Bg: ' . $model->title; -$this->params['breadcrumbs'][] = ['label' => 'Bgs', 'url' => ['index']]; -$this->params['breadcrumbs'][] = ['label' => $model->title, 'url' => ['view', 'id' => $model->id]]; -$this->params['breadcrumbs'][] = 'Update'; + + use common\models\Bg; + use common\models\BgLang; + use yii\helpers\Html; + use yii\web\View; + + /** + * @var View $this + * @var Bg $model + * @var BgLang[] $model_langs + */ + + $this->title = 'Update Bg: ' . $model->title; + $this->params[ 'breadcrumbs' ][] = [ + 'label' => 'Bgs', + 'url' => [ 'index' ], + ]; + $this->params[ 'breadcrumbs' ][] = [ + 'label' => $model->title, + 'url' => [ + 'view', + 'id' => $model->id, + ], + ]; + $this->params[ 'breadcrumbs' ][] = 'Update'; ?>
- +

title) ?>

- + render('_form', [ - 'model' => $model, + 'model' => $model, + 'model_langs' => $model_langs, ]) ?>
diff --git a/backend/views/brand/_form.php b/backend/views/brand/_form.php index 6ae3467..599b346 100644 --- a/backend/views/brand/_form.php +++ b/backend/views/brand/_form.php @@ -1,55 +1,82 @@
- + false, - 'options' => ['enctype' => 'multipart/form-data'] - ]); ?> - - field($model, 'name')->textInput() ?> - - field($model, 'alias')->textInput(['maxlength' => true]) ?> - - field($model, 'image')->widget(\kartik\file\FileInput::classname(), [ - 'language' => 'ru', - 'options' => [ - 'accept' => 'image/*', - 'multiple' => false, - ], - 'pluginOptions' => [ - 'allowedFileExtensions' => ['jpg', 'gif', 'png'], - 'initialPreview' => !empty($model->imageUrl) ? \common\components\artboximage\ArtboxImageHelper::getImage($model->imageUrl, 'list') : '', - 'overwriteInitial' => true, - 'showRemove' => false, - 'showUpload' => false, - 'previewFileType' => 'image', - ], + 'options' => [ 'enctype' => 'multipart/form-data' ], ]); ?> - - field($model, 'meta_title')->textInput(['maxlength' => true]) ?> - - field($model, 'meta_desc')->textarea(['rows' => 6]) ?> - - field($model, 'meta_robots')->textInput(['maxlength' => true]) ?> - - field($model, 'seo_text')->textarea(['rows' => 6]) ?> - + + field($model, 'name') + ->textInput() ?> + + field($model, 'alias') + ->textInput([ 'maxlength' => true ]) ?> + + field($model, 'image') + ->widget(\kartik\file\FileInput::classname(), [ + 'language' => 'ru', + 'options' => [ + 'accept' => 'image/*', + 'multiple' => false, + ], + 'pluginOptions' => [ + 'allowedFileExtensions' => [ + 'jpg', + 'gif', + 'png', + ], + 'initialPreview' => !empty( $model->imageUrl ) ? \common\components\artboximage\ArtboxImageHelper::getImage($model->imageUrl, 'list') : '', + 'overwriteInitial' => true, + 'showRemove' => false, + 'showUpload' => false, + 'previewFileType' => 'image', + ], + ]); ?> + + field($model, 'meta_title') + ->textInput([ 'maxlength' => true ]) ?> + + field($model, 'meta_desc') + ->textarea([ 'rows' => 6 ]) ?> + + field($model, 'meta_robots') + ->textInput([ 'maxlength' => true ]) ?> + + field($model, 'seo_text') + ->textarea([ 'rows' => 6 ]) ?> + + $model_langs, + 'formView' => '@backend/views/brand/_form_language', + 'form' => $form, + ]) ?> +
- isNewRecord ? Yii::t('product', 'Create') : Yii::t('product', 'Update'), ['class' => $model->isNewRecord ? 'btn btn-success' : 'btn btn-primary']) ?> - isNewRecord) :?> - 'create_and_new', 'class' => 'btn btn-primary']) ?> - + isNewRecord ? Yii::t('product', 'Create') : Yii::t('product', 'Update'), [ 'class' => $model->isNewRecord ? 'btn btn-success' : 'btn btn-primary' ]) ?> + isNewRecord) : ?> + 'create_and_new', + 'class' => 'btn btn-primary', + ]) ?> +
- +
diff --git a/backend/views/brand/_form_language.php b/backend/views/brand/_form_language.php new file mode 100644 index 0000000..a4ba5e9 --- /dev/null +++ b/backend/views/brand/_form_language.php @@ -0,0 +1,27 @@ + +field($model_lang, '[' . $language->language_id . ']name') + ->textInput([ 'maxlength' => true ]); ?> + +field($model_lang, '[' . $language->language_id . ']meta_title') + ->textInput([ 'maxlength' => true ]) ?> + +field($model_lang, '[' . $language->language_id . ']meta_robots') + ->textInput([ 'maxlength' => true ]) ?> + +field($model_lang, '[' . $language->language_id . ']meta_desc') + ->textInput([ 'maxlength' => true ]) ?> + +field($model_lang, '[' . $language->language_id . ']seo_text') + ->textarea([ 'rows' => 6 ]) ?> diff --git a/backend/views/brand/create.php b/backend/views/brand/create.php index 7de8216..3872757 100644 --- a/backend/views/brand/create.php +++ b/backend/views/brand/create.php @@ -1,21 +1,30 @@ title = Yii::t('product', 'Create Brand'); -$this->params['breadcrumbs'][] = ['label' => Yii::t('product', 'Brands'), 'url' => ['index']]; -$this->params['breadcrumbs'][] = $this->title; + + use common\modules\product\models\Brand; + use common\modules\product\models\BrandLang; + use yii\helpers\Html; + use yii\web\View; + + /** + * @var View $this + * @var Brand $model + * @var BrandLang[] $model_langs + */ + + $this->title = Yii::t('product', 'Create Brand'); + $this->params[ 'breadcrumbs' ][] = [ + 'label' => Yii::t('product', 'Brands'), + 'url' => [ 'index' ], + ]; + $this->params[ 'breadcrumbs' ][] = $this->title; ?>
- +

title) ?>

- + render('_form', [ - 'model' => $model, + 'model' => $model, + 'model_langs' => $model_langs, ]) ?>
diff --git a/backend/views/brand/update.php b/backend/views/brand/update.php index 26ae057..838d859 100644 --- a/backend/views/brand/update.php +++ b/backend/views/brand/update.php @@ -1,23 +1,39 @@ title = Yii::t('product', 'Update {modelClass}: ', [ - 'modelClass' => 'Brand', -]) . ' ' . $model->brand_id; -$this->params['breadcrumbs'][] = ['label' => Yii::t('product', 'Brands'), 'url' => ['index']]; -$this->params['breadcrumbs'][] = ['label' => $model->brand_id, 'url' => ['view', 'id' => $model->brand_id]]; -$this->params['breadcrumbs'][] = Yii::t('product', 'Update'); + + use common\modules\product\models\Brand; + use common\modules\product\models\BrandLang; + use yii\helpers\Html; + use yii\web\View; + + /** + * @var View $this + * @var Brand $model + * @var BrandLang[] $model_langs + */ + + $this->title = Yii::t('product', 'Update {modelClass}: ', [ + 'modelClass' => 'Brand', + ]) . ' ' . $model->brand_id; + $this->params[ 'breadcrumbs' ][] = [ + 'label' => Yii::t('product', 'Brands'), + 'url' => [ 'index' ], + ]; + $this->params[ 'breadcrumbs' ][] = [ + 'label' => $model->brand_id, + 'url' => [ + 'view', + 'id' => $model->brand_id, + ], + ]; + $this->params[ 'breadcrumbs' ][] = Yii::t('product', 'Update'); ?>
- +

title) ?>

- + render('_form', [ - 'model' => $model, + 'model' => $model, + 'model_langs' => $model_langs, ]) ?>
diff --git a/backend/views/category/_form.php b/backend/views/category/_form.php index 0c86fc5..596d70a 100644 --- a/backend/views/category/_form.php +++ b/backend/views/category/_form.php @@ -1,94 +1,125 @@
- + false, - 'options' => ['enctype' => 'multipart/form-data'] + 'options' => [ 'enctype' => 'multipart/form-data' ], ]); ?> - - field($model, 'name')->textInput() ?> - - field($model, 'alias')->textInput(['maxlength' => true]) ?> - - field($model, 'parent_id')->dropDownList($categories, [ - 'prompt' => Yii::t('rubrication', 'Root category'), - 'options' => [ - $model->category_id => ['disabled' => true] - ] - ])->label(Yii::t('product', 'Parent category')) ?> - + + field($model, 'name') + ->textInput() ?> + + field($model, 'alias') + ->textInput([ 'maxlength' => true ]) ?> + + field($model, 'parent_id') + ->dropDownList($categories, [ + 'prompt' => Yii::t('rubrication', 'Root category'), + 'options' => [ + $model->category_id => [ 'disabled' => true ], + ], + ]) + ->label(Yii::t('product', 'Parent category')) ?> + + field($model, 'taxGroup')->widget(Select2::className(), [ + 'data' => \yii\helpers\ArrayHelper::map(\common\modules\rubrication\models\TaxGroup::find()->all(), 'tax_group_id', 'name'), + 'language' => 'ru', + 'options' => [ + 'placeholder' => 'Linked options', + 'multiple' => true, + ], + 'pluginOptions' => [ + 'allowClear' => true + ], + ] + ) ?> + */ ?> - field($model, 'taxGroup')->widget(Select2::className(), [ - 'data' => \yii\helpers\ArrayHelper::map(\common\modules\rubrication\models\TaxGroup::find()->all(), 'tax_group_id', 'name'), - 'language' => 'ru', - 'options' => [ - 'placeholder' => 'Linked options', - 'multiple' => true, - ], - 'pluginOptions' => [ - 'allowClear' => true - ], - ] - ) ?> - */ - ?> - - field($model, 'imageUpload')->widget(\kartik\file\FileInput::classname(), [ - 'language' => 'ru', - 'options' => [ - 'accept' => 'image/*', - 'multiple' => false, - ], - 'pluginOptions' => [ - 'allowedFileExtensions' => ['jpg', 'gif', 'png'], - 'initialPreview' => !empty($model->imageUrl) ? \common\components\artboximage\ArtboxImageHelper::getImage($model->imageUrl, 'list') : '', - 'overwriteInitial' => true, - 'showRemove' => false, - 'showUpload' => false, - 'previewFileType' => 'image', - ], - ])->hint('Для корректного отображения на сайте, размер изображения должен быть 262x144 либо соблюдать соотношение сторон примерно 2:1'); ?> - - field($model, 'meta_title')->textInput(['maxlength' => true]) ?> - - field($model, 'meta_desc')->textarea(['rows' => 6]) ?> - - field($model, 'meta_robots')->textInput(['maxlength' => true]) ?> - - field($model, 'h1')->textInput(['maxlength' => true]) ?> - - field($model, 'seo_text')->widget(CKEditor::className(), - [ - 'editorOptions' => ElFinder::ckeditorOptions('elfinder',[ - 'preset' => 'full', //разработанны стандартные настройки basic, standard, full данную возможность не обязательно использовать - 'inline' => false, //по умолчанию false]), - 'filebrowserUploadUrl'=>Yii::$app->getUrlManager()->createUrl('file/uploader/images-upload') - ] - ) - ]) ?> - + + field($model, 'imageUpload') + ->widget(\kartik\file\FileInput::classname(), [ + 'language' => 'ru', + 'options' => [ + 'accept' => 'image/*', + 'multiple' => false, + ], + 'pluginOptions' => [ + 'allowedFileExtensions' => [ + 'jpg', + 'gif', + 'png', + ], + 'initialPreview' => !empty( $model->imageUrl ) ? \common\components\artboximage\ArtboxImageHelper::getImage($model->imageUrl, 'list') : '', + 'overwriteInitial' => true, + 'showRemove' => false, + 'showUpload' => false, + 'previewFileType' => 'image', + ], + ]) + ->hint('Для корректного отображения на сайте, размер изображения должен быть 262x144 либо соблюдать соотношение сторон примерно 2:1'); ?> + + field($model, 'meta_title') + ->textInput([ 'maxlength' => true ]) ?> + + field($model, 'meta_desc') + ->textarea([ 'rows' => 6 ]) ?> + + field($model, 'meta_robots') + ->textInput([ 'maxlength' => true ]) ?> + + field($model, 'h1') + ->textInput([ 'maxlength' => true ]) ?> + + field($model, 'seo_text') + ->widget(CKEditor::className(), [ + 'editorOptions' => ElFinder::ckeditorOptions('elfinder', [ + 'preset' => 'full', + //разработанны стандартные настройки basic, standard, full данную возможность не обязательно использовать + 'inline' => false, + //по умолчанию false]), + 'filebrowserUploadUrl' => Yii::$app->getUrlManager() + ->createUrl('file/uploader/images-upload'), + ]), + ]) ?> + + $model_langs, + 'formView' => '@backend/views/category/_form_language', + 'form' => $form, + ]) ?> +
- isNewRecord ? Yii::t('product', 'Create') : Yii::t('product', 'Update'), ['class' => $model->isNewRecord ? 'btn btn-success' : 'btn btn-primary']) ?> - isNewRecord) :?> - 'create_and_new', 'class' => 'btn btn-primary']) ?> - + isNewRecord ? Yii::t('product', 'Create') : Yii::t('product', 'Update'), [ 'class' => $model->isNewRecord ? 'btn btn-success' : 'btn btn-primary' ]) ?> + isNewRecord) : ?> + 'create_and_new', + 'class' => 'btn btn-primary', + ]) ?> +
- +
diff --git a/backend/views/category/_form_language.php b/backend/views/category/_form_language.php new file mode 100644 index 0000000..9087fb8 --- /dev/null +++ b/backend/views/category/_form_language.php @@ -0,0 +1,30 @@ + +field($model_lang, '[' . $language->language_id . ']name') + ->textInput([ 'maxlength' => true ]); ?> + +field($model_lang, '[' . $language->language_id . ']meta_title') + ->textInput([ 'maxlength' => true ]) ?> + +field($model_lang, '[' . $language->language_id . ']meta_robots') + ->textInput([ 'maxlength' => true ]) ?> + +field($model_lang, '[' . $language->language_id . ']meta_desc') + ->textInput([ 'maxlength' => true ]) ?> + +field($model_lang, '[' . $language->language_id . ']seo_text') + ->textarea([ 'rows' => 6 ]) ?> + +field($model_lang, '[' . $language->language_id . ']h1') + ->textInput([ 'maxlength' => true ]) ?> \ No newline at end of file diff --git a/backend/views/category/create.php b/backend/views/category/create.php index 99357a3..4247e2c 100644 --- a/backend/views/category/create.php +++ b/backend/views/category/create.php @@ -1,22 +1,32 @@ title = Yii::t('product', 'Create Category'); -$this->params['breadcrumbs'][] = ['label' => Yii::t('product', 'Categories'), 'url' => ['index']]; -$this->params['breadcrumbs'][] = $this->title; + + use common\modules\product\models\Category; + use common\modules\product\models\CategoryLang; + use yii\helpers\Html; + use yii\web\View; + + /** + * @var View $this + * @var Category $model + * @var CategoryLang[] $model_langs + * @var string[] $categories + */ + + $this->title = Yii::t('product', 'Create Category'); + $this->params[ 'breadcrumbs' ][] = [ + 'label' => Yii::t('product', 'Categories'), + 'url' => [ 'index' ], + ]; + $this->params[ 'breadcrumbs' ][] = $this->title; ?>
- +

title) ?>

- + render('_form', [ - 'model' => $model, - 'categories' => $categories + 'model' => $model, + 'model_langs' => $model_langs, + 'categories' => $categories, ]) ?>
diff --git a/backend/views/category/update.php b/backend/views/category/update.php index befb58c..e951b6d 100644 --- a/backend/views/category/update.php +++ b/backend/views/category/update.php @@ -1,24 +1,41 @@ title = Yii::t('product', 'Update {modelClass}: ', [ - 'modelClass' => 'Category', -]) . ' ' . $model->name; -$this->params['breadcrumbs'][] = ['label' => Yii::t('product', 'Categories'), 'url' => ['index']]; -$this->params['breadcrumbs'][] = ['label' => $model->name, 'url' => ['view', 'id' => $model->category_id]]; -$this->params['breadcrumbs'][] = Yii::t('product', 'Update'); + + use common\modules\product\models\Category; + use common\modules\product\models\CategoryLang; + use yii\helpers\Html; + use yii\web\View; + + /** + * @var View $this + * @var Category $model + * @var CategoryLang[] $model_langs + * @var string[] $categories + */ + + $this->title = Yii::t('product', 'Update {modelClass}: ', [ + 'modelClass' => 'Category', + ]) . ' ' . $model->name; + $this->params[ 'breadcrumbs' ][] = [ + 'label' => Yii::t('product', 'Categories'), + 'url' => [ 'index' ], + ]; + $this->params[ 'breadcrumbs' ][] = [ + 'label' => $model->name, + 'url' => [ + 'view', + 'id' => $model->category_id, + ], + ]; + $this->params[ 'breadcrumbs' ][] = Yii::t('product', 'Update'); ?>
- +

title) ?>

- + render('_form', [ - 'model' => $model, - 'categories' => $categories + 'model' => $model, + 'model_langs' => $model_langs, + 'categories' => $categories, ]) ?>
diff --git a/backend/views/event/_form.php b/backend/views/event/_form.php index 3a12600..764fd36 100644 --- a/backend/views/event/_form.php +++ b/backend/views/event/_form.php @@ -1,75 +1,101 @@
- + false, - 'options' => ['enctype' => 'multipart/form-data'] + 'options' => [ 'enctype' => 'multipart/form-data' ], ]); ?> - - field($model, 'name')->textInput(['maxlength' => true]) ?> - - field($model, 'alias')->textInput(['maxlength' => true]) ?> - - field($model, 'body')->widget(CKEditor::className(), - [ - 'editorOptions' => ElFinder::ckeditorOptions('elfinder',[ - 'preset' => 'full', //разработанны стандартные настройки basic, standard, full данную возможность не обязательно использовать - 'inline' => false, //по умолчанию false]), - 'filebrowserUploadUrl'=>Yii::$app->getUrlManager()->createUrl('file/uploader/images-upload') - ] - ) - ]) ?> - - + + field($model, 'name') + ->textInput([ 'maxlength' => true ]) ?> + + field($model, 'alias') + ->textInput([ 'maxlength' => true ]) ?> + + field($model, 'body') + ->widget(CKEditor::className(), [ + 'editorOptions' => ElFinder::ckeditorOptions('elfinder', [ + 'preset' => 'full', + //разработанны стандартные настройки basic, standard, full данную возможность не обязательно использовать + 'inline' => false, + //по умолчанию false]), + 'filebrowserUploadUrl' => Yii::$app->getUrlManager() + ->createUrl('file/uploader/images-upload'), + ]), + ]) ?> + + field($model, 'end_at') - ->widget(DatePicker::className(), [ - 'pluginOptions' => [ - 'format' => 'dd-mm-yyyy', - 'todayHighlight' => true - ]]) ?> - - - field($model, 'imageUpload')->widget(\kartik\file\FileInput::classname(), [ - 'language' => 'ru', - 'options' => [ - 'accept' => 'image/*', - 'multiple' => false, - ], - 'pluginOptions' => [ - 'allowedFileExtensions' => ['jpg', 'gif', 'png'], - 'initialPreview' => !empty($model->imageUrl) ? \common\components\artboximage\ArtboxImageHelper::getImage($model->imageUrl, 'list') : '', - 'overwriteInitial' => true, - 'showRemove' => false, - 'showUpload' => false, - 'previewFileType' => 'image', - ], - ]); ?> - - field($model, 'meta_title')->textInput(['maxlength' => true]) ?> - - field($model, 'description')->textInput(['maxlength' => true]) ?> - - field($model, 'h1')->textInput(['maxlength' => true]) ?> - - field($model, 'seo_text')->textarea(['rows' => 6]) ?> - - - + ->widget(DatePicker::className(), [ + 'pluginOptions' => [ + 'format' => 'dd-mm-yyyy', + 'todayHighlight' => true, + ], + ]) ?> + + + field($model, 'imageUpload') + ->widget(\kartik\file\FileInput::className(), [ + 'language' => 'ru', + 'options' => [ + 'accept' => 'image/*', + 'multiple' => false, + ], + 'pluginOptions' => [ + 'allowedFileExtensions' => [ + 'jpg', + 'gif', + 'png', + ], + 'initialPreview' => !empty( $model->imageUrl ) ? \common\components\artboximage\ArtboxImageHelper::getImage($model->imageUrl, 'list') : '', + 'overwriteInitial' => true, + 'showRemove' => false, + 'showUpload' => false, + 'previewFileType' => 'image', + ], + ]); ?> + + field($model, 'meta_title') + ->textInput([ 'maxlength' => true ]) ?> + + field($model, 'description') + ->textInput([ 'maxlength' => true ]) ?> + + field($model, 'h1') + ->textInput([ 'maxlength' => true ]) ?> + + field($model, 'seo_text') + ->textarea([ 'rows' => 6 ]) ?> + + $model_langs, + 'formView' => '@backend/views/event/_form_language', + 'form' => $form, + ]) ?> +
- isNewRecord ? Yii::t('app', 'Create') : Yii::t('app', 'Update'), ['class' => $model->isNewRecord ? 'btn btn-success' : 'btn btn-primary']) ?> + isNewRecord ? Yii::t('app', 'Create') : Yii::t('app', 'Update'), [ 'class' => $model->isNewRecord ? 'btn btn-success' : 'btn btn-primary' ]) ?>
- +
diff --git a/backend/views/event/_form_language.php b/backend/views/event/_form_language.php new file mode 100644 index 0000000..0b4257d --- /dev/null +++ b/backend/views/event/_form_language.php @@ -0,0 +1,38 @@ + +field($model_lang, '[' . $language->language_id . ']name') + ->textInput([ 'maxlength' => true ]); ?> +field($model_lang, '[' . $language->language_id . ']body') + ->widget(CKEditor::className(), [ + 'editorOptions' => ElFinder::ckeditorOptions('elfinder', [ + 'preset' => 'full', + 'inline' => false, + 'filebrowserUploadUrl' => Yii::$app->getUrlManager() + ->createUrl('file/uploader/images-upload'), + ]), + ]) ?> + +field($model_lang, '[' . $language->language_id . ']meta_title') + ->textInput([ 'maxlength' => true ]) ?> + +field($model_lang, '[' . $language->language_id . ']description') + ->textInput([ 'maxlength' => true ]) ?> + +field($model_lang, '[' . $language->language_id . ']seo_text') + ->textarea([ 'rows' => 6 ]) ?> + +field($model_lang, '[' . $language->language_id . ']h1') + ->textInput([ 'maxlength' => true ]) ?> \ No newline at end of file diff --git a/backend/views/event/create.php b/backend/views/event/create.php index 7909eca..9bccd33 100644 --- a/backend/views/event/create.php +++ b/backend/views/event/create.php @@ -1,21 +1,30 @@ title = Yii::t('app', 'Create Event'); -$this->params['breadcrumbs'][] = ['label' => Yii::t('app', 'Events'), 'url' => ['index']]; -$this->params['breadcrumbs'][] = $this->title; + + use common\models\Event; + use common\models\EventLang; + use yii\helpers\Html; + use yii\web\View; + + /** + * @var View $this + * @var Event $model + * @var EventLang[] $model_langs + */ + + $this->title = Yii::t('app', 'Create Event'); + $this->params[ 'breadcrumbs' ][] = [ + 'label' => Yii::t('app', 'Events'), + 'url' => [ 'index' ], + ]; + $this->params[ 'breadcrumbs' ][] = $this->title; ?>
- +

title) ?>

- + render('_form', [ - 'model' => $model, + 'model' => $model, + 'model_langs' => $model_langs, ]) ?>
diff --git a/backend/views/event/update.php b/backend/views/event/update.php index 9009f4d..0ed9621 100644 --- a/backend/views/event/update.php +++ b/backend/views/event/update.php @@ -1,23 +1,39 @@ title = Yii::t('app', 'Update {modelClass}: ', [ - 'modelClass' => 'Event', -]) . $model->name; -$this->params['breadcrumbs'][] = ['label' => Yii::t('app', 'Events'), 'url' => ['index']]; -$this->params['breadcrumbs'][] = ['label' => $model->name, 'url' => ['view', 'id' => $model->event_id]]; -$this->params['breadcrumbs'][] = Yii::t('app', 'Update'); + + use common\models\Event; + use common\models\EventLang; + use yii\helpers\Html; + use yii\web\View; + + /** + * @var View $this + * @var Event $model + * @var EventLang[] $model_langs + */ + + $this->title = Yii::t('app', 'Update {modelClass}: ', [ + 'modelClass' => 'Event', + ]) . $model->name; + $this->params[ 'breadcrumbs' ][] = [ + 'label' => Yii::t('app', 'Events'), + 'url' => [ 'index' ], + ]; + $this->params[ 'breadcrumbs' ][] = [ + 'label' => $model->name, + 'url' => [ + 'view', + 'id' => $model->event_id, + ], + ]; + $this->params[ 'breadcrumbs' ][] = Yii::t('app', 'Update'); ?>
- +

title) ?>

- + render('_form', [ - 'model' => $model, + 'model' => $model, + 'model_langs' => $model_langs, ]) ?>
diff --git a/backend/views/layouts/header.php b/backend/views/layouts/header.php index 95aef0e..afd1fd1 100644 --- a/backend/views/layouts/header.php +++ b/backend/views/layouts/header.php @@ -1,17 +1,10 @@
diff --git a/backend/views/page/_form.php b/backend/views/page/_form.php index d4fed28..773723a 100644 --- a/backend/views/page/_form.php +++ b/backend/views/page/_form.php @@ -1,49 +1,73 @@
- + - - field($model, 'title')->textInput(['maxlength' => true]) ?> - - field($model, 'translit')->textInput(['maxlength' => true]) ?> - - field($model, 'body')->widget(CKEditor::className(), - [ - 'editorOptions' => ElFinder::ckeditorOptions('elfinder',[ - 'preset' => 'full', //разработанны стандартные настройки basic, standard, full данную возможность не обязательно использовать - 'inline' => false, //по умолчанию false]), - 'allowedContent' => true, - 'filebrowserUploadUrl'=>Yii::$app->getUrlManager()->createUrl('file/uploader/images-upload') - ] - ) - ]) ?> - - field($model, 'meta_title')->textInput(['maxlength' => true]) ?> - - field($model, 'meta_keywords')->textInput(['maxlength' => true]) ?> - - field($model, 'meta_description')->textInput(['maxlength' => true]) ?> - - field($model, 'seo_text')->textarea(['rows' => 6]) ?> - - field($model, 'h1')->textInput(['maxlength' => true]) ?> - field($model, 'in_menu')->checkbox() ?> - + field($model, 'title') + ->textInput([ 'maxlength' => true ]) ?> + + field($model, 'translit') + ->textInput([ 'maxlength' => true ]) ?> + + field($model, 'body') + ->widget(CKEditor::className(), [ + 'editorOptions' => ElFinder::ckeditorOptions('elfinder', [ + 'preset' => 'full', + //разработанны стандартные настройки basic, standard, full данную возможность не обязательно использовать + 'inline' => false, + //по умолчанию false]), + 'allowedContent' => true, + 'filebrowserUploadUrl' => Yii::$app->getUrlManager() + ->createUrl('file/uploader/images-upload'), + ]), + ]) ?> + + field($model, 'meta_title') + ->textInput([ 'maxlength' => true ]) ?> + + field($model, 'meta_keywords') + ->textInput([ 'maxlength' => true ]) ?> + + field($model, 'meta_description') + ->textInput([ 'maxlength' => true ]) ?> + + field($model, 'seo_text') + ->textarea([ 'rows' => 6 ]) ?> + + field($model, 'h1') + ->textInput([ 'maxlength' => true ]) ?> + + field($model, 'in_menu') + ->checkbox() ?> + + $model_langs, + 'formView' => '@backend/views/page/_form_language', + 'form' => $form, + ]) ?> +
- isNewRecord ? 'Create' : 'Update', ['class' => $model->isNewRecord ? 'btn btn-success' : 'btn btn-primary']) ?> + isNewRecord ? 'Create' : 'Update', [ 'class' => $model->isNewRecord ? 'btn btn-success' : 'btn btn-primary' ]) ?>
- +
diff --git a/backend/views/page/_form_language.php b/backend/views/page/_form_language.php new file mode 100644 index 0000000..a47a53a --- /dev/null +++ b/backend/views/page/_form_language.php @@ -0,0 +1,42 @@ + +field($model_lang, '[' . $language->language_id . ']title') + ->textInput([ 'maxlength' => true ]); ?> + +field($model_lang, '[' . $language->language_id . ']body') + ->widget(CKEditor::className(), [ + 'editorOptions' => ElFinder::ckeditorOptions('elfinder', [ + 'preset' => 'full', + 'inline' => false, + 'filebrowserUploadUrl' => Yii::$app->getUrlManager() + ->createUrl('file/uploader/images-upload'), + ]), + ]) ?> + +field($model_lang, '[' . $language->language_id . ']meta_title') + ->textInput([ 'maxlength' => true ]) ?> + +field($model_lang, '[' . $language->language_id . ']meta_keywords') + ->textInput([ 'maxlength' => true ]) ?> + +field($model_lang, '[' . $language->language_id . ']meta_description') + ->textInput([ 'maxlength' => true ]) ?> + +field($model_lang, '[' . $language->language_id . ']seo_text') + ->textarea([ 'rows' => 6 ]) ?> + +field($model_lang, '[' . $language->language_id . ']h1') + ->textInput([ 'maxlength' => true ]) ?> diff --git a/backend/views/page/create.php b/backend/views/page/create.php index d47a8ad..867fcbb 100644 --- a/backend/views/page/create.php +++ b/backend/views/page/create.php @@ -1,21 +1,29 @@ title = 'Create Page'; -$this->params['breadcrumbs'][] = ['label' => 'Pages', 'url' => ['index']]; -$this->params['breadcrumbs'][] = $this->title; + + use common\models\Page; + use common\models\PageLang; + use yii\helpers\Html; + use yii\web\View; + + /** + * @var View $this + * @var Page $model + * @var PageLang[] $model_langs + */ + $this->title = 'Create Page'; + $this->params[ 'breadcrumbs' ][] = [ + 'label' => 'Pages', + 'url' => [ 'index' ], + ]; + $this->params[ 'breadcrumbs' ][] = $this->title; ?>
- +

title) ?>

- + render('_form', [ - 'model' => $model, + 'model' => $model, + 'model_langs' => $model_langs, ]) ?>
diff --git a/backend/views/page/update.php b/backend/views/page/update.php index a6755db..53ea7c8 100644 --- a/backend/views/page/update.php +++ b/backend/views/page/update.php @@ -1,21 +1,37 @@ title = 'Update Page: ' . $model->title; -$this->params['breadcrumbs'][] = ['label' => 'Pages', 'url' => ['index']]; -$this->params['breadcrumbs'][] = ['label' => $model->title, 'url' => ['view', 'id' => $model->id]]; -$this->params['breadcrumbs'][] = 'Update'; + + use common\models\Page; + use common\models\PageLang; + use yii\helpers\Html; + use yii\web\View; + + /** + * @var View $this + * @var Page $model + * @var PageLang[] $model_langs + */ + + $this->title = 'Update Page: ' . $model->title; + $this->params[ 'breadcrumbs' ][] = [ + 'label' => 'Pages', + 'url' => [ 'index' ], + ]; + $this->params[ 'breadcrumbs' ][] = [ + 'label' => $model->title, + 'url' => [ + 'view', + 'id' => $model->id, + ], + ]; + $this->params[ 'breadcrumbs' ][] = 'Update'; ?>
- +

title) ?>

- + render('_form', [ - 'model' => $model, + 'model' => $model, + 'model_langs' => $model_langs, ]) ?>
diff --git a/backend/views/project/_form.php b/backend/views/project/_form.php index 8b7b9d4..0e6b09a 100644 --- a/backend/views/project/_form.php +++ b/backend/views/project/_form.php @@ -1,63 +1,86 @@
- + ['enctype' => 'multipart/form-data'] + 'options' => [ 'enctype' => 'multipart/form-data' ], ]); ?> - - + + field($model, 'date_add') - ->widget(DatePicker::className(), [ - 'dateFormat' => 'dd-MM-yyyy', - ]) ?> - - field($model, 'title')->textInput(['maxlength' => true]) ?> - - field($model, 'link')->textInput(['maxlength' => true]) ?> - - field($model, 'description')->widget(CKEditor::className(), - [ - 'editorOptions' => ElFinder::ckeditorOptions('elfinder',[ - 'preset' => 'full', //разработанны стандартные настройки basic, standard, full данную возможность не обязательно использовать - 'inline' => false, //по умолчанию false]), - 'filebrowserUploadUrl'=>Yii::$app->getUrlManager()->createUrl('file/uploader/images-upload') - ] - ) - ]) ?> - - field($model, 'imagesUpload[]')->widget(\kartik\file\FileInput::className(), [ - 'language' => 'ru', - 'options' => [ - 'accept' => 'image/*', - 'multiple' => true, - ], - 'pluginOptions' => [ - 'allowedFileExtensions' => ['jpg', 'gif', 'png'], - 'initialPreview' => !empty($model->imagesHTML) ? $model->imagesHTML : [], - 'initialPreviewConfig' => $model->imagesConfig, - 'overwriteInitial' => false, - 'showRemove' => false, - 'showUpload' => false, - 'uploadAsync' => !empty($model->project_id), - 'previewFileType' => 'image', - ], - ]); ?> - + ->widget(DatePicker::className(), [ + 'dateFormat' => 'dd-MM-yyyy', + ]) ?> + + field($model, 'title') + ->textInput([ 'maxlength' => true ]) ?> + + field($model, 'link') + ->textInput([ 'maxlength' => true ]) ?> + + field($model, 'description') + ->widget(CKEditor::className(), [ + 'editorOptions' => ElFinder::ckeditorOptions('elfinder', [ + 'preset' => 'full', + //разработанны стандартные настройки basic, standard, full данную возможность не обязательно использовать + 'inline' => false, + //по умолчанию false]), + 'filebrowserUploadUrl' => Yii::$app->getUrlManager() + ->createUrl('file/uploader/images-upload'), + ]), + ]) ?> + + field($model, 'imagesUpload[]') + ->widget(\kartik\file\FileInput::className(), [ + 'language' => 'ru', + 'options' => [ + 'accept' => 'image/*', + 'multiple' => true, + ], + 'pluginOptions' => [ + 'allowedFileExtensions' => [ + 'jpg', + 'gif', + 'png', + ], + 'initialPreview' => !empty( $model->imagesHTML ) ? $model->imagesHTML : [], + 'initialPreviewConfig' => $model->imagesConfig, + 'overwriteInitial' => false, + 'showRemove' => false, + 'showUpload' => false, + 'uploadAsync' => !empty( $model->project_id ), + 'previewFileType' => 'image', + ], + ]); ?> + + $model_langs, + 'formView' => '@backend/views/project/_form_language', + 'form' => $form, + ]) ?> +
- isNewRecord ? 'Create' : 'Update', ['class' => $model->isNewRecord ? 'btn btn-success' : 'btn btn-primary']) ?> + isNewRecord ? 'Create' : 'Update', [ 'class' => $model->isNewRecord ? 'btn btn-success' : 'btn btn-primary' ]) ?>
- +
diff --git a/backend/views/project/_form_language.php b/backend/views/project/_form_language.php new file mode 100644 index 0000000..9154cd9 --- /dev/null +++ b/backend/views/project/_form_language.php @@ -0,0 +1,26 @@ + +field($model_lang, '[' . $language->language_id . ']title') + ->textInput([ 'maxlength' => true ]); ?> +field($model_lang, '[' . $language->language_id . ']description') + ->widget(CKEditor::className(), [ + 'editorOptions' => ElFinder::ckeditorOptions('elfinder', [ + 'preset' => 'full', + 'inline' => false, + 'filebrowserUploadUrl' => Yii::$app->getUrlManager() + ->createUrl('file/uploader/images-upload'), + ]), + ]) ?> \ No newline at end of file diff --git a/backend/views/project/create.php b/backend/views/project/create.php index 90ac906..dc1cd72 100644 --- a/backend/views/project/create.php +++ b/backend/views/project/create.php @@ -1,21 +1,30 @@ title = 'Create Project'; -$this->params['breadcrumbs'][] = ['label' => 'Projects', 'url' => ['index']]; -$this->params['breadcrumbs'][] = $this->title; + + use common\models\Project; + use common\models\ProjectLang; + use yii\helpers\Html; + use yii\web\View; + + /** + * @var View $this + * @var Project $model + * @var ProjectLang $model_langs + */ + + $this->title = 'Create Project'; + $this->params[ 'breadcrumbs' ][] = [ + 'label' => 'Projects', + 'url' => [ 'index' ], + ]; + $this->params[ 'breadcrumbs' ][] = $this->title; ?>
- +

title) ?>

- + render('_form', [ - 'model' => $model, + 'model' => $model, + 'model_langs' => $model_langs, ]) ?>
diff --git a/backend/views/project/update.php b/backend/views/project/update.php index d62bebb..1f45b53 100644 --- a/backend/views/project/update.php +++ b/backend/views/project/update.php @@ -1,21 +1,36 @@ title = 'Update Project: ' . $model->title; -$this->params['breadcrumbs'][] = ['label' => 'Project', 'url' => ['index']]; -$this->params['breadcrumbs'][] = ['label' => $model->title, 'url' => ['view', 'id' => $model->project_id]]; -$this->params['breadcrumbs'][] = 'Update'; + + use common\models\Project; + use common\models\ProjectLang; + use yii\helpers\Html; + use yii\web\View; + + /** + * @var View $this + * @var Project $model + * @var ProjectLang $model_langs + */ + $this->title = 'Update Project: ' . $model->title; + $this->params[ 'breadcrumbs' ][] = [ + 'label' => 'Project', + 'url' => [ 'index' ], + ]; + $this->params[ 'breadcrumbs' ][] = [ + 'label' => $model->title, + 'url' => [ + 'view', + 'id' => $model->project_id, + ], + ]; + $this->params[ 'breadcrumbs' ][] = 'Update'; ?>
- +

title) ?>

- + render('_form', [ - 'model' => $model, + 'model' => $model, + 'model_langs' => $model_langs, ]) ?>
diff --git a/backend/views/seo-category/_form.php b/backend/views/seo-category/_form.php index ead4d86..00dc571 100644 --- a/backend/views/seo-category/_form.php +++ b/backend/views/seo-category/_form.php @@ -1,27 +1,43 @@
- + - - field($model, 'name')->textInput(['maxlength' => true]) ?> - - field($model, 'controller')->textInput(['maxlength' => true]) ?> - - field($model, 'status')->textInput() ?> - + + field($model, 'name') + ->textInput([ 'maxlength' => true ]) ?> + + field($model, 'controller') + ->textInput([ 'maxlength' => true ]) ?> + + field($model, 'status') + ->textInput() ?> + + $model_langs, + 'formView' => '@backend/views/seo-category/_form_language', + 'form' => $form, + ]) ?> +
- isNewRecord ? Yii::t('app', 'Create') : Yii::t('app', 'Update'), ['class' => $model->isNewRecord ? 'btn btn-success' : 'btn btn-primary']) ?> + isNewRecord ? Yii::t('app', 'Create') : Yii::t('app', 'Update'), [ 'class' => $model->isNewRecord ? 'btn btn-success' : 'btn btn-primary' ]) ?>
- +
diff --git a/backend/views/seo-category/_form_language.php b/backend/views/seo-category/_form_language.php new file mode 100644 index 0000000..e56c7a0 --- /dev/null +++ b/backend/views/seo-category/_form_language.php @@ -0,0 +1,15 @@ + +field($model_lang, '[' . $language->language_id . ']name') + ->textInput([ 'maxlength' => true ]); ?> \ No newline at end of file diff --git a/backend/views/seo-category/create.php b/backend/views/seo-category/create.php index 7729b68..7dbcd09 100644 --- a/backend/views/seo-category/create.php +++ b/backend/views/seo-category/create.php @@ -1,21 +1,30 @@ title = Yii::t('app', 'Create Seo Category'); -$this->params['breadcrumbs'][] = ['label' => Yii::t('app', 'Seo Categories'), 'url' => ['index']]; -$this->params['breadcrumbs'][] = $this->title; + + use common\models\SeoCategory; + use common\models\SeoCategoryLang; + use yii\helpers\Html; + use yii\web\View; + + /** + * @var View $this + * @var SeoCategory $model + * @var SeoCategoryLang[] $model_langs + */ + + $this->title = Yii::t('app', 'Create Seo Category'); + $this->params[ 'breadcrumbs' ][] = [ + 'label' => Yii::t('app', 'Seo Categories'), + 'url' => [ 'index' ], + ]; + $this->params[ 'breadcrumbs' ][] = $this->title; ?>
- +

title) ?>

- + render('_form', [ - 'model' => $model, + 'model' => $model, + 'model_langs' => $model_langs, ]) ?>
diff --git a/backend/views/seo-category/update.php b/backend/views/seo-category/update.php index 34b49fb..e832b95 100644 --- a/backend/views/seo-category/update.php +++ b/backend/views/seo-category/update.php @@ -1,23 +1,39 @@ title = Yii::t('app', 'Update {modelClass}: ', [ - 'modelClass' => 'Seo Category', -]) . $model->name; -$this->params['breadcrumbs'][] = ['label' => Yii::t('app', 'Seo Categories'), 'url' => ['index']]; -$this->params['breadcrumbs'][] = ['label' => $model->name, 'url' => ['view', 'id' => $model->seo_category_id]]; -$this->params['breadcrumbs'][] = Yii::t('app', 'Update'); + + use common\models\SeoCategory; + use common\models\SeoCategoryLang; + use yii\helpers\Html; + use yii\web\View; + + /** + * @var View $this + * @var SeoCategory $model + * @var SeoCategoryLang[] $model_langs + */ + + $this->title = Yii::t('app', 'Update {modelClass}: ', [ + 'modelClass' => 'Seo Category', + ]) . $model->name; + $this->params[ 'breadcrumbs' ][] = [ + 'label' => Yii::t('app', 'Seo Categories'), + 'url' => [ 'index' ], + ]; + $this->params[ 'breadcrumbs' ][] = [ + 'label' => $model->name, + 'url' => [ + 'view', + 'id' => $model->seo_category_id, + ], + ]; + $this->params[ 'breadcrumbs' ][] = Yii::t('app', 'Update'); ?>
- +

title) ?>

- + render('_form', [ - 'model' => $model, + 'model' => $model, + 'model_langs' => $model_langs, ]) ?>
diff --git a/backend/views/seo-dynamic/_form.php b/backend/views/seo-dynamic/_form.php index d39755b..b0486a8 100644 --- a/backend/views/seo-dynamic/_form.php +++ b/backend/views/seo-dynamic/_form.php @@ -1,11 +1,19 @@
- + - - field($model, 'name')->textInput(['maxlength' => true]) ?> - - field($model, 'action')->textInput(['maxlength' => true]) ?> - - field($model, 'param')->textInput(['maxlength' => true]) ?> - - field($model, 'key')->textInput(['maxlength' => true]) ?> - - field($model, 'fields')->textInput(['maxlength' => true]) ?> - - field($model, 'title')->textInput(['maxlength' => true]) ?> - - field($model, 'meta')->textInput(['maxlength' => true]) ?> - - field($model, 'h1')->textInput(['maxlength' => true]) ?> - - field($model, 'description')->textInput(['maxlength' => true]) ?> - - field($model, 'seo_text')->textarea(['rows' => 6]) ?> - - field($model, 'status')->textInput() ?> - + + field($model, 'name') + ->textInput([ 'maxlength' => true ]) ?> + + field($model, 'action') + ->textInput([ 'maxlength' => true ]) ?> + + field($model, 'param') + ->textInput([ 'maxlength' => true ]) ?> + + field($model, 'key') + ->textInput([ 'maxlength' => true ]) ?> + + field($model, 'fields') + ->textInput([ 'maxlength' => true ]) ?> + + field($model, 'title') + ->textInput([ 'maxlength' => true ]) ?> + + field($model, 'meta') + ->textInput([ 'maxlength' => true ]) ?> + + field($model, 'h1') + ->textInput([ 'maxlength' => true ]) ?> + + field($model, 'description') + ->textInput([ 'maxlength' => true ]) ?> + + field($model, 'seo_text') + ->textarea([ 'rows' => 6 ]) ?> + + field($model, 'status') + ->textInput() ?> + + $model_langs, + 'formView' => '@backend/views/seo-dynamic/_form_language', + 'form' => $form, + ]) ?> +
- isNewRecord ? Yii::t('app', 'Create') : Yii::t('app', 'Update'), ['class' => $model->isNewRecord ? 'btn btn-success' : 'btn btn-primary']) ?> + isNewRecord ? Yii::t('app', 'Create') : Yii::t('app', 'Update'), [ 'class' => $model->isNewRecord ? 'btn btn-success' : 'btn btn-primary' ]) ?>
- + - - - - - - - - - - - - -
diff --git a/backend/views/seo-dynamic/_form_language.php b/backend/views/seo-dynamic/_form_language.php new file mode 100644 index 0000000..527d754 --- /dev/null +++ b/backend/views/seo-dynamic/_form_language.php @@ -0,0 +1,45 @@ + +field($model_lang, '[' . $language->language_id . ']name') + ->textInput([ 'maxlength' => true ]); ?> +field($model_lang, '[' . $language->language_id . ']title') + ->textInput(); ?> +field($model_lang, '[' . $language->language_id . ']description') + ->widget(CKEditor::className(), [ + 'editorOptions' => ElFinder::ckeditorOptions('elfinder', [ + 'preset' => 'full', + 'inline' => false, + 'filebrowserUploadUrl' => Yii::$app->getUrlManager() + ->createUrl('file/uploader/images-upload'), + ]), + ]) ?> + +field($model_lang, '[' . $language->language_id . ']seo_text') + ->widget(CKEditor::className(), [ + 'editorOptions' => ElFinder::ckeditorOptions('elfinder', [ + 'preset' => 'full', + 'inline' => false, + 'filebrowserUploadUrl' => Yii::$app->getUrlManager() + ->createUrl('file/uploader/images-upload'), + ]), + ]) ?> +field($model_lang, '[' . $language->language_id . ']key') + ->textInput([ 'maxlength' => true ]) ?> +field($model_lang, '[' . $language->language_id . ']h1') + ->textInput([ 'maxlength' => true ]) ?> + +field($model_lang, '[' . $language->language_id . ']meta') + ->textInput([ 'maxlength' => true ]) ?> \ No newline at end of file diff --git a/backend/views/seo-dynamic/create.php b/backend/views/seo-dynamic/create.php index d71114a..278c923 100644 --- a/backend/views/seo-dynamic/create.php +++ b/backend/views/seo-dynamic/create.php @@ -1,22 +1,35 @@ title = Yii::t('app', 'Create Seo Dynamic'); -$this->params['breadcrumbs'][] = ['label' => Yii::t('app', 'Seo Dynamics'), 'url' => Url::toRoute(['index','seo_category_id'=>$seo_category_id])]; -$this->params['breadcrumbs'][] = $this->title; + + use common\models\SeoDynamic; + use common\models\SeoDynamicLang; + use yii\helpers\Html; + use yii\helpers\Url; + use yii\web\View; + + /** + * @var View $this + * @var SeoDynamic $model + * @var SeoDynamicLang[] $model_langs + * @var int $seo_category_id + */ + + $this->title = Yii::t('app', 'Create Seo Dynamic'); + $this->params[ 'breadcrumbs' ][] = [ + 'label' => Yii::t('app', 'Seo Dynamics'), + 'url' => Url::toRoute([ + 'index', + 'seo_category_id' => $seo_category_id, + ]), + ]; + $this->params[ 'breadcrumbs' ][] = $this->title; ?>
- +

title) ?>

- + render('_form', [ - 'model' => $model, + 'model' => $model, + 'model_langs' => $model_langs, ]) ?>
diff --git a/backend/views/seo-dynamic/update.php b/backend/views/seo-dynamic/update.php index d43fdfc..951606f 100644 --- a/backend/views/seo-dynamic/update.php +++ b/backend/views/seo-dynamic/update.php @@ -1,24 +1,45 @@ title = Yii::t('app', 'Update {modelClass}: ', [ - 'modelClass' => 'Seo Dynamic', -]) . $model->name; -$this->params['breadcrumbs'][] = ['label' => Yii::t('app', 'Seo Dynamics'), 'url' => Url::toRoute(['index','seo_category_id'=>$seo_category_id])]; -$this->params['breadcrumbs'][] = ['label' => $model->name, 'url' => Url::toRoute(['view', 'seo_category_id'=>$seo_category_id, 'id' => $model->seo_dynamic_id])]; -$this->params['breadcrumbs'][] = Yii::t('app', 'Update'); + + use common\models\SeoDynamic; + use common\models\SeoDynamicLang; + use yii\helpers\Html; + use yii\helpers\Url; + use yii\web\View; + + /** + * @var View $this + * @var SeoDynamic $model + * @var SeoDynamicLang[] $model_langs + * @var int $seo_category_id + */ + + $this->title = Yii::t('app', 'Update {modelClass}: ', [ + 'modelClass' => 'Seo Dynamic', + ]) . $model->name; + $this->params[ 'breadcrumbs' ][] = [ + 'label' => Yii::t('app', 'Seo Dynamics'), + 'url' => Url::toRoute([ + 'index', + 'seo_category_id' => $seo_category_id, + ]), + ]; + $this->params[ 'breadcrumbs' ][] = [ + 'label' => $model->name, + 'url' => Url::toRoute([ + 'view', + 'seo_category_id' => $seo_category_id, + 'id' => $model->seo_dynamic_id, + ]), + ]; + $this->params[ 'breadcrumbs' ][] = Yii::t('app', 'Update'); ?>
- +

title) ?>

- + render('_form', [ - 'model' => $model, + 'model' => $model, + 'model_langs' => $model_langs, ]) ?>
diff --git a/backend/views/seo/_form.php b/backend/views/seo/_form.php index 9853be6..c3b7ba0 100644 --- a/backend/views/seo/_form.php +++ b/backend/views/seo/_form.php @@ -1,41 +1,62 @@
- + - - field($model, 'url')->textInput(['maxlength' => true]) ?> - - field($model, 'title')->textInput(['maxlength' => true]) ?> - - field($model, 'meta')->textInput(['maxlength' => true]) ?> - - field($model, 'description')->textInput(['maxlength' => true]) ?> - - field($model, 'h1')->textInput(['maxlength' => true]) ?> - field($model, 'seo_text')->widget(CKEditor::className(), - [ - 'editorOptions' => ElFinder::ckeditorOptions('elfinder',[ - 'preset' => 'full', //разработанны стандартные настройки basic, standard, full данную возможность не обязательно использовать - 'inline' => false, //по умолчанию false]), - 'filebrowserUploadUrl'=>Yii::$app->getUrlManager()->createUrl('file/uploader/images-upload') - ] - ) - ]) ?> - + + field($model, 'url') + ->textInput([ 'maxlength' => true ]) ?> + + field($model, 'title') + ->textInput([ 'maxlength' => true ]) ?> + + field($model, 'meta') + ->textInput([ 'maxlength' => true ]) ?> + + field($model, 'description') + ->textInput([ 'maxlength' => true ]) ?> + + field($model, 'h1') + ->textInput([ 'maxlength' => true ]) ?> + field($model, 'seo_text') + ->widget(CKEditor::className(), [ + 'editorOptions' => ElFinder::ckeditorOptions('elfinder', [ + 'preset' => 'full', + //разработанны стандартные настройки basic, standard, full данную возможность не обязательно использовать + 'inline' => false, + //по умолчанию false]), + 'filebrowserUploadUrl' => Yii::$app->getUrlManager() + ->createUrl('file/uploader/images-upload'), + ]), + ]) ?> + + $model_langs, + 'formView' => '@backend/views/seo/_form_language', + 'form' => $form, + ]) ?> +
- isNewRecord ? Yii::t('app', 'Create') : Yii::t('app', 'Update'), ['class' => $model->isNewRecord ? 'btn btn-success' : 'btn btn-primary']) ?> + isNewRecord ? Yii::t('app', 'Create') : Yii::t('app', 'Update'), [ 'class' => $model->isNewRecord ? 'btn btn-success' : 'btn btn-primary' ]) ?>
- +
diff --git a/backend/views/seo/_form_language.php b/backend/views/seo/_form_language.php new file mode 100644 index 0000000..6b88aa1 --- /dev/null +++ b/backend/views/seo/_form_language.php @@ -0,0 +1,42 @@ + +field($model_lang, '[' . $language->language_id . ']title') + ->textInput([ 'maxlength' => true ]); ?> +field($model_lang, '[' . $language->language_id . ']description') + ->widget(CKEditor::className(), [ + 'editorOptions' => ElFinder::ckeditorOptions('elfinder', [ + 'preset' => 'full', + 'inline' => false, + 'filebrowserUploadUrl' => Yii::$app->getUrlManager() + ->createUrl('file/uploader/images-upload'), + ]), + ]) ?> + +field($model_lang, '[' . $language->language_id . ']seo_text') + ->widget(CKEditor::className(), [ + 'editorOptions' => ElFinder::ckeditorOptions('elfinder', [ + 'preset' => 'full', + 'inline' => false, + 'filebrowserUploadUrl' => Yii::$app->getUrlManager() + ->createUrl('file/uploader/images-upload'), + ]), + ]) ?> + +field($model_lang, '[' . $language->language_id . ']h1') + ->textInput([ 'maxlength' => true ]) ?> + +field($model_lang, '[' . $language->language_id . ']meta') + ->textInput([ 'maxlength' => true ]) ?> \ No newline at end of file diff --git a/backend/views/seo/create.php b/backend/views/seo/create.php index fb2601c..91d7680 100644 --- a/backend/views/seo/create.php +++ b/backend/views/seo/create.php @@ -1,21 +1,30 @@ title = Yii::t('app', 'Create Seo'); -$this->params['breadcrumbs'][] = ['label' => Yii::t('app', 'Seos'), 'url' => ['index']]; -$this->params['breadcrumbs'][] = $this->title; + + use common\models\Seo; + use common\models\SeoLang; + use yii\helpers\Html; + use yii\web\View; + + /** + * @var View $this + * @var Seo $model + * @var SeoLang[] $model_langs + */ + + $this->title = Yii::t('app', 'Create Seo'); + $this->params[ 'breadcrumbs' ][] = [ + 'label' => Yii::t('app', 'Seos'), + 'url' => [ 'index' ], + ]; + $this->params[ 'breadcrumbs' ][] = $this->title; ?>
- +

title) ?>

- + render('_form', [ - 'model' => $model, + 'model' => $model, + 'model_langs' => $model_langs, ]) ?>
diff --git a/backend/views/seo/update.php b/backend/views/seo/update.php index 0cdcc84..9e3d5ef 100644 --- a/backend/views/seo/update.php +++ b/backend/views/seo/update.php @@ -1,23 +1,39 @@ title = Yii::t('app', 'Update {modelClass}: ', [ - 'modelClass' => 'Seo', -]) . $model->title; -$this->params['breadcrumbs'][] = ['label' => Yii::t('app', 'Seos'), 'url' => ['index']]; -$this->params['breadcrumbs'][] = ['label' => $model->title, 'url' => ['view', 'id' => $model->seo_id]]; -$this->params['breadcrumbs'][] = Yii::t('app', 'Update'); + + use common\models\Seo; + use common\models\SeoLang; + use yii\helpers\Html; + use yii\web\View; + + /** + * @var View $this + * @var Seo $model + * @var SeoLang[] $model_langs + */ + + $this->title = Yii::t('app', 'Update {modelClass}: ', [ + 'modelClass' => 'Seo', + ]) . $model->title; + $this->params[ 'breadcrumbs' ][] = [ + 'label' => Yii::t('app', 'Seos'), + 'url' => [ 'index' ], + ]; + $this->params[ 'breadcrumbs' ][] = [ + 'label' => $model->title, + 'url' => [ + 'view', + 'id' => $model->seo_id, + ], + ]; + $this->params[ 'breadcrumbs' ][] = Yii::t('app', 'Update'); ?>
- +

title) ?>

- + render('_form', [ - 'model' => $model, + 'model' => $model, + 'model_langs' => $model_langs, ]) ?>
diff --git a/backend/views/service/_form.php b/backend/views/service/_form.php index 772d197..977fb2a 100644 --- a/backend/views/service/_form.php +++ b/backend/views/service/_form.php @@ -1,66 +1,85 @@
- + - - field($model, 'name')->textInput(['maxlength' => true]) ?> - - field($model, 'alias')->textInput(['maxlength' => true]) ?> - - field($model, 'body')->widget(CKEditor::className(), - [ - 'editorOptions' => ElFinder::ckeditorOptions('elfinder',[ - 'preset' => 'full', //разработанны стандартные настройки basic, standard, full данную возможность не обязательно использовать - 'inline' => false, //по умолчанию false]), - 'filebrowserUploadUrl'=>Yii::$app->getUrlManager()->createUrl('file/uploader/images-upload') - ] - ) - ]) ?> - - + + field($model, 'name') + ->textInput([ 'maxlength' => true ]) ?> + + field($model, 'alias') + ->textInput([ 'maxlength' => true ]) ?> + + field($model, 'body') + ->widget(CKEditor::className(), [ + 'editorOptions' => ElFinder::ckeditorOptions('elfinder', [ + 'preset' => 'full', + //разработанны стандартные настройки basic, standard, full данную возможность не обязательно использовать + 'inline' => false, + //по умолчанию false]), + 'filebrowserUploadUrl' => Yii::$app->getUrlManager() + ->createUrl('file/uploader/images-upload'), + ]), + ]) ?> + + $model, - 'field'=>'image', - 'size' => [ + 'model' => $model, + 'field' => 'image', + 'size' => [ [ - 'width'=>200, - 'height'=>200, + 'width' => 200, + 'height' => 200, ], [ - 'width'=>940, - 'height'=>480, - ] + 'width' => 940, + 'height' => 480, + ], ], - 'multi'=>false, + 'multi' => false, 'gallery' => $model->image, - 'name' => 'Загрузить изображение' - ]); - ?> - - field($model, 'meta_title')->textInput(['maxlength' => true]) ?> - - field($model, 'description')->textInput(['maxlength' => true]) ?> - - field($model, 'h1')->textInput(['maxlength' => true]) ?> - - field($model, 'seo_text')->textarea(['rows' => 6]) ?> - - + 'name' => 'Загрузить изображение', + ]); ?> + + field($model, 'meta_title') + ->textInput([ 'maxlength' => true ]) ?> + + field($model, 'description') + ->textInput([ 'maxlength' => true ]) ?> + + field($model, 'h1') + ->textInput([ 'maxlength' => true ]) ?> + + field($model, 'seo_text') + ->textarea([ 'rows' => 6 ]) ?> + + $model_langs, + 'formView' => '@backend/views/service/_form_language', + 'form' => $form, + ]) ?> +
- isNewRecord ? Yii::t('app', 'Create') : Yii::t('app', 'Update'), ['class' => $model->isNewRecord ? 'btn btn-success' : 'btn btn-primary']) ?> + isNewRecord ? Yii::t('app', 'Create') : Yii::t('app', 'Update'), [ 'class' => $model->isNewRecord ? 'btn btn-success' : 'btn btn-primary' ]) ?>
- +
diff --git a/backend/views/service/_form_language.php b/backend/views/service/_form_language.php new file mode 100644 index 0000000..5e9c5c0 --- /dev/null +++ b/backend/views/service/_form_language.php @@ -0,0 +1,45 @@ + +field($model_lang, '[' . $language->language_id . ']name') + ->textInput([ 'maxlength' => true ]); ?> +field($model_lang, '[' . $language->language_id . ']body') + ->widget(CKEditor::className(), [ + 'editorOptions' => ElFinder::ckeditorOptions('elfinder', [ + 'preset' => 'full', + 'inline' => false, + 'filebrowserUploadUrl' => Yii::$app->getUrlManager() + ->createUrl('file/uploader/images-upload'), + ]), + ]) ?> + +field($model_lang, '[' . $language->language_id . ']seo_text') + ->widget(CKEditor::className(), [ + 'editorOptions' => ElFinder::ckeditorOptions('elfinder', [ + 'preset' => 'full', + 'inline' => false, + 'filebrowserUploadUrl' => Yii::$app->getUrlManager() + ->createUrl('file/uploader/images-upload'), + ]), + ]) ?> + +field($model_lang, '[' . $language->language_id . ']meta_title') + ->textInput([ 'maxlength' => true ]) ?> + +field($model_lang, '[' . $language->language_id . ']description') + ->textInput([ 'maxlength' => true ]) ?> + +field($model_lang, '[' . $language->language_id . ']h1') + ->textInput([ 'maxlength' => true ]) ?> \ No newline at end of file diff --git a/backend/views/service/create.php b/backend/views/service/create.php index b84b8fd..d7867b0 100644 --- a/backend/views/service/create.php +++ b/backend/views/service/create.php @@ -1,21 +1,30 @@ title = Yii::t('app', 'Create Service'); -$this->params['breadcrumbs'][] = ['label' => Yii::t('app', 'Services'), 'url' => ['index']]; -$this->params['breadcrumbs'][] = $this->title; + + use common\models\Service; + use common\models\ServiceLang; + use yii\helpers\Html; + use yii\web\View; + + /** + * @var View $this + * @var Service $model + * @var ServiceLang[] $model_langs + */ + + $this->title = Yii::t('app', 'Create Service'); + $this->params[ 'breadcrumbs' ][] = [ + 'label' => Yii::t('app', 'Services'), + 'url' => [ 'index' ], + ]; + $this->params[ 'breadcrumbs' ][] = $this->title; ?>
- +

title) ?>

- + render('_form', [ - 'model' => $model, + 'model' => $model, + 'model_langs' => $model_langs, ]) ?>
diff --git a/backend/views/service/update.php b/backend/views/service/update.php index 6e0f6ce..fcbc119 100644 --- a/backend/views/service/update.php +++ b/backend/views/service/update.php @@ -1,23 +1,39 @@ title = Yii::t('app', 'Update {modelClass}: ', [ - 'modelClass' => 'Service', -]) . $model->name; -$this->params['breadcrumbs'][] = ['label' => Yii::t('app', 'Services'), 'url' => ['index']]; -$this->params['breadcrumbs'][] = ['label' => $model->name, 'url' => ['view', 'id' => $model->service_id]]; -$this->params['breadcrumbs'][] = Yii::t('app', 'Update'); + + use common\models\Service; + use common\models\ServiceLang; + use yii\helpers\Html; + use yii\web\View; + + /** + * @var View $this + * @var Service $model + * @var ServiceLang[] $model_langs + */ + + $this->title = Yii::t('app', 'Update {modelClass}: ', [ + 'modelClass' => 'Service', + ]) . $model->name; + $this->params[ 'breadcrumbs' ][] = [ + 'label' => Yii::t('app', 'Services'), + 'url' => [ 'index' ], + ]; + $this->params[ 'breadcrumbs' ][] = [ + 'label' => $model->name, + 'url' => [ + 'view', + 'id' => $model->service_id, + ], + ]; + $this->params[ 'breadcrumbs' ][] = Yii::t('app', 'Update'); ?>
- +

title) ?>

- + render('_form', [ - 'model' => $model, + 'model' => $model, + 'model_langs' => $model_langs, ]) ?>
diff --git a/backend/views/slider-image/_form.php b/backend/views/slider-image/_form.php index 52b2954..5dde8b3 100644 --- a/backend/views/slider-image/_form.php +++ b/backend/views/slider-image/_form.php @@ -1,60 +1,88 @@
- - ['enctype' => 'multipart/form-data']]); ?> - - field($model, 'image')->widget(\kartik\file\FileInput::classname(), [ - 'model' => $model, - 'attribute' => 'image', - 'options' => [ - 'accept' => 'image/*', - 'multiple' => true - ], - 'pluginOptions' => [ - 'allowedFileExtensions' => ['jpg','gif','png'], - 'initialPreview' => $model->imageUrl ? \common\components\artboximage\ArtboxImageHelper::getImage($model->imageUrl, 'slider') : '', - 'overwriteInitial' => true, - 'showRemove' => true, - 'showUpload' => false, - ], - ]); ?> - - - field($model, 'alt')->textInput(['maxlength' => true]) ?> - - field($model, 'title')->textInput(['maxlength' => true]) ?> - - field($model, 'url')->textInput(['maxlength' => true]) ?> - - field($model, 'status')->widget(Select2::className(),([ - 'name' => 'status', - 'hideSearch' => true, - 'data' => [1 => 'Active', 2 => 'Inactive'], - 'options' => ['placeholder' => 'Select status...'], - 'pluginOptions' => [ - 'allowClear' => true - ] - ])) ?> - - field($model, 'sort')->textInput() ?> - + + [ 'enctype' => 'multipart/form-data' ] ]); ?> + + field($model, 'image') + ->widget(\kartik\file\FileInput::className(), [ + 'model' => $model, + 'attribute' => 'image', + 'options' => [ + 'accept' => 'image/*', + 'multiple' => true, + ], + 'pluginOptions' => [ + 'allowedFileExtensions' => [ + 'jpg', + 'gif', + 'png', + ], + 'initialPreview' => $model->imageUrl ? \common\components\artboximage\ArtboxImageHelper::getImage($model->imageUrl, 'slider') : '', + 'overwriteInitial' => true, + 'showRemove' => true, + 'showUpload' => false, + ], + ]); ?> + + + field($model, 'alt') + ->textInput([ 'maxlength' => true ]) ?> + + field($model, 'title') + ->textInput([ 'maxlength' => true ]) ?> + + field($model, 'url') + ->textInput([ 'maxlength' => true ]) ?> + + field($model, 'status') + ->widget(Select2::className(), ( [ + 'name' => 'status', + 'hideSearch' => true, + 'data' => [ + 1 => 'Active', + 2 => 'Inactive', + ], + 'options' => [ 'placeholder' => 'Select status...' ], + 'pluginOptions' => [ + 'allowClear' => true, + ], + ] )) ?> + + field($model, 'sort') + ->textInput() ?> + + $model_langs, + 'formView' => '@backend/views/slider-image/_form_language', + 'form' => $form, + ]); + ?> +
- isNewRecord ? Yii::t('app', 'Create') : Yii::t('app', 'Update'), ['class' => $model->isNewRecord ? 'btn btn-success' : 'btn btn-primary']) ?> + isNewRecord ? Yii::t('app', 'Create') : Yii::t('app', 'Update'), [ 'class' => $model->isNewRecord ? 'btn btn-success' : 'btn btn-primary' ]) ?>
- +
diff --git a/backend/views/slider-image/_form_language.php b/backend/views/slider-image/_form_language.php new file mode 100644 index 0000000..b2ca807 --- /dev/null +++ b/backend/views/slider-image/_form_language.php @@ -0,0 +1,17 @@ + +field($model_lang, '[' . $language->language_id . ']title') + ->textInput([ 'maxlength' => true ]); ?> +field($model_lang, '[' . $language->language_id . ']alt') + ->textInput([ 'maxlength' => true ]); ?> \ No newline at end of file diff --git a/backend/views/slider-image/create.php b/backend/views/slider-image/create.php index 1437321..aa399cd 100644 --- a/backend/views/slider-image/create.php +++ b/backend/views/slider-image/create.php @@ -1,25 +1,37 @@ title = Yii::t('app', 'Create Slider Image'); -$this->params['breadcrumbs'][] = ['label' => Yii::t('app', 'Slider Images'), 'url' => Url::toRoute(['index','slider_id'=>$slider_id])]; -$this->params['breadcrumbs'][] = $this->title; + + use common\models\Slider; + use common\models\SliderImage; + use common\models\SliderImageLang; + use yii\helpers\Html; + use yii\helpers\Url; + use yii\web\View; + + /** + * @var View $this + * @var SliderImage $model + * @var SliderImageLang[] $model_langs + * @var Slider $slider + */ + + $this->title = Yii::t('app', 'Create Slider Image'); + $this->params[ 'breadcrumbs' ][] = [ + 'label' => Yii::t('app', 'Slider Images'), + 'url' => Url::toRoute([ + 'index', + 'slider_id' => $slider_id, + ]), + ]; + $this->params[ 'breadcrumbs' ][] = $this->title; ?>
- +

title) ?>

- + render('_form', [ - 'model' => $model, - 'slider' => $slider, + 'model' => $model, + 'model_langs' => $model_langs, + 'slider' => $slider, ]) ?>
diff --git a/backend/views/slider-image/update.php b/backend/views/slider-image/update.php index e7cf1af..f049b86 100644 --- a/backend/views/slider-image/update.php +++ b/backend/views/slider-image/update.php @@ -1,27 +1,48 @@ title = Yii::t('app', 'Update {modelClass}: ', [ - 'modelClass' => 'Slider Image', -]) . $model->title; -$this->params['breadcrumbs'][] = ['label' => Yii::t('app', 'Slider Images'), 'url' => Url::toRoute(['index','slider_id'=>$slider_id])]; -$this->params['breadcrumbs'][] = ['label' => $model->title, 'url' => Url::toRoute(['view', 'slider_id'=>$slider_id, 'id' => $model->slider_image_id])]; -$this->params['breadcrumbs'][] = Yii::t('app', 'Update'); + + use common\models\SliderImage; + use common\models\SliderImageLang; + use yii\helpers\Html; + use common\models\Slider; + use yii\helpers\Url; + use yii\web\View; + + /** + * @var View $this + * @var SliderImage $model + * @var SliderImageLang[] $model_langs + * @var Slider $slider + * @var int $slider_id + */ + + $this->title = Yii::t('app', 'Update {modelClass}: ', [ + 'modelClass' => 'Slider Image', + ]) . $model->title; + $this->params[ 'breadcrumbs' ][] = [ + 'label' => Yii::t('app', 'Slider Images'), + 'url' => Url::toRoute([ + 'index', + 'slider_id' => $slider_id, + ]), + ]; + $this->params[ 'breadcrumbs' ][] = [ + 'label' => $model->title, + 'url' => Url::toRoute([ + 'view', + 'slider_id' => $slider_id, + 'id' => $model->slider_image_id, + ]), + ]; + $this->params[ 'breadcrumbs' ][] = Yii::t('app', 'Update'); ?>
- +

title) ?>

- + render('_form', [ - 'model' => $model, - 'slider' => $slider, + 'model' => $model, + 'model_langs' => $model_langs, + 'slider' => $slider, ]) ?>
diff --git a/common/behaviors/SaveImgBehavior.php b/common/behaviors/SaveImgBehavior.php index 2c16501..89b0dbe 100644 --- a/common/behaviors/SaveImgBehavior.php +++ b/common/behaviors/SaveImgBehavior.php @@ -1,83 +1,77 @@ 'beforeUpdate', - ActiveRecord::EVENT_BEFORE_INSERT => 'beforeInsert', - ]; - } - - public function beforeUpdate($event) - { - - - if ( ($image = UploadedFile::getInstance($this->owner, 'image')) ) { - $this->owner->image = $image->name; - } - - if(!$this->owner->image){ - $this->owner->image = $this->owner->getOldAttribute('image'); + + public $fields; + public $is_language = false; + + public function events() + { + return [ + ActiveRecord::EVENT_BEFORE_UPDATE => 'beforeSave', + ActiveRecord::EVENT_BEFORE_INSERT => 'beforeSave', + ]; } - - - if ($image) { - $imgDir = \Yii::getAlias('@storage/'.$this->directory.'/'); - - if(!is_dir($imgDir)) { - mkdir($imgDir, 0755, true); + + /** + * @param ModelEvent $event + */ + public function beforeSave($event) { + foreach($this->fields as $field){ + $field_name = $field['name']; + $name = $field_name; + if($this->is_language) { + $name = '['.$this->owner->language_id.']'.$name; + } + + $image = UploadedFile::getInstance($this->owner, $name); + + if(empty($image) && $event->name == ActiveRecord::EVENT_BEFORE_UPDATE) { + $this->owner->$field_name = $this->owner->getOldAttribute($field_name); + } else { + $imgDir = \Yii::getAlias('@storage/'.$field['directory'].'/'); + + if(!is_dir($imgDir)) { + mkdir($imgDir, 0755, true); + } + + $baseName = $image->baseName; + + $iteration = 0; + $file_name = $imgDir.$baseName.'.'.$image->extension; + while(file_exists($file_name)) { + $baseName = $image->baseName.'_'.++$iteration; + $file_name = $imgDir.$baseName.'.'.$image->extension; + } + unset($iteration); + + $this->owner->$field_name = $baseName.'.'.$image->extension; + + $image->saveAs($file_name); + } } - - $image->saveAs(\Yii::getAlias('@storage/'.$this->directory.'/' . $image->name)); } - } - - - public function beforeInsert($event) - { - - - if ( ($image = UploadedFile::getInstance($this->owner, 'image')) ) { - $this->owner->image = $image->name; + + public function getImageFile($image = 'image') { + return empty($this->owner->$image) ? null : '/storage/'.$this->fields[0]['directory'].'/'. $this->owner->$image; } - - - - if ($image) { - $imgDir = \Yii::getAlias('@storage/'.$this->directory.'/'); - - if(!is_dir($imgDir)) { - mkdir($imgDir, 0755, true); - } - - $image->saveAs(\Yii::getAlias('@storage/'.$this->directory.'/' . $image->name)); + + public function getImageUrl($image = 'image') { + return empty($this->owner->$image) ? null : '/storage/'.$this->fields[0]['directory'].'/'. $this->owner->$image; } - } - - - - public function getImageFile() { - return empty($this->owner->image) ? null : '/storage/'.$this->directory.'/'. $this->owner->image; - } - - public function getImageUrl() { - return empty($this->owner->image) ? null : '/storage/'.$this->directory.'/'. $this->owner->image; - } -} \ No newline at end of file + + + + } \ No newline at end of file diff --git a/common/models/Articles.php b/common/models/Articles.php index 7e4ec9e..10388d0 100644 --- a/common/models/Articles.php +++ b/common/models/Articles.php @@ -1,135 +1,216 @@ [ - 'class' => 'common\behaviors\Slug', - 'in_attribute' => 'title', - 'out_attribute' => 'translit', - 'translit' => true - ], - [ - 'class' => SaveImgBehavior::className(), - ], - ]; - } - - /** - * @inheritdoc - */ - public function rules() - { - return [ - [['date'], 'default', 'value' => function() { - return time(); - }], - [['date'], 'safe'], - [['title', 'body'], 'required'], - [['body', 'body_preview', 'seo_text'], 'string'], - [['title', 'image', 'translit', 'meta_title', 'meta_keywords', 'meta_description', 'h1'], 'string', 'max' => 255], - [['imageUpload'], 'safe'], - [['imageUpload'], 'file', 'extensions' => 'jpg, gif, png'], - [['date'], 'filter', 'filter' => function($value) { - return strtotime($value)?:time(); - }], - ]; - } - + + namespace common\models; + + use common\modules\language\behaviors\LanguageBehavior; + use common\behaviors\SaveImgBehavior; + use common\modules\comment\models\CommentModel; + use Yii; + use yii\db\ActiveQuery; + use yii\db\ActiveRecord; + use yii\web\Request; + /** - * @inheritdoc + * This is the model class for table "articles". + * @property integer $id + * @property integer $date + * @property string $title + * @property string $body + * @property string $image + * @property string $translit + * @property string $meta_title + * @property string $meta_keywords + * @property string $meta_description + * @property string $seo_text + * @property string $h1 + * @property string $body_preview + * * From language behavior * + * @property ArticlesLang $lang + * @property ArticlesLang[] $langs + * @property ArticlesLang $object_lang + * @property string $ownerKey + * @property string $langKey + * @method string getOwnerKey() + * @method void setOwnerKey(string $value) + * @method string getLangKey() + * @method void setLangKey(string $value) + * @method ActiveQuery getLangs() + * @method ActiveQuery getLang( integer $language_id ) + * @method ArticlesLang[] generateLangs() + * @method void loadLangs(Request $request, ActiveRecord[] $model_langs) + * @method bool linkLangs(ActiveRecord[] $model_langs) + * @method bool saveLangs(ActiveRecord[] $model_langs) + * * End language behavior * */ - public function attributeLabels() - { - return [ - 'id' => 'ID', - 'date' => 'Date', - 'title' => 'Title', - 'body' => 'Body', - 'body_preview' => 'Body preview', - 'image' => 'Image', - 'imageUrl' => Yii::t('app', 'Image'), - 'translit' => 'Translit', - 'meta_title' => 'Meta Title', - 'meta_keywords' => 'Meta Keywords', - 'meta_description' => 'Meta Description', - 'seo_text' => 'Seo Text', - 'h1' => 'H1', - ]; - } - - public function getImageFile() { - return empty($this->image) ? null : Yii::getAlias('@imagesDir/articles/'. $this->image); - } - - public function getImageUrl() + class Articles extends \yii\db\ActiveRecord { - return empty($this->image) ? null : Yii::getAlias('@imagesUrl/articles/' . $this->image); - } - - public function recalculateRating() { + public $imageUpload; + /** - * @var ArticleToRating $averageRating + * @inheritdoc */ - $average = $this->getComments()->joinWith('rating')->select(['average' => 'avg(artbox_comment_rating.value)::float'])->scalar(); - if(!$average) { - $average = 0; + public static function tableName() + { + return 'articles'; } - $averageRating = $this->averageRating; - if(!empty($averageRating)) { - $averageRating->value = $average; - } else { - $averageRating = new ArticleToRating(['articles_id' => $this->id, 'value' => $average]); + + /** + * @inheritdoc + */ + public function behaviors() + { + return [ + 'slug' => [ + 'class' => 'common\behaviors\Slug', + 'in_attribute' => 'title', + 'out_attribute' => 'translit', + 'translit' => true, + ], + [ + 'class' => SaveImgBehavior::className(), + ], + 'language' => [ + 'class' => LanguageBehavior::className(), + ], + ]; } - if($averageRating->save()) { - return true; - } else { - return false; + + /** + * @inheritdoc + */ + public function rules() + { + return [ + [ + [ 'date' ], + 'default', + 'value' => function() { + return time(); + }, + ], + [ + [ 'date' ], + 'safe', + ], + [ + [ + 'title', + 'body', + ], + 'required', + ], + [ + [ + 'body', + 'body_preview', + 'seo_text', + ], + 'string', + ], + [ + [ + 'title', + 'image', + 'translit', + 'meta_title', + 'meta_keywords', + 'meta_description', + 'h1', + ], + 'string', + 'max' => 255, + ], + [ + [ 'imageUpload' ], + 'safe', + ], + [ + [ 'imageUpload' ], + 'file', + 'extensions' => 'jpg, gif, png', + ], + [ + [ 'date' ], + 'filter', + 'filter' => function($value) { + return strtotime($value) ? : time(); + }, + ], + ]; + } + + /** + * @inheritdoc + */ + public function attributeLabels() + { + return [ + 'id' => 'ID', + 'date' => 'Date', + 'title' => 'Title', + 'body' => 'Body', + 'body_preview' => 'Body preview', + 'image' => 'Image', + 'imageUrl' => Yii::t('app', 'Image'), + 'translit' => 'Translit', + 'meta_title' => 'Meta Title', + 'meta_keywords' => 'Meta Keywords', + 'meta_description' => 'Meta Description', + 'seo_text' => 'Seo Text', + 'h1' => 'H1', + ]; + } + + public function getImageFile() + { + return empty( $this->image ) ? NULL : Yii::getAlias('@imagesDir/articles/' . $this->image); + } + + public function getImageUrl() + { + return empty( $this->image ) ? NULL : Yii::getAlias('@imagesUrl/articles/' . $this->image); + } + + public function recalculateRating() + { + /** + * @var ArticleToRating $averageRating + */ + $average = $this->getComments() + ->joinWith('rating') + ->select([ 'average' => 'avg(artbox_comment_rating.value)::float' ]) + ->scalar(); + if(!$average) { + $average = 0; + } + $averageRating = $this->averageRating; + if(!empty( $averageRating )) { + $averageRating->value = $average; + } else { + $averageRating = new ArticleToRating([ + 'articles_id' => $this->id, + 'value' => $average, + ]); + } + if($averageRating->save()) { + return true; + } else { + return false; + } + } + + public function getComments() + { + return $this->hasMany(CommentModel::className(), [ 'entity_id' => 'id' ]) + ->where([ + 'artbox_comment.entity' => self::className(), + 'artbox_comment.status' => CommentModel::STATUS_ACTIVE, + 'artbox_comment.artbox_comment_pid' => NULL, + ]); + } + + public function getAverageRating() + { + return $this->hasOne(ArticleToRating::className(), [ 'articles_id' => 'id' ]); } } - - public function getComments() { - return $this->hasMany(CommentModel::className(), ['entity_id' => 'id'])->where(['artbox_comment.entity' => self::className(), 'artbox_comment.status' => CommentModel::STATUS_ACTIVE, 'artbox_comment.artbox_comment_pid' => NULL]); - } - - public function getAverageRating() { - return $this->hasOne(ArticleToRating::className(), ['articles_id' => 'id']); - } -} diff --git a/common/models/ArticlesLang.php b/common/models/ArticlesLang.php new file mode 100644 index 0000000..c394983 --- /dev/null +++ b/common/models/ArticlesLang.php @@ -0,0 +1,92 @@ + 255], + [['articles_id', 'language_id'], 'unique', 'targetAttribute' => ['articles_id', 'language_id'], 'message' => 'The combination of Articles ID and Language ID has already been taken.'], + [['articles_id'], 'exist', 'skipOnError' => true, 'targetClass' => Articles::className(), 'targetAttribute' => ['articles_id' => 'id']], + [['language_id'], 'exist', 'skipOnError' => true, 'targetClass' => Language::className(), 'targetAttribute' => ['language_id' => 'language_id']], + ]; + } + + /** + * @inheritdoc + */ + public function attributeLabels() + { + return [ + 'articles_id' => Yii::t('app', 'Articles ID'), + 'language_id' => Yii::t('app', 'Language ID'), + 'title' => Yii::t('app', 'Title'), + 'body' => Yii::t('app', 'Body'), + 'meta_title' => Yii::t('app', 'Meta Title'), + 'meta_keywords' => Yii::t('app', 'Meta Keywords'), + 'meta_description' => Yii::t('app', 'Meta Description'), + 'seo_text' => Yii::t('app', 'Seo Text'), + 'h1' => Yii::t('app', 'H1'), + 'body_preview' => Yii::t('app', 'Body Preview'), + ]; + } + + /** + * @return \yii\db\ActiveQuery + */ + public function getArticles() + { + return $this->hasOne(Articles::className(), ['id' => 'articles_id'])->inverseOf('langs'); + } + + /** + * @return \yii\db\ActiveQuery + */ + public function getLanguage() + { + return $this->hasOne(Language::className(), ['language_id' => 'language_id']); + } +} diff --git a/common/models/ArticlesSearch.php b/common/models/ArticlesSearch.php index ce150d9..096fa9e 100644 --- a/common/models/ArticlesSearch.php +++ b/common/models/ArticlesSearch.php @@ -22,7 +22,12 @@ class ArticlesSearch extends Articles [['title', 'body', 'translit', 'meta_title', 'meta_keywords', 'meta_description', 'seo_text', 'h1'], 'safe'], ]; } - + + public function behaviors() + { + return []; + } + /** * @inheritdoc */ diff --git a/common/models/Banner.php b/common/models/Banner.php index 4638770..f8c29dc 100644 --- a/common/models/Banner.php +++ b/common/models/Banner.php @@ -2,7 +2,11 @@ namespace common\models; +use common\modules\language\behaviors\LanguageBehavior; use Yii; +use yii\db\ActiveQuery; +use yii\db\ActiveRecord; +use yii\web\Request; /** * This is the model class for table "banner". @@ -13,8 +17,23 @@ use Yii; * @property string $title * @property string $url * @property integer $status - * @property integer $width - * @property integer $height + * * From language behavior * + * @property BannerLang $lang + * @property BannerLang[] $langs + * @property BannerLang $object_lang + * @property string $ownerKey + * @property string $langKey + * @method string getOwnerKey() + * @method void setOwnerKey(string $value) + * @method string getLangKey() + * @method void setLangKey(string $value) + * @method ActiveQuery getLangs() + * @method ActiveQuery getLang( integer $language_id ) + * @method BannerLang[] generateLangs() + * @method void loadLangs(Request $request, ActiveRecord[] $model_langs) + * @method bool linkLangs(ActiveRecord[] $model_langs) + * @method bool saveLangs(ActiveRecord[] $model_langs) + * * End language behavior * */ class Banner extends \yii\db\ActiveRecord { @@ -25,16 +44,24 @@ class Banner extends \yii\db\ActiveRecord { return 'banner'; } - + + public function behaviors() + { + return [ + 'language' => [ + 'class' => LanguageBehavior::className(), + ], + ]; + } + /** * @inheritdoc */ public function rules() { return [ - [['status', 'width', 'height'], 'integer'], + [['status'], 'integer'], [['image', 'alt', 'title', 'url'], 'string', 'max' => 255], - [['width', 'height'], 'required'], ['title', 'unique', 'targetClass' => '\common\models\Slider', 'message' => Yii::t('app','message',[ 'field' => 'Title' ])], @@ -53,15 +80,6 @@ class Banner extends \yii\db\ActiveRecord 'title' => Yii::t('app', 'title'), 'url' => Yii::t('app', 'url'), 'status' => Yii::t('app', 'status'), - 'width' => Yii::t('app', 'width'), - 'height' => Yii::t('app', 'height'), ]; } - - static function getFileExtension ($filename) - { - $ext = explode ('.', $filename); - - return end ($ext); - } } diff --git a/common/models/BannerLang.php b/common/models/BannerLang.php new file mode 100644 index 0000000..660dad8 --- /dev/null +++ b/common/models/BannerLang.php @@ -0,0 +1,97 @@ + SaveImgBehavior::className(), + 'is_language' => true, + 'fields' => [ + [ + 'name' => 'image', + 'directory' => 'banner', + ], + ], + ] + ]; + } + + /** + * @inheritdoc + */ + public function rules() + { + return [ + [['alt', 'title', 'image'], 'string', 'max' => 255], + [['banner_id', 'language_id'], 'unique', 'targetAttribute' => ['banner_id', 'language_id'], 'message' => 'The combination of Banner ID and Language ID has already been taken.'], + [['banner_id'], 'exist', 'skipOnError' => true, 'targetClass' => Banner::className(), 'targetAttribute' => ['banner_id' => 'banner_id']], + [['language_id'], 'exist', 'skipOnError' => true, 'targetClass' => Language::className(), 'targetAttribute' => ['language_id' => 'language_id']], + ]; + } + + /** + * @inheritdoc + */ + public function attributeLabels() + { + return [ + 'banner_id' => Yii::t('app', 'Banner ID'), + 'language_id' => Yii::t('app', 'Language ID'), + 'alt' => Yii::t('app', 'Alt'), + 'title' => Yii::t('app', 'Title'), + ]; + } + + /** + * @return \yii\db\ActiveQuery + */ + public function getBanner() + { + return $this->hasOne(Banner::className(), ['banner_id' => 'banner_id']); + } + + /** + * @return \yii\db\ActiveQuery + */ + public function getLanguage() + { + return $this->hasOne(Language::className(), ['language_id' => 'language_id']); + } +} diff --git a/common/models/BannerSearch.php b/common/models/BannerSearch.php index 32929ba..a6fa15a 100644 --- a/common/models/BannerSearch.php +++ b/common/models/BannerSearch.php @@ -23,6 +23,11 @@ class BannerSearch extends Banner ]; } + public function behaviors() + { + return []; + } + /** * @inheritdoc */ diff --git a/common/models/Basket.php b/common/models/Basket.php index 785a143..9ffc7bd 100644 --- a/common/models/Basket.php +++ b/common/models/Basket.php @@ -11,11 +11,11 @@ public $session; - public function __construct(array $config = [ ]) + public function __construct(array $config = []) { $this->session = \Yii::$app->session; if(!$this->session->has('basket')) { - $this->session->set('basket', [ ]); + $this->session->set('basket', []); } parent::__construct($config); } @@ -25,8 +25,8 @@ $data = $this->getData(); if(array_key_exists($product_variant_id, $data)) { $data[ $product_variant_id ][ 'count' ] = 1; - if($data[$product_variant_id]['count'] <= 0) { - unset($data[$product_variant_id]); + if($data[ $product_variant_id ][ 'count' ] <= 0) { + unset( $data[ $product_variant_id ] ); } } else { if($this->findModel($product_variant_id)) { @@ -37,14 +37,14 @@ } $this->setData($data); } - + private function set(int $product_variant_id, int $count) { $data = $this->getData(); if(array_key_exists($product_variant_id, $data)) { $data[ $product_variant_id ][ 'count' ] = $count; - if($data[$product_variant_id]['count'] <= 0) { - unset($data[$product_variant_id]); + if($data[ $product_variant_id ][ 'count' ] <= 0) { + unset( $data[ $product_variant_id ] ); } } elseif($count > 0) { if($this->findModel($product_variant_id)) { @@ -56,7 +56,8 @@ $this->setData($data); } - public function delete(int $product_variant_id) { + public function delete(int $product_variant_id) + { $this->set($product_variant_id, 0); } @@ -65,10 +66,11 @@ return $this->session->get('basket'); } - public function getItem(int $product_variant_id) { + public function getItem(int $product_variant_id) + { $data = $this->getData(); - if(!empty($data[$product_variant_id])) { - return $data[$product_variant_id]; + if(!empty( $data[ $product_variant_id ] )) { + return $data[ $product_variant_id ]; } else { return false; } @@ -79,7 +81,8 @@ $this->session->set('basket', $data); } - public function getCount(): int { + public function getCount(): int + { $data = $this->getData(); return count($data); } @@ -90,10 +93,11 @@ * @var ProductVariant $model */ $model = ProductVariant::find() - ->where([ 'product_variant_id' => $product_variant_id ]) + ->where([ 'product_variant.product_variant_id' => $product_variant_id ]) + ->joinWith('lang', true, 'INNER JOIN') ->one(); if(empty( $model )) { - throw new NotFoundHttpException('Product not found'); + throw new NotFoundHttpException(\Yii::t('app', 'Product not found')); } else { return $model; } @@ -102,7 +106,8 @@ public function findModels(array $product_variant_ids) { return ProductVariant::find() - ->where([ 'product_variant_id' => $product_variant_ids ]) + ->where([ 'product_variant.product_variant_id' => $product_variant_ids ]) + ->joinWith('lang', true, 'INNER JOIN') ->with([ 'product', 'image', diff --git a/common/models/Bg.php b/common/models/Bg.php index aabd040..e6c3ad7 100644 --- a/common/models/Bg.php +++ b/common/models/Bg.php @@ -2,6 +2,31 @@ namespace common\models; +use common\modules\language\behaviors\LanguageBehavior; +use yii\db\ActiveQuery; +use yii\db\ActiveRecord; +use yii\web\Request; + +/** + * Class Bg + * * From language behavior * + * @property BgLang $lang + * @property BgLang[] $langs + * @property BgLang $object_lang + * @property string $ownerKey + * @property string $langKey + * @method string getOwnerKey() + * @method void setOwnerKey(string $value) + * @method string getLangKey() + * @method void setLangKey(string $value) + * @method ActiveQuery getLangs() + * @method ActiveQuery getLang( integer $language_id ) + * @method BgLang[] generateLangs() + * @method void loadLangs(Request $request, ActiveRecord[] $model_langs) + * @method bool linkLangs(ActiveRecord[] $model_langs) + * @method bool saveLangs(ActiveRecord[] $model_langs) + * * End language behavior * + */ class Bg extends \yii\db\ActiveRecord { public $old_image; @@ -10,8 +35,17 @@ class Bg extends \yii\db\ActiveRecord { return 'bg'; } - - public function rules() + + public function behaviors() + { + return [ + 'language' => [ + 'class' => LanguageBehavior::className(), + ], + ]; + } + + public function rules() { return [ [['title'], 'required'], diff --git a/common/models/BgLang.php b/common/models/BgLang.php new file mode 100644 index 0000000..f054ebc --- /dev/null +++ b/common/models/BgLang.php @@ -0,0 +1,78 @@ + 255], + [['bg_id', 'language_id'], 'unique', 'targetAttribute' => ['bg_id', 'language_id'], 'message' => 'The combination of Bg ID and Language ID has already been taken.'], + [['bg_id'], 'exist', 'skipOnError' => true, 'targetClass' => Bg::className(), 'targetAttribute' => ['bg_id' => 'id']], + [['language_id'], 'exist', 'skipOnError' => true, 'targetClass' => Language::className(), 'targetAttribute' => ['language_id' => 'language_id']], + ]; + } + + /** + * @inheritdoc + */ + public function attributeLabels() + { + return [ + 'bg_id' => Yii::t('app', 'Bg ID'), + 'language_id' => Yii::t('app', 'Language ID'), + 'title' => Yii::t('app', 'Title'), + ]; + } + + /** + * @return \yii\db\ActiveQuery + */ + public function getBg() + { + return $this->hasOne(Bg::className(), ['id' => 'bg_id']); + } + + /** + * @return \yii\db\ActiveQuery + */ + public function getLanguage() + { + return $this->hasOne(Language::className(), ['language_id' => 'language_id']); + } +} diff --git a/common/models/BgSearch.php b/common/models/BgSearch.php index 485aa6e..44577a1 100644 --- a/common/models/BgSearch.php +++ b/common/models/BgSearch.php @@ -22,7 +22,12 @@ class BgSearch extends Bg [['title', 'url', 'image'], 'safe'], ]; } - + + public function behaviors() + { + return []; + } + /** * @inheritdoc */ diff --git a/common/models/Delivery.php b/common/models/Delivery.php index d1a9304..04f1ce0 100644 --- a/common/models/Delivery.php +++ b/common/models/Delivery.php @@ -2,8 +2,44 @@ namespace common\models; +use common\modules\language\behaviors\LanguageBehavior; +use yii\db\ActiveQuery; +use yii\db\ActiveRecord; +use yii\web\Request; + +/** + * Class Delivery + * + * * From language behavior * + * @property OrdersDeliveryLang $lang + * @property OrdersDeliveryLang[] $langs + * @property OrdersDeliveryLang $object_lang + * @property string $ownerKey + * @property string $langKey + * @method string getOwnerKey() + * @method void setOwnerKey(string $value) + * @method string getLangKey() + * @method void setLangKey(string $value) + * @method ActiveQuery getLangs() + * @method ActiveQuery getLang( integer $language_id ) + * @method OrdersDeliveryLang[] generateLangs() + * @method void loadLangs(Request $request, ActiveRecord[] $model_langs) + * @method bool linkLangs(ActiveRecord[] $model_langs) + * @method bool saveLangs(ActiveRecord[] $model_langs) + * * End language behavior * + */ class Delivery extends \yii\db\ActiveRecord { + + public function behaviors() + { + return [ + 'language' => [ + 'class' => LanguageBehavior::className(), + ], + ]; + } + public static function tableName() { return 'orders_delivery'; diff --git a/common/models/Event.php b/common/models/Event.php index c49e402..1c2bb5a 100644 --- a/common/models/Event.php +++ b/common/models/Event.php @@ -2,8 +2,13 @@ namespace common\models; +use common\modules\language\behaviors\LanguageBehavior; use Yii; use yii\behaviors\TimestampBehavior; +use yii\db\ActiveQuery; +use yii\db\ActiveRecord; +use yii\web\Request; + /** * This is the model class for table "event". * @@ -19,6 +24,24 @@ use yii\behaviors\TimestampBehavior; * @property integer $created_at * @property integer $updated_at * @property integer $end_at + * + * *From language behavior * + * @property EventLang $lang + * @property EventLang[] $langs + * @property EventLang $object_lang + * @property string $ownerKey + * @property string $langKey + * @method string getOwnerKey() + * @method void setOwnerKey(string $value) + * @method string getLangKey() + * @method void setLangKey(string $value) + * @method ActiveQuery getLangs() + * @method ActiveQuery getLang( integer $language_id ) + * @method EventLang[] generateLangs() + * @method void loadLangs(Request $request, ActiveRecord[] $model_langs) + * @method bool linkLangs(ActiveRecord[] $model_langs) + * @method bool saveLangs(ActiveRecord[] $model_langs) + * * End language behavior * */ class Event extends \yii\db\ActiveRecord { @@ -48,6 +71,9 @@ class Event extends \yii\db\ActiveRecord [ 'class' => 'common\behaviors\ShowImage', ], + 'language' => [ + 'class' => LanguageBehavior::className(), + ], ]; } diff --git a/common/models/EventLang.php b/common/models/EventLang.php new file mode 100644 index 0000000..f76afca --- /dev/null +++ b/common/models/EventLang.php @@ -0,0 +1,89 @@ + 255], + [['event_id', 'language_id'], 'unique', 'targetAttribute' => ['event_id', 'language_id'], 'message' => 'The combination of Event ID and Language ID has already been taken.'], + [['event_id'], 'exist', 'skipOnError' => true, 'targetClass' => Event::className(), 'targetAttribute' => ['event_id' => 'event_id']], + [['language_id'], 'exist', 'skipOnError' => true, 'targetClass' => Language::className(), 'targetAttribute' => ['language_id' => 'language_id']], + ]; + } + + /** + * @inheritdoc + */ + public function attributeLabels() + { + return [ + 'event_id' => Yii::t('app', 'Event ID'), + 'language_id' => Yii::t('app', 'Language ID'), + 'name' => Yii::t('app', 'Name'), + 'body' => Yii::t('app', 'Body'), + 'meta_title' => Yii::t('app', 'Meta Title'), + 'description' => Yii::t('app', 'Description'), + 'seo_text' => Yii::t('app', 'Seo Text'), + 'h1' => Yii::t('app', 'H1'), + ]; + } + + /** + * @return \yii\db\ActiveQuery + */ + public function getEvent() + { + return $this->hasOne(Event::className(), ['event_id' => 'event_id']); + } + + /** + * @return \yii\db\ActiveQuery + */ + public function getLanguage() + { + return $this->hasOne(Language::className(), ['language_id' => 'language_id']); + } +} diff --git a/common/models/EventSearch.php b/common/models/EventSearch.php index 60c85b9..a6fa7e9 100644 --- a/common/models/EventSearch.php +++ b/common/models/EventSearch.php @@ -2,10 +2,8 @@ namespace common\models; -use Yii; use yii\base\Model; use yii\data\ActiveDataProvider; -use common\models\Event; /** * EventSearch represents the model behind the search form about `common\models\Event`. @@ -22,9 +20,12 @@ class EventSearch extends Event [['name', 'alias', 'body', 'image', 'meta_title', 'description', 'h1', 'seo_text'], 'safe'], ]; } - - - + + public function behaviors() + { + return []; + } + /** * @inheritdoc */ diff --git a/common/models/OrdersDeliveryLang.php b/common/models/OrdersDeliveryLang.php new file mode 100644 index 0000000..c53e93f --- /dev/null +++ b/common/models/OrdersDeliveryLang.php @@ -0,0 +1,81 @@ + 255], + [['orders_delivery_id', 'language_id'], 'unique', 'targetAttribute' => ['orders_delivery_id', 'language_id'], 'message' => 'The combination of Orders Delivery ID and Language ID has already been taken.'], + [['language_id'], 'exist', 'skipOnError' => true, 'targetClass' => Language::className(), 'targetAttribute' => ['language_id' => 'language_id']], + [['orders_delivery_id'], 'exist', 'skipOnError' => true, 'targetClass' => OrdersDelivery::className(), 'targetAttribute' => ['orders_delivery_id' => 'id']], + ]; + } + + /** + * @inheritdoc + */ + public function attributeLabels() + { + return [ + 'orders_delivery_id' => Yii::t('app', 'Orders Delivery ID'), + 'language_id' => Yii::t('app', 'Language ID'), + 'title' => Yii::t('app', 'Title'), + 'text' => Yii::t('app', 'Text'), + ]; + } + + /** + * @return \yii\db\ActiveQuery + */ + public function getLanguage() + { + return $this->hasOne(Language::className(), ['language_id' => 'language_id']); + } + + /** + * @return \yii\db\ActiveQuery + */ + public function getDelivery() + { + return $this->hasOne(Delivery::className(), ['id' => 'orders_delivery_id']); + } +} diff --git a/common/models/Page.php b/common/models/Page.php index 1bf0df5..bb0315f 100644 --- a/common/models/Page.php +++ b/common/models/Page.php @@ -1,7 +1,11 @@ 'translit', 'translit' => true, ], + 'language' => [ + 'class' => LanguageBehavior::className(), + ], ]; } diff --git a/common/models/PageLang.php b/common/models/PageLang.php new file mode 100644 index 0000000..702427b --- /dev/null +++ b/common/models/PageLang.php @@ -0,0 +1,91 @@ + 255], + [['page_id', 'language_id'], 'unique', 'targetAttribute' => ['page_id', 'language_id'], 'message' => 'The combination of Page ID and Language ID has already been taken.'], + [['language_id'], 'exist', 'skipOnError' => true, 'targetClass' => Language::className(), 'targetAttribute' => ['language_id' => 'language_id']], + [['page_id'], 'exist', 'skipOnError' => true, 'targetClass' => Page::className(), 'targetAttribute' => ['page_id' => 'id']], + ]; + } + + /** + * @inheritdoc + */ + public function attributeLabels() + { + return [ + 'page_id' => Yii::t('app', 'Page ID'), + 'language_id' => Yii::t('app', 'Language ID'), + 'title' => Yii::t('app', 'Title'), + 'body' => Yii::t('app', 'Body'), + 'meta_title' => Yii::t('app', 'Meta Title'), + 'meta_keywords' => Yii::t('app', 'Meta Keywords'), + 'meta_description' => Yii::t('app', 'Meta Description'), + 'seo_text' => Yii::t('app', 'Seo Text'), + 'h1' => Yii::t('app', 'H1'), + ]; + } + + /** + * @return \yii\db\ActiveQuery + */ + public function getLanguage() + { + return $this->hasOne(Language::className(), ['language_id' => 'language_id']); + } + + /** + * @return \yii\db\ActiveQuery + */ + public function getPage() + { + return $this->hasOne(Page::className(), ['id' => 'page_id']); + } +} diff --git a/common/models/PageSearch.php b/common/models/PageSearch.php index 3123ec7..39fa69c 100644 --- a/common/models/PageSearch.php +++ b/common/models/PageSearch.php @@ -29,7 +29,12 @@ class PageSearch extends Page // bypass scenarios() implementation in the parent class return Model::scenarios(); } - + + public function behaviors() + { + return []; + } + /** * Creates data provider instance with search query applied * diff --git a/common/models/ProductSpec.php b/common/models/ProductSpec.php index a457977..41479cc 100644 --- a/common/models/ProductSpec.php +++ b/common/models/ProductSpec.php @@ -2,7 +2,11 @@ namespace common\models; + use common\modules\language\behaviors\LanguageBehavior; use common\modules\product\models\Product; + use yii\db\ActiveQuery; + use yii\db\ActiveRecord; + use yii\web\Request; use yii\web\UploadedFile; /** @@ -14,6 +18,24 @@ * @property string $tech_char_link * @property string $instruction * @property Product $product + * + * * From language behavior * + * @property ProductSpecLang $lang + * @property ProductSpecLang[] $langs + * @property ProductSpecLang $object_lang + * @property string $ownerKey + * @property string $langKey + * @method string getOwnerKey() + * @method void setOwnerKey(string $value) + * @method string getLangKey() + * @method void setLangKey(string $value) + * @method ActiveQuery getLangs() + * @method ActiveQuery getLang( integer $language_id ) + * @method ProductSpecLang[] generateLangs() + * @method void loadLangs(Request $request, ActiveRecord[] $model_langs) + * @method bool linkLangs(ActiveRecord[] $model_langs) + * @method bool saveLangs(ActiveRecord[] $model_langs) + * * End language behavior * */ class ProductSpec extends \yii\db\ActiveRecord { @@ -36,6 +58,15 @@ return 'product_spec'; } + public function behaviors() + { + return [ + 'language' => [ + 'class' => LanguageBehavior::className(), + ], + ]; + } + /** * @inheritdoc */ @@ -49,13 +80,6 @@ ], 'string', ], -// [ -// [ 'product_id' ], -// 'exist', -// 'skipOnError' => true, -// 'targetClass' => Product::className(), -// 'targetAttribute' => [ 'product_id' => 'product_id' ], -// ], [ [ 'techSpecFile', diff --git a/common/models/ProductSpecLang.php b/common/models/ProductSpecLang.php new file mode 100644 index 0000000..32a53ec --- /dev/null +++ b/common/models/ProductSpecLang.php @@ -0,0 +1,79 @@ + ['product_spec_id', 'language_id'], 'message' => 'The combination of Product Spec ID and Language ID has already been taken.'], + [['language_id'], 'exist', 'skipOnError' => true, 'targetClass' => Language::className(), 'targetAttribute' => ['language_id' => 'language_id']], + [['product_spec_id'], 'exist', 'skipOnError' => true, 'targetClass' => ProductSpec::className(), 'targetAttribute' => ['product_spec_id' => 'product_spec_id']], + ]; + } + + /** + * @inheritdoc + */ + public function attributeLabels() + { + return [ + 'product_spec_id' => Yii::t('app', 'Product Spec ID'), + 'language_id' => Yii::t('app', 'Language ID'), + 'tech_spec_text' => Yii::t('app', 'Tech Spec Text'), + 'instruction' => Yii::t('app', 'Instruction'), + ]; + } + + /** + * @return \yii\db\ActiveQuery + */ + public function getLanguage() + { + return $this->hasOne(Language::className(), ['language_id' => 'language_id']); + } + + /** + * @return \yii\db\ActiveQuery + */ + public function getProductSpec() + { + return $this->hasOne(ProductSpec::className(), ['product_spec_id' => 'product_spec_id']); + } +} diff --git a/common/models/Project.php b/common/models/Project.php index 0af6493..9524646 100644 --- a/common/models/Project.php +++ b/common/models/Project.php @@ -2,7 +2,11 @@ namespace common\models; + use common\modules\language\behaviors\LanguageBehavior; use common\modules\product\models\ProductVariant; + use yii\db\ActiveQuery; + use yii\db\ActiveRecord; + use yii\web\Request; /** * This is the model class for table "project". @@ -16,6 +20,23 @@ * @property array $imagesConfig * @property ProductVariant[] $variants * @property ProductToProject[] $productToProject + * * From language behavior * + * @property ProjectLang $lang + * @property ProjectLang[] $langs + * @property ProjectLang $object_lang + * @property string $ownerKey + * @property string $langKey + * @method string getOwnerKey() + * @method void setOwnerKey( string $value ) + * @method string getLangKey() + * @method void setLangKey( string $value ) + * @method ActiveQuery getLangs() + * @method ActiveQuery getLang( integer $language_id ) + * @method ProjectLang[] generateLangs() + * @method void loadLangs( Request $request, ActiveRecord[] $model_langs ) + * @method bool linkLangs( ActiveRecord[] $model_langs ) + * @method bool saveLangs( ActiveRecord[] $model_langs ) + * * End language behavior * */ class Project extends \yii\db\ActiveRecord { @@ -36,12 +57,15 @@ public function behaviors() { return [ - 'slug' => [ + 'slug' => [ 'class' => 'common\behaviors\Slug', 'in_attribute' => 'title', 'out_attribute' => 'link', 'translit' => true, ], + 'language' => [ + 'class' => LanguageBehavior::className(), + ], ]; } diff --git a/common/models/ProjectLang.php b/common/models/ProjectLang.php new file mode 100644 index 0000000..37bafe7 --- /dev/null +++ b/common/models/ProjectLang.php @@ -0,0 +1,81 @@ + 255], + [['project_id', 'language_id'], 'unique', 'targetAttribute' => ['project_id', 'language_id'], 'message' => 'The combination of Project ID and Language ID has already been taken.'], + [['language_id'], 'exist', 'skipOnError' => true, 'targetClass' => Language::className(), 'targetAttribute' => ['language_id' => 'language_id']], + [['project_id'], 'exist', 'skipOnError' => true, 'targetClass' => Project::className(), 'targetAttribute' => ['project_id' => 'project_id']], + ]; + } + + /** + * @inheritdoc + */ + public function attributeLabels() + { + return [ + 'project_id' => Yii::t('app', 'Project ID'), + 'language_id' => Yii::t('app', 'Language ID'), + 'title' => Yii::t('app', 'Title'), + 'description' => Yii::t('app', 'Description'), + ]; + } + + /** + * @return \yii\db\ActiveQuery + */ + public function getLanguage() + { + return $this->hasOne(Language::className(), ['language_id' => 'language_id']); + } + + /** + * @return \yii\db\ActiveQuery + */ + public function getProject() + { + return $this->hasOne(Project::className(), ['project_id' => 'project_id']); + } +} diff --git a/common/models/ProjectSearch.php b/common/models/ProjectSearch.php index 040014a..e2ec7cf 100644 --- a/common/models/ProjectSearch.php +++ b/common/models/ProjectSearch.php @@ -2,16 +2,20 @@ namespace common\models; -use Yii; use yii\base\Model; use yii\data\ActiveDataProvider; -use common\models\Project; /** * ProjectSearch represents the model behind the search form about `common\models\Project`. */ class ProjectSearch extends Project { + + public function behaviors() + { + return []; + } + /** * @inheritdoc */ diff --git a/common/models/Seo.php b/common/models/Seo.php index 86df70e..68fdceb 100644 --- a/common/models/Seo.php +++ b/common/models/Seo.php @@ -2,7 +2,11 @@ namespace common\models; +use common\modules\language\behaviors\LanguageBehavior; use Yii; +use yii\db\ActiveQuery; +use yii\db\ActiveRecord; +use yii\web\Request; /** * This is the model class for table "seo". @@ -14,6 +18,24 @@ use Yii; * @property string $description * @property string $h1 * @property string $seo_text + * + * * From language behavior * + * @property SeoLang $lang + * @property SeoLang[] $langs + * @property SeoLang $object_lang + * @property string $ownerKey + * @property string $langKey + * @method string getOwnerKey() + * @method void setOwnerKey(string $value) + * @method string getLangKey() + * @method void setLangKey(string $value) + * @method ActiveQuery getLangs() + * @method ActiveQuery getLang( integer $language_id ) + * @method SeoLang[] generateLangs() + * @method void loadLangs(Request $request, ActiveRecord[] $model_langs) + * @method bool linkLangs(ActiveRecord[] $model_langs) + * @method bool saveLangs(ActiveRecord[] $model_langs) + * * End language behavior * */ class Seo extends \yii\db\ActiveRecord { @@ -25,6 +47,15 @@ class Seo extends \yii\db\ActiveRecord return 'seo'; } + public function behaviors() + { + return [ + 'language' => [ + 'class' => LanguageBehavior::className(), + ], + ]; + } + /** * @inheritdoc */ diff --git a/common/models/SeoCategory.php b/common/models/SeoCategory.php index 4cd7459..bca8edf 100644 --- a/common/models/SeoCategory.php +++ b/common/models/SeoCategory.php @@ -2,7 +2,11 @@ namespace common\models; +use common\modules\language\behaviors\LanguageBehavior; use Yii; +use yii\db\ActiveQuery; +use yii\db\ActiveRecord; +use yii\web\Request; /** * This is the model class for table "seo_category". @@ -12,6 +16,24 @@ use Yii; * @property string $controller * @property integer $status * + * * From language behavior * + * @property SeoCategoryLang $lang + * @property SeoCategoryLang[] $langs + * @property SeoCategoryLang $object_lang + * @property string $ownerKey + * @property string $langKey + * @method string getOwnerKey() + * @method void setOwnerKey(string $value) + * @method string getLangKey() + * @method void setLangKey(string $value) + * @method ActiveQuery getLangs() + * @method ActiveQuery getLang( integer $language_id ) + * @method SeoCategoryLang[] generateLangs() + * @method void loadLangs(Request $request, ActiveRecord[] $model_langs) + * @method bool linkLangs(ActiveRecord[] $model_langs) + * @method bool saveLangs(ActiveRecord[] $model_langs) + * * End language behavior * + * * @property SeoDynamic[] $seoDynamics */ class SeoCategory extends \yii\db\ActiveRecord @@ -23,7 +45,16 @@ class SeoCategory extends \yii\db\ActiveRecord { return 'seo_category'; } - + + public function behaviors() + { + return [ + 'language' => [ + 'class' => LanguageBehavior::className(), + ], + ]; + } + /** * @inheritdoc */ diff --git a/common/models/SeoCategoryLang.php b/common/models/SeoCategoryLang.php new file mode 100644 index 0000000..85aa6fb --- /dev/null +++ b/common/models/SeoCategoryLang.php @@ -0,0 +1,77 @@ + 255], + [['seo_category_id', 'language_id'], 'unique', 'targetAttribute' => ['seo_category_id', 'language_id'], 'message' => 'The combination of Seo Category ID and Language ID has already been taken.'], + [['language_id'], 'exist', 'skipOnError' => true, 'targetClass' => Language::className(), 'targetAttribute' => ['language_id' => 'language_id']], + [['seo_category_id'], 'exist', 'skipOnError' => true, 'targetClass' => SeoCategory::className(), 'targetAttribute' => ['seo_category_id' => 'seo_category_id']], + ]; + } + + /** + * @inheritdoc + */ + public function attributeLabels() + { + return [ + 'seo_category_id' => Yii::t('app', 'Seo Category ID'), + 'language_id' => Yii::t('app', 'Language ID'), + 'name' => Yii::t('app', 'Name'), + ]; + } + + /** + * @return \yii\db\ActiveQuery + */ + public function getLanguage() + { + return $this->hasOne(Language::className(), ['language_id' => 'language_id']); + } + + /** + * @return \yii\db\ActiveQuery + */ + public function getSeoCategory() + { + return $this->hasOne(SeoCategory::className(), ['seo_category_id' => 'seo_category_id']); + } +} diff --git a/common/models/SeoCategorySearch.php b/common/models/SeoCategorySearch.php index 120800b..bfdab8d 100644 --- a/common/models/SeoCategorySearch.php +++ b/common/models/SeoCategorySearch.php @@ -12,6 +12,12 @@ use common\models\SeoCategory; */ class SeoCategorySearch extends SeoCategory { + + public function behaviors() + { + return []; + } + /** * @inheritdoc */ diff --git a/common/models/SeoDynamic.php b/common/models/SeoDynamic.php index 2d58dad..c427dde 100644 --- a/common/models/SeoDynamic.php +++ b/common/models/SeoDynamic.php @@ -2,8 +2,11 @@ namespace common\models; +use common\modules\language\behaviors\LanguageBehavior; use Yii; - +use yii\db\ActiveQuery; +use yii\db\ActiveRecord; +use yii\web\Request; /** * This is the model class for table "seo_dynamic". * @@ -20,6 +23,23 @@ use Yii; * @property string $param * @property string $key * + * * From language behavior * + * @property SeoDynamicLang $lang + * @property SeoDynamicLang[] $langs + * @property SeoDynamicLang $object_lang + * @property string $ownerKey + * @property string $langKey + * @method string getOwnerKey() + * @method void setOwnerKey(string $value) + * @method string getLangKey() + * @method void setLangKey(string $value) + * @method ActiveQuery getLangs() + * @method ActiveQuery getLang( integer $language_id ) + * @method SeoDynamicLang[] generateLangs() + * @method void loadLangs(Request $request, ActiveRecord[] $model_langs) + * @method bool linkLangs(ActiveRecord[] $model_langs) + * @method bool saveLangs(ActiveRecord[] $model_langs) + * * End language behavior * * @property SeoCategory $seoCategory */ class SeoDynamic extends \yii\db\ActiveRecord @@ -31,7 +51,16 @@ class SeoDynamic extends \yii\db\ActiveRecord { return 'seo_dynamic'; } - + + public function behaviors() + { + return [ + 'language' => [ + 'class' => LanguageBehavior::className(), + ], + ]; + } + /** * @inheritdoc */ diff --git a/common/models/SeoDynamicLang.php b/common/models/SeoDynamicLang.php new file mode 100644 index 0000000..d2dd954 --- /dev/null +++ b/common/models/SeoDynamicLang.php @@ -0,0 +1,90 @@ + 255], + [['seo_dynamic_id', 'language_id'], 'unique', 'targetAttribute' => ['seo_dynamic_id', 'language_id'], 'message' => 'The combination of Seo Dynamic ID and Language ID has already been taken.'], + [['language_id'], 'exist', 'skipOnError' => true, 'targetClass' => Language::className(), 'targetAttribute' => ['language_id' => 'language_id']], + [['seo_dynamic_id'], 'exist', 'skipOnError' => true, 'targetClass' => SeoDynamic::className(), 'targetAttribute' => ['seo_dynamic_id' => 'seo_dynamic_id']], + ]; + } + + /** + * @inheritdoc + */ + public function attributeLabels() + { + return [ + 'seo_dynamic_id' => Yii::t('app', 'Seo Dynamic ID'), + 'language_id' => Yii::t('app', 'Language ID'), + 'name' => Yii::t('app', 'Name'), + 'title' => Yii::t('app', 'Title'), + 'h1' => Yii::t('app', 'H1'), + 'key' => Yii::t('app', 'Key'), + 'meta' => Yii::t('app', 'Meta'), + 'description' => Yii::t('app', 'Description'), + 'seo_text' => Yii::t('app', 'Seo Text'), + ]; + } + + /** + * @return \yii\db\ActiveQuery + */ + public function getLanguage() + { + return $this->hasOne(Language::className(), ['language_id' => 'language_id']); + } + + /** + * @return \yii\db\ActiveQuery + */ + public function getSeoDynamic() + { + return $this->hasOne(SeoDynamic::className(), ['seo_dynamic_id' => 'seo_dynamic_id']); + } +} diff --git a/common/models/SeoDynamicSearch.php b/common/models/SeoDynamicSearch.php index 6c57b34..6b02e4c 100644 --- a/common/models/SeoDynamicSearch.php +++ b/common/models/SeoDynamicSearch.php @@ -12,6 +12,12 @@ use common\models\SeoDynamic; */ class SeoDynamicSearch extends SeoDynamic { + + public function behaviors() + { + return []; + } + /** * @inheritdoc */ diff --git a/common/models/SeoLang.php b/common/models/SeoLang.php new file mode 100644 index 0000000..3a838ed --- /dev/null +++ b/common/models/SeoLang.php @@ -0,0 +1,86 @@ + 255], + [['seo_id', 'language_id'], 'unique', 'targetAttribute' => ['seo_id', 'language_id'], 'message' => 'The combination of Seo ID and Language ID has already been taken.'], + [['language_id'], 'exist', 'skipOnError' => true, 'targetClass' => Language::className(), 'targetAttribute' => ['language_id' => 'language_id']], + [['seo_id'], 'exist', 'skipOnError' => true, 'targetClass' => Seo::className(), 'targetAttribute' => ['seo_id' => 'seo_id']], + ]; + } + + /** + * @inheritdoc + */ + public function attributeLabels() + { + return [ + 'seo_id' => Yii::t('app', 'Seo ID'), + 'language_id' => Yii::t('app', 'Language ID'), + 'title' => Yii::t('app', 'Title'), + 'description' => Yii::t('app', 'Description'), + 'h1' => Yii::t('app', 'H1'), + 'meta' => Yii::t('app', 'Meta'), + 'seo_text' => Yii::t('app', 'Seo Text'), + ]; + } + + /** + * @return \yii\db\ActiveQuery + */ + public function getLanguage() + { + return $this->hasOne(Language::className(), ['language_id' => 'language_id']); + } + + /** + * @return \yii\db\ActiveQuery + */ + public function getSeo() + { + return $this->hasOne(Seo::className(), ['seo_id' => 'seo_id']); + } +} diff --git a/common/models/SeoSearch.php b/common/models/SeoSearch.php index e8882bc..3b1266c 100644 --- a/common/models/SeoSearch.php +++ b/common/models/SeoSearch.php @@ -12,6 +12,12 @@ use common\models\Seo; */ class SeoSearch extends Seo { + + public function behaviors() + { + return []; + } + /** * @inheritdoc */ diff --git a/common/models/Service.php b/common/models/Service.php index 05ed8f8..0a72cec 100644 --- a/common/models/Service.php +++ b/common/models/Service.php @@ -2,8 +2,13 @@ namespace common\models; +use common\modules\language\behaviors\LanguageBehavior; use Yii; use yii\behaviors\TimestampBehavior; +use yii\db\ActiveQuery; +use yii\db\ActiveRecord; +use yii\web\Request; + /** * This is the model class for table "service". * @@ -18,6 +23,24 @@ use yii\behaviors\TimestampBehavior; * @property string $seo_text * @property integer $created_at * @property integer $updated_at + * + * * From language behavior * + * @property ServiceLang $lang + * @property ServiceLang[] $langs + * @property ServiceLang $object_lang + * @property string $ownerKey + * @property string $langKey + * @method string getOwnerKey() + * @method void setOwnerKey(string $value) + * @method string getLangKey() + * @method void setLangKey(string $value) + * @method ActiveQuery getLangs() + * @method ActiveQuery getLang( integer $language_id ) + * @method ServiceLang[] generateLangs() + * @method void loadLangs(Request $request, ActiveRecord[] $model_langs) + * @method bool linkLangs(ActiveRecord[] $model_langs) + * @method bool saveLangs(ActiveRecord[] $model_langs) + * * End language behavior * */ class Service extends \yii\db\ActiveRecord { @@ -28,7 +51,7 @@ class Service extends \yii\db\ActiveRecord { return 'service'; } - + /** * @inheritdoc */ @@ -57,6 +80,9 @@ class Service extends \yii\db\ActiveRecord [ 'class' => 'common\behaviors\ShowImage', ], + 'language' => [ + 'class' => LanguageBehavior::className(), + ], ]; } /** diff --git a/common/models/ServiceLang.php b/common/models/ServiceLang.php new file mode 100644 index 0000000..99e6541 --- /dev/null +++ b/common/models/ServiceLang.php @@ -0,0 +1,131 @@ + 255, + ], + [ + [ + 'service_id', + 'language_id', + ], + 'unique', + 'targetAttribute' => [ + 'service_id', + 'language_id', + ], + 'message' => 'The combination of Service ID and Language ID has already been taken.', + ], + [ + [ 'language_id' ], + 'exist', + 'skipOnError' => true, + 'targetClass' => Language::className(), + 'targetAttribute' => [ 'language_id' => 'language_id' ], + ], + [ + [ 'service_id' ], + 'exist', + 'skipOnError' => true, + 'targetClass' => Service::className(), + 'targetAttribute' => [ 'service_id' => 'service_id' ], + ], + ]; + } + + /** + * @inheritdoc + */ + public function attributeLabels() + { + return [ + 'service_id' => Yii::t('app', 'Service ID'), + 'language_id' => Yii::t('app', 'Language ID'), + 'name' => Yii::t('app', 'Name'), + 'body' => Yii::t('app', 'Body'), + 'seo_text' => Yii::t('app', 'Seo Text'), + 'meta_title' => Yii::t('app', 'Meta Title'), + 'description' => Yii::t('app', 'Description'), + 'h1' => Yii::t('app', 'H1'), + ]; + } + + /** + * @return \yii\db\ActiveQuery + */ + public function getLanguage() + { + return $this->hasOne(Language::className(), [ 'language_id' => 'language_id' ]); + } + + /** + * @return \yii\db\ActiveQuery + */ + public function getService() + { + return $this->hasOne(Service::className(), [ 'service_id' => 'service_id' ]); + } + } diff --git a/common/models/ServiceSearch.php b/common/models/ServiceSearch.php index 8b1edac..ea16c41 100644 --- a/common/models/ServiceSearch.php +++ b/common/models/ServiceSearch.php @@ -12,6 +12,12 @@ use common\models\Service; */ class ServiceSearch extends Service { + + public function behaviors() + { + return []; + } + /** * @inheritdoc */ diff --git a/common/models/SliderImage.php b/common/models/SliderImage.php index b24fa3c..c9dc95e 100644 --- a/common/models/SliderImage.php +++ b/common/models/SliderImage.php @@ -1,76 +1,129 @@ 255, + ], + [ + [ 'slider_id' ], + 'exist', + 'skipOnError' => true, + 'targetClass' => Slider::className(), + 'targetAttribute' => [ 'slider_id' => 'slider_id' ], + ], + ]; + } + + public function behaviors() + { + return [ + 'language' => [ + 'class' => LanguageBehavior::className(), + ], + ]; + } + + /** + * @inheritdoc + */ + public function attributeLabels() + { + return [ + 'slider_image_id' => Yii::t('app', 'slider_image_id'), + 'slider_id' => Yii::t('app', 'slider_id'), + 'image' => Yii::t('app', 'image'), + 'alt' => Yii::t('app', 'alt'), + 'title' => Yii::t('app', 'title'), + 'url' => Yii::t('app', 'url'), + 'status' => Yii::t('app', 'status'), + 'sort' => Yii::t('app', 'sort'), + ]; + } + + /** + * @return \yii\db\ActiveQuery + */ + public function getSlider() + { + return $this->hasOne(Slider::className(), [ 'slider_id' => 'slider_id' ]); + } + + public function getImageFile() + { + return empty( $this->image ) ? NULL : '/storage/slider/' . $this->image; + } + + public function getImageUrl() + { + return empty( $this->image ) ? NULL : '/storage/slider/' . $this->image; + } + } - - /** - * @inheritdoc - */ - public function rules() - { - return [ - [['slider_id', 'status', 'sort'], 'integer'], - [['image', 'alt', 'title', 'url'], 'string', 'max' => 255], - [['slider_id'], 'exist', 'skipOnError' => true, 'targetClass' => Slider::className(), 'targetAttribute' => ['slider_id' => 'slider_id']], - ]; - } - - /** - * @inheritdoc - */ - public function attributeLabels() - { - return [ - 'slider_image_id' => Yii::t('app', 'slider_image_id'), - 'slider_id' => Yii::t('app', 'slider_id'), - 'image' => Yii::t('app', 'image'), - 'alt' => Yii::t('app', 'alt'), - 'title' => Yii::t('app', 'title'), - 'url' => Yii::t('app', 'url'), - 'status' => Yii::t('app', 'status'), - 'sort' => Yii::t('app', 'sort'), - ]; - } - - /** - * @return \yii\db\ActiveQuery - */ - public function getSlider() - { - return $this->hasOne(Slider::className(), ['slider_id' => 'slider_id']); - } - - public function getImageFile() { - return empty($this->image) ? null : '/storage/slider/'. $this->image; - } - - public function getImageUrl() { - return empty($this->image) ? null : '/storage/slider/'. $this->image; - } - -} diff --git a/common/models/SliderImageLang.php b/common/models/SliderImageLang.php new file mode 100644 index 0000000..8201767 --- /dev/null +++ b/common/models/SliderImageLang.php @@ -0,0 +1,79 @@ + 255], + [['slider_image_id', 'language_id'], 'unique', 'targetAttribute' => ['slider_image_id', 'language_id'], 'message' => 'The combination of Slider Image ID and Language ID has already been taken.'], + [['language_id'], 'exist', 'skipOnError' => true, 'targetClass' => Language::className(), 'targetAttribute' => ['language_id' => 'language_id']], + [['slider_image_id'], 'exist', 'skipOnError' => true, 'targetClass' => SliderImage::className(), 'targetAttribute' => ['slider_image_id' => 'slider_image_id']], + ]; + } + + /** + * @inheritdoc + */ + public function attributeLabels() + { + return [ + 'slider_image_id' => Yii::t('app', 'Slider Image ID'), + 'language_id' => Yii::t('app', 'Language ID'), + 'title' => Yii::t('app', 'Title'), + 'alt' => Yii::t('app', 'Alt'), + ]; + } + + /** + * @return \yii\db\ActiveQuery + */ + public function getLanguage() + { + return $this->hasOne(Language::className(), ['language_id' => 'language_id']); + } + + /** + * @return \yii\db\ActiveQuery + */ + public function getSliderImage() + { + return $this->hasOne(SliderImage::className(), ['slider_image_id' => 'slider_image_id']); + } +} diff --git a/common/models/SliderImageSearch.php b/common/models/SliderImageSearch.php index 56368eb..9bd5da8 100644 --- a/common/models/SliderImageSearch.php +++ b/common/models/SliderImageSearch.php @@ -1,77 +1,113 @@ $query, - ]); - - $this->load($params); - - if (!$this->validate()) { - // uncomment the following line if you do not want to return any records when validation fails - // $query->where('0=1'); + + public function behaviors() + { + return []; + } + + /** + * @inheritdoc + */ + public function rules() + { + return [ + [ + [ + 'slider_image_id', + 'slider_id', + 'status', + 'sort', + ], + 'integer', + ], + [ + [ + 'image', + 'alt', + 'title', + 'url', + ], + 'safe', + ], + ]; + } + + /** + * @inheritdoc + */ + public function scenarios() + { + // bypass scenarios() implementation in the parent class + return Model::scenarios(); + } + + /** + * Creates data provider instance with search query applied + * + * @param array $params + * @param $slider_id Slider id + * + * @return ActiveDataProvider + */ + public function search($slider_id, $params) + { + $query = SliderImage::find(); + + // add conditions that should always apply here + + $dataProvider = new ActiveDataProvider([ + 'query' => $query, + ]); + + $this->load($params); + + if(!$this->validate()) { + // uncomment the following line if you do not want to return any records when validation fails + // $query->where('0=1'); + return $dataProvider; + } + + // grid filtering conditions + $query->andFilterWhere([ + 'slider_image_id' => $this->slider_image_id, + 'slider_id' => $slider_id, + 'status' => $this->status, + 'sort' => $this->sort, + ]); + + $query->andFilterWhere([ + 'like', + 'image', + $this->image, + ]) + ->andFilterWhere([ + 'like', + 'alt', + $this->alt, + ]) + ->andFilterWhere([ + 'like', + 'title', + $this->title, + ]) + ->andFilterWhere([ + 'like', + 'url', + $this->url, + ]); + return $dataProvider; } - - // grid filtering conditions - $query->andFilterWhere([ - 'slider_image_id' => $this->slider_image_id, - 'slider_id' => $slider_id, - 'status' => $this->status, - 'sort' => $this->sort, - ]); - - $query->andFilterWhere(['like', 'image', $this->image]) - ->andFilterWhere(['like', 'alt', $this->alt]) - ->andFilterWhere(['like', 'title', $this->title]) - ->andFilterWhere(['like', 'url', $this->url]); - - return $dataProvider; } -} diff --git a/common/modules/language/behaviors/LanguageBehavior.php b/common/modules/language/behaviors/LanguageBehavior.php new file mode 100644 index 0000000..c97508e --- /dev/null +++ b/common/modules/language/behaviors/LanguageBehavior.php @@ -0,0 +1,222 @@ +_owner_key )) { + return $this->_owner_key; + } else { + return $this->owner->primaryKey()[ 0 ]; + } + } + + /** + * Set which attribute to use as $owner primary key to link language model + * + * @param string $value + */ + public function setOwnerKey(string $value) + { + $this->_owner_key = $value; + } + + /** + * Get language model attribute that is used as foreign key to $owner + * @return string + */ + public function getLangKey():string + { + if(!empty( $this->_lang_key )) { + return $this->_lang_key; + } else { + $owner = $this->owner; + return $owner::getTableSchema()->name . '_id'; + } + } + + /** + * Set which attribute to use as language model foreign key to $owner + * + * @param $value + */ + public function setLangKey(string $value) + { + $this->_lang_key = $value; + } + + /** + * Additional checks to attach this behavior + * + * @param ActiveRecord $owner + * + * @throws InvalidConfigException + */ + public function attach($owner) + { + if(empty( $this->object_lang )) { + $this->object_lang = $owner::className() . 'Lang'; + } elseif(!is_string($this->object_lang)) { + throw new InvalidConfigException('Object lang must be fully classified namespaced classname'); + } + try { + $this->object_lang = \Yii::createObject($this->object_lang); + } catch(\ReflectionException $exception) { + throw new InvalidConfigException('Object lang must be fully classified namespaced classname'); + } + if(( !$owner instanceof ActiveRecord ) || ( !$this->object_lang instanceof ActiveRecord )) { + throw new InvalidConfigException('Object lang must be fully classified namespaced classname'); + } + parent::attach($owner); + } + + /** + * Get query to get all language models for $owner indexed by language_id + * @return ActiveQuery + */ + public function getLangs() + { + $object_lang = $this->object_lang; + $owner = $this->owner; + return $owner->hasMany($object_lang::className(), [ $this->getLangKey() => $this->getOwnerKey() ]) + ->indexBy('language_id'); + } + + /** + * Get query to get language model for $owner for language_id, default to + * Language::getCurrent() + * + * @param int $language_id + * + * @return ActiveQuery + */ + public function getLang(int $language_id = NULL) + { + if(empty( $language_id )) { + $language_id = Language::getCurrent()->language_id; + } + $object_lang = $this->object_lang; + $table_name = $object_lang::getTableSchema()->name; + $owner = $this->owner; + return $owner->hasOne($object_lang::className(), [ $this->getLangKey() => $this->getOwnerKey() ]) + ->where([ $table_name.'.language_id' => $language_id ]); + } + + /** + * Generate language models for $owner for active languages. If $owner not new and language + * models already inserted, models will be filled with them. + * @return ActiveRecord[] + */ + public function generateLangs() + { + $owner = $this->owner; + $languages = Language::find() + ->where([ 'status' => true ]) + ->asArray() + ->column(); + $object_lang = $this->object_lang; + $owner_key = $this->getOwnerKey(); + $langs = []; + if(!$owner->isNewRecord) { + $langs = $this->getLangs() + ->andFilterWhere([ 'language_id' => $languages ]) + ->all(); + } + foreach($languages as $language) { + if(!array_key_exists($language, $langs)) { + $langs[ $language ] = \Yii::createObject([ + 'class' => $object_lang::className(), + 'language_id' => $language, + $this->getLangKey() => ( $owner->isNewRecord ? NULL : $owner->$owner_key ), + ]); + } + } + return $langs; + } + + /** + * Load language models with post data. + * + * @param Request $request + * @param ActiveRecord[] $model_langs + */ + public function loadLangs(Request $request, array $model_langs) + { + foreach($request->post($this->object_lang->formName(), []) as $lang => $value) { + if(!empty( $model_langs[ $lang ] )) { + $model_langs[ $lang ]->attributes = $value; + $model_langs[ $lang ]->language_id = $lang; + } + } + } + + /** + * Link language models with $owner by setting language model language key to owner key of + * owner + * + * @param ActiveRecord[] $model_langs + * + * @return bool If $owner is new record then return false else true + */ + public function linkLangs(array $model_langs) + { + $owner = $this->owner; + if($owner->isNewRecord) { + return false; + } + $lang_key = $this->getLangKey(); + $owner_key = $this->getOwnerKey(); + foreach($model_langs as $model_lang) { + $model_lang->$lang_key = $owner->$owner_key; + } + return true; + } + + /** + * Try to save all language models to the db. Validation function is run for all models. + * + * @param ActiveRecord[] $model_langs + * + * @return bool Whether all models are valid + */ + public function saveLangs(array $model_langs) + { + $success = true; + foreach($model_langs as $model_lang) { + if(!$model_lang->save()) { + $success = false; + } + } + return $success; + } + } \ No newline at end of file diff --git a/common/modules/language/migrations/m160927_124151_add_status_column.php b/common/modules/language/migrations/m160927_124151_add_status_column.php new file mode 100644 index 0000000..d1482e3 --- /dev/null +++ b/common/modules/language/migrations/m160927_124151_add_status_column.php @@ -0,0 +1,16 @@ +addColumn('language', 'status', $this->boolean()->notNull()->defaultValue(false)); + } + + public function down() + { + $this->dropColumn('language', 'status'); + } +} diff --git a/common/modules/language/readme.txt b/common/modules/language/readme.txt index b16841a..973803e 100644 --- a/common/modules/language/readme.txt +++ b/common/modules/language/readme.txt @@ -1,3 +1,4 @@ +Как включить мультиязычность на сайте: 1. Запускаем миграцию: php yii migrate --migrationPath=common/modules/language/migrations 2. Добавляем в файл конфигурации: 'urlManager' => [ @@ -29,4 +30,59 @@ 5. Переводы писать в файл frontend\messages\{language}\app.php, где {language} - нужный язык, например ru. 6. Для вывода на странице сообщения с переводом используем функцию: Yii::t('app', {message}, $params = [], $language = null), где {message} - нужное сообщение, $params - массив параметров, $language - нужный язык (по умолчанию используется текущий язык). -7. В наличие также виджет переключения языка: LanguagePicker::widget() \ No newline at end of file +7. В наличие также виджет переключения языка: LanguagePicker::widget() + + +Как использовать мультиязычность для Active Record: +1. Создаем для таблицы {table} таблицу с языками {table_lang}. +2. Создаем для класса {Table} класс с языками {TableLang}. +3. Подключаеи для класса {Table} поведение LanguageBehavior: +public function behaviors() { + return [ + 'language' => [ + 'class' => LanguageBehavior::className(), + 'object_lang' => {TableLang}::className() // optional, default to {TableLang}::className() + 'ownerKey' => {Table}->id //optional, default to {Table}->primaryKey()[0] + 'langKey' => {TableLang}->table_id //optional, default to {Table}->tableName().'_id' + ], + ]; +} +3.1. PHPDoc для {Table}: + * * From language behavior * + * @property {TableLang} $lang + * @property {TableLang}[] $langs + * @property {TableLang} $object_lang + * @property string $ownerKey + * @property string $langKey + * @method string getOwnerKey() + * @method void setOwnerKey(string $value) + * @method string getLangKey() + * @method void setLangKey(string $value) + * @method ActiveQuery getLangs() + * @method ActiveQuery getLang( integer $language_id ) + * @method {TableLang}[] generateLangs() + * @method void loadLangs(Request $request, ActiveRecord[] $model_langs) + * @method bool linkLangs(ActiveRecord[] $model_langs) + * @method bool saveLangs(ActiveRecord[] $model_langs) + * * End language behavior * +3.2. Убрать language behavior с наследуемых таблиц от {Table} ({TableSearch}...) +4. Доступные полезные методы: + {Table}->getLangs() - получить все текущие {TableLang} для {Table} проиндексированные по language_id + {Table}->getLang($language_id = NULL) - получить {TableLang} для определенного языка (default: текущий язык) для {Table} + {Table}->generateLangs() - получить массив {TableLang} под каждый язык, включая существующие записи, для {Table} + {Table}->loadLangs($request, $model_langs) - заполнить массив {TableLang} данными с POST + {Table}->linkLangs($model_langs) - связать каждый элемент массива {TableLang} с текущей {Table} + {Table}->saveLangs($model_langs) - провалидировать и сохранить каждый элемент массива {TableLang} +5. Добавить поля в форму (к примеру через Bootstrap Tabs). + В наличии: + LanguageForm::widget([ + 'model_langs' => {TableLang}[], + 'formView' => string, + 'form' => ActiveForm, + ]); +6. Обрабатывать данные в контроллере. + 1. После создания/поиска {Table} создаем/находим языковые модели {Table}->generateLangs() + 2. При POST запросе загружаем данные в языковые модели {Table}->loadLangs(Request $request, {TableLangs[]} $model_langs) + 3. Связываем модель {Table} с языковыми моделями {Table}->linkLangs({TableLang[]} $model_langs). Возвращает true при успехе. + 4. Сохраняе языковые модели в базу {Table}->saveLangs({TableLang[]} $model_langs). Возвращает true при успешной валидации каждого {TableLang}. +7. Получать данные на публичной части сайта через {Table}->lang. \ No newline at end of file diff --git a/common/modules/language/widgets/LanguageForm.php b/common/modules/language/widgets/LanguageForm.php new file mode 100644 index 0000000..9afab8c --- /dev/null +++ b/common/modules/language/widgets/LanguageForm.php @@ -0,0 +1,78 @@ +formView === NULL) { + throw new InvalidConfigException('Form view must be set'); + } + if(empty( $this->model_langs ) || !is_array($this->model_langs)) { + throw new InvalidConfigException('Language models must be passed'); + } + if(empty( $this->getForm() )) { + throw new InvalidConfigException('Form model must be set'); + } + $this->languages = Language::find() + ->where([ 'status' => true ]) + ->orderBy([ 'default' => SORT_DESC ]) + ->indexBy('language_id') + ->all(); + } + + public function run() + { + return $this->render('language_form_frame', [ + 'languages' => $this->languages, + 'form_view' => $this->formView, + 'model_langs' => $this->model_langs, + 'form' => $this->getForm(), + 'id_prefix' => $this->id_prefix, + ]); + } + + public function getForm(): ActiveForm + { + return $this->_form; + } + + public function setForm(ActiveForm $value) + { + $this->_form = $value; + } + } \ No newline at end of file diff --git a/common/modules/language/widgets/views/language_form_frame.php b/common/modules/language/widgets/views/language_form_frame.php new file mode 100644 index 0000000..d1d3ce2 --- /dev/null +++ b/common/modules/language/widgets/views/language_form_frame.php @@ -0,0 +1,69 @@ + +
+ 1) { + ?> + +
+ $model_lang) { + if(!array_key_exists($lang, $languages)) { + continue; + } + echo Html::tag('div', $this->render($form_view, [ + 'model_lang' => $model_lang, + 'language' => $languages[ $lang ], + 'form' => $form, + ]), [ + 'class' => 'tab-pane' . ( $first ? ' active' : '' ), + 'id' => $id_prefix . '_' . $lang, + ]); + $first = false; + } + ?> +
+ language_id ] )) { + echo $this->render($form_view, [ + 'model_lang' => $model_langs[ $language->language_id ], + 'language' => $language, + 'form' => $form, + ]); + } + } + ?> +
diff --git a/common/modules/product/controllers/ManageController.php b/common/modules/product/controllers/ManageController.php index 164c829..bb9a0ea 100644 --- a/common/modules/product/controllers/ManageController.php +++ b/common/modules/product/controllers/ManageController.php @@ -90,10 +90,13 @@ public function actionCreate() { $model = new Product(); + $model_langs = $model->generateLangs(); $product_spec = new ProductSpec(); + $product_spec_langs = $product_spec->generateLangs(); if($model->load(Yii::$app->request->post())) { + $model->loadLangs(\Yii::$app->request, $model_langs); $model->imagesUpload = UploadedFile::getInstances($model, 'imagesUpload'); $model->certificateUpload = UploadedFile::getInstances($model, 'certificateUpload'); @@ -107,38 +110,54 @@ $imageModel->save(); } } - + if(!empty( $model->certificateUpload ) && ( ( $certificates = $model->certificateUpload() ) !== false )) { foreach($certificates as $certificate) { $certificateModel = new ProductCertificate([ 'product_id' => $model->product_id, - 'link' => $certificate, + 'link' => $certificate, ]); $certificateModel->save(false); } } - + if($product_spec->load(Yii::$app->request->post())) { + $product_spec->loadLangs(\Yii::$app->request, $product_spec_langs); $product_spec->product_id = $model->product_id; $product_spec->techSpecFile = UploadedFile::getInstance($product_spec, 'techSpecFile'); $product_spec->techCharFile = UploadedFile::getInstance($product_spec, 'techCharFile'); - if($product_spec->upload()) { + if($product_spec->upload() && $model->linkLangs($model_langs) && $model->saveLangs($model_langs)) { $product_spec->save(false); - return $this->redirect([ - 'view', - 'id' => $model->product_id, - ]); + if($product_spec->linkLangs($product_spec_langs) && $product_spec->saveLangs($product_spec_langs)) { + return $this->redirect([ + 'view', + 'id' => $model->product_id, + ]); + } else { + return $this->redirect([ + 'update', + 'id' => $model->product_id, + ]); + } } - } else { + } elseif($model->linkLangs($model_langs) && $model->saveLangs($model_langs)) { return $this->redirect([ 'view', 'id' => $model->product_id, ]); - } } + } else { + return $this->redirect([ + 'update', + 'id' => $model->product_id, + ]); + } + } } return $this->render('create', [ - 'model' => $model, - 'product_spec' => $product_spec, + 'model' => $model, + 'model_langs' => $model_langs, + 'product_spec' => $product_spec, + 'product_spec_langs' => $product_spec_langs, ]); } @@ -153,6 +172,7 @@ public function actionUpdate($id) { $model = $this->findModel($id); + $model_langs = $model->generateLangs(); if(!empty( $model->productSpec )) { $product_spec = $model->productSpec; } else { @@ -160,7 +180,9 @@ 'product_id' => $model->product_id, ]); } + $product_spec_langs = $product_spec->generateLangs(); if($model->load(Yii::$app->request->post())) { + $model->loadLangs(\Yii::$app->request, $model_langs); $model->imagesUpload = UploadedFile::getInstances($model, 'imagesUpload'); $model->certificateUpload = UploadedFile::getInstances($model, 'certificateUpload'); if($model->save()) { @@ -173,27 +195,30 @@ } } - if(!empty($model->certificateUpload) && (( $certificates = $model->certificateUpload()) !== false)) { + if(!empty( $model->certificateUpload ) && ( ( $certificates = $model->certificateUpload() ) !== false )) { foreach($certificates as $certificate) { $certificateModel = new ProductCertificate([ 'product_id' => $model->product_id, - 'link' => $certificate, + 'link' => $certificate, ]); $certificateModel->save(false); } } if($product_spec->load(Yii::$app->request->post())) { + $product_spec->loadLangs(\Yii::$app->request, $product_spec_langs); $product_spec->techSpecFile = UploadedFile::getInstance($product_spec, 'techSpecFile'); $product_spec->techCharFile = UploadedFile::getInstance($product_spec, 'techCharFile'); - if($product_spec->upload()) { + if($product_spec->upload() && $model->linkLangs($model_langs) && $model->saveLangs($model_langs)) { $product_spec->save(false); - return $this->redirect([ - 'view', - 'id' => $model->product_id, - ]); + if($product_spec->linkLangs($product_spec_langs) && $product_spec->saveLangs($product_spec_langs)) { + return $this->redirect([ + 'view', + 'id' => $model->product_id, + ]); + } } - } else { + } elseif($model->linkLangs($model_langs) && $model->saveLangs($model_langs)) { return $this->redirect([ 'view', 'id' => $model->product_id, @@ -202,11 +227,12 @@ } } $groups = $model->getTaxGroupsByLevel(0); - return $this->render('update', [ - 'model' => $model, - 'groups' => $groups, - 'product_spec' => $product_spec, + 'model' => $model, + 'model_langs' => $model_langs, + 'groups' => $groups, + 'product_spec' => $product_spec, + 'product_spec_langs' => $product_spec_langs, ]); } @@ -237,15 +263,15 @@ print '1'; exit; } - + public function actionDelcert($id) { $certificate = ProductCertificate::findOne($id); - + if($certificate) { $certificate->delete(); } - + print '1'; exit; } diff --git a/common/modules/product/controllers/ProductUnitController.php b/common/modules/product/controllers/ProductUnitController.php index 7ee6139..16b9a5f 100644 --- a/common/modules/product/controllers/ProductUnitController.php +++ b/common/modules/product/controllers/ProductUnitController.php @@ -1,124 +1,154 @@ [ - 'class' => VerbFilter::className(), - 'actions' => [ - 'delete' => ['POST'], + + /** + * @inheritdoc + */ + public function behaviors() + { + return [ + 'verbs' => [ + 'class' => VerbFilter::className(), + 'actions' => [ + 'delete' => [ 'POST' ], + ], ], - ], - ]; - } - - /** - * Lists all ProductUnit models. - * @return mixed - */ - public function actionIndex() - { - $searchModel = new ProductUnitSearch(); - $dataProvider = $searchModel->search(Yii::$app->request->queryParams); - - return $this->render('index', [ - 'searchModel' => $searchModel, - 'dataProvider' => $dataProvider, - ]); - } - - /** - * Displays a single ProductUnit model. - * @param integer $id - * @return mixed - */ - public function actionView($id) - { - return $this->render('view', [ - 'model' => $this->findModel($id), - ]); - } - - /** - * Creates a new ProductUnit model. - * If creation is successful, the browser will be redirected to the 'view' page. - * @return mixed - */ - public function actionCreate() - { - $model = new ProductUnit(); - - if ($model->load(Yii::$app->request->post()) && $model->save()) { - return $this->redirect(['view', 'id' => $model->product_unit_id]); - } else { - return $this->render('create', [ - 'model' => $model, + ]; + } + + /** + * Lists all ProductUnit models. + * @return mixed + */ + public function actionIndex() + { + $searchModel = new ProductUnitSearch(); + $dataProvider = $searchModel->search(Yii::$app->request->queryParams); + + return $this->render('index', [ + 'searchModel' => $searchModel, + 'dataProvider' => $dataProvider, ]); } - } - - /** - * Updates an existing ProductUnit model. - * If update is successful, the browser will be redirected to the 'view' page. - * @param integer $id - * @return mixed - */ - public function actionUpdate($id) - { - $model = $this->findModel($id); - - if ($model->load(Yii::$app->request->post()) && $model->save()) { - return $this->redirect(['view', 'id' => $model->product_unit_id]); - } else { + + /** + * Displays a single ProductUnit model. + * + * @param integer $id + * + * @return mixed + */ + public function actionView($id) + { + return $this->render('view', [ + 'model' => $this->findModel($id), + ]); + } + + /** + * Creates a new ProductUnit model. + * If creation is successful, the browser will be redirected to the 'view' page. + * @return mixed + */ + public function actionCreate() + { + $model = new ProductUnit(); + $model_langs = $model->generateLangs(); + + if($model->load(Yii::$app->request->post()) && $model->save()) { + $model->loadLangs(\Yii::$app->request, $model_langs); + if($model->linkLangs($model_langs) && $model->saveLangs($model_langs)) { + return $this->redirect([ + 'view', + 'id' => $model->product_unit_id, + ]); + } else { + return $this->redirect([ + 'update', + 'id' => $model->product_unit_id, + ]); + } + } else { + return $this->render('create', [ + 'model' => $model, + 'model_langs' => $model_langs, + ]); + } + } + + /** + * Updates an existing ProductUnit model. + * If update is successful, the browser will be redirected to the 'view' page. + * + * @param integer $id + * + * @return mixed + */ + public function actionUpdate($id) + { + $model = $this->findModel($id); + $model_langs = $model->generateLangs(); + + if($model->load(Yii::$app->request->post()) && $model->save()) { + $model->loadLangs(\Yii::$app->request, $model_langs); + if($model->linkLangs($model_langs) && $model->saveLangs($model_langs)) { + return $this->redirect([ + 'view', + 'id' => $model->product_unit_id, + ]); + } + } return $this->render('update', [ - 'model' => $model, + 'model' => $model, + 'model_langs' => $model_langs, ]); } - } - - /** - * Deletes an existing ProductUnit model. - * If deletion is successful, the browser will be redirected to the 'index' page. - * @param integer $id - * @return mixed - */ - public function actionDelete($id) - { - $this->findModel($id)->delete(); - - return $this->redirect(['index']); - } - - /** - * Finds the ProductUnit model based on its primary key value. - * If the model is not found, a 404 HTTP exception will be thrown. - * @param integer $id - * @return ProductUnit the loaded model - * @throws NotFoundHttpException if the model cannot be found - */ - protected function findModel($id) - { - if (($model = ProductUnit::findOne($id)) !== null) { - return $model; - } else { - throw new NotFoundHttpException('The requested page does not exist.'); + + /** + * Deletes an existing ProductUnit model. + * If deletion is successful, the browser will be redirected to the 'index' page. + * + * @param integer $id + * + * @return mixed + */ + public function actionDelete($id) + { + $this->findModel($id) + ->delete(); + + return $this->redirect([ 'index' ]); + } + + /** + * Finds the ProductUnit model based on its primary key value. + * If the model is not found, a 404 HTTP exception will be thrown. + * + * @param integer $id + * + * @return ProductUnit the loaded model + * @throws NotFoundHttpException if the model cannot be found + */ + protected function findModel($id) + { + if(( $model = ProductUnit::findOne($id) ) !== NULL) { + return $model; + } else { + throw new NotFoundHttpException('The requested page does not exist.'); + } } } -} diff --git a/common/modules/product/controllers/VariantController.php b/common/modules/product/controllers/VariantController.php index 35acda2..eda1231 100644 --- a/common/modules/product/controllers/VariantController.php +++ b/common/modules/product/controllers/VariantController.php @@ -1,321 +1,353 @@ [ - 'class' => VerbFilter::className(), - 'actions' => [ - 'delete' => ['POST'], + + /** + * @inheritdoc + */ + public function behaviors() + { + return [ + 'verbs' => [ + 'class' => VerbFilter::className(), + 'actions' => [ + 'delete' => [ 'POST' ], + ], ], - ], - ]; - } - - /** - * Lists all ProductVariant models. - * @return mixed - */ - public function actionIndex($product_id) - { - $searchModel = new ProductVariantListSearch(); - $dataProvider = $searchModel->search(Yii::$app->request->queryParams,$product_id); - - if ( ($product = Yii::$app->request->get('product_id')) !== null) { - $product = Product::findOne($product); + ]; } - - return $this->render('index', [ - 'searchModel' => $searchModel, - 'dataProvider' => $dataProvider, - 'product' => $product, - 'product_id' => $product_id, - ]); - } - - /** - * Displays a single ProductVariant model. - * @param integer $id - * @return mixed - */ - public function actionView($id) - { - return $this->render('view', [ - 'model' => $this->findModel($id), - ]); - } - - /** - * Creates a new ProductVariant model. - * If creation is successful, the browser will be redirected to the 'view' page. - * @return mixed - */ - public function actionCreate($product_id) - { - $model = new ProductVariant(); - $model->product_id = $product_id; - if ($model->load(Yii::$app->request->post())) { - - $model->imagesUpload = UploadedFile::getInstances($model, 'imagesUpload'); - $model->validate(); - - if ($model->save()) { - - if ( ($image = UploadedFile::getInstance($model, 'image')) ) { - $imageModel = ProductImage::find()->where(['product_variant_id' => $model->product_variant_id])->one(); - - if($imageModel instanceof ProductImage) { - $imageModel->product_id = $model->product_id; - $imageModel->product_variant_id = $model->product_variant_id; - $imageModel->image = $image->name; - $imageModel->save(); - } else { - $imageModel = new ProductImage(); - $imageModel->product_id = $model->product_id; - $imageModel->product_variant_id = $model->product_variant_id; - $imageModel->image = $image->name; - $imageModel->save(); - } + /** + * Lists all ProductVariant models. + * @return mixed + */ + public function actionIndex($product_id) + { + $searchModel = new ProductVariantListSearch(); + $dataProvider = $searchModel->search(Yii::$app->request->queryParams, $product_id); + + if(( $product = Yii::$app->request->get('product_id') ) !== NULL) { + $product = Product::findOne($product); + } + + return $this->render('index', [ + 'searchModel' => $searchModel, + 'dataProvider' => $dataProvider, + 'product' => $product, + 'product_id' => $product_id, + ]); + } - $imgDir = Yii::getAlias('@storage/products/'); + /** + * Displays a single ProductVariant model. + * + * @param integer $id + * + * @return mixed + */ + public function actionView($id) + { + return $this->render('view', [ + 'model' => $this->findModel($id), + ]); + } - if(!is_dir($imgDir)) { - mkdir($imgDir, 0755, true); + /** + * Creates a new ProductVariant model. + * If creation is successful, the browser will be redirected to the 'view' page. + * @return mixed + */ + public function actionCreate($product_id) + { + $model = new ProductVariant(); + $model->product_id = $product_id; + $model_langs = $model->generateLangs(); + if($model->load(Yii::$app->request->post())) { + $model->loadLangs(\Yii::$app->request, $model_langs); + $model->imagesUpload = UploadedFile::getInstances($model, 'imagesUpload'); + $model->validate(); + + if($model->save()) { + + if(( $image = UploadedFile::getInstance($model, 'image') )) { + $imageModel = ProductImage::find() + ->where([ 'product_variant_id' => $model->product_variant_id ]) + ->one(); + + if($imageModel instanceof ProductImage) { + $imageModel->product_id = $model->product_id; + $imageModel->product_variant_id = $model->product_variant_id; + $imageModel->image = $image->name; + $imageModel->save(); + } else { + $imageModel = new ProductImage(); + $imageModel->product_id = $model->product_id; + $imageModel->product_variant_id = $model->product_variant_id; + $imageModel->image = $image->name; + $imageModel->save(); + } + + $imgDir = Yii::getAlias('@storage/products/'); + + if(!is_dir($imgDir)) { + mkdir($imgDir, 0755, true); + } + + $image->saveAs(Yii::getAlias('@storage/products/' . $image->name)); } - - $image->saveAs(Yii::getAlias('@storage/products/' . $image->name)); - } - - $ProductStocks = Yii::$app->request->post('ProductStock'); - - $total_quantity = 0; - - if(!empty($ProductStocks) && is_array($ProductStocks)) { - $model->unlinkAll('stocks', true); - $sorted_array = []; - foreach ($ProductStocks as $subArray) { - if(!empty($subArray['name']) && !empty($subArray['quantity'])) { - if(!empty($sorted_array[$subArray['name']])) { - $sorted_array[$subArray['name']] += $subArray['quantity']; - } else { - $sorted_array[$subArray['name']] = $subArray['quantity']; + + $ProductStocks = Yii::$app->request->post('ProductStock'); + + $total_quantity = 0; + + if(!empty( $ProductStocks ) && is_array($ProductStocks)) { + $model->unlinkAll('stocks', true); + $sorted_array = []; + foreach($ProductStocks as $subArray) { + if(!empty( $subArray[ 'name' ] ) && !empty( $subArray[ 'quantity' ] )) { + if(!empty( $sorted_array[ $subArray[ 'name' ] ] )) { + $sorted_array[ $subArray[ 'name' ] ] += $subArray[ 'quantity' ]; + } else { + $sorted_array[ $subArray[ 'name' ] ] = $subArray[ 'quantity' ]; + } } } - } - $ProductStocks = $sorted_array; - $stock_names = array_keys($ProductStocks); - $stocks = Stock::find()->where(['name' => $stock_names])->indexBy('name')->one(); - foreach($ProductStocks as $name => $quantity) { - $quantity = (int) $quantity; - if(!array_key_exists($name, $stocks)) { - $stock = new Stock([ - 'name' => $name + $ProductStocks = $sorted_array; + $stock_names = array_keys($ProductStocks); + $stocks = Stock::find() + ->where([ 'name' => $stock_names ]) + ->indexBy('name') + ->all(); + foreach($ProductStocks as $name => $quantity) { + $quantity = (int) $quantity; + if(!array_key_exists($name, $stocks)) { + $stock = new Stock([ + 'name' => $name, + ]); + if(!$stock->save()) { + continue; + } + } else { + $stock = $stocks[ $name ]; + } + $psModel = new ProductStock([ + 'product_id' => $model->product_id, + 'product_variant_id' => $model->product_variant_id, + 'stock_id' => $stock->stock_id, + 'quantity' => $quantity, ]); - if(!$stock->save()) { - continue; + if($psModel->save()) { + $total_quantity += $quantity; } - } else { - $stock = $stocks[$name]; } - $psModel = new ProductStock([ - 'product_id' => $model->product_id, - 'product_variant_id' => $model->product_variant_id, - 'stock_id' => $stock->stock_id, - 'quantity' => $quantity, + } else { + $model->unlinkAll('stocks', true); + } + + $model->stock = $total_quantity; + $model->save(); + if($model->linkLangs($model_langs) && $model->saveLangs($model_langs)) { + return $this->redirect([ + 'index', + 'product_id' => $product_id, + ]); + } else { + return $this->redirect([ + 'update', + 'product_id' => $product_id, + 'id' => $model->product_variant_id, ]); - if($psModel->save()) { - $total_quantity += $quantity; - } } - } else { - $model->unlinkAll('stocks', true); } - - $model->stock = $total_quantity; - $model->save(); - - return $this->redirect(['index', 'product_id' => $product_id]); } - } else { $groups = $model->getTaxGroupsByLevel(1); - + return $this->render('create', [ - 'model' => $model, - 'groups' => $groups, - 'stocks' => [new ProductStock()], + 'model' => $model, + 'model_langs' => $model_langs, + 'groups' => $groups, + 'stocks' => [ new ProductStock() ], ]); } - } - - /** - * Updates an existing ProductVariant model. - * If update is successful, the browser will be redirected to the 'view' page. - * @param integer $product_id - * @param integer $id - * @return mixed - */ - public function actionUpdate($product_id, $id) - { - $model = $this->findModel($id); - if ($model->load(Yii::$app->request->post())) { - - if ($model->save()) { - - - if ( ($image = UploadedFile::getInstance($model, 'image')) ) { - $imageModel = ProductImage::find()->where(['product_variant_id' => $model->product_variant_id])->one(); - - if($imageModel instanceof ProductImage) { - $imageModel->product_id = $model->product_id; - $imageModel->product_variant_id = $model->product_variant_id; - $imageModel->image = $image->name; - $imageModel->save(); - } else { - $imageModel = new ProductImage(); - $imageModel->product_id = $model->product_id; - $imageModel->product_variant_id = $model->product_variant_id; - $imageModel->image = $image->name; - $imageModel->save(); - } - - - $imgDir = Yii::getAlias('@storage/products/'); - - if(!is_dir($imgDir)) { - mkdir($imgDir, 0755, true); + + /** + * Updates an existing ProductVariant model. + * If update is successful, the browser will be redirected to the 'view' page. + * + * @param integer $product_id + * @param integer $id + * + * @return mixed + */ + public function actionUpdate($product_id, $id) + { + $model = $this->findModel($id); + $model_langs = $model->generateLangs(); + if($model->load(Yii::$app->request->post())) { + $model->loadLangs(\Yii::$app->request, $model_langs); + if($model->save()) { + + if(( $image = UploadedFile::getInstance($model, 'image') )) { + $imageModel = ProductImage::find() + ->where([ 'product_variant_id' => $model->product_variant_id ]) + ->one(); + + if($imageModel instanceof ProductImage) { + $imageModel->product_id = $model->product_id; + $imageModel->product_variant_id = $model->product_variant_id; + $imageModel->image = $image->name; + $imageModel->save(); + } else { + $imageModel = new ProductImage(); + $imageModel->product_id = $model->product_id; + $imageModel->product_variant_id = $model->product_variant_id; + $imageModel->image = $image->name; + $imageModel->save(); + } + + $imgDir = Yii::getAlias('@storage/products/'); + + if(!is_dir($imgDir)) { + mkdir($imgDir, 0755, true); + } + + $image->saveAs(Yii::getAlias('@storage/products/' . $image->name)); } - - $image->saveAs(Yii::getAlias('@storage/products/' . $image->name)); - } - - - $ProductStocks = Yii::$app->request->post('ProductStock'); - - $total_quantity = 0; - - if(!empty($ProductStocks) && is_array($ProductStocks)) { - $model->unlinkAll('stocks', true); - $sorted_array = []; - foreach ($ProductStocks as $subArray) { - if(!empty($subArray['name']) && !empty($subArray['quantity'])) { - if(!empty($sorted_array[$subArray['name']])) { - $sorted_array[$subArray['name']] += $subArray['quantity']; - } else { - $sorted_array[$subArray['name']] = $subArray['quantity']; + + $ProductStocks = Yii::$app->request->post('ProductStock'); + + $total_quantity = 0; + + if(!empty( $ProductStocks ) && is_array($ProductStocks)) { + $model->unlinkAll('stocks', true); + $sorted_array = []; + foreach($ProductStocks as $subArray) { + if(!empty( $subArray[ 'name' ] ) && !empty( $subArray[ 'quantity' ] )) { + if(!empty( $sorted_array[ $subArray[ 'name' ] ] )) { + $sorted_array[ $subArray[ 'name' ] ] += $subArray[ 'quantity' ]; + } else { + $sorted_array[ $subArray[ 'name' ] ] = $subArray[ 'quantity' ]; + } } } - } - $ProductStocks = $sorted_array; - $stock_names = array_keys($ProductStocks); - $stocks = Stock::find()->where(['name' => $stock_names])->indexBy('name')->one(); - foreach($ProductStocks as $name => $quantity) { - $quantity = (int) $quantity; - if(!array_key_exists($name, $stocks)) { - $stock = new Stock([ - 'name' => $name + $ProductStocks = $sorted_array; + $stock_names = array_keys($ProductStocks); + $stocks = Stock::find() + ->where([ 'name' => $stock_names ]) + ->indexBy('name') + ->all(); + foreach($ProductStocks as $name => $quantity) { + $quantity = (int) $quantity; + if(!array_key_exists($name, $stocks)) { + $stock = new Stock([ + 'name' => $name, + ]); + if(!$stock->save()) { + continue; + } + } else { + $stock = $stocks[ $name ]; + } + $psModel = new ProductStock([ + 'product_id' => $model->product_id, + 'product_variant_id' => $model->product_variant_id, + 'stock_id' => $stock->stock_id, + 'quantity' => $quantity, ]); - if(!$stock->save()) { - continue; + if($psModel->save()) { + $total_quantity += $quantity; } - } else { - $stock = $stocks[$name]; } - $psModel = new ProductStock([ - 'product_id' => $model->product_id, - 'product_variant_id' => $model->product_variant_id, - 'stock_id' => $stock->stock_id, - 'quantity' => $quantity, + } else { + $model->unlinkAll('stocks', true); + } + + $model->stock = $total_quantity; + if($model->save() && $model->linkLangs($model_langs) && $model->saveLangs($model_langs)) { + return $this->redirect([ + 'index', + 'product_id' => $product_id, ]); - if($psModel->save()) { - $total_quantity += $quantity; - } } - } else { - $model->unlinkAll('stocks', true); } - - $model->stock = $total_quantity; - $model->save(); } - return $this->redirect(['index', 'product_id'=>$product_id]); - - - - - } else { $groups = $model->getTaxGroupsByLevel(1); - + return $this->render('update', [ - 'model' => $model, - 'groups' => $groups, - 'stocks' => (!empty($model->variantStocks)) ? $model->variantStocks : [new ProductStock], + 'model' => $model, + 'model_langs' => $model_langs, + 'groups' => $groups, + 'stocks' => ( !empty( $model->variantStocks ) ) ? $model->variantStocks : [ new ProductStock ], ]); + } - } - - /** - * Deletes an existing ProductVariant model. - * If deletion is successful, the browser will be redirected to the 'index' page. - * @param integer $id - * @return mixed - */ - public function actionDelete($product_id, $id) - { - - $this->findModel($id)->delete(); - - return $this->redirect(['index', 'product_id'=>$product_id]); - } - - public function actionDelimg($id) - { - $image = ProductImage::findOne($id); - - if ($image) { - $image->delete(); + + /** + * Deletes an existing ProductVariant model. + * If deletion is successful, the browser will be redirected to the 'index' page. + * + * @param integer $id + * + * @return mixed + */ + public function actionDelete($product_id, $id) + { + + $this->findModel($id) + ->delete(); + + return $this->redirect([ + 'index', + 'product_id' => $product_id, + ]); } - - print '1'; - exit; - } - - /** - * Finds the ProductVariant model based on its primary key value. - * If the model is not found, a 404 HTTP exception will be thrown. - * @param integer $id - * @return ProductVariant the loaded model - * @throws NotFoundHttpException if the model cannot be found - */ - protected function findModel($id) - { - if (($model = ProductVariant::findOne($id)) !== null) { - return $model; - } else { - throw new NotFoundHttpException('The requested page does not exist.'); + + public function actionDelimg($id) + { + $image = ProductImage::findOne($id); + + if($image) { + $image->delete(); + } + + print '1'; + exit; + } + + /** + * Finds the ProductVariant model based on its primary key value. + * If the model is not found, a 404 HTTP exception will be thrown. + * + * @param integer $id + * + * @return ProductVariant the loaded model + * @throws NotFoundHttpException if the model cannot be found + */ + protected function findModel($id) + { + if(( $model = ProductVariant::findOne($id) ) !== NULL) { + return $model; + } else { + throw new NotFoundHttpException('The requested page does not exist.'); + } } } -} diff --git a/common/modules/product/models/Brand.php b/common/modules/product/models/Brand.php index d36cb69..c7d9191 100644 --- a/common/modules/product/models/Brand.php +++ b/common/modules/product/models/Brand.php @@ -3,7 +3,11 @@ namespace common\modules\product\models; use common\behaviors\SaveImgBehavior; +use common\modules\language\behaviors\LanguageBehavior; use Yii; +use yii\db\ActiveQuery; +use yii\db\ActiveRecord; +use yii\web\Request; /** * This is the model class for table "brand". @@ -19,11 +23,26 @@ use Yii; * @property string $name * * @property Product[] $products + * * From language behavior * + * @property BrandLang $lang + * @property BrandLang[] $langs + * @property BrandLang $object_lang + * @property string $ownerKey + * @property string $langKey + * @method string getOwnerKey() + * @method void setOwnerKey(string $value) + * @method string getLangKey() + * @method void setLangKey(string $value) + * @method ActiveQuery getLangs() + * @method ActiveQuery getLang( integer $language_id ) + * @method BrandLang[] generateLangs() + * @method void loadLangs(Request $request, ActiveRecord[] $model_langs) + * @method bool linkLangs(ActiveRecord[] $model_langs) + * @method bool saveLangs(ActiveRecord[] $model_langs) + * * End language behavior * */ class Brand extends \yii\db\ActiveRecord { - public $imageUpload; - public $_items_count = 0; /** @@ -46,6 +65,15 @@ class Brand extends \yii\db\ActiveRecord ], [ 'class' => SaveImgBehavior::className(), + 'fields' => [ + [ + 'name' => 'image', + 'directory' => 'brand', + ], + ], + ], + 'language' => [ + 'class' => LanguageBehavior::className(), ], ]; } @@ -61,8 +89,6 @@ class Brand extends \yii\db\ActiveRecord [['alias', 'name'], 'string', 'max' => 250], [['meta_title', 'image'], 'string', 'max' => 255], [['meta_robots'], 'string', 'max' => 50], - [['imageUpload'], 'safe'], - [['imageUpload'], 'file', 'extensions' => 'jpg, gif, png'], ]; } @@ -93,13 +119,4 @@ class Brand extends \yii\db\ActiveRecord { return $this->hasMany(Product::className(), ['brand_id' => 'brand_id']); } - - public function getImageFile() { - return empty($this->image) ? null : Yii::getAlias('@imagesDir/brand/'. $this->image); - } - - public function getImageUrl() - { - return empty($this->image) ? null : Yii::getAlias('@imagesUrl/brand/' . $this->image); - } } diff --git a/common/modules/product/models/BrandLang.php b/common/modules/product/models/BrandLang.php new file mode 100644 index 0000000..c529e48 --- /dev/null +++ b/common/modules/product/models/BrandLang.php @@ -0,0 +1,87 @@ + 255], + [['brand_id', 'language_id'], 'unique', 'targetAttribute' => ['brand_id', 'language_id'], 'message' => 'The combination of Brand ID and Language ID has already been taken.'], + [['brand_id'], 'exist', 'skipOnError' => true, 'targetClass' => Brand::className(), 'targetAttribute' => ['brand_id' => 'brand_id']], + [['language_id'], 'exist', 'skipOnError' => true, 'targetClass' => Language::className(), 'targetAttribute' => ['language_id' => 'language_id']], + ]; + } + + /** + * @inheritdoc + */ + public function attributeLabels() + { + return [ + 'brand_id' => Yii::t('app', 'Brand ID'), + 'language_id' => Yii::t('app', 'Language ID'), + 'name' => Yii::t('app', 'Name'), + 'meta_title' => Yii::t('app', 'Meta Title'), + 'meta_robots' => Yii::t('app', 'Meta Robots'), + 'meta_desc' => Yii::t('app', 'Meta Desc'), + 'seo_text' => Yii::t('app', 'Seo Text'), + ]; + } + + /** + * @return \yii\db\ActiveQuery + */ + public function getBrand() + { + return $this->hasOne(Brand::className(), ['brand_id' => 'brand_id']); + } + + /** + * @return \yii\db\ActiveQuery + */ + public function getLanguage() + { + return $this->hasOne(Language::className(), ['language_id' => 'language_id']); + } +} diff --git a/common/modules/product/models/BrandSearch.php b/common/modules/product/models/BrandSearch.php index 31ff34e..64ef3a7 100644 --- a/common/modules/product/models/BrandSearch.php +++ b/common/modules/product/models/BrandSearch.php @@ -23,7 +23,12 @@ class BrandSearch extends Brand [['alias', 'image', 'meta_title', 'meta_desc', 'meta_robots', 'seo_text', 'brand_name'], 'safe'], ]; } - + + public function behaviors() + { + return []; + } + /** * @inheritdoc */ diff --git a/common/modules/product/models/Category.php b/common/modules/product/models/Category.php index b865dbd..eccffc5 100644 --- a/common/modules/product/models/Category.php +++ b/common/modules/product/models/Category.php @@ -1,253 +1,334 @@ [ - 'class' => ArtboxTreeBehavior::className(), - 'keyNameGroup' => null, - 'keyNamePath' => 'path', - ], - 'slug' => [ - 'class' => 'common\behaviors\Slug', - 'in_attribute' => 'name', - 'out_attribute' => 'alias', - 'translit' => true - ], - - ]; - } - - /** - * @inheritdoc - */ - public static function tableName() - { - return 'category'; - } - - /** - * @inheritdoc - */ - public function rules() - { - return [ - [['name'], 'string'], - [['parent_id', 'depth', 'product_unit_id'], 'integer'], - [['path', 'meta_desc', 'h1', 'seo_text'], 'string'], - [['meta_title', 'image'], 'string', 'max' => 255], - [['meta_robots'], 'string', 'max' => 50], - [['alias', 'name'], 'string', 'max' => 250], - [['imageUpload'], 'safe'], - [['imageUpload'], 'file', 'extensions' => 'jpg, gif, png'], - ]; - } - - /** - * @inheritdoc - */ - public function attributeLabels() - { - return [ - 'category_id' => Yii::t('product', 'Category ID'), - 'parent_id' => Yii::t('product', 'Parent ID'), - 'path' => Yii::t('product', 'Path'), - 'depth' => Yii::t('product', 'Depth'), - 'image' => Yii::t('product', 'Image'), - 'imageUrl' => Yii::t('product', 'Image'), - 'meta_title' => Yii::t('product', 'Meta Title'), - 'meta_desc' => Yii::t('product', 'Meta Desc'), - 'meta_robots' => Yii::t('product', 'Meta Robots'), - 'h1' => Yii::t('product', 'h1'), - 'seo_text' => Yii::t('product', 'Seo Text'), - 'product_unit_id' => Yii::t('product', 'Product Unit ID'), - 'alias' => Yii::t('product', 'Alias'), - 'name' => Yii::t('product', 'Name'), - 'remote_id' => Yii::t('product', 'Remote ID'), - ]; - } - - public static function find() - { - return new CategoryQuery(get_called_class()); - } - - /** - * @return \yii\db\ActiveQuery - */ - public function getProductUnit() - { - return $this->hasOne(ProductUnit::className(), ['product_unit_id' => 'product_unit_id']); - } - - public function getProducts() { - return $this->hasMany(Product::className(), ['product_id' => 'product_id']) - ->viaTable('product_category', ['category_id' => 'category_id']); - } - - + + namespace common\modules\product\models; + + use common\components\artboxtree\ArtboxTreeBehavior; + use common\components\artboxtree\ArtboxTreeHelper; + use common\modules\language\behaviors\LanguageBehavior; + use common\modules\rubrication\models\TaxGroup; + use Yii; + use yii\db\ActiveQuery; + use yii\db\ActiveRecord; + use yii\db\Query; + use yii\web\Request; + /** - * @return \yii\db\ActiveQuery + * This is the model class for table "category". + * @property integer $category_id + * @property string $remote_id + * @property integer $parent_id + * @property string $path + * @property integer $depth + * @property string $image + * @property string $meta_title + * @property string $meta_desc + * @property string $meta_robots + * @property string $seo_text + * @property integer $product_unit_id + * @property string $alias + * @property boolean $name + * * From language behavior * + * @property CategoryLang $lang + * @property CategoryLang[] $langs + * @property CategoryLang $object_lang + * @property string $ownerKey + * @property string $langKey + * @method string getOwnerKey() + * @method void setOwnerKey( string $value ) + * @method string getLangKey() + * @method void setLangKey( string $value ) + * @method ActiveQuery getLangs() + * @method ActiveQuery getLang( integer $language_id ) + * @method CategoryLang[] generateLangs() + * @method void loadLangs( Request $request, ActiveRecord[] $model_langs ) + * @method bool linkLangs( ActiveRecord[] $model_langs ) + * @method bool saveLangs( ActiveRecord[] $model_langs ) + * * End language behavior * + * @property Product[] $products + * @property ProductUnit $productUnit + * @property ProductCategory[] $productCategories */ - public function getProductCategories() - { - return $this->hasMany(ProductCategory::className(), ['category_id' => 'category_id']); - } - - public function getBrands(){ - return $this->getProducts()->select('brand.*')->joinWith('brand')->groupBy('brand.brand_id'); - - } - - public function getTaxGroupsByLevel($level) - { - return $this->hasMany(TaxGroup::className(), ['tax_group_id' => 'tax_group_id']) - ->viaTable('tax_group_to_category', ['category_id' => 'category_id']) - ->andWhere(['level' => $level]); - } - - public function getRemote_category() - { - return ArtboxTreeHelper::getArrayField($this->remote_id); - } - - public function setRemote_category($value) + class Category extends \yii\db\ActiveRecord { - if (!empty($value) && is_array($value)) { - $this->remote_id = ArtboxTreeHelper::setArrayField($value, false); + + public $imageUpload; + + public function behaviors() + { + return [ + 'artboxtree' => [ + 'class' => ArtboxTreeBehavior::className(), + 'keyNameGroup' => NULL, + 'keyNamePath' => 'path', + ], + 'slug' => [ + 'class' => 'common\behaviors\Slug', + 'in_attribute' => 'name', + 'out_attribute' => 'alias', + 'translit' => true, + ], + 'language' => [ + 'class' => LanguageBehavior::className(), + ], + ]; } - } - - public function getImageFile() { - return empty($this->image) ? '/images/no_photo.png' : Yii::getAlias('@imagesDir/categories/'. $this->image); - } - - public function getImageUrl() - { - return empty($this->image) ? '/images/no_photo.png' : Yii::getAlias('@imagesUrl/categories/' . $this->image); - } - - public function beforeSave($insert) - { - if (parent::beforeSave($insert)) { - - if (empty($this->parent_id)) - $this->parent_id = 0; - - return true; - } - return false; - } - - public function getActiveFilters() { - $query1 = (new Query()) - ->distinct() - ->select([ - 'option_id' - ]) - ->from('tax_option') - ->innerJoin('product_variant_option', 'tax_option.tax_option_id = product_variant_option.option_id') - ->innerJoin('tax_group', 'tax_group.tax_group_id = tax_option.tax_group_id') - ->innerJoin('product_variant', 'product_variant.product_variant_id = product_variant_option.product_variant_id') - ->innerJoin('product', 'product.product_id = product_variant.product_id') - ->innerJoin('product_category', 'product_category.product_id = product.product_id') - ->where(['product_category.category_id' => $this->category_id, 'tax_group.is_filter' => TRUE]) - ->andWhere(['!=', 'product_variant.stock', 0]); - - $query2 = (new Query()) - ->distinct() - ->select([ - 'option_id' - ]) - ->from('tax_option') - ->innerJoin('product_option', 'tax_option.tax_option_id = product_option.option_id') - ->innerJoin('tax_group', 'tax_group.tax_group_id = tax_option.tax_group_id') - ->innerJoin('product', 'product.product_id = product_option.product_id') - ->innerJoin('product_category', 'product_category.product_id = product.product_id') - ->innerJoin('product_variant', 'product_variant.product_id = product.product_id') - ->where(['product_category.category_id' => $this->category_id, 'tax_group.is_filter' => TRUE]) - ->andWhere(['!=', 'product_variant.stock', 0]); - $query3 = (new Query()) - ->select([ - 'tax_option.*', - 'tax_group.*', - 'tax_option.alias as option_alias', - 'tax_group.alias as group_alias', - 'tax_option.value as value', - 'tax_option.sort AS tax_option_sort', - 'tax_group.sort AS tax_group_sort', - ]) - ->from(['tax_option' ]) - ->where(['tax_option.tax_option_id'=>$query1->union($query2)]) - ->innerJoin('tax_group','tax_group.tax_group_id = tax_option.tax_group_id') - ->orderBy('tax_option.sort, tax_group.sort'); - return $query3; - } - - public function getTaxGroupsForMenu() - { - $connection = Yii::$app->getDb(); - $command = $connection->createCommand(' - SELECT ton.alias as option_alias, * - FROM tax_option as ton + + /** + * @inheritdoc + */ + public static function tableName() + { + return 'category'; + } + + /** + * @inheritdoc + */ + public function rules() + { + return [ + [ + [ 'name' ], + 'string', + ], + [ + [ + 'parent_id', + 'depth', + 'product_unit_id', + ], + 'integer', + ], + [ + [ + 'path', + 'meta_desc', + 'h1', + 'seo_text', + ], + 'string', + ], + [ + [ + 'meta_title', + 'image', + ], + 'string', + 'max' => 255, + ], + [ + [ 'meta_robots' ], + 'string', + 'max' => 50, + ], + [ + [ + 'alias', + 'name', + ], + 'string', + 'max' => 250, + ], + [ + [ 'imageUpload' ], + 'safe', + ], + [ + [ 'imageUpload' ], + 'file', + 'extensions' => 'jpg, gif, png', + ], + ]; + } + + /** + * @inheritdoc + */ + public function attributeLabels() + { + return [ + 'category_id' => Yii::t('product', 'Category ID'), + 'parent_id' => Yii::t('product', 'Parent ID'), + 'path' => Yii::t('product', 'Path'), + 'depth' => Yii::t('product', 'Depth'), + 'image' => Yii::t('product', 'Image'), + 'imageUrl' => Yii::t('product', 'Image'), + 'meta_title' => Yii::t('product', 'Meta Title'), + 'meta_desc' => Yii::t('product', 'Meta Desc'), + 'meta_robots' => Yii::t('product', 'Meta Robots'), + 'h1' => Yii::t('product', 'h1'), + 'seo_text' => Yii::t('product', 'Seo Text'), + 'product_unit_id' => Yii::t('product', 'Product Unit ID'), + 'alias' => Yii::t('product', 'Alias'), + 'name' => Yii::t('product', 'Name'), + 'remote_id' => Yii::t('product', 'Remote ID'), + ]; + } + + public static function find() + { + return new CategoryQuery(get_called_class()); + } + + /** + * @return \yii\db\ActiveQuery + */ + public function getProductUnit() + { + return $this->hasOne(ProductUnit::className(), [ 'product_unit_id' => 'product_unit_id' ]); + } + + public function getProducts() + { + return $this->hasMany(Product::className(), [ 'product_id' => 'product_id' ]) + ->viaTable('product_category', [ 'category_id' => 'category_id' ]); + } + + /** + * @return \yii\db\ActiveQuery + */ + public function getProductCategories() + { + return $this->hasMany(ProductCategory::className(), [ 'category_id' => 'category_id' ]); + } + + public function getBrands() + { + return $this->getProducts() + ->select('brand.*') + ->joinWith('brand') + ->groupBy('brand.brand_id'); + + } + + public function getTaxGroupsByLevel($level) + { + return $this->hasMany(TaxGroup::className(), [ 'tax_group_id' => 'tax_group_id' ]) + ->viaTable('tax_group_to_category', [ 'category_id' => 'category_id' ]) + ->andWhere([ 'level' => $level ]); + } + + public function getRemote_category() + { + return ArtboxTreeHelper::getArrayField($this->remote_id); + } + + public function setRemote_category($value) + { + if(!empty( $value ) && is_array($value)) { + $this->remote_id = ArtboxTreeHelper::setArrayField($value, false); + } + } + + public function getImageFile() + { + return empty( $this->image ) ? '/images/no_photo.png' : Yii::getAlias('@imagesDir/categories/' . $this->image); + } + + public function getImageUrl() + { + return empty( $this->image ) ? '/images/no_photo.png' : Yii::getAlias('@imagesUrl/categories/' . $this->image); + } + + public function beforeSave($insert) + { + if(parent::beforeSave($insert)) { + + if(empty( $this->parent_id )) { + $this->parent_id = 0; + } + + return true; + } + return false; + } + + public function getActiveFilters() + { + $query1 = ( new Query() )->distinct() + ->select([ + 'option_id', + ]) + ->from('tax_option') + ->innerJoin('product_variant_option', 'tax_option.tax_option_id = product_variant_option.option_id') + ->innerJoin('tax_group', 'tax_group.tax_group_id = tax_option.tax_group_id') + ->innerJoin('product_variant', 'product_variant.product_variant_id = product_variant_option.product_variant_id') + ->innerJoin('product', 'product.product_id = product_variant.product_id') + ->innerJoin('product_category', 'product_category.product_id = product.product_id') + ->where([ + 'product_category.category_id' => $this->category_id, + 'tax_group.is_filter' => true, + ]) + ->andWhere([ + '!=', + 'product_variant.stock', + 0, + ]); + + $query2 = ( new Query() )->distinct() + ->select([ + 'option_id', + ]) + ->from('tax_option') + ->innerJoin('product_option', 'tax_option.tax_option_id = product_option.option_id') + ->innerJoin('tax_group', 'tax_group.tax_group_id = tax_option.tax_group_id') + ->innerJoin('product', 'product.product_id = product_option.product_id') + ->innerJoin('product_category', 'product_category.product_id = product.product_id') + ->innerJoin('product_variant', 'product_variant.product_id = product.product_id') + ->where([ + 'product_category.category_id' => $this->category_id, + 'tax_group.is_filter' => true, + ]) + ->andWhere([ + '!=', + 'product_variant.stock', + 0, + ]); + $query3 = ( new Query() )->select([ + 'tax_option.*', + 'tax_group.*', + 'tax_option.alias as option_alias', + 'tax_group.alias as group_alias', + 'tax_option.value as value', + 'tax_option.sort AS tax_option_sort', + 'tax_group.sort AS tax_group_sort', + ]) + ->from([ 'tax_option' ]) + ->where([ 'tax_option.tax_option_id' => $query1->union($query2) ]) + ->innerJoin('tax_group', 'tax_group.tax_group_id = tax_option.tax_group_id') + ->orderBy('tax_option.sort, tax_group.sort'); + return $query3; + } + + public function getTaxGroupsForMenu() + { + $connection = Yii::$app->getDb(); + $command = $connection->createCommand(' + SELECT ton.alias AS option_alias, * + FROM tax_option AS ton RIGHT JOIN tax_group ON ton.tax_group_id = tax_group.tax_group_id RIGHT JOIN tax_group_to_category ON tax_group.tax_group_id = tax_group_to_category.tax_group_id WHERE ton.tax_option_id IN ( - SELECT po.option_id FROM product_option as po + SELECT po.option_id FROM product_option AS po WHERE po.product_id IN ( SELECT product_id FROM product_category WHERE category_id = :category_id ) ) - AND tax_group.is_menu = true AND tax_group_to_category.category_id = :category_id', - [ - ':category_id' => $this->category_id - - ]); - return $command->queryAll(); - } - - - public function setTaxGroup($value) - { - return $this->tax_group = $value; - } - - public function getTaxGroup() - { - return $this->hasMany(TaxGroup::className(), ['tax_group_id' => 'tax_group_id']) - ->viaTable('tax_group_to_category', ['category_id' => 'category_id']); + AND tax_group.is_menu = TRUE AND tax_group_to_category.category_id = :category_id', [ + ':category_id' => $this->category_id, + + ]); + return $command->queryAll(); + } + + public function setTaxGroup($value) + { + return $this->tax_group = $value; + } + + public function getTaxGroup() + { + return $this->hasMany(TaxGroup::className(), [ 'tax_group_id' => 'tax_group_id' ]) + ->viaTable('tax_group_to_category', [ 'category_id' => 'category_id' ]); + } } -} diff --git a/common/modules/product/models/CategoryLang.php b/common/modules/product/models/CategoryLang.php new file mode 100644 index 0000000..4226466 --- /dev/null +++ b/common/modules/product/models/CategoryLang.php @@ -0,0 +1,88 @@ + 255], + [['category_id', 'language_id'], 'unique', 'targetAttribute' => ['category_id', 'language_id'], 'message' => 'The combination of Category ID and Language ID has already been taken.'], + [['category_id'], 'exist', 'skipOnError' => true, 'targetClass' => Category::className(), 'targetAttribute' => ['category_id' => 'category_id']], + [['language_id'], 'exist', 'skipOnError' => true, 'targetClass' => Language::className(), 'targetAttribute' => ['language_id' => 'language_id']], + ]; + } + + /** + * @inheritdoc + */ + public function attributeLabels() + { + return [ + 'category_id' => Yii::t('app', 'Category ID'), + 'language_id' => Yii::t('app', 'Language ID'), + 'name' => Yii::t('app', 'Name'), + 'meta_title' => Yii::t('app', 'Meta Title'), + 'meta_robots' => Yii::t('app', 'Meta Robots'), + 'meta_desc' => Yii::t('app', 'Meta Desc'), + 'seo_text' => Yii::t('app', 'Seo Text'), + 'h1' => Yii::t('app', 'H1'), + ]; + } + + /** + * @return \yii\db\ActiveQuery + */ + public function getCategory() + { + return $this->hasOne(Category::className(), ['category_id' => 'category_id']); + } + + /** + * @return \yii\db\ActiveQuery + */ + public function getLanguage() + { + return $this->hasOne(Language::className(), ['language_id' => 'language_id']); + } +} diff --git a/common/modules/product/models/CategorySearch.php b/common/modules/product/models/CategorySearch.php index b6062ad..c3eaedd 100644 --- a/common/modules/product/models/CategorySearch.php +++ b/common/modules/product/models/CategorySearch.php @@ -14,14 +14,7 @@ class CategorySearch extends Category { public function behaviors() { - $behaviors = parent::behaviors(); - if (isset($behaviors['slug'])) { - unset($behaviors['slug']); - } - if (isset($behaviors['timestamp'])) { - unset($behaviors['timestamp']); - } - return $behaviors; + return []; } /** diff --git a/common/modules/product/models/Product.php b/common/modules/product/models/Product.php index 0f2da56..b52d53b 100644 --- a/common/modules/product/models/Product.php +++ b/common/modules/product/models/Product.php @@ -7,6 +7,7 @@ use common\models\ProductSpec; use common\models\ProductToRating; use common\modules\comment\models\CommentModel; + use common\modules\language\behaviors\LanguageBehavior; use common\modules\product\behaviors\FilterBehavior; use common\modules\rubrication\models\TaxGroup; use common\modules\rubrication\models\TaxOption; @@ -14,6 +15,7 @@ use yii\db\ActiveQuery; use yii\db\ActiveRecord; use yii\helpers\ArrayHelper; + use yii\web\Request; /** * This is the model class for table "{{%product}}". @@ -40,6 +42,23 @@ * @property ProductVariant[] $variants * @property ProductSpec $productSpec * @property ProductCertificate[] $productCertificates + * * From language behavior * + * @property ProductLang $lang + * @property ProductLang[] $langs + * @property ProductLang $object_lang + * @property string $ownerKey + * @property string $langKey + * @method string getOwnerKey() + * @method void setOwnerKey( string $value ) + * @method string getLangKey() + * @method void setLangKey( string $value ) + * @method ActiveQuery getLangs() + * @method ActiveQuery getLang( integer $language_id ) + * @method ProductLang[] generateLangs() + * @method void loadLangs( Request $request, ActiveRecord[] $model_langs ) + * @method bool linkLangs( ActiveRecord[] $model_langs ) + * @method bool saveLangs( ActiveRecord[] $model_langs ) + * * End language behavior * */ class Product extends \yii\db\ActiveRecord { @@ -67,6 +86,9 @@ 'out_attribute' => 'alias', 'translit' => true, ], + 'language' => [ + 'class' => LanguageBehavior::className(), + ], ]; } diff --git a/common/modules/product/models/ProductLang.php b/common/modules/product/models/ProductLang.php new file mode 100644 index 0000000..a4a40b8 --- /dev/null +++ b/common/modules/product/models/ProductLang.php @@ -0,0 +1,81 @@ + 255], + [['product_id', 'language_id'], 'unique', 'targetAttribute' => ['product_id', 'language_id'], 'message' => 'The combination of Product ID and Language ID has already been taken.'], + [['language_id'], 'exist', 'skipOnError' => true, 'targetClass' => Language::className(), 'targetAttribute' => ['language_id' => 'language_id']], + [['product_id'], 'exist', 'skipOnError' => true, 'targetClass' => Product::className(), 'targetAttribute' => ['product_id' => 'product_id']], + ]; + } + + /** + * @inheritdoc + */ + public function attributeLabels() + { + return [ + 'product_id' => Yii::t('app', 'Product ID'), + 'language_id' => Yii::t('app', 'Language ID'), + 'name' => Yii::t('app', 'Name'), + 'description' => Yii::t('app', 'Description'), + ]; + } + + /** + * @return \yii\db\ActiveQuery + */ + public function getLanguage() + { + return $this->hasOne(Language::className(), ['language_id' => 'language_id']); + } + + /** + * @return \yii\db\ActiveQuery + */ + public function getProduct() + { + return $this->hasOne(Product::className(), ['product_id' => 'product_id']); + } +} diff --git a/common/modules/product/models/ProductSearch.php b/common/modules/product/models/ProductSearch.php index 2a96810..a51e1a3 100644 --- a/common/modules/product/models/ProductSearch.php +++ b/common/modules/product/models/ProductSearch.php @@ -18,6 +18,15 @@ class ProductSearch extends Product public $category_name; public $variant_sku; + public function behaviors() + { + $behaviors = parent::behaviors(); + if(isset($behaviors['language'])) { + unset($behaviors['language']); + } + return $behaviors; + } + /** * @inheritdoc */ diff --git a/common/modules/product/models/ProductUnit.php b/common/modules/product/models/ProductUnit.php index f6dbe42..a8ddccd 100644 --- a/common/modules/product/models/ProductUnit.php +++ b/common/modules/product/models/ProductUnit.php @@ -2,7 +2,11 @@ namespace common\modules\product\models; +use common\modules\language\behaviors\LanguageBehavior; use Yii; +use yii\db\ActiveQuery; +use yii\db\ActiveRecord; +use yii\web\Request; /** * This is the model class for table "product_unit". @@ -14,6 +18,24 @@ use Yii; * * @property Category[] $categories * @property ProductVariant[] $productVariants + * + * * From language behavior * + * @property ProductUnitLang $lang + * @property ProductUnitLang[] $langs + * @property ProductUnitLang $object_lang + * @property string $ownerKey + * @property string $langKey + * @method string getOwnerKey() + * @method void setOwnerKey(string $value) + * @method string getLangKey() + * @method void setLangKey(string $value) + * @method ActiveQuery getLangs() + * @method ActiveQuery getLang( integer $language_id ) + * @method ProductUnitLang[] generateLangs() + * @method void loadLangs(Request $request, ActiveRecord[] $model_langs) + * @method bool linkLangs(ActiveRecord[] $model_langs) + * @method bool saveLangs(ActiveRecord[] $model_langs) + * * End language behavior * */ class ProductUnit extends \yii\db\ActiveRecord { @@ -24,7 +46,16 @@ class ProductUnit extends \yii\db\ActiveRecord { return 'product_unit'; } - + + public function behaviors() + { + return [ + 'language' => [ + 'class' => LanguageBehavior::className(), + ], + ]; + } + /** * @inheritdoc */ diff --git a/common/modules/product/models/ProductUnitLang.php b/common/modules/product/models/ProductUnitLang.php new file mode 100644 index 0000000..b6c6f72 --- /dev/null +++ b/common/modules/product/models/ProductUnitLang.php @@ -0,0 +1,80 @@ + 255], + [['product_unit_id', 'language_id'], 'unique', 'targetAttribute' => ['product_unit_id', 'language_id'], 'message' => 'The combination of Product Unit ID and Language ID has already been taken.'], + [['language_id'], 'exist', 'skipOnError' => true, 'targetClass' => Language::className(), 'targetAttribute' => ['language_id' => 'language_id']], + [['product_unit_id'], 'exist', 'skipOnError' => true, 'targetClass' => ProductUnit::className(), 'targetAttribute' => ['product_unit_id' => 'product_unit_id']], + ]; + } + + /** + * @inheritdoc + */ + public function attributeLabels() + { + return [ + 'product_unit_id' => Yii::t('app', 'Product Unit ID'), + 'language_id' => Yii::t('app', 'Language ID'), + 'name' => Yii::t('app', 'Name'), + 'short' => Yii::t('app', 'Short'), + ]; + } + + /** + * @return \yii\db\ActiveQuery + */ + public function getLanguage() + { + return $this->hasOne(Language::className(), ['language_id' => 'language_id']); + } + + /** + * @return \yii\db\ActiveQuery + */ + public function getProductUnit() + { + return $this->hasOne(ProductUnit::className(), ['product_unit_id' => 'product_unit_id']); + } +} diff --git a/common/modules/product/models/ProductUnitSearch.php b/common/modules/product/models/ProductUnitSearch.php index c4a7d15..271b0fb 100644 --- a/common/modules/product/models/ProductUnitSearch.php +++ b/common/modules/product/models/ProductUnitSearch.php @@ -10,6 +10,12 @@ use yii\data\ActiveDataProvider; */ class ProductUnitSearch extends ProductUnit { + + public function behaviors() + { + return []; + } + /** * @inheritdoc */ diff --git a/common/modules/product/models/ProductVariant.php b/common/modules/product/models/ProductVariant.php index b556786..0c2f907 100644 --- a/common/modules/product/models/ProductVariant.php +++ b/common/modules/product/models/ProductVariant.php @@ -2,26 +2,47 @@ namespace common\modules\product\models; + use common\modules\language\behaviors\LanguageBehavior; use common\modules\rubrication\models\TaxGroup; use common\modules\rubrication\models\TaxOption; use Yii; + use yii\db\ActiveQuery; + use yii\db\ActiveRecord; use yii\helpers\ArrayHelper; + use yii\web\Request; /** * This is the model class for table "product_variant". - * @property integer $product_variant_id - * @property integer $product_id - * @property string $name - * @property string $remote_id - * @property string $sku - * @property double $price - * @property double $price_old - * @property double $stock - * @property integer $product_unit_id - * @property ProductImage $image - * @property array $images - * @property TaxOption[] $options - * @property ProductUnit $productUnit + * @property integer $product_variant_id + * @property integer $product_id + * @property string $name + * @property string $remote_id + * @property string $sku + * @property double $price + * @property double $price_old + * @property double $stock + * @property integer $product_unit_id + * @property ProductImage $image + * @property array $images + * @property TaxOption[] $options + * @property ProductUnit $productUnit + * * From language behavior * + * @property ProductVariantLang $lang + * @property ProductVariantLang[] $langs + * @property ProductVariantLang $object_lang + * @property string $ownerKey + * @property string $langKey + * @method string getOwnerKey() + * @method void setOwnerKey( string $value ) + * @method string getLangKey() + * @method void setLangKey( string $value ) + * @method ActiveQuery getLangs() + * @method ActiveQuery getLang( integer $language_id ) + * @method ProductVariantLang[] generateLangs() + * @method void loadLangs( Request $request, ActiveRecord[] $model_langs ) + * @method bool linkLangs( ActiveRecord[] $model_langs ) + * @method bool saveLangs( ActiveRecord[] $model_langs ) + * * End language behavior * */ class ProductVariant extends \yii\db\ActiveRecord { @@ -51,6 +72,15 @@ return 'product_variant'; } + public function behaviors() + { + return [ + 'language' => [ + 'class' => LanguageBehavior::className(), + ], + ]; + } + /** * @inheritdoc */ @@ -258,19 +288,22 @@ return $this->hasMany(TaxOption::className(), [ 'tax_option_id' => 'option_id' ]) ->viaTable('product_variant_option', [ 'product_variant_id' => 'product_variant_id' ]); } - + /** * @return TaxGroup[] */ public function getProperties() { $groups = $options = []; - foreach($this->options as $option) { + foreach($this->getOptions() + ->with('lang') + ->all() as $option) { $options[ $option->tax_group_id ][] = $option; } foreach(TaxGroup::find() - ->where([ 'tax_group_id' => array_keys($options) ]) + ->where([ 'tax_group.tax_group_id' => array_keys($options) ]) ->orderBy([ 'sort' => SORT_ASC ]) + ->with('lang') ->all() as $group) { if(!empty( $options[ $group->tax_group_id ] )) { $group->_options = $options[ $group->tax_group_id ]; diff --git a/common/modules/product/models/ProductVariantLang.php b/common/modules/product/models/ProductVariantLang.php new file mode 100644 index 0000000..4b1122a --- /dev/null +++ b/common/modules/product/models/ProductVariantLang.php @@ -0,0 +1,78 @@ + 255], + [['product_variant_id', 'language_id'], 'unique', 'targetAttribute' => ['product_variant_id', 'language_id'], 'message' => 'The combination of Product Variant ID and Language ID has already been taken.'], + [['language_id'], 'exist', 'skipOnError' => true, 'targetClass' => Language::className(), 'targetAttribute' => ['language_id' => 'language_id']], + [['product_variant_id'], 'exist', 'skipOnError' => true, 'targetClass' => ProductVariant::className(), 'targetAttribute' => ['product_variant_id' => 'product_variant_id']], + ]; + } + + /** + * @inheritdoc + */ + public function attributeLabels() + { + return [ + 'product_variant_id' => Yii::t('app', 'Product Variant ID'), + 'language_id' => Yii::t('app', 'Language ID'), + 'name' => Yii::t('app', 'Name'), + ]; + } + + /** + * @return \yii\db\ActiveQuery + */ + public function getLanguage() + { + return $this->hasOne(Language::className(), ['language_id' => 'language_id']); + } + + /** + * @return \yii\db\ActiveQuery + */ + public function getProductVariant() + { + return $this->hasOne(ProductVariant::className(), ['product_variant_id' => 'product_variant_id']); + } +} diff --git a/common/modules/product/models/ProductVariantListSearch.php b/common/modules/product/models/ProductVariantListSearch.php index 3b96801..c723e99 100644 --- a/common/modules/product/models/ProductVariantListSearch.php +++ b/common/modules/product/models/ProductVariantListSearch.php @@ -10,6 +10,11 @@ use yii\data\ActiveDataProvider; */ class ProductVariantListSearch extends ProductVariant { + public function behaviors() + { + return []; + } + /** * @inheritdoc */ diff --git a/common/modules/product/models/ProductVariantSearch.php b/common/modules/product/models/ProductVariantSearch.php index fbc42dd..4eb51e0 100644 --- a/common/modules/product/models/ProductVariantSearch.php +++ b/common/modules/product/models/ProductVariantSearch.php @@ -16,6 +16,12 @@ class ProductVariantSearch extends ProductVariant public $is_top; public $is_new; public $akciya; + + public function behaviors() + { + return []; + } + /** * @inheritdoc */ diff --git a/common/modules/product/views/manage/_form.php b/common/modules/product/views/manage/_form.php index 358bfad..f0c97ce 100644 --- a/common/modules/product/views/manage/_form.php +++ b/common/modules/product/views/manage/_form.php @@ -1,6 +1,9 @@ field($model, 'certificateUpload[]') - ->widget(\kartik\file\FileInput::className(), [ - 'language' => 'ru', - 'options' => [ - 'multiple' => true, - ], - 'pluginOptions' => [ - 'allowedFileExtensions' => [ - 'pdf', - ], - 'initialPreview' => $model->productCertificates?ArrayHelper::getColumn($model->productCertificates, 'link'): [], - 'initialPreviewConfig' => $certOptions, - 'overwriteInitial' => false, - 'showRemove' => false, - 'showUpload' => false, - 'previewFileType' => 'image', - ], - ]); ?> + echo $form->field($model, 'certificateUpload[]') + ->widget(\kartik\file\FileInput::className(), [ + 'language' => 'ru', + 'options' => [ + 'multiple' => true, + ], + 'pluginOptions' => [ + 'allowedFileExtensions' => [ + 'pdf', + ], + 'initialPreview' => $model->productCertificates ? ArrayHelper::getColumn($model->productCertificates, 'link') : [], + 'initialPreviewConfig' => $certOptions, + 'overwriteInitial' => false, + 'showRemove' => false, + 'showUpload' => false, + 'previewFileType' => 'image', + ], + ]); ?> all() as $group) : ?> @@ -131,11 +136,11 @@ field($product_spec, 'tech_spec_text') ->widget(\mihaildev\ckeditor\CKEditor::className(), [ - 'editorOptions' => [ - 'preset' => 'full', - 'inline' => false, - ], - ]); + 'editorOptions' => [ + 'preset' => 'full', + 'inline' => false, + ], + ]); echo $form->field($product_spec, 'techCharFile') ->widget(\kartik\file\FileInput::className(), [ @@ -180,6 +185,19 @@ ]); ?> + $model_langs, + 'formView' => '@common/modules/product/views/manage/_form_language', + 'form' => $form, + ]) ?> + + $product_spec_langs, + 'formView' => '@common/modules/product/views/manage/_form_spec_language', + 'form' => $form, + 'id_prefix' => 'spec', + ]) ?> +
isNewRecord ? Yii::t('product', 'Create') : Yii::t('product', 'Update'), [ 'class' => $model->isNewRecord ? 'btn btn-success' : 'btn btn-primary' ]) ?>
diff --git a/common/modules/product/views/manage/_form_language.php b/common/modules/product/views/manage/_form_language.php new file mode 100644 index 0000000..b885885 --- /dev/null +++ b/common/modules/product/views/manage/_form_language.php @@ -0,0 +1,26 @@ + +field($model_lang, '[' . $language->language_id . ']name') + ->textInput([ 'maxlength' => true ]); ?> +field($model_lang, '[' . $language->language_id . ']description') + ->widget(CKEditor::className(), [ + 'editorOptions' => ElFinder::ckeditorOptions('elfinder', [ + 'preset' => 'full', + 'inline' => false, + 'filebrowserUploadUrl' => Yii::$app->getUrlManager() + ->createUrl('file/uploader/images-upload'), + ]), + ]) ?> \ No newline at end of file diff --git a/common/modules/product/views/manage/_form_spec_language.php b/common/modules/product/views/manage/_form_spec_language.php new file mode 100644 index 0000000..1644579 --- /dev/null +++ b/common/modules/product/views/manage/_form_spec_language.php @@ -0,0 +1,33 @@ + +field($model_lang, '[' . $language->language_id . ']tech_spec_text') + ->widget(CKEditor::className(), [ + 'editorOptions' => ElFinder::ckeditorOptions('elfinder', [ + 'preset' => 'full', + 'inline' => false, + 'filebrowserUploadUrl' => Yii::$app->getUrlManager() + ->createUrl('file/uploader/images-upload'), + ]), + ]) ?> +field($model_lang, '[' . $language->language_id . ']instruction') + ->widget(CKEditor::className(), [ + 'editorOptions' => ElFinder::ckeditorOptions('elfinder', [ + 'preset' => 'full', + 'inline' => false, + 'filebrowserUploadUrl' => Yii::$app->getUrlManager() + ->createUrl('file/uploader/images-upload'), + ]), + ]) ?> \ No newline at end of file diff --git a/common/modules/product/views/manage/create.php b/common/modules/product/views/manage/create.php index dd483f6..55cf60a 100644 --- a/common/modules/product/views/manage/create.php +++ b/common/modules/product/views/manage/create.php @@ -1,14 +1,18 @@ title = Yii::t('product', 'Create Product'); @@ -23,8 +27,10 @@

title) ?>

render('_form', [ - 'model' => $model, - 'product_spec' => $product_spec, + 'model' => $model, + 'model_langs' => $model_langs, + 'product_spec' => $product_spec, + 'product_spec_langs' => $product_spec_langs, ]) ?> diff --git a/common/modules/product/views/manage/update.php b/common/modules/product/views/manage/update.php index 54d8d50..84f3ce5 100644 --- a/common/modules/product/views/manage/update.php +++ b/common/modules/product/views/manage/update.php @@ -1,14 +1,18 @@ title = Yii::t('product', 'Update {modelClass}: ', [ @@ -33,8 +37,10 @@ render('_form', [ 'model' => $model, + 'model_langs' => $model_langs, 'groups' => $groups, 'product_spec' => $product_spec, + 'product_spec_langs' => $product_spec_langs, ]) ?> diff --git a/common/modules/product/views/product-unit/_form.php b/common/modules/product/views/product-unit/_form.php index f1a1206..6ec74a9 100644 --- a/common/modules/product/views/product-unit/_form.php +++ b/common/modules/product/views/product-unit/_form.php @@ -1,27 +1,43 @@
- + - - field($model, 'name')->textInput(['maxlength' => true]) ?> - - field($model, 'code')->textInput(['maxlength' => true]) ?> - - field($model, 'is_default')->checkbox() ?> - + + field($model, 'name') + ->textInput([ 'maxlength' => true ]) ?> + + field($model, 'code') + ->textInput([ 'maxlength' => true ]) ?> + + field($model, 'is_default') + ->checkbox() ?> + + $model_langs, + 'form' => $form, + 'formView' => '@common/modules/product/views/product-unit/_form_language', + ]) ?> +
- isNewRecord ? Yii::t('product', 'Create') : Yii::t('product', 'Update'), ['class' => $model->isNewRecord ? 'btn btn-success' : 'btn btn-primary']) ?> + isNewRecord ? Yii::t('product', 'Create') : Yii::t('product', 'Update'), [ 'class' => $model->isNewRecord ? 'btn btn-success' : 'btn btn-primary' ]) ?>
- +
diff --git a/common/modules/product/views/product-unit/_form_language.php b/common/modules/product/views/product-unit/_form_language.php new file mode 100644 index 0000000..868196a --- /dev/null +++ b/common/modules/product/views/product-unit/_form_language.php @@ -0,0 +1,17 @@ + +field($model_lang, '[' . $language->language_id . ']name') + ->textInput([ 'maxlength' => true ]); ?> +field($model_lang, '[' . $language->language_id . ']short') + ->textInput([ 'maxlength' => true ]); ?> \ No newline at end of file diff --git a/common/modules/product/views/product-unit/create.php b/common/modules/product/views/product-unit/create.php index 5c54fcc..dc908f5 100644 --- a/common/modules/product/views/product-unit/create.php +++ b/common/modules/product/views/product-unit/create.php @@ -1,21 +1,30 @@ title = Yii::t('product', 'Create Product Unit'); -$this->params['breadcrumbs'][] = ['label' => Yii::t('product', 'Product Units'), 'url' => ['index']]; -$this->params['breadcrumbs'][] = $this->title; + + use common\modules\product\models\ProductUnit; + use common\modules\product\models\ProductUnitLang; + use yii\helpers\Html; + use yii\web\View; + + /** + * @var View $this + * @var ProductUnit $model + * @var ProductUnitLang[] $model_langs + */ + + $this->title = Yii::t('product', 'Create Product Unit'); + $this->params[ 'breadcrumbs' ][] = [ + 'label' => Yii::t('product', 'Product Units'), + 'url' => [ 'index' ], + ]; + $this->params[ 'breadcrumbs' ][] = $this->title; ?>
- +

title) ?>

- + render('_form', [ - 'model' => $model, + 'model' => $model, + 'model_langs' => $model_langs, ]) ?>
diff --git a/common/modules/product/views/product-unit/update.php b/common/modules/product/views/product-unit/update.php index fcd5ef7..95baf52 100644 --- a/common/modules/product/views/product-unit/update.php +++ b/common/modules/product/views/product-unit/update.php @@ -1,23 +1,39 @@ title = Yii::t('product', 'Update {modelClass}: ', [ - 'modelClass' => 'Product Unit', -]) . $model->name; -$this->params['breadcrumbs'][] = ['label' => Yii::t('product', 'Product Units'), 'url' => ['index']]; -$this->params['breadcrumbs'][] = ['label' => $model->name, 'url' => ['view', 'id' => $model->product_unit_id]]; -$this->params['breadcrumbs'][] = Yii::t('product', 'Update'); + + use common\modules\product\models\ProductUnit; + use common\modules\product\models\ProductUnitLang; + use yii\helpers\Html; + use yii\web\View; + + /** + * @var View $this + * @var ProductUnit $model + * @var ProductUnitLang[] $model_langs + */ + + $this->title = Yii::t('product', 'Update {modelClass}: ', [ + 'modelClass' => 'Product Unit', + ]) . $model->name; + $this->params[ 'breadcrumbs' ][] = [ + 'label' => Yii::t('product', 'Product Units'), + 'url' => [ 'index' ], + ]; + $this->params[ 'breadcrumbs' ][] = [ + 'label' => $model->name, + 'url' => [ + 'view', + 'id' => $model->product_unit_id, + ], + ]; + $this->params[ 'breadcrumbs' ][] = Yii::t('product', 'Update'); ?>
- +

title) ?>

- + render('_form', [ - 'model' => $model, + 'model' => $model, + 'model_langs' => $model_langs, ]) ?>
diff --git a/common/modules/product/views/variant/_form.php b/common/modules/product/views/variant/_form.php index 841d683..8885754 100644 --- a/common/modules/product/views/variant/_form.php +++ b/common/modules/product/views/variant/_form.php @@ -1,18 +1,26 @@ registerJs($js, View::POS_END); + + $this->registerJs($js, View::POS_END); ?>
- + 'dynamic-form', - 'options' => ['enctype' => 'multipart/form-data'] - ]); ?> - - field($model, 'name')->textInput(['maxlength' => true]) ?> - - field($model, 'product_id')->hiddenInput()->label(false); ?> - - field($model, 'sku')->textarea(); ?> - field($model, 'price')->textarea(); ?> - field($model, 'price_old')->textarea(); ?> - field($model, 'image')->widget(\kartik\file\FileInput::classname(), [ - 'model' => $model, - 'attribute' => 'image', - 'options' => [ - 'accept' => 'image/*', - 'multiple' => false - ], - 'pluginOptions' => [ - 'allowedFileExtensions' => ['jpg','gif','png'], - 'initialPreview' => $model->imageUrl ? \common\components\artboximage\ArtboxImageHelper::getImage($model->imageUrl, 'products') : '', - 'overwriteInitial' => true, - 'showRemove' => true, - 'showUpload' => false, - ], + 'id' => 'dynamic-form', + 'options' => [ 'enctype' => 'multipart/form-data' ], ]); ?> - + + field($model, 'name') + ->textInput([ 'maxlength' => true ]) ?> + + field($model, 'product_id') + ->hiddenInput() + ->label(false); ?> + + field($model, 'sku') + ->textarea(); ?> + field($model, 'price') + ->textarea(); ?> + field($model, 'price_old') + ->textarea(); ?> + field($model, 'image') + ->widget(\kartik\file\FileInput::className(), [ + 'model' => $model, + 'attribute' => 'image', + 'options' => [ + 'accept' => 'image/*', + 'multiple' => false, + ], + 'pluginOptions' => [ + 'allowedFileExtensions' => [ + 'jpg', + 'gif', + 'png', + ], + 'initialPreview' => $model->imageUrl ? \common\components\artboximage\ArtboxImageHelper::getImage($model->imageUrl, 'products') : '', + 'overwriteInitial' => true, + 'showRemove' => true, + 'showUpload' => false, + ], + ]); ?> + + $model_langs, + 'formView' => '@common/modules/product/views/variant/_form_language', + 'form' => $form, + ]) ?> + 'dynamicform_wrapper', // required: only alphanumeric characters plus "_" [A-Za-z0-9_] - 'widgetBody' => '.container-items', // required: css class selector - 'widgetItem' => '.item', // required: css class - 'limit' => 10, // the maximum times, an element can be added (default 999) - 'min' => 0, // 0 or 1 (default 1) - 'insertButton' => '.add-item', // css class - 'deleteButton' => '.remove-item', // css class - 'model' => $stocks[0], - 'formId' => 'dynamic-form', - 'formFields' => [ + 'widgetContainer' => 'dynamicform_wrapper', + // required: only alphanumeric characters plus "_" [A-Za-z0-9_] + 'widgetBody' => '.container-items', + // required: css class selector + 'widgetItem' => '.item', + // required: css class + 'limit' => 10, + // the maximum times, an element can be added (default 999) + 'min' => 0, + // 0 or 1 (default 1) + 'insertButton' => '.add-item', + // css class + 'deleteButton' => '.remove-item', + // css class + 'model' => $stocks[ 0 ], + 'formId' => 'dynamic-form', + 'formFields' => [ 'quantity', 'name', ], ]); ?> - +

Склады - +

- $stock): ?> + $stock): ?>
isNewRecord) { - echo Html::activeHiddenInput($stock, "[{$i}]stock_id"); - } + // necessary for update action. + if(!$stock->isNewRecord) { + echo Html::activeHiddenInput($stock, "[{$i}]stock_id"); + } ?>
- field($stock, "[{$i}]quantity")->textInput(['maxlength' => true]) ?> + field($stock, "[{$i}]quantity") + ->textInput([ 'maxlength' => true ]) ?>
- field($stock, "[{$i}]name")->textInput(['maxlength' => true]) ?> + field($stock, "[{$i}]name") + ->textInput([ 'maxlength' => true ]) ?>
- +
@@ -121,29 +158,29 @@ $this->registerJs($js, View::POS_END);
- - field($model, 'product_unit_id')->dropDownList( - ArrayHelper::map(\common\modules\product\models\ProductUnit::find()->all(), 'product_unit_id', 'name'), - [ - 'prompt' => Yii::t('product', 'Unit'), - ])->label(Yii::t('product', 'Unit')) ?> - - all() as $group) :?> - field($model, 'options')->checkboxList( - ArrayHelper::map($group->options, 'tax_option_id', 'value'), - [ - 'multiple' => true, - 'unselect' => null, - ] - )->label($group->name);?> - - - + field($model, 'product_unit_id') + ->dropDownList(ArrayHelper::map(\common\modules\product\models\ProductUnit::find() + ->all(), 'product_unit_id', 'name'), [ + 'prompt' => Yii::t('product', 'Unit'), + ]) + ->label(Yii::t('product', 'Unit')) ?> + + + all() as $group) : ?> + field($model, 'options') + ->checkboxList(ArrayHelper::map($group->options, 'tax_option_id', 'value'), [ + 'multiple' => true, + 'unselect' => NULL, + ]) + ->label($group->name); ?> + + +
- isNewRecord ? Yii::t('product', 'Create') : Yii::t('product', 'Update'), ['class' => $model->isNewRecord ? 'btn btn-success' : 'btn btn-primary']) ?> + isNewRecord ? Yii::t('product', 'Create') : Yii::t('product', 'Update'), [ 'class' => $model->isNewRecord ? 'btn btn-success' : 'btn btn-primary' ]) ?>
- +
diff --git a/common/modules/product/views/variant/_form_language.php b/common/modules/product/views/variant/_form_language.php new file mode 100644 index 0000000..e109e1b --- /dev/null +++ b/common/modules/product/views/variant/_form_language.php @@ -0,0 +1,15 @@ + +field($model_lang, '[' . $language->language_id . ']name') + ->textInput([ 'maxlength' => true ]); ?> \ No newline at end of file diff --git a/common/modules/product/views/variant/create.php b/common/modules/product/views/variant/create.php index 1c3d2de..6df229a 100644 --- a/common/modules/product/views/variant/create.php +++ b/common/modules/product/views/variant/create.php @@ -1,23 +1,35 @@ title = Yii::t('product', 'Create Product'); -$this->params['breadcrumbs'][] = ['label' => Yii::t('product', 'Products'), 'url' => ['index']]; -$this->params['breadcrumbs'][] = $this->title; + + use common\modules\product\models\ProductStock; + use common\modules\product\models\ProductVariant; + use common\modules\product\models\ProductVariantLang; + use yii\db\ActiveQuery; + use yii\helpers\Html; + use yii\web\View; + + /** + * @var View $this + * @var ProductVariant $model + * @var ProductVariantLang[] $model_langs + * @var ActiveQuery $groups + * @var ProductStock[] $stocks + */ + $this->title = Yii::t('product', 'Create Product'); + $this->params[ 'breadcrumbs' ][] = [ + 'label' => Yii::t('product', 'Products'), + 'url' => [ 'index' ], + ]; + $this->params[ 'breadcrumbs' ][] = $this->title; ?>
- +

title) ?>

- + render('_form', [ - 'model' => $model, - 'groups' => $groups, - 'stocks' => $stocks, + 'model' => $model, + 'model_langs' => $model_langs, + 'groups' => $groups, + 'stocks' => $stocks, ]) ?>
diff --git a/common/modules/product/views/variant/update.php b/common/modules/product/views/variant/update.php index a146f7d..536797a 100644 --- a/common/modules/product/views/variant/update.php +++ b/common/modules/product/views/variant/update.php @@ -1,27 +1,52 @@ title = Yii::t('product', 'Update {modelClass}: ', [ - 'modelClass' => 'Product', -]) . ' ' . $model->name; -$this->params['breadcrumbs'][] = ['label' => Yii::t('product', 'Products'), 'url' => ['index']]; -$this->params['breadcrumbs'][] = ['label' => $model->product->name, 'url' => ['view', 'id' => $model->product->product_id]]; -$this->params['breadcrumbs'][] = ['label' => Yii::t('product', 'Variants'), 'url' => Url::to(['/product/variant', 'product_id' => $model->product->product_id])]; -$this->params['breadcrumbs'][] = Yii::t('product', 'Update'); + + use common\modules\product\models\ProductStock; + use common\modules\product\models\ProductVariant; + use common\modules\product\models\ProductVariantLang; + use yii\db\ActiveQuery; + use yii\helpers\Html; + use yii\helpers\Url; + use yii\web\View; + + /** + * @var View $this + * @var ProductVariant $model + * @var ProductVariantLang[] $model_langs + * @var ActiveQuery $groups + * @var ProductStock[] $stocks + */ + $this->title = Yii::t('product', 'Update {modelClass}: ', [ + 'modelClass' => 'Product', + ]) . ' ' . $model->name; + $this->params[ 'breadcrumbs' ][] = [ + 'label' => Yii::t('product', 'Products'), + 'url' => [ 'index' ], + ]; + $this->params[ 'breadcrumbs' ][] = [ + 'label' => $model->product->name, + 'url' => [ + 'view', + 'id' => $model->product->product_id, + ], + ]; + $this->params[ 'breadcrumbs' ][] = [ + 'label' => Yii::t('product', 'Variants'), + 'url' => Url::to([ + '/product/variant', + 'product_id' => $model->product->product_id, + ]), + ]; + $this->params[ 'breadcrumbs' ][] = Yii::t('product', 'Update'); ?>
- +

title) ?>

- + render('_form', [ - 'model' => $model, - 'groups' => $groups, - 'stocks' => $stocks, + 'model' => $model, + 'model_langs' => $model_langs, + 'groups' => $groups, + 'stocks' => $stocks, ]) ?>
diff --git a/common/modules/rubrication/controllers/TaxGroupController.php b/common/modules/rubrication/controllers/TaxGroupController.php index 450ea84..0eee7e7 100644 --- a/common/modules/rubrication/controllers/TaxGroupController.php +++ b/common/modules/rubrication/controllers/TaxGroupController.php @@ -1,140 +1,173 @@ [ - 'class' => VerbFilter::className(), - 'actions' => [ - 'delete' => ['POST'], + + /** + * @inheritdoc + */ + public function behaviors() + { + return [ + 'verbs' => [ + 'class' => VerbFilter::className(), + 'actions' => [ + 'delete' => [ 'POST' ], + ], ], - ], - ]; - } - - /** - * Lists all TaxGroup models. - * @param $level integer - * @return mixed - */ - public function actionIndex($level) - { - $dataProvider = new ActiveDataProvider([ - 'query' => TaxGroup::find()->where(['level' => $level]), - ]); - - return $this->render('index', [ - 'dataProvider' => $dataProvider, - 'level' => $level - ]); - } - - /** - * Displays a single TaxGroup model. - * @param integer $id - * @return mixed - */ - public function actionView($level,$id) - { - return $this->render('view', [ - 'model' => $this->findModel($id), - ]); - } - - /** - * Creates a new TaxGroup model. - * If creation is successful, the browser will be redirected to the 'view' page. - * @param $level integer - * @return mixed - */ - public function actionCreate($level) - { - $model = new TaxGroup(); - - if ($model->load(Yii::$app->request->post()) && $model->validate()) { - $model->level = $level; - $model->save(); - return $this->redirect(['index', 'level' => $level]); - } else { + ]; + } + + /** + * Lists all TaxGroup models. + * + * @param $level integer + * + * @return mixed + */ + public function actionIndex($level) + { + $dataProvider = new ActiveDataProvider([ + 'query' => TaxGroup::find() + ->where([ 'level' => $level ]), + ]); + + return $this->render('index', [ + 'dataProvider' => $dataProvider, + 'level' => $level, + ]); + } + + /** + * Displays a single TaxGroup model. + * + * @param integer $id + * + * @return mixed + */ + public function actionView($level, $id) + { + return $this->render('view', [ + 'model' => $this->findModel($id), + ]); + } + + /** + * Creates a new TaxGroup model. + * If creation is successful, the browser will be redirected to the 'view' page. + * + * @param $level integer + * + * @return mixed + */ + public function actionCreate($level) + { + $model = new TaxGroup(); + $model_langs = $model->generateLangs(); + + if($model->load(Yii::$app->request->post()) && $model->validate()) { + $model->loadLangs(\Yii::$app->request, $model_langs); + $model->level = $level; + if($model->save() && $model->linkLangs($model_langs) && $model->saveLangs($model_langs)) { + return $this->redirect([ + 'index', + 'level' => $level, + ]); + } + } return $this->render('create', [ - 'model' => $model, + 'model' => $model, + 'model_langs' => $model_langs, ]); } - } - - /** - * Updates an existing TaxGroup model. - * If update is successful, the browser will be redirected to the 'view' page. - * @param $level integer - * @param integer $id - * @return mixed - */ - public function actionUpdate($level,$id) - { - $model = $this->findModel($id); - - if ($model->load(Yii::$app->request->post()) && $model->save()) { - return $this->redirect(['index', 'level' => $level]); - } else { + + /** + * Updates an existing TaxGroup model. + * If update is successful, the browser will be redirected to the 'view' page. + * + * @param $level integer + * @param integer $id + * + * @return mixed + */ + public function actionUpdate($level, $id) + { + $model = $this->findModel($id); + $model_langs = $model->generateLangs(); + + if($model->load(Yii::$app->request->post())) { + $model->loadLangs(\Yii::$app->request, $model_langs); + if($model->save() && $model->linkLangs($model_langs) && $model->saveLangs($model_langs)) { + return $this->redirect([ + 'index', + 'level' => $level, + ]); + } + } return $this->render('update', [ - 'model' => $model, + 'model' => $model, + 'model_langs' => $model_langs, ]); } - } - - /** - * Deletes an existing TaxGroup model. - * If deletion is successful, the browser will be redirected to the 'index' page. - * @param $level integer - * @param integer $id - * @return mixed - */ - public function actionDelete($level,$id) - { - $this->findModel($id)->delete(); - return $this->redirect(['index', 'level' => $level]); - } - - /* - * Rebuilp MP-params for group options - */ - public function actionRebuild($id) { - TaxOption::find()->rebuildMP($id); - - return $this->redirect(['index']); - } - - /** - * Finds the TaxGroup model based on its primary key value. - * If the model is not found, a 404 HTTP exception will be thrown. - * @param integer $id - * @return TaxGroup the loaded model - * @throws NotFoundHttpException if the model cannot be found - */ - protected function findModel($id) - { - if (($model = TaxGroup::findOne($id)) !== null) { - return $model; - } else { - throw new NotFoundHttpException('The requested page does not exist.'); + + /** + * Deletes an existing TaxGroup model. + * If deletion is successful, the browser will be redirected to the 'index' page. + * + * @param $level integer + * @param integer $id + * + * @return mixed + */ + public function actionDelete($level, $id) + { + $this->findModel($id) + ->delete(); + return $this->redirect([ + 'index', + 'level' => $level, + ]); + } + + /* + * Rebuilp MP-params for group options + */ + public function actionRebuild($id) + { + TaxOption::find() + ->rebuildMP($id); + + return $this->redirect([ 'index' ]); + } + + /** + * Finds the TaxGroup model based on its primary key value. + * If the model is not found, a 404 HTTP exception will be thrown. + * + * @param integer $id + * + * @return TaxGroup the loaded model + * @throws NotFoundHttpException if the model cannot be found + */ + protected function findModel($id) + { + if(( $model = TaxGroup::findOne($id) ) !== NULL) { + return $model; + } else { + throw new NotFoundHttpException('The requested page does not exist.'); + } } } -} diff --git a/common/modules/rubrication/controllers/TaxOptionController.php b/common/modules/rubrication/controllers/TaxOptionController.php index 2816fac..b2bb1c3 100644 --- a/common/modules/rubrication/controllers/TaxOptionController.php +++ b/common/modules/rubrication/controllers/TaxOptionController.php @@ -1,178 +1,208 @@ [ - 'class' => VerbFilter::className(), - 'actions' => [ - 'delete' => ['POST'], + + /** + * @inheritdoc + */ + public function behaviors() + { + return [ + 'verbs' => [ + 'class' => VerbFilter::className(), + 'actions' => [ + 'delete' => [ 'POST' ], + ], ], - ], - ]; - } - - /** - * Lists all TaxOption models. - * @return mixed - */ - public function actionIndex() - { - $searchModel = new TaxOptionSearch(); - $dataProvider = $searchModel->search(Yii::$app->request->queryParams); - - $group = TaxGroup::findOne(Yii::$app->request->queryParams['group']); - - return $this->render('index', [ - 'searchModel' => $searchModel, - 'dataProvider' => $dataProvider, - 'group' => $group, - ]); - } - - /** - * Displays a single TaxOption model. - * @param string $id - * @return mixed - */ - public function actionView($id) - { - $model = $this->findModel($id); - $group = TaxGroup::findOne($model->tax_group_id); - return $this->render('view', [ - 'model' => $model, - 'group' => $group, - ]); - } - - /** - * Creates a new TaxOption model. - * If creation is successful, the browser will be redirected to the 'view' page. - * @return mixed - */ - public function actionCreate() - { - $model = new TaxOption(); - $group = TaxGroup::findOne(Yii::$app->request->queryParams['group']); - - if ($model->load(Yii::$app->request->post())) { - if ( ($image = UploadedFile::getInstance($model, 'image')) ) { - $model->image = $image->name; - } - if ($model->save() && $image) { - - $imgDir = Yii::getAlias('@storage/tax_option/'); - - if(!is_dir($imgDir)) { - mkdir($imgDir, 0755, true); - } - - $image->saveAs(Yii::getAlias('@storage/tax_option/' . $image->name)); - } + ]; + } + + /** + * Lists all TaxOption models. + * @return mixed + */ + public function actionIndex() + { + $searchModel = new TaxOptionSearch(); + $dataProvider = $searchModel->search(Yii::$app->request->queryParams); - $model->save(); - - return is_null(Yii::$app->request->post('create_and_new')) ? $this->redirect(['view', 'id' => $model->tax_option_id]) : $this->redirect(array_merge(['create'], Yii::$app->request->queryParams)); - } else { - $model->tax_group_id = $group->tax_group_id; - if (!empty(Yii::$app->request->queryParams['parent'])) { - $model->parent_id = Yii::$app->request->queryParams['parent']; - } - return $this->render('create', [ + $group = TaxGroup::findOne(Yii::$app->request->queryParams[ 'group' ]); + + return $this->render('index', [ + 'searchModel' => $searchModel, + 'dataProvider' => $dataProvider, + 'group' => $group, + ]); + } + + /** + * Displays a single TaxOption model. + * + * @param string $id + * + * @return mixed + */ + public function actionView($id) + { + $model = $this->findModel($id); + $group = TaxGroup::findOne($model->tax_group_id); + return $this->render('view', [ 'model' => $model, 'group' => $group, ]); } - } - - /** - * Updates an existing TaxOption model. - * If update is successful, the browser will be redirected to the 'view' page. - * @param string $id - * @return mixed - */ - public function actionUpdate($id) - { - $model = $this->findModel($id); - $group = TaxGroup::findOne($model->tax_group_id); - - - if ($model->load(Yii::$app->request->post())) { - - - if ( ($image = UploadedFile::getInstance($model, 'image')) ) { - $model->image = $image->name; + + /** + * Creates a new TaxOption model. + * If creation is successful, the browser will be redirected to the 'view' page. + * @return mixed + */ + public function actionCreate() + { + $model = new TaxOption(); + $model_langs = $model->generateLangs(); + $group = TaxGroup::findOne(Yii::$app->request->queryParams[ 'group' ]); + + if($model->load(Yii::$app->request->post())) { + $model->loadLangs(\Yii::$app->request, $model_langs); + if(( $image = UploadedFile::getInstance($model, 'image') )) { + $model->image = $image->name; + } + if($model->save() && $image) { + + $imgDir = Yii::getAlias('@storage/tax_option/'); + + if(!is_dir($imgDir)) { + mkdir($imgDir, 0755, true); + } + + $image->saveAs(Yii::getAlias('@storage/tax_option/' . $image->name)); + } + + $model->save(); + + if($model->linkLangs($model_langs) && $model->saveLangs($model_langs)) { + return is_null(Yii::$app->request->post('create_and_new')) ? $this->redirect([ + 'view', + 'id' => $model->tax_option_id, + ]) : $this->redirect(array_merge([ 'create' ], Yii::$app->request->queryParams)); + } else { + return $this->redirect([ + 'update', + 'id' => $model->tax_option_id, + ]); + } + + } else { + $model->tax_group_id = $group->tax_group_id; + if(!empty( Yii::$app->request->queryParams[ 'parent' ] )) { + $model->parent_id = Yii::$app->request->queryParams[ 'parent' ]; + } + return $this->render('create', [ + 'model' => $model, + 'model_langs' => $model_langs, + 'group' => $group, + ]); } - if ($model->save() && $image) { - - $imgDir = Yii::getAlias('@storage/tax_option/'); - - if(!is_dir($imgDir)) { - mkdir($imgDir, 0755, true); + } + + /** + * Updates an existing TaxOption model. + * If update is successful, the browser will be redirected to the 'view' page. + * + * @param string $id + * + * @return mixed + */ + public function actionUpdate($id) + { + $model = $this->findModel($id); + $model_langs = $model->generateLangs(); + $group = TaxGroup::findOne($model->tax_group_id); + + if($model->load(Yii::$app->request->post())) { + $model->loadLangs(\Yii::$app->request, $model_langs); + if(( $image = UploadedFile::getInstance($model, 'image') )) { + $model->image = $image->name; + } + if($model->save() && $image) { + + $imgDir = Yii::getAlias('@storage/tax_option/'); + + if(!is_dir($imgDir)) { + mkdir($imgDir, 0755, true); + } + + $image->saveAs(Yii::getAlias('@storage/tax_option/' . $image->name)); + } + + TaxOption::find() + ->rebuildMP($model->tax_group_id); + if($model->linkLangs($model_langs) && $model->saveLangs($model_langs)) { + return $this->redirect([ + 'view', + 'id' => $model->tax_option_id, + ]); } - - $image->saveAs(Yii::getAlias('@storage/tax_option/' . $image->name)); } - - TaxOption::find()->rebuildMP($model->tax_group_id); - - return $this->redirect(['view', 'id' => $model->tax_option_id]); - } else { return $this->render('update', [ - 'model' => $model, - 'group' => $group + 'model' => $model, + 'model_langs' => $model_langs, + 'group' => $group, ]); } - } - - /** - * Deletes an existing TaxOption model. - * If deletion is successful, the browser will be redirected to the 'index' page. - * @param string $id - * @return mixed - */ - public function actionDelete($id) - { - $model = $this->findModel($id); - $group_id = $model->tax_group_id; - - $model->delete(); - - return $this->redirect(['index', 'group' => $group_id]); - } - - /** - * Finds the TaxOption model based on its primary key value. - * If the model is not found, a 404 HTTP exception will be thrown. - * @param string $id - * @return TaxOption the loaded model - * @throws NotFoundHttpException if the model cannot be found - */ - protected function findModel($id) - { - if (($model = TaxOption::findOne($id)) !== null) { - return $model; - } else { - throw new NotFoundHttpException('The requested page does not exist.'); + + /** + * Deletes an existing TaxOption model. + * If deletion is successful, the browser will be redirected to the 'index' page. + * + * @param string $id + * + * @return mixed + */ + public function actionDelete($id) + { + $model = $this->findModel($id); + $group_id = $model->tax_group_id; + + $model->delete(); + + return $this->redirect([ + 'index', + 'group' => $group_id, + ]); + } + + /** + * Finds the TaxOption model based on its primary key value. + * If the model is not found, a 404 HTTP exception will be thrown. + * + * @param string $id + * + * @return TaxOption the loaded model + * @throws NotFoundHttpException if the model cannot be found + */ + protected function findModel($id) + { + if(( $model = TaxOption::findOne($id) ) !== NULL) { + return $model; + } else { + throw new NotFoundHttpException('The requested page does not exist.'); + } } } -} diff --git a/common/modules/rubrication/models/TaxGroup.php b/common/modules/rubrication/models/TaxGroup.php index 312a728..6adf067 100644 --- a/common/modules/rubrication/models/TaxGroup.php +++ b/common/modules/rubrication/models/TaxGroup.php @@ -2,8 +2,12 @@ namespace common\modules\rubrication\models; + use common\modules\language\behaviors\LanguageBehavior; use common\modules\product\models\Category; - + use yii\db\ActiveQuery; + use yii\db\ActiveRecord; + use yii\web\Request; + /** * This is the model class for table "{{%tax_group}}". * @property integer $tax_group_id @@ -18,6 +22,24 @@ * @property TaxOption[] $taxOptions * @property Category[] $categories * @property TaxOption[] $options + * + * * From language behavior * + * @property TaxGroupLang $lang + * @property TaxGroupLang[] $langs + * @property TaxGroupLang $object_lang + * @property string $ownerKey + * @property string $langKey + * @method string getOwnerKey() + * @method void setOwnerKey(string $value) + * @method string getLangKey() + * @method void setLangKey(string $value) + * @method ActiveQuery getLangs() + * @method ActiveQuery getLang( integer $language_id ) + * @method TaxGroupLang[] generateLangs() + * @method void loadLangs(Request $request, ActiveRecord[] $model_langs) + * @method bool linkLangs(ActiveRecord[] $model_langs) + * @method bool saveLangs(ActiveRecord[] $model_langs) + * * End language behavior * */ class TaxGroup extends \yii\db\ActiveRecord { @@ -39,6 +61,9 @@ 'out_attribute' => 'alias', 'translit' => true, ], + 'language' => [ + 'class' => LanguageBehavior::className(), + ], ]; } diff --git a/common/modules/rubrication/models/TaxGroupLang.php b/common/modules/rubrication/models/TaxGroupLang.php new file mode 100644 index 0000000..932ed16 --- /dev/null +++ b/common/modules/rubrication/models/TaxGroupLang.php @@ -0,0 +1,81 @@ + 255], + [['tax_group_id', 'language_id'], 'unique', 'targetAttribute' => ['tax_group_id', 'language_id'], 'message' => 'The combination of Tax Group ID and Language ID has already been taken.'], + [['language_id'], 'exist', 'skipOnError' => true, 'targetClass' => Language::className(), 'targetAttribute' => ['language_id' => 'language_id']], + [['tax_group_id'], 'exist', 'skipOnError' => true, 'targetClass' => TaxGroup::className(), 'targetAttribute' => ['tax_group_id' => 'tax_group_id']], + ]; + } + + /** + * @inheritdoc + */ + public function attributeLabels() + { + return [ + 'tax_group_id' => Yii::t('app', 'Tax Group ID'), + 'language_id' => Yii::t('app', 'Language ID'), + 'name' => Yii::t('app', 'Name'), + 'description' => Yii::t('app', 'Description'), + ]; + } + + /** + * @return \yii\db\ActiveQuery + */ + public function getLanguage() + { + return $this->hasOne(Language::className(), ['language_id' => 'language_id']); + } + + /** + * @return \yii\db\ActiveQuery + */ + public function getTaxGroup() + { + return $this->hasOne(TaxGroup::className(), ['tax_group_id' => 'tax_group_id']); + } +} diff --git a/common/modules/rubrication/models/TaxOption.php b/common/modules/rubrication/models/TaxOption.php index 42ed81f..23af484 100644 --- a/common/modules/rubrication/models/TaxOption.php +++ b/common/modules/rubrication/models/TaxOption.php @@ -2,11 +2,14 @@ namespace common\modules\rubrication\models; + use common\modules\language\behaviors\LanguageBehavior; use common\modules\product\models\Product; use Yii; use common\components\artboxtree\ArtboxTreeBehavior; + use yii\db\ActiveQuery; use yii\db\ActiveRecord; - + use yii\web\Request; + /** * This is the model class for table "{{%tax_option}}". * @property string $tax_option_id @@ -23,6 +26,24 @@ * @property TaxOption $parent * @property TaxOption[] $taxOptions * @property Product[] $products + * + * * From language behavior * + * @property TaxOptionLang $lang + * @property TaxOptionLang[] $langs + * @property TaxOptionLang $object_lang + * @property string $ownerKey + * @property string $langKey + * @method string getOwnerKey() + * @method void setOwnerKey(string $value) + * @method string getLangKey() + * @method void setLangKey(string $value) + * @method ActiveQuery getLangs() + * @method ActiveQuery getLang( integer $language_id ) + * @method TaxOptionLang[] generateLangs() + * @method void loadLangs(Request $request, ActiveRecord[] $model_langs) + * @method bool linkLangs(ActiveRecord[] $model_langs) + * @method bool saveLangs(ActiveRecord[] $model_langs) + * * End language behavior * */ class TaxOption extends \yii\db\ActiveRecord { @@ -45,7 +66,9 @@ 'out_attribute' => 'alias', 'translit' => true, ], - + 'language' => [ + 'class' => LanguageBehavior::className(), + ], ]; } diff --git a/common/modules/rubrication/models/TaxOptionLang.php b/common/modules/rubrication/models/TaxOptionLang.php new file mode 100644 index 0000000..2199401 --- /dev/null +++ b/common/modules/rubrication/models/TaxOptionLang.php @@ -0,0 +1,78 @@ + 255], + [['tax_option_id', 'language_id'], 'unique', 'targetAttribute' => ['tax_option_id', 'language_id'], 'message' => 'The combination of Tax Option ID and Language ID has already been taken.'], + [['language_id'], 'exist', 'skipOnError' => true, 'targetClass' => Language::className(), 'targetAttribute' => ['language_id' => 'language_id']], + [['tax_option_id'], 'exist', 'skipOnError' => true, 'targetClass' => TaxOption::className(), 'targetAttribute' => ['tax_option_id' => 'tax_option_id']], + ]; + } + + /** + * @inheritdoc + */ + public function attributeLabels() + { + return [ + 'tax_option_id' => Yii::t('app', 'Tax Option ID'), + 'language_id' => Yii::t('app', 'Language ID'), + 'value' => Yii::t('app', 'Value'), + ]; + } + + /** + * @return \yii\db\ActiveQuery + */ + public function getLanguage() + { + return $this->hasOne(Language::className(), ['language_id' => 'language_id']); + } + + /** + * @return \yii\db\ActiveQuery + */ + public function getTaxOption() + { + return $this->hasOne(TaxOption::className(), ['tax_option_id' => 'tax_option_id']); + } +} diff --git a/common/modules/rubrication/models/TaxOptionSearch.php b/common/modules/rubrication/models/TaxOptionSearch.php index fed7996..31d246b 100644 --- a/common/modules/rubrication/models/TaxOptionSearch.php +++ b/common/modules/rubrication/models/TaxOptionSearch.php @@ -10,6 +10,16 @@ use yii\data\ActiveDataProvider; */ class TaxOptionSearch extends TaxOption { + + public function behaviors() + { + $behaviors = parent::behaviors(); + if(isset($behaviors['language'])) { + unset($behaviors['language']); + } + return $behaviors; + } + /** * @inheritdoc */ diff --git a/common/modules/rubrication/views/tax-group/_form.php b/common/modules/rubrication/views/tax-group/_form.php index ebd116a..5b7f20c 100644 --- a/common/modules/rubrication/views/tax-group/_form.php +++ b/common/modules/rubrication/views/tax-group/_form.php @@ -1,44 +1,65 @@
- - ['enctype' => 'multipart/form-data']]); ?> - - field($model, 'name')->textInput(['maxlength' => true]) ?> - - field($model, 'alias')->textInput(['maxlength' => true]) ?> - - field($model, 'description')->textarea(['rows' => 6]) ?> - - field($model, 'categories')->dropDownList( - ArtboxTreeHelper::treeMap(ProductHelper::getCategories(), 'category_id', 'name'), - [ - 'multiple' => true - ] - )->label('Use in the following categories') ?> - field($model, 'is_filter')->checkbox() ?> + [ 'enctype' => 'multipart/form-data' ] ]); ?> + + field($model, 'name') + ->textInput([ 'maxlength' => true ]) ?> + + field($model, 'alias') + ->textInput([ 'maxlength' => true ]) ?> + + field($model, 'description') + ->textarea([ 'rows' => 6 ]) ?> + + field($model, 'categories') + ->dropDownList(ArtboxTreeHelper::treeMap(ProductHelper::getCategories(), 'category_id', 'name'), [ + 'multiple' => true, + ]) + ->label('Use in the following categories') ?> + + field($model, 'is_filter') + ->checkbox() ?> + + field($model, 'display') + ->checkbox() ?> + + field($model, 'is_menu') + ->checkbox() ?> + + field($model, 'sort') + ->textInput() ?> + + $model_langs, + 'formView' => '@common/modules/rubrication/views/tax-group/_form_language', + 'form' => $form, + ]); + ?> - field($model, 'display')->checkbox() ?> - - field($model, 'is_menu')->checkbox() ?> - - field($model, 'sort')->textInput() ?> -
- isNewRecord ? Yii::t('rubrication', 'Create') : Yii::t('rubrication', 'Update'), ['class' => $model->isNewRecord ? 'btn btn-success' : 'btn btn-primary']) ?> + isNewRecord ? Yii::t('rubrication', 'Create') : Yii::t('rubrication', 'Update'), [ 'class' => $model->isNewRecord ? 'btn btn-success' : 'btn btn-primary' ]) ?>
- +
diff --git a/common/modules/rubrication/views/tax-group/_form_language.php b/common/modules/rubrication/views/tax-group/_form_language.php new file mode 100644 index 0000000..00be83b --- /dev/null +++ b/common/modules/rubrication/views/tax-group/_form_language.php @@ -0,0 +1,17 @@ + +field($model_lang, '[' . $language->language_id . ']name') + ->textInput([ 'maxlength' => true ]); ?> +field($model_lang, '[' . $language->language_id . ']description') + ->textarea([ 'rows' => 6 ]) ?> \ No newline at end of file diff --git a/common/modules/rubrication/views/tax-group/create.php b/common/modules/rubrication/views/tax-group/create.php index ddcc890..8b0a309 100644 --- a/common/modules/rubrication/views/tax-group/create.php +++ b/common/modules/rubrication/views/tax-group/create.php @@ -1,21 +1,29 @@ title = Yii::t('rubrication', 'Create Tax Group'); -$this->params['breadcrumbs'][] = ['label' => Yii::t('rubrication', 'Tax Groups'), 'url' => ['index']]; -$this->params['breadcrumbs'][] = $this->title; + + use common\modules\rubrication\models\TaxGroup; + use common\modules\rubrication\models\TaxGroupLang; + use yii\helpers\Html; + use yii\web\View; + + /** + * @var View $this + * @var TaxGroup $model + * @var TaxGroupLang[] $model_langs + */ + $this->title = Yii::t('rubrication', 'Create Tax Group'); + $this->params[ 'breadcrumbs' ][] = [ + 'label' => Yii::t('rubrication', 'Tax Groups'), + 'url' => [ 'index' ], + ]; + $this->params[ 'breadcrumbs' ][] = $this->title; ?>
- +

title) ?>

- + render('_form', [ - 'model' => $model, + 'model' => $model, + 'model_langs' => $model_langs, ]) ?>
diff --git a/common/modules/rubrication/views/tax-group/update.php b/common/modules/rubrication/views/tax-group/update.php index 8414ea0..32e358d 100644 --- a/common/modules/rubrication/views/tax-group/update.php +++ b/common/modules/rubrication/views/tax-group/update.php @@ -1,23 +1,39 @@ title = Yii::t('rubrication', 'Update {modelClass}: ', [ - 'modelClass' => 'Tax Group', -]) . ' ' . $model->name; -$this->params['breadcrumbs'][] = ['label' => Yii::t('rubrication', 'Groups'), 'url' => ['index']]; -$this->params['breadcrumbs'][] = ['label' => $model->name, 'url' => ['view', 'id' => $model->tax_group_id]]; -$this->params['breadcrumbs'][] = Yii::t('rubrication', 'Update'); + + use common\modules\rubrication\models\TaxGroup; + use common\modules\rubrication\models\TaxGroupLang; + use yii\helpers\Html; + use yii\web\View; + + /** + * @var View $this + * @var TaxGroup $model + * @var TaxGroupLang[] $model_langs + */ + + $this->title = Yii::t('rubrication', 'Update {modelClass}: ', [ + 'modelClass' => 'Tax Group', + ]) . ' ' . $model->name; + $this->params[ 'breadcrumbs' ][] = [ + 'label' => Yii::t('rubrication', 'Groups'), + 'url' => [ 'index' ], + ]; + $this->params[ 'breadcrumbs' ][] = [ + 'label' => $model->name, + 'url' => [ + 'view', + 'id' => $model->tax_group_id, + ], + ]; + $this->params[ 'breadcrumbs' ][] = Yii::t('rubrication', 'Update'); ?>
- +

title) ?>

- + render('_form', [ - 'model' => $model, + 'model' => $model, + 'model_langs' => $model_langs, ]) ?>
diff --git a/common/modules/rubrication/views/tax-option/_form.php b/common/modules/rubrication/views/tax-option/_form.php index 805b6d2..306ff19 100644 --- a/common/modules/rubrication/views/tax-option/_form.php +++ b/common/modules/rubrication/views/tax-option/_form.php @@ -1,6 +1,8 @@
- - ['enctype' => 'multipart/form-data']]); ?> - tax_group_id)) :?> - field($model, 'tax_group_id')->dropDownList( - ArrayHelper::map(TaxOption::find()->all(), 'tax_group_id', 'value'), - [ - 'prompt' => Yii::t('rubrication', 'Select group'), - ] - ) ?> - - field($model, 'tax_group_id')->hiddenInput()->label('') ?> - - - - field($model, 'value')->textInput(['maxlength' => true]) ?> - - field($model, 'alias')->textInput(['maxlength' => true]) ?> - - field($model, 'image')->widget(\kartik\file\FileInput::classname(), [ - 'language' => 'ru', - 'options' => [ - 'accept' => 'image/*', - 'multiple' => false, - ], - 'pluginOptions' => [ - 'allowedFileExtensions' => ['jpg', 'gif', 'png'], - 'initialPreview' => !empty($model->imageUrl) ? \common\components\artboximage\ArtboxImageHelper::getImage($model->imageUrl, 'list') : '', - 'overwriteInitial' => true, - 'showRemove' => false, - 'showUpload' => false, - 'previewFileType' => 'image', - ], - ])->hint((($model->tax_group_id == 5)?'Для корректного отображения на сайте, размер изображения должен быть 262x144 либо соблюдать соотношение сторон примерно 2:1':'')); ?> - field($model, 'sort')->dropDownList(RubricationHelper::SortArray()) ?> - + + [ 'enctype' => 'multipart/form-data' ] ]); ?> + tax_group_id )) : ?> + field($model, 'tax_group_id') + ->dropDownList(ArrayHelper::map(TaxOption::find() + ->all(), 'tax_group_id', 'value'), [ + 'prompt' => Yii::t('rubrication', 'Select group'), + ]) ?> + + field($model, 'tax_group_id') + ->hiddenInput() + ->label('') ?> + + + + field($model, 'value') + ->textInput([ 'maxlength' => true ]) ?> + + field($model, 'alias') + ->textInput([ 'maxlength' => true ]) ?> + + field($model, 'image') + ->widget(\kartik\file\FileInput::classname(), [ + 'language' => 'ru', + 'options' => [ + 'accept' => 'image/*', + 'multiple' => false, + ], + 'pluginOptions' => [ + 'allowedFileExtensions' => [ + 'jpg', + 'gif', + 'png', + ], + 'initialPreview' => !empty( $model->imageUrl ) ? \common\components\artboximage\ArtboxImageHelper::getImage($model->imageUrl, 'list') : '', + 'overwriteInitial' => true, + 'showRemove' => false, + 'showUpload' => false, + 'previewFileType' => 'image', + ], + ]) + ->hint(( ( $model->tax_group_id == 5 ) ? 'Для корректного отображения на сайте, размер изображения должен быть 262x144 либо соблюдать соотношение сторон примерно 2:1' : '' )); ?> + field($model, 'sort') + ->dropDownList(RubricationHelper::SortArray()) ?> + + $model_langs, + 'formView' => '@common/modules/rubrication/views/tax-option/_form_language', + 'form' => $form, + ]); + ?> +
- isNewRecord ? Yii::t('rubrication', 'Create') : Yii::t('rubrication', 'Update'), ['class' => $model->isNewRecord ? 'btn btn-success' : 'btn btn-primary']) ?> - isNewRecord) :?> - 'create_and_new', 'class' => 'btn btn-primary']) ?> - + isNewRecord ? Yii::t('rubrication', 'Create') : Yii::t('rubrication', 'Update'), [ 'class' => $model->isNewRecord ? 'btn btn-success' : 'btn btn-primary' ]) ?> + isNewRecord) : ?> + 'create_and_new', + 'class' => 'btn btn-primary', + ]) ?> +
- +
diff --git a/common/modules/rubrication/views/tax-option/_form_language.php b/common/modules/rubrication/views/tax-option/_form_language.php new file mode 100644 index 0000000..1472fb3 --- /dev/null +++ b/common/modules/rubrication/views/tax-option/_form_language.php @@ -0,0 +1,15 @@ + +field($model_lang, '[' . $language->language_id . ']value') + ->textInput([ 'maxlength' => true ]); ?> \ No newline at end of file diff --git a/common/modules/rubrication/views/tax-option/create.php b/common/modules/rubrication/views/tax-option/create.php index ac61968..297654d 100644 --- a/common/modules/rubrication/views/tax-option/create.php +++ b/common/modules/rubrication/views/tax-option/create.php @@ -1,14 +1,15 @@ title = Yii::t('rubrication', 'Create Tax Option'); $this->params[ 'breadcrumbs' ][] = [ 'label' => Yii::t('rubrication', 'Groups'), @@ -35,8 +36,9 @@

title) ?>

render('_form', [ - 'model' => $model, - 'group' => $group, + 'model' => $model, + 'model_langs' => $model_langs, + 'group' => $group, ]) ?>
diff --git a/common/modules/rubrication/views/tax-option/update.php b/common/modules/rubrication/views/tax-option/update.php index b115adb..148060a 100644 --- a/common/modules/rubrication/views/tax-option/update.php +++ b/common/modules/rubrication/views/tax-option/update.php @@ -1,25 +1,46 @@ title = Yii::t('rubrication', 'Update {modelClass}: ', [ - 'modelClass' => 'Tax Option', -]) . ' ' . $model->tax_option_id; -$this->params['breadcrumbs'][] = ['label' => Yii::t('rubrication', 'Groups'), 'url' => ['tax-group/index']]; -$this->params['breadcrumbs'][] = ['label' => $group->name, 'url' => ['view', 'id' => $group->tax_group_id]]; -$this->params['breadcrumbs'][] = ['label' => Yii::t('rubrication', Yii::t('rubrication', 'Options of {name}', ['name' => $group->name])), 'url' => ['index', 'group' => $group->tax_group_id]]; -$this->params['breadcrumbs'][] = Yii::t('rubrication', 'Update'); + + use common\modules\rubrication\models\TaxGroup; + use common\modules\rubrication\models\TaxOptionLang; + use yii\helpers\Html; + + /** + * @var yii\web\View $this + * @var common\modules\rubrication\models\TaxOption $model + * @var TaxGroup $group + * @var TaxOptionLang[] $model_langs + */ + $this->title = Yii::t('rubrication', 'Update {modelClass}: ', [ + 'modelClass' => 'Tax Option', + ]) . ' ' . $model->tax_option_id; + $this->params[ 'breadcrumbs' ][] = [ + 'label' => Yii::t('rubrication', 'Groups'), + 'url' => [ 'tax-group/index' ], + ]; + $this->params[ 'breadcrumbs' ][] = [ + 'label' => $group->name, + 'url' => [ + 'view', + 'id' => $group->tax_group_id, + ], + ]; + $this->params[ 'breadcrumbs' ][] = [ + 'label' => Yii::t('rubrication', Yii::t('rubrication', 'Options of {name}', [ 'name' => $group->name ])), + 'url' => [ + 'index', + 'group' => $group->tax_group_id, + ], + ]; + $this->params[ 'breadcrumbs' ][] = Yii::t('rubrication', 'Update'); ?>
- +

title) ?>

- + render('_form', [ - 'model' => $model, - 'group' => $group + 'model' => $model, + 'model_langs' => $model_langs, + 'group' => $group, ]) ?>
diff --git a/console/migrations/m160926_122456_create_articles_lang_table.php b/console/migrations/m160926_122456_create_articles_lang_table.php new file mode 100644 index 0000000..7630b40 --- /dev/null +++ b/console/migrations/m160926_122456_create_articles_lang_table.php @@ -0,0 +1,49 @@ +createTable('articles_lang', [ + 'articles_id' => $this->integer() + ->notNull(), + 'language_id' => $this->integer() + ->notNull(), + 'title' => $this->string() + ->notNull(), + 'body' => $this->text() + ->notNull(), + 'meta_title' => $this->string(), + 'meta_keywords' => $this->string(), + 'meta_description' => $this->string(), + 'seo_text' => $this->text(), + 'h1' => $this->string(), + 'body_preview' => $this->text(), + ]); + + $this->createIndex('articles_lang_article_language_key', 'articles_lang', [ + 'articles_id', + 'language_id', + ], true); + + $this->addForeignKey('articles_fk', 'articles_lang', 'articles_id', 'articles', 'id', 'CASCADE', 'CASCADE'); + $this->addForeignKey('language_fk', 'articles_lang', 'language_id', 'language', 'language_id', 'RESTRICT', 'CASCADE'); + } + + /** + * @inheritdoc + */ + public function down() + { + $this->dropTable('articles_lang'); + } + } diff --git a/console/migrations/m160928_100918_create_page_lang_table.php b/console/migrations/m160928_100918_create_page_lang_table.php new file mode 100644 index 0000000..8e5e91f --- /dev/null +++ b/console/migrations/m160928_100918_create_page_lang_table.php @@ -0,0 +1,47 @@ +createTable('page_lang', [ + 'page_id' => $this->integer() + ->notNull(), + 'language_id' => $this->integer() + ->notNull(), + 'title' => $this->string() + ->notNull(), + 'body' => $this->text() + ->notNull(), + 'meta_title' => $this->string(), + 'meta_keywords' => $this->string(), + 'meta_description' => $this->string(), + 'seo_text' => $this->text(), + 'h1' => $this->string(), + ]); + + $this->createIndex('page_lang_page_language_key', 'page_lang', [ + 'page_id', + 'language_id', + ], true); + + $this->addForeignKey('page_fk', 'page_lang', 'page_id', 'page', 'id', 'CASCADE', 'CASCADE'); + $this->addForeignKey('language_fk', 'page_lang', 'language_id', 'language', 'language_id', 'RESTRICT', 'CASCADE'); + } + + /** + * @inheritdoc + */ + public function down() + { + $this->dropTable('page_lang'); + } +} diff --git a/console/migrations/m160928_104529_create_banner_lang_table.php b/console/migrations/m160928_104529_create_banner_lang_table.php new file mode 100644 index 0000000..4dc16aa --- /dev/null +++ b/console/migrations/m160928_104529_create_banner_lang_table.php @@ -0,0 +1,41 @@ +createTable('banner_lang', [ + 'banner_id' => $this->integer() + ->notNull(), + 'language_id' => $this->integer() + ->notNull(), + 'alt' => $this->string(), + 'title' => $this->string(), + ]); + + $this->createIndex('banner_lang_banner_language_key', 'banner_lang', [ + 'banner_id', + 'language_id', + ], true); + + $this->addForeignKey('banner_fk', 'banner_lang', 'banner_id', 'banner', 'banner_id', 'CASCADE', 'CASCADE'); + $this->addForeignKey('language_fk', 'banner_lang', 'language_id', 'language', 'language_id', 'RESTRICT', 'CASCADE'); + } + + /** + * @inheritdoc + */ + public function down() + { + $this->dropTable('banner_lang'); + } + } diff --git a/console/migrations/m160928_112124_create_bg_lang_table.php b/console/migrations/m160928_112124_create_bg_lang_table.php new file mode 100644 index 0000000..388af18 --- /dev/null +++ b/console/migrations/m160928_112124_create_bg_lang_table.php @@ -0,0 +1,39 @@ +createTable('bg_lang', [ + 'bg_id' => $this->integer() + ->notNull(), + 'language_id' => $this->integer() + ->notNull(), + 'title' => $this->string()->notNull(), + ]); + + $this->createIndex('bg_lang_bg_language_key', 'bg_lang', [ + 'bg_id', + 'language_id', + ], true); + + $this->addForeignKey('bg_fk', 'bg_lang', 'bg_id', 'bg', 'id', 'CASCADE', 'CASCADE'); + $this->addForeignKey('language_fk', 'bg_lang', 'language_id', 'language', 'language_id', 'RESTRICT', 'CASCADE'); + } + + /** + * @inheritdoc + */ + public function down() + { + $this->dropTable('bg_lang'); + } +} diff --git a/console/migrations/m160928_122509_create_brand_lang_table.php b/console/migrations/m160928_122509_create_brand_lang_table.php new file mode 100644 index 0000000..6f6b22b --- /dev/null +++ b/console/migrations/m160928_122509_create_brand_lang_table.php @@ -0,0 +1,45 @@ +createTable('brand_lang', [ + 'brand_id' => $this->integer() + ->notNull(), + 'language_id' => $this->integer() + ->notNull(), + 'name' => $this->string() + ->notNull(), + 'meta_title' => $this->string(), + 'meta_robots' => $this->string(), + 'meta_desc' => $this->string(), + 'seo_text' => $this->text(), + ]); + + $this->createIndex('brand_lang_brand_language_key', 'brand_lang', [ + 'brand_id', + 'language_id', + ], true); + + $this->addForeignKey('brand_fk', 'brand_lang', 'brand_id', 'brand', 'brand_id', 'CASCADE', 'CASCADE'); + $this->addForeignKey('language_fk', 'brand_lang', 'language_id', 'language', 'language_id', 'RESTRICT', 'CASCADE'); + } + + /** + * @inheritdoc + */ + public function down() + { + $this->dropTable('brand_lang'); + } + } diff --git a/console/migrations/m160928_133403_create_category_lang_table.php b/console/migrations/m160928_133403_create_category_lang_table.php new file mode 100644 index 0000000..7a9ac1d --- /dev/null +++ b/console/migrations/m160928_133403_create_category_lang_table.php @@ -0,0 +1,44 @@ +createTable('category_lang', [ + 'category_id' => $this->integer() + ->notNull(), + 'language_id' => $this->integer() + ->notNull(), + 'name' => $this->string() + ->notNull(), + 'meta_title' => $this->string(), + 'meta_robots' => $this->string(), + 'meta_desc' => $this->string(), + 'seo_text' => $this->text(), + 'h1' => $this->string(), + ]); + $this->createIndex('category_lang_category_language_key', 'category_lang', [ + 'category_id', + 'language_id', + ], true); + + $this->addForeignKey('category_fk', 'category_lang', 'category_id', 'category', 'category_id', 'CASCADE', 'CASCADE'); + $this->addForeignKey('language_fk', 'category_lang', 'language_id', 'language', 'language_id', 'RESTRICT', 'CASCADE'); + } + + /** + * @inheritdoc + */ + public function down() + { + $this->dropTable('category_lang'); + } +} diff --git a/console/migrations/m160928_161047_create_event_lang_table.php b/console/migrations/m160928_161047_create_event_lang_table.php new file mode 100644 index 0000000..76f54f5 --- /dev/null +++ b/console/migrations/m160928_161047_create_event_lang_table.php @@ -0,0 +1,45 @@ +createTable('event_lang', [ + 'event_id' => $this->integer() + ->notNull(), + 'language_id' => $this->integer() + ->notNull(), + 'name' => $this->string() + ->notNull(), + 'body' => $this->text() + ->notNull(), + 'meta_title' => $this->string(), + 'description' => $this->string(), + 'seo_text' => $this->text(), + 'h1' => $this->string(), + ]); + $this->createIndex('event_lang_event_language_key', 'event_lang', [ + 'event_id', + 'language_id', + ], true); + + $this->addForeignKey('event_fk', 'event_lang', 'event_id', 'event', 'event_id', 'CASCADE', 'CASCADE'); + $this->addForeignKey('language_fk', 'event_lang', 'language_id', 'language', 'language_id', 'RESTRICT', 'CASCADE'); + } + + /** + * @inheritdoc + */ + public function down() + { + $this->dropTable('event_lang'); + } +} diff --git a/console/migrations/m160929_135920_create_orders_delivery_lang_table.php b/console/migrations/m160929_135920_create_orders_delivery_lang_table.php new file mode 100644 index 0000000..1422852 --- /dev/null +++ b/console/migrations/m160929_135920_create_orders_delivery_lang_table.php @@ -0,0 +1,42 @@ +createTable('orders_delivery_lang', [ + 'orders_delivery_id' => $this->integer() + ->notNull(), + 'language_id' => $this->integer() + ->notNull(), + 'title' => $this->string() + ->notNull(), + 'text' => $this->text() + ->notNull(), + ]); + $this->createIndex('orders_delivery_lang_orders_delivery_language_key', 'orders_delivery_lang', [ + 'orders_delivery_id', + 'language_id', + ], true); + + $this->addForeignKey('orders_delivery_fk', 'orders_delivery_lang', 'orders_delivery_id', 'orders_delivery', 'id', 'CASCADE', 'CASCADE'); + $this->addForeignKey('language_fk', 'orders_delivery_lang', 'language_id', 'language', 'language_id', 'RESTRICT', 'CASCADE'); + } + + /** + * @inheritdoc + */ + public function down() + { + $this->dropTable('orders_delivery'); + } + } diff --git a/console/migrations/m160929_142458_create_orders_label_lang_table.php b/console/migrations/m160929_142458_create_orders_label_lang_table.php new file mode 100644 index 0000000..754d294 --- /dev/null +++ b/console/migrations/m160929_142458_create_orders_label_lang_table.php @@ -0,0 +1,40 @@ +createTable('orders_label_lang', [ + 'orders_label_id' => $this->integer() + ->notNull(), + 'language_id' => $this->integer() + ->notNull(), + 'name' => $this->string() + ->notNull(), + ]); + $this->createIndex('orders_label_lang_orders_label_language_key', 'orders_label_lang', [ + 'orders_label_id', + 'language_id', + ], true); + + $this->addForeignKey('orders_label_fk', 'orders_label_lang', 'orders_label_id', 'orders_label', 'id', 'CASCADE', 'CASCADE'); + $this->addForeignKey('language_fk', 'orders_label_lang', 'language_id', 'language', 'language_id', 'RESTRICT', 'CASCADE'); + } + + /** + * @inheritdoc + */ + public function down() + { + $this->dropTable('orders_label_lang'); + } + } diff --git a/console/migrations/m160929_144357_create_product_lang_table.php b/console/migrations/m160929_144357_create_product_lang_table.php new file mode 100644 index 0000000..7d87855 --- /dev/null +++ b/console/migrations/m160929_144357_create_product_lang_table.php @@ -0,0 +1,40 @@ +createTable('product_lang', [ + 'product_id' => $this->integer() + ->notNull(), + 'language_id' => $this->integer() + ->notNull(), + 'name' => $this->string() + ->notNull(), + 'description' => $this->text(), + ]); + $this->createIndex('product_lang_product_language_key', 'product_lang', [ + 'product_id', + 'language_id', + ], true); + + $this->addForeignKey('product_fk', 'product_lang', 'product_id', 'product', 'product_id', 'CASCADE', 'CASCADE'); + $this->addForeignKey('language_fk', 'product_lang', 'language_id', 'language', 'language_id', 'RESTRICT', 'CASCADE'); + } + + /** + * @inheritdoc + */ + public function down() + { + $this->dropTable('product_lang'); + } +} diff --git a/console/migrations/m160929_155222_create_product_spec_lang_table.php b/console/migrations/m160929_155222_create_product_spec_lang_table.php new file mode 100644 index 0000000..9005842 --- /dev/null +++ b/console/migrations/m160929_155222_create_product_spec_lang_table.php @@ -0,0 +1,40 @@ +createTable('product_spec_lang', [ + 'product_spec_id' => $this->integer() + ->notNull(), + 'language_id' => $this->integer() + ->notNull(), + 'tech_spec_text' => $this->text(), + 'instruction' => $this->text(), + ]); + $this->createIndex('product_spec_lang_product_spec_language_key', 'product_spec_lang', [ + 'product_spec_id', + 'language_id', + ], true); + + $this->addForeignKey('product_spec_fk', 'product_spec_lang', 'product_spec_id', 'product_spec', 'product_spec_id', 'CASCADE', 'CASCADE'); + $this->addForeignKey('language_fk', 'product_spec_lang', 'language_id', 'language', 'language_id', 'RESTRICT', 'CASCADE'); + } + + /** + * @inheritdoc + */ + public function down() + { + $this->dropTable('product_spec_lang'); + } + } diff --git a/console/migrations/m160929_173535_create_product_unit_lang_table.php b/console/migrations/m160929_173535_create_product_unit_lang_table.php new file mode 100644 index 0000000..e1707fa --- /dev/null +++ b/console/migrations/m160929_173535_create_product_unit_lang_table.php @@ -0,0 +1,42 @@ +createTable('product_unit_lang', [ + 'product_unit_id' => $this->integer() + ->notNull(), + 'language_id' => $this->integer() + ->notNull(), + 'name' => $this->string() + ->notNull(), + 'short' => $this->string(), + ]); + + $this->createIndex('product_unit_lang_product_unit_language_key', 'product_unit_lang', [ + 'product_unit_id', + 'language_id', + ], true); + + $this->addForeignKey('product_unit_fk', 'product_unit_lang', 'product_unit_id', 'product_unit', 'product_unit_id', 'CASCADE', 'CASCADE'); + $this->addForeignKey('language_fk', 'product_unit_lang', 'language_id', 'language', 'language_id', 'RESTRICT', 'CASCADE'); + } + + /** + * @inheritdoc + */ + public function down() + { + $this->dropTable('product_unit_lang'); + } + } diff --git a/console/migrations/m160929_175821_create_product_variant_lang_table.php b/console/migrations/m160929_175821_create_product_variant_lang_table.php new file mode 100644 index 0000000..36e78c2 --- /dev/null +++ b/console/migrations/m160929_175821_create_product_variant_lang_table.php @@ -0,0 +1,40 @@ +createTable('product_variant_lang', [ + 'product_variant_id' => $this->integer() + ->notNull(), + 'language_id' => $this->integer() + ->notNull(), + 'name' => $this->string() + ->notNull(), + ]); + $this->createIndex('product_variant_lang_product_variant_language_key', 'product_variant_lang', [ + 'product_variant_id', + 'language_id', + ], true); + + $this->addForeignKey('product_variant_fk', 'product_variant_lang', 'product_variant_id', 'product_variant', 'product_variant_id', 'CASCADE', 'CASCADE'); + $this->addForeignKey('language_fk', 'product_variant_lang', 'language_id', 'language', 'language_id', 'RESTRICT', 'CASCADE'); + } + + /** + * @inheritdoc + */ + public function down() + { + $this->dropTable('product_variant_lang'); + } + } diff --git a/console/migrations/m160930_082350_create_project_lang_table.php b/console/migrations/m160930_082350_create_project_lang_table.php new file mode 100644 index 0000000..447dec1 --- /dev/null +++ b/console/migrations/m160930_082350_create_project_lang_table.php @@ -0,0 +1,41 @@ +createTable('project_lang', [ + 'project_id' => $this->integer() + ->notNull(), + 'language_id' => $this->integer() + ->notNull(), + 'title' => $this->string() + ->notNull(), + 'description' => $this->text(), + ]); + $this->createIndex('project_lang_project_language_key', 'project_lang', [ + 'project_id', + 'language_id', + ], true); + + $this->addForeignKey('project_fk', 'project_lang', 'project_id', 'project', 'project_id', 'CASCADE', 'CASCADE'); + $this->addForeignKey('language_fk', 'project_lang', 'language_id', 'language', 'language_id', 'RESTRICT', 'CASCADE'); + } + + /** + * @inheritdoc + */ + public function down() + { + $this->dropTable('project_lang'); + } + } diff --git a/console/migrations/m160930_100954_create_seo_lang_table.php b/console/migrations/m160930_100954_create_seo_lang_table.php new file mode 100644 index 0000000..2dd6843 --- /dev/null +++ b/console/migrations/m160930_100954_create_seo_lang_table.php @@ -0,0 +1,79 @@ +createTable('seo_lang', [ + 'seo_id' => $this->integer() + ->notNull(), + 'language_id' => $this->integer() + ->notNull(), + 'title' => $this->string(), + 'description' => $this->text(), + 'h1' => $this->string(), + 'meta' => $this->string(), + 'seo_text' => $this->text(), + ]); + $this->createIndex('seo_lang_seo_language_key', 'seo_lang', [ + 'seo_id', + 'language_id', + ], true); + + $this->addForeignKey('seo_fk', 'seo_lang', 'seo_id', 'seo', 'seo_id', 'CASCADE', 'CASCADE'); + $this->addForeignKey('language_fk', 'seo_lang', 'language_id', 'language', 'language_id', 'RESTRICT', 'CASCADE'); + $this->createTable('seo_category_lang', [ + 'seo_category_id' => $this->integer() + ->notNull(), + 'language_id' => $this->integer() + ->notNull(), + 'name' => $this->string(), + ]); + $this->createIndex('seo_category_lang_seo_category_language_key', 'seo_category_lang', [ + 'seo_category_id', + 'language_id', + ], true); + + $this->addForeignKey('seo_category_fk', 'seo_category_lang', 'seo_category_id', 'seo_category', 'seo_category_id', 'CASCADE', 'CASCADE'); + $this->addForeignKey('language_fk', 'seo_category_lang', 'language_id', 'language', 'language_id', 'RESTRICT', 'CASCADE'); + $this->createTable('seo_dynamic_lang', [ + 'seo_dynamic_id' => $this->integer() + ->notNull(), + 'language_id' => $this->integer() + ->notNull(), + 'name' => $this->string(), + 'title' => $this->text(), + 'h1' => $this->string(), + 'key' => $this->string(), + 'meta' => $this->string(), + 'description' => $this->text(), + 'seo_text' => $this->text(), + ]); + $this->createIndex('seo_dynamic_lang_seo_dynamic_language_key', 'seo_dynamic_lang', [ + 'seo_dynamic_id', + 'language_id', + ], true); + + $this->addForeignKey('seo_dynamic_fk', 'seo_dynamic_lang', 'seo_dynamic_id', 'seo_dynamic', 'seo_dynamic_id', 'CASCADE', 'CASCADE'); + $this->addForeignKey('language_fk', 'seo_dynamic_lang', 'language_id', 'language', 'language_id', 'RESTRICT', 'CASCADE'); + } + + /** + * @inheritdoc + */ + public function down() + { + $this->dropTable('seo_lang'); + $this->dropTable('seo_category_lang'); + $this->dropTable('seo_dynamic_lang'); + } + } diff --git a/console/migrations/m160930_133757_create_service_lang_table.php b/console/migrations/m160930_133757_create_service_lang_table.php new file mode 100644 index 0000000..e285a9a --- /dev/null +++ b/console/migrations/m160930_133757_create_service_lang_table.php @@ -0,0 +1,46 @@ +createTable('service_lang', [ + 'service_id' => $this->integer() + ->notNull(), + 'language_id' => $this->integer() + ->notNull(), + 'name' => $this->string() + ->notNull(), + 'body' => $this->text() + ->notNull(), + 'seo_text' => $this->text(), + 'meta_title' => $this->string(), + 'description' => $this->string(), + 'h1' => $this->string(), + ]); + $this->createIndex('service_lang_service_language_key', 'service_lang', [ + 'service_id', + 'language_id', + ], true); + + $this->addForeignKey('service_fk', 'service_lang', 'service_id', 'service', 'service_id', 'CASCADE', 'CASCADE'); + $this->addForeignKey('language_fk', 'service_lang', 'language_id', 'language', 'language_id', 'RESTRICT', 'CASCADE'); + } + + /** + * @inheritdoc + */ + public function down() + { + $this->dropTable('service_lang'); + } + } diff --git a/console/migrations/m160930_142752_create_slider_image_lang_table.php b/console/migrations/m160930_142752_create_slider_image_lang_table.php new file mode 100644 index 0000000..04c7e17 --- /dev/null +++ b/console/migrations/m160930_142752_create_slider_image_lang_table.php @@ -0,0 +1,40 @@ +createTable('slider_image_lang', [ + 'slider_image_id' => $this->integer() + ->notNull(), + 'language_id' => $this->integer() + ->notNull(), + 'title' => $this->string(), + 'alt' => $this->string(), + ]); + $this->createIndex('slider_image_lang_slider_image_language_key', 'slider_image_lang', [ + 'slider_image_id', + 'language_id', + ], true); + + $this->addForeignKey('slider_image_fk', 'slider_image_lang', 'slider_image_id', 'slider_image', 'slider_image_id', 'CASCADE', 'CASCADE'); + $this->addForeignKey('language_fk', 'slider_image_lang', 'language_id', 'language', 'language_id', 'RESTRICT', 'CASCADE'); + } + + /** + * @inheritdoc + */ + public function down() + { + $this->dropTable('slider_image_lang'); + } + } diff --git a/console/migrations/m160930_145734_create_tax_group_lang_table.php b/console/migrations/m160930_145734_create_tax_group_lang_table.php new file mode 100644 index 0000000..ee9d54d --- /dev/null +++ b/console/migrations/m160930_145734_create_tax_group_lang_table.php @@ -0,0 +1,41 @@ +createTable('tax_group_lang', [ + 'tax_group_id' => $this->integer() + ->notNull(), + 'language_id' => $this->integer() + ->notNull(), + 'name' => $this->string() + ->notNull(), + 'description' => $this->text(), + ]); + $this->createIndex('tax_group_lang_tax_group_language_key', 'tax_group_lang', [ + 'tax_group_id', + 'language_id', + ], true); + + $this->addForeignKey('tax_group_fk', 'tax_group_lang', 'tax_group_id', 'tax_group', 'tax_group_id', 'CASCADE', 'CASCADE'); + $this->addForeignKey('language_fk', 'tax_group_lang', 'language_id', 'language', 'language_id', 'RESTRICT', 'CASCADE'); + } + + /** + * @inheritdoc + */ + public function down() + { + $this->dropTable('tax_group_lang'); + } + } diff --git a/console/migrations/m160930_151832_create_tax_option_lang_table.php b/console/migrations/m160930_151832_create_tax_option_lang_table.php new file mode 100644 index 0000000..7d9e0ad --- /dev/null +++ b/console/migrations/m160930_151832_create_tax_option_lang_table.php @@ -0,0 +1,39 @@ +createTable('tax_option_lang', [ + 'tax_option_id' => $this->integer() + ->notNull(), + 'language_id' => $this->integer() + ->notNull(), + 'value' => $this->string() + ->notNull(), + ]); + $this->createIndex('tax_option_lang_tax_option_language_key', 'tax_option_lang', [ + 'tax_option_id', + 'language_id', + ], true); + + $this->addForeignKey('tax_option_fk', 'tax_option_lang', 'tax_option_id', 'tax_option', 'tax_option_id', 'CASCADE', 'CASCADE'); + $this->addForeignKey('language_fk', 'tax_option_lang', 'language_id', 'language', 'language_id', 'RESTRICT', 'CASCADE'); + } + + /** + * @inheritdoc + */ + public function down() + { + $this->dropTable('tax_option_lang'); + } +} diff --git a/frontend/controllers/ArticleController.php b/frontend/controllers/ArticleController.php index 82a3af4..5b82f99 100755 --- a/frontend/controllers/ArticleController.php +++ b/frontend/controllers/ArticleController.php @@ -6,7 +6,7 @@ use common\models\ArticlesSearch; use yii\web\Controller; use yii\web\NotFoundHttpException; - + /** * Article controller */ @@ -21,7 +21,8 @@ { $searchModel = new ArticlesSearch(); $dataProvider = $searchModel->search(\Yii::$app->request->queryParams); - $dataProvider->query->orderBy(['date' => SORT_DESC]); + $dataProvider->query->orderBy([ 'date' => SORT_DESC ]) + ->joinWith('lang', true, 'INNER JOIN'); $dataProvider->pagination = [ 'pageSize' => 10, ]; @@ -44,9 +45,13 @@ ]); } - private function findModel($id) { - $model = Articles::findOne($id); - if(!empty($model)) { + private function findModel($id) + { + $model = Articles::find() + ->where([ 'articles_id' => $id ]) + ->joinWith('lang', true, 'INNER JOIN') + ->one(); + if(!empty( $model )) { return $model; } else { throw new NotFoundHttpException(); diff --git a/frontend/controllers/CollectionController.php b/frontend/controllers/CollectionController.php index ab178eb..a704631 100755 --- a/frontend/controllers/CollectionController.php +++ b/frontend/controllers/CollectionController.php @@ -42,6 +42,7 @@ $variant = $variants[ $variant_id ]; $projects = Project::find() ->joinWith('productToProject') + ->joinWith('lang', true, 'INNER JOIN') ->with('image') ->where([ 'product_to_project.product_variant_id' => $variant->product_variant_id ]) ->all(); @@ -62,10 +63,12 @@ private function findCollection($id, $variant_id = NULL) { $model = Product::find() - ->joinWith('variants', true, 'INNER JOIN') - ->with('productSpec') + ->joinWith('variants.lang', true, 'INNER JOIN') + ->joinWith('lang', true, 'INNER JOIN') + ->joinWith('brand.lang', true, 'INNER JOIN') + ->with('productSpec.lang') ->where([ 'product.product_id' => $id ]) - ->andFilterWhere([ 'product_variant_id' => $variant_id ]) + ->andFilterWhere([ 'product_variant.product_variant_id' => $variant_id ]) ->one(); if(empty( $model )) { throw new NotFoundHttpException(); diff --git a/frontend/controllers/FilterController.php b/frontend/controllers/FilterController.php index 24f4182..04ce4c3 100755 --- a/frontend/controllers/FilterController.php +++ b/frontend/controllers/FilterController.php @@ -20,9 +20,10 @@ $category = $this->findCategory($category_id); $purpose = $this->findPurpose($purpose_id); $brands = Brand::find() - ->joinWith('products') - ->joinWith('products.categories') - ->joinWith('products.options') + ->joinWith('lang', true, 'INNER JOIN') + ->joinWith('products.lang') + ->joinWith('products.categories.lang') + ->joinWith('products.options.lang') ->where([ 'category.category_id' => $category->category_id, 'tax_option.tax_option_id' => $purpose->tax_option_id, @@ -43,9 +44,10 @@ { $category = $this->findCategory($id); $purposes = TaxOption::find() - ->joinWith('products') - ->joinWith('products.categories') - ->joinWith('products.brand') + ->joinWith('lang', true, 'INNER JOIN') + ->joinWith('products.lang') + ->joinWith('products.categories.lang') + ->joinWith('products.brand.lang') ->joinWith('taxGroup') ->where([ 'category.category_id' => $category->category_id, @@ -83,10 +85,10 @@ { $purpose = $this->findPurpose($id); $categories = Category::find() - ->joinWith('products') - ->joinWith('products.brand') - ->joinWith('products.options') - ->where([ 'tax_option_id' => $purpose->tax_option_id ]) + ->joinWith('products.lang') + ->joinWith('products.brand.lang') + ->joinWith('products.options.lang') + ->where([ 'tax_option.tax_option_id' => $purpose->tax_option_id ]) ->all(); $brands = []; foreach($categories as $category) { @@ -117,10 +119,11 @@ $dataProvider = $searchModel->search(\Yii::$app->request->queryParams); $dataProvider->pagination = false; $query = $dataProvider->query; - $query->with('variants') - ->joinWith('brand') - ->joinWith('options') - ->joinWith('categories') + $query->with('variants.lang') + ->joinWith('lang', true, 'INNER JOIN') + ->joinWith('brand.lang') + ->joinWith('options.lang') + ->joinWith('categories.lang') ->andWhere([ 'category.category_id' => $category->category_id, 'tax_option.tax_option_id' => $purpose->tax_option_id, @@ -146,9 +149,10 @@ $model = TaxOption::find() ->joinWith('taxGroup') ->where([ - 'tax_option_id' => $id, - 'tax_group.alias' => 'purpose', + 'tax_option.tax_option_id' => $id, + 'tax_group.alias' => 'purpose', ]) + ->joinWith('lang', true, 'INNER JOIN') ->one(); if(empty( $model )) { throw new NotFoundHttpException(); @@ -166,8 +170,9 @@ { $model = Category::find() ->where([ - 'category_id' => $id, + 'category.category_id' => $id, ]) + ->joinWith('lang', true, 'INNER JOIN') ->one(); if(empty( $model )) { throw new NotFoundHttpException(); @@ -188,8 +193,9 @@ */ $model = Brand::find() ->where([ - 'brand_id' => $id, + 'brand.brand_id' => $id, ]) + ->joinWith('lang', true, 'INNER JOIN') ->one(); if(empty( $model )) { throw new NotFoundHttpException(); diff --git a/frontend/controllers/OrderController.php b/frontend/controllers/OrderController.php index 7dc1b98..9e3a421 100644 --- a/frontend/controllers/OrderController.php +++ b/frontend/controllers/OrderController.php @@ -9,22 +9,22 @@ use common\modules\product\models\ProductVariant; use yii\filters\VerbFilter; use yii\web\BadRequestHttpException; - + class OrderController extends \yii\web\Controller { public $enableCsrfValidation = false; - + public function behaviors() { return [ 'verbs' => [ 'class' => VerbFilter::className(), 'actions' => [ - 'make' => [ 'post' ], + 'make' => [ 'post' ], ], ], - 'ajax' => [ + 'ajax' => [ 'class' => AjaxFilter::className(), ], ]; @@ -44,13 +44,17 @@ if($order->load($post) && $order->save()) { if(!empty( $basket_items )) { foreach($basket_items as $basket_item) { - $product = ProductVariant::findOne($basket_item); + $product = ProductVariant::find() + ->where([ 'product_variant.product_variant_id' => $basket_item ]) + ->joinWith('lang', true, 'INNER JOIN') + ->joinWith('product.lang', true, 'INNER JOIN') + ->one(); if(!empty( $product )) { $orderProduct = new OrdersProducts([ 'order_id' => $order->id, - 'product_name' => $product->product->name, + 'product_name' => $product->product->lang->name, 'mod_id' => $product->product_variant_id, - 'name' => $product->name, + 'name' => $product->lang->name, 'sku' => $product->sku, 'count' => 1, ]); diff --git a/frontend/controllers/ProjectController.php b/frontend/controllers/ProjectController.php index 2978cfa..d9efee0 100755 --- a/frontend/controllers/ProjectController.php +++ b/frontend/controllers/ProjectController.php @@ -24,7 +24,7 @@ $dataProvider->pagination = [ 'pageSize' => 10, ]; - $dataProvider->query->with('images'); + $dataProvider->query->with('images')->joinWith('lang', true, 'INNER JOIN'); return $this->render('index', [ 'searchModel' => $searchModel, 'dataProvider' => $dataProvider, @@ -41,7 +41,10 @@ private function findModel($id) { - $model = Project::findOne($id); + $model = Project::find() + ->where([ 'project.project_id' => $id ]) + ->joinWith('lang', true, 'INNER JOIN') + ->one(); if(empty( $model )) { throw new NotFoundHttpException(); } diff --git a/frontend/controllers/SearchController.php b/frontend/controllers/SearchController.php index 3866d08..22f4b29 100755 --- a/frontend/controllers/SearchController.php +++ b/frontend/controllers/SearchController.php @@ -23,21 +23,22 @@ return $this->redirect([ 'site/index' ]); } $query = Product::find() - ->joinWith('variants', true, 'INNER JOIN') - ->joinWith('brand') + ->joinWith('lang', true, 'INNER JOIN') + ->joinWith('variants.lang', true, 'INNER JOIN') + ->joinWith('brand.lang', true, 'INNER JOIN') ->where([ 'ilike', - 'product.name', + 'product_lang.name', $search, ]) ->orWhere([ 'ilike', - 'brand.name', + 'brand_lang.name', $search, ]) ->orWhere([ 'ilike', - 'product_variant.name', + 'product_variant_lang.name', $search, ]); $dataProvider = new ActiveDataProvider([ diff --git a/frontend/controllers/SiteController.php b/frontend/controllers/SiteController.php index 73b6de9..74293a0 100755 --- a/frontend/controllers/SiteController.php +++ b/frontend/controllers/SiteController.php @@ -84,29 +84,31 @@ { $categories = Category::find() ->where([ 'depth' => 0 ]) + ->joinWith('lang', true, 'INNER JOIN') ->all(); $purposes = TaxGroup::find() ->where([ - 'alias' => 'purpose', + 'tax_group.alias' => 'purpose', 'level' => 0, ]) - ->with('options') + ->joinWith('options.lang') ->one(); $banners = Banner::find() ->where([ - 'banner_id' => [ + 'banner.banner_id' => [ 3, 4, ], 'status' => 1, ]) + ->joinWith('lang', true, 'INNER JOIN') ->all(); $slider = Slider::find() ->where([ - 'slider_id' => 2, - 'status' => 1, + 'slider.slider_id' => 2, + 'slider.status' => 1, ]) - ->with('sliderImage') + ->joinWith('sliderImage.lang') ->one(); return $this->render('index', [ 'categories' => $categories, @@ -120,32 +122,32 @@ * Logs in a user. * @return mixed */ -// public function actionLogin() -// { -// if(!Yii::$app->user->isGuest) { -// return $this->goHome(); -// } -// -// $model = new LoginForm(); -// if($model->load(Yii::$app->request->post()) && $model->login()) { -// return $this->goBack(); -// } else { -// return $this->render('login', [ -// 'model' => $model, -// ]); -// } -// } + // public function actionLogin() + // { + // if(!Yii::$app->user->isGuest) { + // return $this->goHome(); + // } + // + // $model = new LoginForm(); + // if($model->load(Yii::$app->request->post()) && $model->login()) { + // return $this->goBack(); + // } else { + // return $this->render('login', [ + // 'model' => $model, + // ]); + // } + // } /** * Logs out the current user. * @return mixed */ -// public function actionLogout() -// { -// Yii::$app->user->logout(); -// -// return $this->goHome(); -// } + // public function actionLogout() + // { + // Yii::$app->user->logout(); + // + // return $this->goHome(); + // } /** * Displays contact page. @@ -160,45 +162,45 @@ * Signs user up. * @return mixed */ -// public function actionSignup() -// { -// $model = new SignupForm(); -// if($model->load(Yii::$app->request->post())) { -// if($user = $model->signup()) { -// if(Yii::$app->getUser() -// ->login($user) -// ) { -// return $this->goHome(); -// } -// } -// } -// -// return $this->render('signup', [ -// 'model' => $model, -// ]); -// } + // public function actionSignup() + // { + // $model = new SignupForm(); + // if($model->load(Yii::$app->request->post())) { + // if($user = $model->signup()) { + // if(Yii::$app->getUser() + // ->login($user) + // ) { + // return $this->goHome(); + // } + // } + // } + // + // return $this->render('signup', [ + // 'model' => $model, + // ]); + // } /** * Requests password reset. * @return mixed */ -// public function actionRequestPasswordReset() -// { -// $model = new PasswordResetRequestForm(); -// if($model->load(Yii::$app->request->post()) && $model->validate()) { -// if($model->sendEmail()) { -// Yii::$app->session->setFlash('success', 'Check your email for further instructions.'); -// -// return $this->goHome(); -// } else { -// Yii::$app->session->setFlash('error', 'Sorry, we are unable to reset password for email provided.'); -// } -// } -// -// return $this->render('requestPasswordResetToken', [ -// 'model' => $model, -// ]); -// } + // public function actionRequestPasswordReset() + // { + // $model = new PasswordResetRequestForm(); + // if($model->load(Yii::$app->request->post()) && $model->validate()) { + // if($model->sendEmail()) { + // Yii::$app->session->setFlash('success', 'Check your email for further instructions.'); + // + // return $this->goHome(); + // } else { + // Yii::$app->session->setFlash('error', 'Sorry, we are unable to reset password for email provided.'); + // } + // } + // + // return $this->render('requestPasswordResetToken', [ + // 'model' => $model, + // ]); + // } /** * Resets password. @@ -208,24 +210,24 @@ * @return mixed * @throws BadRequestHttpException */ -// public function actionResetPassword($token) -// { -// try { -// $model = new ResetPasswordForm($token); -// } catch(InvalidParamException $e) { -// throw new BadRequestHttpException($e->getMessage()); -// } -// -// if($model->load(Yii::$app->request->post()) && $model->validate() && $model->resetPassword()) { -// Yii::$app->session->setFlash('success', 'New password was saved.'); -// -// return $this->goHome(); -// } -// -// return $this->render('resetPassword', [ -// 'model' => $model, -// ]); -// } + // public function actionResetPassword($token) + // { + // try { + // $model = new ResetPasswordForm($token); + // } catch(InvalidParamException $e) { + // throw new BadRequestHttpException($e->getMessage()); + // } + // + // if($model->load(Yii::$app->request->post()) && $model->validate() && $model->resetPassword()) { + // Yii::$app->session->setFlash('success', 'New password was saved.'); + // + // return $this->goHome(); + // } + // + // return $this->render('resetPassword', [ + // 'model' => $model, + // ]); + // } /** * Show certificates page. @@ -245,7 +247,7 @@ public function actionPage($id) { - $model = Page::findOne($id); + $model = Page::find()->where(['page.id' => $id])->joinWith('lang', true, 'INNER JOIN')->one(); if(empty( $model )) { throw new NotFoundHttpException(); } diff --git a/frontend/views/article/_list_item.php b/frontend/views/article/_list_item.php index a50e963..0f568ad 100644 --- a/frontend/views/article/_list_item.php +++ b/frontend/views/article/_list_item.php @@ -20,7 +20,7 @@
title, [ 'article/view', 'id' => $model->id ]); + echo Html::a($model->lang->title, [ 'article/view', 'id' => $model->id ]); ?>
@@ -36,15 +36,15 @@
body_preview)) { - echo $model->body_preview; + if(!empty($model->lang->body_preview)) { + echo $model->lang->body_preview; } else { - echo $model->body; + echo $model->lang->body; } ?>

$model->id ]); + echo Html::a(Yii::t('app', 'Подробнее'), [ 'article/view', 'id' => $model->id ]); ?>

diff --git a/frontend/views/article/index.php b/frontend/views/article/index.php index 22ecc68..26348f8 100755 --- a/frontend/views/article/index.php +++ b/frontend/views/article/index.php @@ -9,7 +9,7 @@ use yii\widgets\LinkPager; use yii\widgets\ListView; - $this->title = 'Статьи'; // Test + $this->title = Yii::t('app', 'Статьи'); $this->params[ 'breadcrumbs' ][] = $this->title; ?>
title; ?>
diff --git a/frontend/views/article/view.php b/frontend/views/article/view.php index ed98ff3..53409f7 100755 --- a/frontend/views/article/view.php +++ b/frontend/views/article/view.php @@ -7,9 +7,9 @@ use common\models\Articles; use yii\helpers\Html; - $this->title = $model->title; + $this->title = $model->lang->title; $this->params[ 'breadcrumbs' ][] = [ - 'label' => 'Статьи', + 'label' => Yii::t('app', 'Статьи'), 'url' => [ '/article' ], ]; $this->params[ 'breadcrumbs' ][] = $this->title; @@ -38,7 +38,7 @@ 'class' => 'float-left col-xs-12 col-sm-6', ]); } - echo $model->body; + echo $model->lang->body; ?> diff --git a/frontend/views/basket/cart.php b/frontend/views/basket/cart.php index eeab303..a20b416 100644 --- a/frontend/views/basket/cart.php +++ b/frontend/views/basket/cart.php @@ -5,6 +5,6 @@ * @var View $this * @var int $count */ + echo \Yii::t('app', 'Отправить запрос'); ?> -Отправить запрос \ No newline at end of file diff --git a/frontend/views/basket/modal_items.php b/frontend/views/basket/modal_items.php index ca665bf..776dcdf 100644 --- a/frontend/views/basket/modal_items.php +++ b/frontend/views/basket/modal_items.php @@ -17,7 +17,7 @@ ?>
-
Запрос на просчет
+
'basket_form', @@ -80,8 +80,8 @@ 'collection_id' => $model->product_id, 'variant_id' => $model->product_variant_id, ]); ?>"> - name; ?> -
Номер по каталогу: + lang->name; ?> +
: sku; ?> @@ -100,10 +100,10 @@ ->textarea(); ?> diff --git a/frontend/views/collection/view.php b/frontend/views/collection/view.php index 0ef7edd..5c2ec05 100755 --- a/frontend/views/collection/view.php +++ b/frontend/views/collection/view.php @@ -15,7 +15,7 @@ use yii\helpers\Url; use yii\widgets\Pjax; - $this->title = $collection->brand->name . ' ' . $collection->name; + $this->title = $collection->brand->lang->name . ' ' . $collection->lang->name; $this->params[ 'breadcrumbs' ][] = $this->title; $groups = $variant->getProperties(); ?> @@ -40,12 +40,12 @@
name; + echo $variant->lang->name; ?>
- +
Номер по каталогу:: sku; @@ -55,14 +55,14 @@ _options, 'value', false); + $values = ArrayHelper::getColumn($group->_options, 'lang.value', false); if(!empty( $values )) { $value = implode('; ', $values); } ?>
- name; ?>: + lang->name; ?>:
'to_order', 'data-id' => $variant->product_variant_id, ]); @@ -89,7 +89,10 @@
    getImageUrl(), 'brand_collection_variant')) . Html::tag('p', $variant_item->name), [ + if(empty($variant_item->lang)) { + continue; + } + echo Html::tag('li', Html::a(Html::tag('div', ArtboxImageHelper::getImage($variant_item->getImageUrl(), 'brand_collection_variant')) . Html::tag('p', $variant_item->lang->name), [ 'collection/view', 'collection_id' => $collection->product_id, 'variant_id' => $variant_item->product_variant_id, @@ -107,34 +110,34 @@
      -
    • Технические характеристики
    • +
    • productCertificates )) { - echo Html::tag('li', Html::tag('span', 'Сертификаты')); + echo Html::tag('li', Html::tag('span', \Yii::t('app', 'Сертификаты'))); } ?> productSpec->instruction )) { - echo Html::tag('li', Html::tag('span', 'Монтаж, уборка, уход')); + if(!empty( $collection->productSpec->lang->instruction )) { + echo Html::tag('li', Html::tag('span', \Yii::t('app', 'Монтаж, уборка, уход'))); } ?>
    productSpec->tech_spec_text )) { - echo $collection->productSpec->tech_spec_text; + if(!empty( $collection->productSpec->lang->tech_spec_text )) { + echo $collection->productSpec->lang->tech_spec_text; } if(!empty( $collection->productSpec->getTechSpecUrl() )) { - echo Html::tag('p', 'Документ технической документации: ' . Html::a('скачать', $collection->productSpec->getTechSpecUrl(), [ 'download' => true ])); + echo Html::tag('p', \Yii::t('app', 'Документ технической документации').':' . Html::a(\Yii::t('app', 'скачать'), $collection->productSpec->getTechSpecUrl(), [ 'download' => true ])); } if(!empty( $collection->productSpec->getTechCharUrl() )) { - echo Html::tag('p', 'Вы также можете скачать таблицу с ' . Html::a('техническими характеристиками', $collection->productSpec->getTechCharUrl(), [ 'download' => true ])); + echo Html::tag('p', \Yii::t('app', 'Вы также можете скачать таблицу с ' ). Html::a(\Yii::t('app', 'техническими характеристиками'), $collection->productSpec->getTechCharUrl(), [ 'download' => true ])); } ?>
    @@ -156,8 +159,8 @@
    productSpec->instruction )) { - echo Html::tag('div', $collection->productSpec->instruction, [ 'class' => 'tabs-content' ]); + if(!empty( $collection->productSpec->lang->instruction )) { + echo Html::tag('div', $collection->productSpec->lang->instruction, [ 'class' => 'tabs-content' ]); } if(!empty( $projects )) { diff --git a/frontend/views/filter/_brand_item.php b/frontend/views/filter/_brand_item.php index be2f37e..11b8c06 100644 --- a/frontend/views/filter/_brand_item.php +++ b/frontend/views/filter/_brand_item.php @@ -25,7 +25,7 @@
    brand->name . ' ' . $model->name; + echo $model->brand->lang->name . ' ' . $model->lang->name; ?>
    @@ -39,11 +39,11 @@
    description; + echo $model->lang->description; ?>

    $model->product_id, ]); @@ -58,7 +58,7 @@ ?>

  • getImageUrl(), 'brand_collection_variant')) . Html::tag('p', $variant->name), [ + echo Html::a(Html::tag('div', ArtboxImageHelper::getImage($variant->getImageUrl(), 'brand_collection_variant')) . Html::tag('p', $variant->lang->name), [ 'collection/view', 'collection_id' => $model->product_id, 'variant_id' => $variant->product_variant_id, diff --git a/frontend/views/filter/brand.php b/frontend/views/filter/brand.php index 4a4c142..2346b84 100755 --- a/frontend/views/filter/brand.php +++ b/frontend/views/filter/brand.php @@ -17,23 +17,23 @@ use yii\web\View; use yii\widgets\ListView; - $this->title = $category->name . ' ' . $brand->name . ' ' . mb_strtolower($purpose->value); + $this->title = $category->lang->name . ' ' . $brand->lang->name . ' ' . mb_strtolower($purpose->lang->value); $this->params[ 'breadcrumbs' ][] = [ - 'label' => $category->name, + 'label' => $category->lang->name, 'url' => [ 'filter/category', 'id' => $category->category_id, ], ]; $this->params[ 'breadcrumbs' ][] = [ - 'label' => $purpose->value, + 'label' => $purpose->lang->value, 'url' => [ 'filter/purpose', 'id' => $purpose->tax_option_id, ], ]; $this->params[ 'breadcrumbs' ][] = [ - 'label' => $category->name . ' ' . mb_strtolower($purpose->value), + 'label' => $category->lang->name . ' ' . mb_strtolower($purpose->lang->value), 'url' => [ 'filter/index', 'category_id' => $category->category_id, @@ -56,7 +56,7 @@
    seo_text; + echo $brand->lang->seo_text; ?>
    diff --git a/frontend/views/filter/category.php b/frontend/views/filter/category.php index b395398..70554a0 100755 --- a/frontend/views/filter/category.php +++ b/frontend/views/filter/category.php @@ -11,7 +11,7 @@ use common\modules\rubrication\models\TaxOption; use yii\helpers\Html; - $this->title = $category->name; + $this->title = $category->lang->name; $this->params[ 'breadcrumbs' ][] = $this->title; ?>
    title ?>
    @@ -23,13 +23,13 @@
    value), [ + echo Html::a(Html::tag('p', $purpose->lang->value), [ 'filter/index', 'category_id' => $category->category_id, 'purpose_id' => $purpose->tax_option_id, ], [ 'class' => 'link-cat', - 'style' => 'background-image: url("'.ArtboxImageHelper::getImageSrc($purpose->getImageUrl(), 'filter_image').'")', + 'style' => 'background-image: url("' . ArtboxImageHelper::getImageSrc($purpose->getImageUrl(), 'filter_image') . '")', ]); ?>
    @@ -41,7 +41,7 @@ /** * @var Brand $brand */ - echo Html::tag('li', Html::a($brand->name, [ + echo Html::tag('li', Html::a($brand->lang->name, [ 'filter/brand', 'purpose_id' => $purpose->tax_option_id, 'category_id' => $category->category_id, @@ -51,8 +51,15 @@ } ?>
+ tax_option_id ]) > 5) { + ?> +
+

+ -

развернуть

diff --git a/frontend/views/filter/index.php b/frontend/views/filter/index.php index da3eb47..e160717 100755 --- a/frontend/views/filter/index.php +++ b/frontend/views/filter/index.php @@ -11,16 +11,16 @@ use common\modules\rubrication\models\TaxOption; use yii\helpers\Html; - $this->title = $category->name . ' ' . mb_strtolower($purpose->value); + $this->title = $category->lang->name . ' ' . mb_strtolower($purpose->lang->value); $this->params[ 'breadcrumbs' ][] = [ - 'label' => $category->name, + 'label' => $category->lang->name, 'url' => [ 'filter/category', 'id' => $category->category_id, ], ]; $this->params[ 'breadcrumbs' ][] = [ - 'label' => $purpose->value, + 'label' => $purpose->lang->value, 'url' => [ 'filter/purpose', 'id' => $purpose->tax_option_id, @@ -39,7 +39,7 @@
seo_text; + echo $category->lang->seo_text; ?>
diff --git a/frontend/views/filter/purpose.php b/frontend/views/filter/purpose.php index 30b8654..0201a7f 100755 --- a/frontend/views/filter/purpose.php +++ b/frontend/views/filter/purpose.php @@ -11,7 +11,7 @@ use common\modules\rubrication\models\TaxOption; use yii\helpers\Html; - $this->title = $purpose->value; + $this->title = $purpose->lang->value; $this->params[ 'breadcrumbs' ][] = $this->title; ?>
title ?>
@@ -23,13 +23,13 @@
name), [ + echo Html::a(Html::tag('p', $category->lang->name), [ 'filter/index', 'category_id' => $category->category_id, 'purpose_id' => $purpose->tax_option_id, ], [ 'class' => 'link-cat', - 'style' => 'background-image: url("'.ArtboxImageHelper::getImageSrc($category->getImageUrl(), 'filter_image').'")', + 'style' => 'background-image: url("' . ArtboxImageHelper::getImageSrc($category->getImageUrl(), 'filter_image') . '")', ]); ?>
@@ -41,7 +41,7 @@ /** * @var Brand $brand */ - echo Html::tag('li', Html::a($brand->name, [ + echo Html::tag('li', Html::a($brand->lang->name, [ 'filter/brand', 'purpose_id' => $purpose->tax_option_id, 'category_id' => $category->category_id, @@ -52,7 +52,14 @@ ?> -

развернуть

+ category_id ]) > 5) { + ?> +
+

+
diff --git a/frontend/views/layouts/main.php b/frontend/views/layouts/main.php index d7b8400..9236acc 100755 --- a/frontend/views/layouts/main.php +++ b/frontend/views/layouts/main.php @@ -13,8 +13,9 @@ use yii\widgets\ActiveForm; use yii\widgets\Breadcrumbs; use yii\widgets\Menu; + $this->registerMetaTag([ - 'name' => 'robots', + 'name' => 'robots', 'content' => 'noindex, nofollow', ]); AppAsset::register($this); @@ -22,13 +23,14 @@ * @var Page[] $pages */ $pages = Page::find() + ->joinWith('lang', true, 'INNER JOIN') ->where([ 'in_menu' => true ]) ->orderBy([ 'id' => SORT_DESC ]) ->all(); $pages_items = []; foreach($pages as $page) { $pages_items[] = [ - 'label' => $page->title, + 'label' => $page->lang->title, 'url' => [ 'site/page', 'id' => $page->id, @@ -36,12 +38,13 @@ ]; } $categories = Category::find() + ->joinWith('lang', true, 'INNER JOIN') ->where([ 'depth' => 0 ]) ->all(); $submenu_items = []; foreach($categories as $category) { $submenu_items[] = [ - 'label' => $category->name, + 'label' => $category->lang->name, 'url' => [ 'filter/category', 'id' => $category->category_id, @@ -50,20 +53,20 @@ } $menu_items = [ [ - 'label' => 'Контрактные продукты', + 'label' => Yii::t('app', 'Контрактные продукты'), 'url' => '#', 'items' => $submenu_items, ], [ - 'label' => 'Галерея объектов', + 'label' => Yii::t('app', 'Галерея объектов'), 'url' => [ '/project' ], ], [ - 'label' => 'Статьи', + 'label' => Yii::t('app', 'Статьи'), 'url' => [ '/article' ], ], [ - 'label' => 'Контакты', + 'label' => Yii::t('app', 'Контакты'), 'url' => [ 'site/contact' ], ], ]; @@ -199,7 +202,7 @@
['search/index'], + 'action' => [ 'search/index' ], 'method' => 'get', ]); echo Html::input('search', 'search'); @@ -356,7 +359,7 @@ ], ], ], - 'linkTemplate' => '{label}', + 'linkTemplate' => '{label}', ]); ?>
@@ -423,7 +426,7 @@
endBody() ?> diff --git a/frontend/views/project/_list_item.php b/frontend/views/project/_list_item.php index 98a5ab1..6c16fcb 100644 --- a/frontend/views/project/_list_item.php +++ b/frontend/views/project/_list_item.php @@ -16,7 +16,7 @@
title, [ + echo Html::a($model->lang->title, [ 'project/view', 'id' => $model->project_id, ]); @@ -37,11 +37,11 @@ ?>
description; + echo $model->lang->description; ?>

$model->project_id, ]); diff --git a/frontend/views/project/index.php b/frontend/views/project/index.php index f36c515..40be462 100755 --- a/frontend/views/project/index.php +++ b/frontend/views/project/index.php @@ -6,11 +6,9 @@ */ use common\models\ProjectSearch; use yii\data\ActiveDataProvider; - use yii\helpers\Html; - use yii\helpers\Url; use yii\widgets\ListView; - $this->title = 'Галерея объектов'; + $this->title = \Yii::t('app', 'Галерея объектов'); $this->params[ 'breadcrumbs' ][] = $this->title; ?>

title; ?>
diff --git a/frontend/views/project/view.php b/frontend/views/project/view.php index fea8ef6..5e8e657 100755 --- a/frontend/views/project/view.php +++ b/frontend/views/project/view.php @@ -7,13 +7,12 @@ use common\models\Project; use common\models\ProjectImage; use common\modules\product\models\ProductVariant; - use yii\helpers\Html; use yii\helpers\Url; - $this->title = $model->title; + $this->title = $model->lang->title; $this->params[ 'breadcrumbs' ][] = [ 'url' => [ '/project' ], - 'label' => 'Галерея объектов', + 'label' => \Yii::t('app', 'Галерея объектов'), ]; $this->params[ 'breadcrumbs' ][] = $this->title; ?> @@ -37,7 +36,7 @@
description; + echo $model->lang->description; ?>
@@ -74,7 +73,7 @@ ?>
-
Продукты, используемые в данном проекте
+
    @@ -97,7 +96,7 @@

name; + echo $variant->lang->name; ?>

diff --git a/frontend/views/search/_search_item.php b/frontend/views/search/_search_item.php index 73ade94..9a869ea 100644 --- a/frontend/views/search/_search_item.php +++ b/frontend/views/search/_search_item.php @@ -25,7 +25,7 @@
brand->name . ' ' . $model->name; + echo $model->brand->lang->name . ' ' . $model->lang->name; ?>
@@ -39,11 +39,11 @@
description; + echo $model->lang->description; ?>

$model->product_id, ]); @@ -58,7 +58,7 @@ ?>

  • getImageUrl(), 'brand_collection_variant')) . Html::tag('p', $variant->name), [ + echo Html::a(Html::tag('div', ArtboxImageHelper::getImage($variant->getImageUrl(), 'brand_collection_variant')) . Html::tag('p', $variant->lang->name), [ 'collection/view', 'collection_id' => $model->product_id, 'variant_id' => $variant->product_variant_id, diff --git a/frontend/views/search/index.php b/frontend/views/search/index.php index 889ada1..ca17386 100755 --- a/frontend/views/search/index.php +++ b/frontend/views/search/index.php @@ -10,11 +10,11 @@ $this->title = $search; $this->params[ 'breadcrumbs' ][] = [ - 'label' => 'Поиск', + 'label' => \Yii::t('app', 'Поиск'), ]; $this->params[ 'breadcrumbs' ][] = $this->title; ?> -
    Результаты поиска для: title ?>
    +
    : title ?>
    title = 'Главная'; + $this->title = Yii::t('app', 'Главная'); ?>
    @@ -33,8 +34,8 @@ ]); ?>
    -

    title; ?>

    - alt; ?> +

    lang->title; ?>

    + lang->alt; ?>
    $category->name, + 'label' => $category->lang->name, 'url' => [ 'filter/category', 'id' => $category->category_id, @@ -78,7 +79,7 @@

    value; ?>

    + ]); ?>">

    lang->value; ?>

    @@ -94,7 +95,7 @@

    value; ?>

    + ]); ?>">

    lang->value; ?>

    @@ -110,7 +111,7 @@

    value; ?>

    + ]); ?>">

    lang->value; ?>

    @@ -126,7 +127,7 @@

    value; ?>

    + ]); ?>">

    lang->value; ?>

    @@ -142,7 +143,7 @@

    value; ?>

    + ]); ?>">

    lang->value; ?>

  • @@ -158,7 +159,7 @@

    value; ?>

    + ]); ?>">

    lang->value; ?>

    @@ -174,7 +175,7 @@

    value; ?>

    + ]); ?>">

    lang->value; ?>

    @@ -194,7 +195,7 @@ ?>
    image), [ $banner->url ]); + echo Html::a(Html::img($banner->lang->imageUrl), [ $banner->url ]); ?>
    title = $model->title; + $this->title = $model->lang->title; $this->params[ 'breadcrumbs' ][] = $this->title; ?>
    title; ?>
    body; + echo $model->lang->body; ?>
    diff --git a/todo b/todo new file mode 100644 index 0000000..b18ef70 --- /dev/null +++ b/todo @@ -0,0 +1,10 @@ +1. OrdersDelivery - добавить возможность добавления. +2. Переименовать все id в table_id. +3. Переименовать все table!s! в table. +4. Пересмотреть структура таблицы orders_products. +5. Посмотреть разницу ProductVariantSearch и ProductVariantListSearch. +6. Wishlist +7. Lookbook (типа коллекций)? +8. Compare +9. Tags для блога +10. Social integration \ No newline at end of file -- libgit2 0.21.4