Commit aa182b5c9d190b9e6e351ebdf043847ad0619a27
1 parent
84ebac3d
test
Showing
5 changed files
with
200 additions
and
26 deletions
Show diff stats
common/models/Project.php
... | ... | @@ -73,6 +73,7 @@ |
73 | 73 | ], |
74 | 74 | [ |
75 | 75 | [ |
76 | + 'deadline', | |
76 | 77 | 'project_pid', |
77 | 78 | 'payment_variant', |
78 | 79 | 'contractual', |
... | ... | @@ -85,6 +86,13 @@ |
85 | 86 | ], |
86 | 87 | [ |
87 | 88 | [ |
89 | + 'specializationInput', | |
90 | + 'paymentInput', | |
91 | + ], | |
92 | + 'safe', | |
93 | + ], | |
94 | + [ | |
95 | + [ | |
88 | 96 | 'name', |
89 | 97 | 'link', |
90 | 98 | 'budget', |
... | ... | @@ -104,23 +112,26 @@ |
104 | 112 | public function attributeLabels() |
105 | 113 | { |
106 | 114 | return [ |
107 | - 'project_id' => Yii::t('app', 'Project ID'), | |
108 | - 'user_id' => Yii::t('app', 'User ID'), | |
109 | - 'name' => Yii::t('app', 'Название'), | |
110 | - 'link' => Yii::t('app', 'URL'), | |
111 | - 'project_pid' => Yii::t('app', 'Родительский проект'), | |
112 | - 'date_add' => Yii::t('app', 'Дата добавления'), | |
113 | - 'date_end' => Yii::t('app', 'Дата окончания'), | |
114 | - 'user_add_id' => Yii::t('app', 'User Add ID'), | |
115 | - 'view_count' => Yii::t('app', 'Количество просмотров'), | |
116 | - 'budget' => Yii::t('app', 'Бюджет'), | |
117 | - 'city' => Yii::t('app', 'Город'), | |
118 | - 'street' => Yii::t('app', 'Улица'), | |
119 | - 'house' => Yii::t('app', 'Дом'), | |
120 | - 'payment_variant' => Yii::t('app', 'Варианты оплаты'), | |
121 | - 'deadline' => Yii::t('app', 'Deadline'), | |
122 | - 'description' => Yii::t('app', 'Описание'), | |
123 | - 'contractual' => Yii::t('app', 'Договорной'), | |
115 | + 'project_id' => Yii::t('app', 'Project ID'), | |
116 | + 'user_id' => Yii::t('app', 'User ID'), | |
117 | + 'name' => Yii::t('app', 'Название'), | |
118 | + 'link' => Yii::t('app', 'URL'), | |
119 | + 'project_pid' => Yii::t('app', 'Родительский проект'), | |
120 | + 'date_add' => Yii::t('app', 'Дата добавления'), | |
121 | + 'date_end' => Yii::t('app', 'Дата окончания'), | |
122 | + 'user_add_id' => Yii::t('app', 'User Add ID'), | |
123 | + 'view_count' => Yii::t('app', 'Количество просмотров'), | |
124 | + 'budget' => Yii::t('app', 'Бюджет'), | |
125 | + 'city' => Yii::t('app', 'Город'), | |
126 | + 'street' => Yii::t('app', 'Улица'), | |
127 | + 'house' => Yii::t('app', 'Дом'), | |
128 | + 'payment_variant' => Yii::t('app', 'Варианты оплаты'), | |
129 | + 'deadline' => Yii::t('app', 'Срок выполнения'), | |
130 | + 'description' => Yii::t('app', 'Описание'), | |
131 | + 'contractual' => Yii::t('app', 'Договорной'), | |
132 | + 'file' => Yii::t('app', 'Присоединить файл'), | |
133 | + 'specializationInput' => Yii::t('app', 'Специализации'), | |
134 | + 'paymentInput' => Yii::t('app', 'Способ оплаты'), | |
124 | 135 | ]; |
125 | 136 | } |
126 | 137 | |
... | ... | @@ -135,7 +146,7 @@ |
135 | 146 | public function getPayments() |
136 | 147 | { |
137 | 148 | return $this->hasMany(Payment::className(), [ 'payment_id' => 'payment_id' ]) |
138 | - ->viaTable('project_specialization', [ 'project_id' => 'project_id' ]); | |
149 | + ->viaTable('project_payment', [ 'project_id' => 'project_id' ]); | |
139 | 150 | } |
140 | 151 | |
141 | 152 | /** |
... | ... | @@ -159,7 +170,8 @@ |
159 | 170 | ->column(); |
160 | 171 | } |
161 | 172 | |
162 | - public function setSpecializationInput($value) { | |
173 | + public function setSpecializationInput($value) | |
174 | + { | |
163 | 175 | $this->specializationInput = $value; |
164 | 176 | } |
165 | 177 | |
... | ... | @@ -170,7 +182,8 @@ |
170 | 182 | ->column(); |
171 | 183 | } |
172 | 184 | |
173 | - public function setPaymentInput($value) { | |
185 | + public function setPaymentInput($value) | |
186 | + { | |
174 | 187 | $this->paymentInput = $value; |
175 | 188 | } |
176 | 189 | } | ... | ... |
console/migrations/m160209_104201_add_field_project_budget.php
... | ... | @@ -7,10 +7,12 @@ class m160209_104201_add_field_project_budget extends Migration |
7 | 7 | public function up() |
8 | 8 | { |
9 | 9 | $this->addColumn('{{%project}}', 'contractual', $this->smallInteger()); |
10 | + $this->addColumn('{{%project}}', 'file', $this->string()); | |
10 | 11 | } |
11 | 12 | |
12 | 13 | public function down() |
13 | 14 | { |
14 | 15 | $this->dropColumn('{{%project}}', 'contractual'); |
16 | + $this->dropColumn('{{%project}}', 'file'); | |
15 | 17 | } |
16 | 18 | } | ... | ... |
frontend/controllers/AccountsController.php
... | ... | @@ -414,24 +414,101 @@ |
414 | 414 | ->indexBy('payment_id') |
415 | 415 | ->asArray() |
416 | 416 | ->column(); |
417 | + $projects = Project::find() | |
418 | + ->select([ | |
419 | + 'name', | |
420 | + 'project_id', | |
421 | + ]) | |
422 | + ->where([ 'user_id' => \Yii::$app->user->getId() ]) | |
423 | + ->indexBy('project_id') | |
424 | + ->asArray() | |
425 | + ->column(); | |
417 | 426 | $post = \Yii::$app->request->post(); |
418 | - if(!empty($post)) { | |
427 | + if(!empty( $post )) { | |
419 | 428 | $project->load($post); |
420 | 429 | $project->validate(); |
421 | 430 | if(!$project->hasErrors()) { |
422 | 431 | $project->save(); |
423 | 432 | $project->unlinkAll('specializations', true); |
424 | 433 | foreach($project->specializationInput as $one_specialization) { |
425 | - $project->link('specialization', Specialization::findOne($one_specialization)); | |
434 | + $project->link('specializations', Specialization::findOne($one_specialization)); | |
426 | 435 | } |
427 | 436 | $project->unlinkAll('payments', true); |
428 | 437 | foreach($project->paymentInput as $one_payment) { |
429 | - $project->link('payment', Payment::findOne($one_payment)); | |
438 | + $project->link('payments', Payment::findOne($one_payment)); | |
430 | 439 | } |
431 | 440 | return $this->redirect('projects'); |
432 | 441 | } |
433 | 442 | } |
434 | - return $this->render('_projects_form', [ 'project' => $project, 'specialization' => $specialization, 'payment' => $payment ]); | |
443 | + return $this->render('_projects_form', [ | |
444 | + 'project' => $project, | |
445 | + 'specialization' => $specialization, | |
446 | + 'payment' => $payment, | |
447 | + 'projects' => $projects, | |
448 | + ]); | |
449 | + } | |
450 | + | |
451 | + public function actionProjectsUpdate($id) | |
452 | + { | |
453 | + $project = Project::findOne($id); | |
454 | + $specialization = Specialization::find() | |
455 | + ->select([ | |
456 | + 'specialization_name', | |
457 | + 'specialization_id', | |
458 | + ]) | |
459 | + ->indexBy('specialization_id') | |
460 | + ->asArray() | |
461 | + ->column(); | |
462 | + $payment = Payment::find() | |
463 | + ->select([ | |
464 | + 'name', | |
465 | + 'payment_id', | |
466 | + ]) | |
467 | + ->indexBy('payment_id') | |
468 | + ->asArray() | |
469 | + ->column(); | |
470 | + $projects = Project::find() | |
471 | + ->select([ | |
472 | + 'name', | |
473 | + 'project_id', | |
474 | + ]) | |
475 | + ->where([ 'user_id' => \Yii::$app->user->getId() ]) | |
476 | + ->andWhere([ | |
477 | + 'not', | |
478 | + [ 'project_id' => $project->project_id ], | |
479 | + ]) | |
480 | + ->indexBy('project_id') | |
481 | + ->asArray() | |
482 | + ->column(); | |
483 | + $post = \Yii::$app->request->post(); | |
484 | + if(!empty( $post )) { | |
485 | + $project->load($post); | |
486 | + $project->validate(); | |
487 | + if(!$project->hasErrors()) { | |
488 | + $project->save(); | |
489 | + $project->unlinkAll('specializations', true); | |
490 | + foreach($project->specializationInput as $one_specialization) { | |
491 | + $project->link('specializations', Specialization::findOne($one_specialization)); | |
492 | + } | |
493 | + $project->unlinkAll('payments', true); | |
494 | + foreach($project->paymentInput as $one_payment) { | |
495 | + $project->link('payments', Payment::findOne($one_payment)); | |
496 | + } | |
497 | + return $this->render('_projects_form', [ | |
498 | + 'project' => $project, | |
499 | + 'specialization' => $specialization, | |
500 | + 'payment' => $payment, | |
501 | + 'projects' => $projects, | |
502 | + ]); | |
503 | + //return $this->redirect('projects'); | |
504 | + } | |
505 | + } | |
506 | + return $this->render('_projects_form', [ | |
507 | + 'project' => $project, | |
508 | + 'specialization' => $specialization, | |
509 | + 'payment' => $payment, | |
510 | + 'projects' => $projects, | |
511 | + ]); | |
435 | 512 | } |
436 | 513 | |
437 | 514 | public function actionGallery() | ... | ... |
frontend/views/accounts/_blog_form.php
1 | +<?php | |
2 | + /** | |
3 | + * @var Project $project | |
4 | + * @var Specialization[] $specialization | |
5 | + * @var Payment[] $payment | |
6 | + * @var string[] $projects | |
7 | + */ | |
8 | + use common\models\Payment; | |
9 | + use common\models\Project; | |
10 | + use common\models\Specialization; | |
11 | + use common\widgets\ImageUploader; | |
12 | + use mihaildev\ckeditor\CKEditor; | |
13 | + use yii\helpers\Html; | |
14 | + use yii\widgets\ActiveForm; | |
15 | + | |
16 | + $this->title = 'Мой профиль'; | |
17 | + $this->params[ 'breadcrumbs' ][] = $this->title; | |
18 | +?> | |
19 | +<h1><?= $this->title ?></h1> | |
20 | + | |
21 | +<?php | |
22 | + $form = ActiveForm::begin(); | |
23 | +?> | |
24 | + | |
25 | +<?= $form->field($project, 'name') | |
26 | + ->textInput() ?> | |
27 | + | |
28 | +<?= $form->field($project, 'link') | |
29 | + ->textInput() ?> | |
30 | + | |
31 | +<?= $form->field($project, 'project_pid') | |
32 | + ->dropDownList($projects) ?> | |
33 | + | |
34 | +<?= $form->field($project, 'specializationInput') | |
35 | + ->checkboxList($specialization) ?> | |
36 | + | |
37 | +<div class="form-inline"> | |
38 | + Адрес: | |
39 | + <?= $form->field($project, 'city', [ 'template' => "{label}{input}{hint}{error}" ]) | |
40 | + ->textInput() ?> | |
41 | + <?= $form->field($project, 'street', [ 'template' => "{label}{input}{hint}{error}" ]) | |
42 | + ->textInput() ?> | |
43 | + <?= $form->field($project, 'house', [ 'template' => "{label}{input}{hint}{error}" ]) | |
44 | + ->textInput() ?> | |
45 | +</div> | |
46 | + | |
47 | +<?= $form->field($project, 'budget') | |
48 | + ->textInput() ?> | |
49 | + | |
50 | +<?= $form->field($project, 'contractual') | |
51 | + ->checkbox() ?> | |
52 | + | |
53 | +<?= $form->field($project, 'payment_variant') | |
54 | + ->radioList([ | |
55 | + 1 => 'Без предоплаты', | |
56 | + 2 => 'Предоплата возможна', | |
57 | + ]) ?> | |
58 | + | |
59 | +<?= $form->field($project, 'paymentInput') | |
60 | + ->checkboxList($payment) ?> | |
61 | + | |
62 | +<?= $form->field($project, 'deadline', [ 'template' => "{label}{input} дней\n{hint}\n{error}" ]) | |
63 | + ->input('number') ?> | |
64 | + | |
65 | +<?= $form->field($project, 'description') | |
66 | + ->widget(CKEditor::className()) ?> | |
67 | + | |
68 | +<?= $form->field($project, 'file') | |
69 | + ->fileInput([ 'multiple' => 'multiple' ]) ?> | |
70 | + | |
71 | +<?= $form->field($project, 'date_end') | |
72 | + ->dropDownList([ | |
73 | + 'День', | |
74 | + 'Неделю', | |
75 | + 'Месяц', | |
76 | + 'Год', | |
77 | + ]) ?> | |
78 | + | |
79 | +<?= Html::submitButton('Добавить') ?> | |
80 | + | |
81 | +<?php | |
82 | + $form->end(); | |
83 | +?> | ... | ... |