diff --git a/common/models/Blog.php b/common/models/Blog.php new file mode 100644 index 0000000..e504045 --- /dev/null +++ b/common/models/Blog.php @@ -0,0 +1,96 @@ + 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', + ], + [ + [ 'description' ], + 'string', + ], + [ + [ + 'name', + 'link', + 'cover', + ], + 'string', + 'max' => 255, + ], + ]; + } + + /** + * @inheritdoc + */ + public function attributeLabels() + { + return [ + 'blog_id' => Yii::t('app', 'Blog 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', 'Количество просмотров'), + 'description' => Yii::t('app', 'Описание'), + 'cover' => Yii::t('app', 'Фото главное'), + ]; + } + } diff --git a/common/models/Portfolio.php b/common/models/Portfolio.php index f14075e..2500d79 100644 --- a/common/models/Portfolio.php +++ b/common/models/Portfolio.php @@ -9,24 +9,25 @@ /** * This is the model class for table "portfolio". - * @property integer $portfolio_id - * @property integer $user_id - * @property string $name - * @property string $link - * @property string $date_add - * @property integer $user_add_id Currently inactive attribute - * @property integer $view_count - * @property string $city - * @property string $street - * @property string $house - * @property string $description - * @property string $cover - * @property integer $gallery_id + * @property integer $portfolio_id + * @property integer $user_id + * @property string $name + * @property string $link + * @property string $date_add + * @property integer $user_add_id Currently inactive attribute + * @property integer $view_count + * @property string $city + * @property string $street + * @property string $house + * @property string $description + * @property string $cover + * @property integer $gallery_id * @property PortfolioSpecialization[] $portfolioSpecializations - * @property Specialization[] $specializations + * @property Specialization[] $specializations */ class Portfolio extends \yii\db\ActiveRecord { + /** * @inheritdoc */ @@ -42,15 +43,15 @@ { return [ [ - 'class' => BlameableBehavior::className(), + 'class' => BlameableBehavior::className(), 'createdByAttribute' => 'user_id', 'updatedByAttribute' => false, ], [ - 'class' => TimestampBehavior::className(), + 'class' => TimestampBehavior::className(), 'createdAtAttribute' => 'date_add', 'updatedAtAttribute' => false, - 'value' => new Expression('NOW()'), + 'value' => new Expression('NOW()'), ], ]; } @@ -69,7 +70,6 @@ ], [ [ - 'view_count', 'gallery_id', ], 'integer', @@ -94,7 +94,7 @@ ], [ [ - 'specializationInput' + 'specializationInput', ], 'safe', ], @@ -139,7 +139,9 @@ public function getSpecializationInput() { - return $this->getSpecializations()->asArray()->column(); + return $this->getSpecializations() + ->asArray() + ->column(); } public function setSpecializationInput($value) diff --git a/common/models/Project.php b/common/models/Project.php new file mode 100644 index 0000000..283db00 --- /dev/null +++ b/common/models/Project.php @@ -0,0 +1,176 @@ + 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', + ], + [ + [ + 'project_pid', + 'payment_variant', + 'contractual', + ], + 'integer', + ], + [ + [ 'description' ], + 'string', + ], + [ + [ + 'name', + 'link', + 'budget', + 'city', + 'street', + 'house', + ], + 'string', + 'max' => 255, + ], + ]; + } + + /** + * @inheritdoc + */ + public function attributeLabels() + { + return [ + 'project_id' => Yii::t('app', 'Project ID'), + 'user_id' => Yii::t('app', 'User ID'), + 'name' => Yii::t('app', 'Название'), + 'link' => Yii::t('app', 'URL'), + 'project_pid' => Yii::t('app', 'Родительский проект'), + 'date_add' => Yii::t('app', 'Дата добавления'), + 'date_end' => Yii::t('app', 'Дата окончания'), + 'user_add_id' => Yii::t('app', 'User Add ID'), + 'view_count' => Yii::t('app', 'Количество просмотров'), + 'budget' => Yii::t('app', 'Бюджет'), + 'city' => Yii::t('app', 'Город'), + 'street' => Yii::t('app', 'Улица'), + 'house' => Yii::t('app', 'Дом'), + 'payment_variant' => Yii::t('app', 'Варианты оплаты'), + 'deadline' => Yii::t('app', 'Deadline'), + 'description' => Yii::t('app', 'Описание'), + 'contractual' => Yii::t('app', 'Договорной'), + ]; + } + + /** + * @return \yii\db\ActiveQuery + */ + public function getProjectPayments() + { + return $this->hasMany(ProjectPayment::className(), [ 'project_id' => 'project_id' ]); + } + + public function getPayments() + { + return $this->hasMany(Payment::className(), [ 'payment_id' => 'payment_id' ]) + ->viaTable('project_specialization', [ 'project_id' => 'project_id' ]); + } + + /** + * @return \yii\db\ActiveQuery + */ + public function getProjectSpecializations() + { + return $this->hasMany(ProjectSpecialization::className(), [ 'project_id' => 'project_id' ]); + } + + public function getSpecializations() + { + return $this->hasMany(Specialization::className(), [ 'specialization_id' => 'specialization_id' ]) + ->viaTable('project_specialization', [ 'project_id' => 'project_id' ]); + } + + public function getSpecializationInput() + { + return $this->getSpecializations() + ->asArray() + ->column(); + } + + public function setSpecializationInput($value) { + $this->specializationInput = $value; + } + + public function getPaymentInput() + { + return $this->getPayments() + ->asArray() + ->column(); + } + + public function setPaymentInput($value) { + $this->paymentInput = $value; + } + } diff --git a/common/models/ProjectPayment.php b/common/models/ProjectPayment.php new file mode 100644 index 0000000..653f200 --- /dev/null +++ b/common/models/ProjectPayment.php @@ -0,0 +1,66 @@ + true, 'targetClass' => Payment::className(), 'targetAttribute' => ['payment_id' => 'payment_id']], + [['project_id'], 'exist', 'skipOnError' => true, 'targetClass' => Project::className(), 'targetAttribute' => ['project_id' => 'project_id']], + ]; + } + + /** + * @inheritdoc + */ + public function attributeLabels() + { + return [ + 'project_payment_id' => Yii::t('app', 'Project Payment ID'), + 'project_id' => Yii::t('app', 'Project ID'), + 'payment_id' => Yii::t('app', 'Payment ID'), + ]; + } + + /** + * @return \yii\db\ActiveQuery + */ + public function getPayment() + { + return $this->hasOne(Payment::className(), ['payment_id' => 'payment_id']); + } + + /** + * @return \yii\db\ActiveQuery + */ + public function getProject() + { + return $this->hasOne(Project::className(), ['project_id' => 'project_id']); + } +} diff --git a/common/models/ProjectSpecialization.php b/common/models/ProjectSpecialization.php new file mode 100644 index 0000000..6c542a9 --- /dev/null +++ b/common/models/ProjectSpecialization.php @@ -0,0 +1,66 @@ + true, 'targetClass' => Project::className(), 'targetAttribute' => ['project_id' => 'project_id']], + [['specialization_id'], 'exist', 'skipOnError' => true, 'targetClass' => Specialization::className(), 'targetAttribute' => ['specialization_id' => 'specialization_id']], + ]; + } + + /** + * @inheritdoc + */ + public function attributeLabels() + { + return [ + 'project_specialization_id' => Yii::t('app', 'Project Specialization ID'), + 'project_id' => Yii::t('app', 'Project ID'), + 'specialization_id' => Yii::t('app', 'Specialization ID'), + ]; + } + + /** + * @return \yii\db\ActiveQuery + */ + public function getProject() + { + return $this->hasOne(Project::className(), ['project_id' => 'project_id']); + } + + /** + * @return \yii\db\ActiveQuery + */ + public function getSpecialization() + { + return $this->hasOne(Specialization::className(), ['specialization_id' => 'specialization_id']); + } +} diff --git a/console/migrations/m160209_104201_add_field_project_budget.php b/console/migrations/m160209_104201_add_field_project_budget.php new file mode 100644 index 0000000..e6786d9 --- /dev/null +++ b/console/migrations/m160209_104201_add_field_project_budget.php @@ -0,0 +1,16 @@ +addColumn('{{%project}}', 'contractual', $this->smallInteger()); + } + + public function down() + { + $this->dropColumn('{{%project}}', 'contractual'); + } +} diff --git a/frontend/controllers/AccountsController.php b/frontend/controllers/AccountsController.php index 93b11ed..df4b0ce 100755 --- a/frontend/controllers/AccountsController.php +++ b/frontend/controllers/AccountsController.php @@ -1,6 +1,7 @@ render('blog'); + } + + public function actionBlogCreate() + { + $blog = new Blog(); + $post = \Yii::$app->request->post(); + if($blog->load($post) && $blog->save()) { + return $this->redirect('blog'); + } else { + return $this->render('_blog_form', [ 'blog' => $blog ]); + } + } + + public function actionBlogUpdate($id) + { + $blog = Blog::findOne($id); + $post = \Yii::$app->request->post(); + if($blog->load($post) && $blog->save()) { + return $this->redirect('blog'); + } else { + return $this->render('_blog_form', [ 'blog' => $blog ]); + } + } + public function actionPortfolio() { return $this->render('portfolio'); @@ -127,7 +156,7 @@ ->asArray() ->column(); $post = \Yii::$app->request->post(); - if(!empty($post)) { + if(!empty( $post )) { $portfolio->load($post); $portfolio->validate(); if(!$portfolio->hasErrors()) { @@ -136,10 +165,13 @@ foreach($portfolio->specializationInput as $one_specialization) { $portfolio->link('specializations', Specialization::findOne($one_specialization)); } - return $this->render('portfolio'); + return $this->redirect('portfolio'); } } - return $this->render('_portfolio_form', [ 'portfolio' => $portfolio, 'specialization' => $specialization ]); + return $this->render('_portfolio_form', [ + 'portfolio' => $portfolio, + 'specialization' => $specialization, + ]); } public function actionPortfolioUpdate($id) @@ -154,7 +186,7 @@ ->asArray() ->column(); $post = \Yii::$app->request->post(); - if(!empty($post)) { + if(!empty( $post )) { $portfolio->load($post); $portfolio->validate(); if(!$portfolio->hasErrors()) { @@ -163,10 +195,13 @@ foreach($portfolio->specializationInput as $one_specialization) { $portfolio->link('specializations', Specialization::findOne($one_specialization)); } - return $this->render('portfolio'); + return $this->redirect('portfolio'); } } - return $this->render('_portfolio_form', [ 'portfolio' => $portfolio, 'specialization' => $specialization ]); + return $this->render('_portfolio_form', [ + 'portfolio' => $portfolio, + 'specialization' => $specialization, + ]); } /** @@ -360,6 +395,45 @@ return $this->render('projects'); } + public function actionProjectsCreate() + { + $project = new Project(); + $specialization = Specialization::find() + ->select([ + 'specialization_name', + 'specialization_id', + ]) + ->indexBy('specialization_id') + ->asArray() + ->column(); + $payment = Payment::find() + ->select([ + 'name', + 'payment_id', + ]) + ->indexBy('payment_id') + ->asArray() + ->column(); + $post = \Yii::$app->request->post(); + if(!empty($post)) { + $project->load($post); + $project->validate(); + if(!$project->hasErrors()) { + $project->save(); + $project->unlinkAll('specializations', true); + foreach($project->specializationInput as $one_specialization) { + $project->link('specialization', Specialization::findOne($one_specialization)); + } + $project->unlinkAll('payments', true); + foreach($project->paymentInput as $one_payment) { + $project->link('payment', Payment::findOne($one_payment)); + } + return $this->redirect('projects'); + } + } + return $this->render('_projects_form', [ 'project' => $project, 'specialization' => $specialization, 'payment' => $payment ]); + } + public function actionGallery() { diff --git a/frontend/views/accounts/_blog_form.php b/frontend/views/accounts/_blog_form.php new file mode 100644 index 0000000..19a5714 --- /dev/null +++ b/frontend/views/accounts/_blog_form.php @@ -0,0 +1,46 @@ +title = 'Мой профиль'; + $this->params[ 'breadcrumbs' ][] = $this->title; +?> +

title ?>

+ + + +field($blog, 'date_add') + ->textInput([ 'disabled' => 'disabled' ]) ?> + +field($blog, 'name') + ->textInput() ?> + +field($blog, 'link') + ->textInput() ?> + +field($blog, 'description')->widget(CKEditor::className()) ?> + + $blog, + 'field'=>'cover', + 'width'=>100, + 'height'=>100, + 'multi'=>false, + 'gallery' =>$blog->cover, + 'name' => 'Загрузить главное фото' +]); +?> + + + +end(); +?> diff --git a/frontend/views/accounts/blog.php b/frontend/views/accounts/blog.php new file mode 100644 index 0000000..2e17d4e --- /dev/null +++ b/frontend/views/accounts/blog.php @@ -0,0 +1,10 @@ +title = 'Мой профиль'; + $this->params['breadcrumbs'][] = $this->title; +?> +

title ?>

\ No newline at end of file -- libgit2 0.21.4