diff --git a/common/models/Gallery.php b/common/models/Gallery.php new file mode 100644 index 0000000..6203ae2 --- /dev/null +++ b/common/models/Gallery.php @@ -0,0 +1,59 @@ + 255], + ]; + } + + /** + * @inheritdoc + */ + public function attributeLabels() + { + return [ + 'gallery_id' => Yii::t('app', 'Gallery ID'), + 'user_id' => Yii::t('app', 'User ID'), + 'name' => Yii::t('app', 'Name'), + 'date_add' => Yii::t('app', 'Date Add'), + 'user_add_id' => Yii::t('app', 'User Add ID'), + 'cover' => Yii::t('app', 'Cover'), + 'type' => Yii::t('app', 'Type'), + 'photo' => Yii::t('app', 'Photo'), + ]; + } +} diff --git a/common/models/Portfolio.php b/common/models/Portfolio.php new file mode 100644 index 0000000..f14075e --- /dev/null +++ b/common/models/Portfolio.php @@ -0,0 +1,149 @@ + BlameableBehavior::className(), + 'createdByAttribute' => 'user_id', + 'updatedByAttribute' => false, + ], + [ + 'class' => TimestampBehavior::className(), + 'createdAtAttribute' => 'date_add', + 'updatedAtAttribute' => false, + 'value' => new Expression('NOW()'), + ], + ]; + } + + /** + * @inheritdoc + */ + public function rules() + { + return [ + [ + [ + 'name', + ], + 'required', + ], + [ + [ + 'view_count', + 'gallery_id', + ], + 'integer', + ], + [ + [ + 'description', + 'cover', + ], + 'string', + ], + [ + [ + 'name', + 'link', + 'city', + 'street', + 'house', + ], + 'string', + 'max' => 255, + ], + [ + [ + 'specializationInput' + ], + 'safe', + ], + ]; + } + + /** + * @inheritdoc + */ + public function attributeLabels() + { + return [ + 'portfolio_id' => Yii::t('app', 'Portfolio ID'), + 'user_id' => Yii::t('app', 'User ID'), + 'name' => Yii::t('app', 'Название'), + 'link' => Yii::t('app', 'URL'), + 'date_add' => Yii::t('app', 'Дата добавления'), + 'user_add_id' => Yii::t('app', 'User Add ID'), + 'view_count' => Yii::t('app', 'Количество просмотров'), + 'city' => Yii::t('app', 'Город'), + 'street' => Yii::t('app', 'Улица'), + 'house' => Yii::t('app', 'Дом'), + 'description' => Yii::t('app', 'Описание'), + 'cover' => Yii::t('app', 'Фото главное'), + 'gallery_id' => Yii::t('app', 'Фото галерея'), + ]; + } + + /** + * @return \yii\db\ActiveQuery + */ + public function getPortfolioSpecializations() + { + return $this->hasMany(PortfolioSpecialization::className(), [ 'portfolio_id' => 'portfolio_id' ]); + } + + public function getSpecializations() + { + return $this->hasMany(Specialization::className(), [ 'specialization_id' => 'specialization_id' ]) + ->viaTable('portfolio_specialization', [ 'portfolio_id' => 'portfolio_id' ]); + } + + public function getSpecializationInput() + { + return $this->getSpecializations()->asArray()->column(); + } + + public function setSpecializationInput($value) + { + $this->specializationInput = $value; + } + } diff --git a/common/models/PortfolioSpecialization.php b/common/models/PortfolioSpecialization.php new file mode 100644 index 0000000..cb04527 --- /dev/null +++ b/common/models/PortfolioSpecialization.php @@ -0,0 +1,66 @@ + true, 'targetClass' => Portfolio::className(), 'targetAttribute' => ['portfolio_id' => 'portfolio_id']], + [['specialization_id'], 'exist', 'skipOnError' => true, 'targetClass' => Specialization::className(), 'targetAttribute' => ['specialization_id' => 'specialization_id']], + ]; + } + + /** + * @inheritdoc + */ + public function attributeLabels() + { + return [ + 'portfolio_specialization_id' => Yii::t('app', 'Portfolio Specialization ID'), + 'portfolio_id' => Yii::t('app', 'Portfolio ID'), + 'specialization_id' => Yii::t('app', 'Specialization ID'), + ]; + } + + /** + * @return \yii\db\ActiveQuery + */ + public function getPortfolio() + { + return $this->hasOne(Portfolio::className(), ['portfolio_id' => 'portfolio_id']); + } + + /** + * @return \yii\db\ActiveQuery + */ + public function getSpecialization() + { + return $this->hasOne(Specialization::className(), ['specialization_id' => 'specialization_id']); + } +} diff --git a/frontend/controllers/AccountsController.php b/frontend/controllers/AccountsController.php index c7d1d82..93b11ed 100755 --- a/frontend/controllers/AccountsController.php +++ b/frontend/controllers/AccountsController.php @@ -6,6 +6,8 @@ use common\models\Job; use common\models\Language; use common\models\Payment; + use common\models\Portfolio; + use common\models\PortfolioSpecialization; use common\models\Specialization; use common\models\UserPayment; use common\models\UserSpecialization; @@ -110,7 +112,61 @@ public function actionPortfolio() { + return $this->render('portfolio'); + } + + public function actionPortfolioCreate() + { + $portfolio = new Portfolio(); + $specialization = Specialization::find() + ->select([ + 'specialization_name', + 'specialization_id', + ]) + ->indexBy('specialization_id') + ->asArray() + ->column(); + $post = \Yii::$app->request->post(); + if(!empty($post)) { + $portfolio->load($post); + $portfolio->validate(); + if(!$portfolio->hasErrors()) { + $portfolio->save(); + $portfolio->unlinkAll('specializations', true); + foreach($portfolio->specializationInput as $one_specialization) { + $portfolio->link('specializations', Specialization::findOne($one_specialization)); + } + return $this->render('portfolio'); + } + } + return $this->render('_portfolio_form', [ 'portfolio' => $portfolio, 'specialization' => $specialization ]); + } + public function actionPortfolioUpdate($id) + { + $portfolio = Portfolio::findOne($id); + $specialization = Specialization::find() + ->select([ + 'specialization_name', + 'specialization_id', + ]) + ->indexBy('specialization_id') + ->asArray() + ->column(); + $post = \Yii::$app->request->post(); + if(!empty($post)) { + $portfolio->load($post); + $portfolio->validate(); + if(!$portfolio->hasErrors()) { + $portfolio->save(); + $portfolio->unlinkAll('specializations', true); + foreach($portfolio->specializationInput as $one_specialization) { + $portfolio->link('specializations', Specialization::findOne($one_specialization)); + } + return $this->render('portfolio'); + } + } + return $this->render('_portfolio_form', [ 'portfolio' => $portfolio, 'specialization' => $specialization ]); } /** @@ -184,13 +240,15 @@ UserSpecialization::deleteAll([ 'user_id' => \Yii::$app->user->getId() ]); UserPayment::deleteAll([ 'user_id' => \Yii::$app->user->getId() ]); foreach($post[ 'UserSpecialization' ][ 'specialization_id' ] as $index => $value) { - $user_specialization_values[] = (new UserSpecialization([ 'user_id' => \Yii::$app->user->getId(), - 'specialization_id' => $value, + $user_specialization_values[] = (new UserSpecialization([ + 'user_id' => \Yii::$app->user->getId(), + 'specialization_id' => $value, ]))->save(); } foreach($post[ 'UserPayment' ][ 'payment_id' ] as $index => $value) { - $user_payment_values[] = (new UserPayment([ 'user_id' => \Yii::$app->user->getId(), - 'payment_id' => $value, + $user_payment_values[] = (new UserPayment([ + 'user_id' => \Yii::$app->user->getId(), + 'payment_id' => $value, ]))->save(); } } @@ -234,10 +292,10 @@ public function actionAddSkills() { $user = \Yii::$app->user->identity; - if(!empty(\Yii::$app->request->post())) { + if(!empty( \Yii::$app->request->post() )) { Fields::saveFieldData(Yii::$app->request->post('Fields'), \Yii::$app->user->identity->id, User::className(), 'ru'); } - return $this->render('add-skills', ['user' => $user]); + return $this->render('add-skills', [ 'user' => $user ]); } public function actionDescription() @@ -249,7 +307,7 @@ $user_info = new UserInfo([ 'user_id' => \Yii::$app->user->getId() ]); } $post = \Yii::$app->request->post(); - if(!empty($post)) { + if(!empty( $post )) { $user_info->load($post); $user_info->save(); } diff --git a/frontend/views/accounts/_portfolio_form.php b/frontend/views/accounts/_portfolio_form.php new file mode 100644 index 0000000..f2b1281 --- /dev/null +++ b/frontend/views/accounts/_portfolio_form.php @@ -0,0 +1,58 @@ +title = 'Мой профиль'; + $this->params[ 'breadcrumbs' ][] = $this->title; +?> +