Commit be662d1f23f553ff03a40b893bc9d9b4afc46c16

Authored by Yarik
1 parent 2261f70a

test

common/models/Message.php
... ... @@ -89,8 +89,6 @@ class Message extends \yii\db\ActiveRecord
89 89  
90 90 }
91 91  
92   -
93   -
94 92 public function isMy(){
95 93 if($this->user_id == \Yii::$app->user->id){
96 94 return true;
... ...
common/models/TenderSearch.php
... ... @@ -66,6 +66,13 @@
66 66 ],
67 67 [
68 68 [
  69 + 'contractual',
  70 + ],
  71 + 'default',
  72 + 'value' => 1,
  73 + ],
  74 + [
  75 + [
69 76 'budget_currency',
70 77 ],
71 78 'default',
... ...
common/models/User.php
... ... @@ -9,6 +9,7 @@
9 9 use yii\behaviors\TimestampBehavior;
10 10 use yii\db\ActiveQuery;
11 11 use yii\db\ActiveRecord;
  12 + use yii\helpers\Url;
12 13 use yii\rbac\ManagerInterface;
13 14 use yii\rbac\Role;
14 15 use yii\web\IdentityInterface;
... ... @@ -28,6 +29,32 @@
28 29 * @property string $password write-only password
29 30 * @property string $type
30 31 * @property UserInfo $userInfo
  32 + * @property string $userName
  33 + * @property array[] $roles
  34 + * @property CompanyInfo $companyInfo
  35 + * @property array[] $phones
  36 + * @property array[] $site
  37 + * @property string $address
  38 + * @property string $liveTime
  39 + * @property Payment[] $payments
  40 + * @property integer[] $paymentInput
  41 + * @property Specialization[] $specializations
  42 + * @property integer[] $specializationInput
  43 + * @property Blog[] $blog
  44 + * @property Job[] $jobs
  45 + * @property Job $currentJob
  46 + * @property Portfolio[] $portfolios
  47 + * @property Project[] $projects
  48 + * @property Team[] $teams
  49 + * @property Vacancy[] $vacancies
  50 + * @property Gallery[] $galleries
  51 + * @property UserInfo|CompanyInfo $owner
  52 + * @property string $name
  53 + * @property Comment[] $comments
  54 + * @property Rating[] $commentRating
  55 + * @property int $ratingPG
  56 + * @property string $lastVisit
  57 + * @property string $link
31 58 */
32 59 class User extends ActiveRecord implements IdentityInterface, UserRbacInterface
33 60 {
... ... @@ -51,8 +78,6 @@
51 78 return '{{%user}}';
52 79 }
53 80  
54   -
55   -
56 81 /**
57 82 * @inheritdoc
58 83 */
... ... @@ -60,7 +85,7 @@
60 85 {
61 86 return [
62 87 [
63   - 'class' => 'common\behaviors\ShowImage',
  88 + 'class' => 'common\behaviors\ShowImage',
64 89 ],
65 90 TimestampBehavior::className(),
66 91 ];
... ... @@ -560,11 +585,21 @@
560 585 ->inverseOf('user');
561 586 }
562 587  
  588 + /**
  589 + * Return all user's galleries
  590 + *
  591 + * @return ActiveQuery
  592 + */
563 593 public function getGalleries()
564 594 {
565 595 return $this->hasMany(Gallery::className(), [ 'user_id' => 'id' ]);
566 596 }
567 597  
  598 + /**
  599 + * Return company info or user info according to user type
  600 + *
  601 + * @return ActiveQuery
  602 + */
568 603 public function getOwner()
569 604 {
570 605 if($this->type == 2) {
... ... @@ -574,6 +609,11 @@
574 609 }
575 610 }
576 611  
  612 + /**
  613 + * Return company name or user firstname and lastname according to user type
  614 + *
  615 + * @return string
  616 + */
577 617 public function getName()
578 618 {
579 619 if($this->type == 2) {
... ... @@ -584,6 +624,8 @@
584 624 }
585 625  
586 626 /**
  627 + * Return all comments to user
  628 + *
587 629 * @return ActiveQuery
588 630 */
589 631 public function getComments()
... ... @@ -597,6 +639,8 @@
597 639 }
598 640  
599 641 /**
  642 + * Return all ratings to user
  643 + *
600 644 * @return ActiveQuery
601 645 */
602 646 public function getCommentRating()
... ... @@ -608,6 +652,13 @@
608 652 ]);
609 653 }
610 654  
  655 + /**
  656 + * Return user's rating<br>
  657 + * <b>Available only for PostgreSQL</b>
  658 + *
  659 + * @return int
  660 + * @throws InvalidConfigException
  661 + */
611 662 public function getRatingPG()
612 663 {
613 664 if(\Yii::$app->db->driverName != 'pgsql') {
... ... @@ -622,6 +673,15 @@
622 673 ->scalar();
623 674 }
624 675  
  676 + /**
  677 + * Recalculate rating and write it to db.
  678 + *
  679 + * <b>Only for PostgreSQL</b>
  680 + *
  681 + * @see \common\models\User::getRatingPG()
  682 + *
  683 + * @throws InvalidConfigException
  684 + */
625 685 public function updateRating()
626 686 {
627 687 if($rating = $this->getRatingPG()) {
... ... @@ -630,4 +690,23 @@
630 690 }
631 691 }
632 692  
  693 + public function getLastVisit()
  694 + {
  695 + return \Yii::$app->formatter->asRelativeTime($this->userInfo->date_visit);
  696 + }
  697 +
  698 + /**
  699 + * Return link to user personal page according to user type
  700 + *
  701 + * @return string
  702 + */
  703 + public function getLink($page = 'common')
  704 + {
  705 + if($this->type == 2) {
  706 + return Url::to(['company/'.$page, 'company_id' => $this->id]);
  707 + } else {
  708 + return Url::to(['performer/'.$page, 'performer_id' => $this->id]);
  709 + }
  710 + }
  711 +
633 712 }
... ...
common/modules/comment/models/CommentProject.php
... ... @@ -3,26 +3,29 @@
3 3  
4 4 use common\models\Currency;
5 5 use common\models\File;
  6 + use common\models\User;
6 7 use yii\db\ActiveQuery;
  8 + use yii\db\ActiveRecord;
7 9 use yii\web\UploadedFile;
8 10  
9 11 /**
10 12 * Class Comment
11   - * @property bool $guestComment
12   - * @property integer $comment_id
13   - * @property string $text
14   - * @property int $user_id
15   - * @property int $status
16   - * @property string $date_add
17   - * @property string $date_update
18   - * @property string $date_delete
19   - * @property string $model
20   - * @property int $model_id
21   - * @property string $files
22   - * @property float $budget_from
23   - * @property float $budget_to
24   - * @property int $term_from
25   - * @property int $term_to
  13 + * @property bool $guestComment
  14 + * @property integer $comment_id
  15 + * @property string $text
  16 + * @property int $user_id
  17 + * @property int $status
  18 + * @property string $date_add
  19 + * @property string $date_update
  20 + * @property string $date_delete
  21 + * @property string $model
  22 + * @property int $model_id
  23 + * @property string $files
  24 + * @property float $budget_from
  25 + * @property float $budget_to
  26 + * @property int $term_from
  27 + * @property int $term_to
  28 + * @property Currency $currency
26 29 * @package common\modules\comment\models
27 30 */
28 31 class CommentProject extends \yii\db\ActiveRecord
... ... @@ -42,6 +45,7 @@
42 45 * @var bool
43 46 */
44 47 public $guestComment = false;
  48 +
45 49 public $file;
46 50  
47 51 public function rules()
... ... @@ -84,7 +88,7 @@
84 88 [
85 89 [ 'budget_currency' ],
86 90 'exist',
87   - 'targetClass' => Currency::className(),
  91 + 'targetClass' => Currency::className(),
88 92 'targetAttribute' => 'currency_id',
89 93 ],
90 94 [
... ... @@ -118,7 +122,7 @@
118 122 'term_to',
119 123 'file',
120 124 ],
121   - self::SCENARIO_GUEST => [
  125 + self::SCENARIO_GUEST => [
122 126  
123 127 ],
124 128 ];
... ... @@ -150,11 +154,11 @@
150 154 public function attributeLabels()
151 155 {
152 156 return [
153   - 'text' => \Yii::t('app', 'Текст ответа'),
  157 + 'text' => \Yii::t('app', 'Текст ответа'),
154 158 'budget_from' => \Yii::t('app', 'от'),
155   - 'budget_to' => \Yii::t('app', 'до'),
156   - 'term_from' => \Yii::t('app', 'от'),
157   - 'term_to' => \Yii::t('app', 'до'),
  159 + 'budget_to' => \Yii::t('app', 'до'),
  160 + 'term_from' => \Yii::t('app', 'от'),
  161 + 'term_to' => \Yii::t('app', 'до'),
158 162 ];
159 163 }
160 164  
... ... @@ -163,10 +167,10 @@
163 167 return $this->guestComment;
164 168 }
165 169  
166   -// public function setGuestComment($value)
167   -// {
168   -// $this->guestComment = $value;
169   -// }
  170 + // public function setGuestComment($value)
  171 + // {
  172 + // $this->guestComment = $value;
  173 + // }
170 174  
171 175 /**
172 176 * @param string $model
... ... @@ -181,27 +185,28 @@
181 185 'comment_project.model' => $model,
182 186 'comment_project.model_id' => $model_id,
183 187 'comment_project.status' => 1,
184   - ]);
  188 + ])
  189 + ->with('currency', 'user', 'user.userInfo', 'user.companyInfo', 'user.comments');
185 190 }
186 191  
187 192 public function postComment()
188 193 {
189 194 if($this->checkCreate()) {
190   - if(!empty(\Yii::$app->request->post($this->formName())['anonymous'])) {
  195 + if(!empty( \Yii::$app->request->post($this->formName())[ 'anonymous' ] )) {
191 196 $this->status = self::STATUS_ANONYMOUS;
192 197 }
193 198 $this->file = UploadedFile::getInstances($this, 'file');
194   - if(!empty($this->file)) {
195   - $file_id = [];
196   - if(is_array($this->file)){
197   - foreach($this->file as $file){
198   - if($file instanceof UploadedFile){
  199 + if(!empty( $this->file )) {
  200 + $file_id = [ ];
  201 + if(is_array($this->file)) {
  202 + foreach($this->file as $file) {
  203 + if($file instanceof UploadedFile) {
199 204 $file_model = new File();
200 205 $file_id[] = $file_model->saveFile($file);
201 206 }
202 207 }
203 208 } else {
204   - if($this->file instanceof UploadedFile){
  209 + if($this->file instanceof UploadedFile) {
205 210 $file_model = new File();
206 211 $file_id[] = $file_model->saveFile($this->file);
207 212 }
... ... @@ -325,4 +330,47 @@
325 330 // }
326 331 }
327 332  
  333 + /**
  334 + * @return ActiveQuery
  335 + */
  336 + public function getCurrency()
  337 + {
  338 + return $this->hasOne(Currency::className(), [ 'currency_id' => 'budget_currency' ]);
  339 + }
  340 +
  341 + /**
  342 + * @return File[]
  343 + */
  344 + public function getFilesList()
  345 + {
  346 + $files = json_decode($this->files);
  347 + if(!empty( $files )) {
  348 + return File::findAll($files);
  349 + } else {
  350 + return [ ];
  351 + }
  352 + }
  353 +
  354 + /**
  355 + * @return ActiveRecord
  356 + * @throws \TypeError
  357 + */
  358 + public function getOwner()
  359 + {
  360 + $model = new $this->model();
  361 + if($model instanceof ActiveRecord) {
  362 + return $model->findOne($this->model_id);
  363 + } else {
  364 + throw new \TypeError('Model must extends Active Record Class');
  365 + }
  366 + }
  367 +
  368 + /**
  369 + * @return User
  370 + */
  371 + public function getUser()
  372 + {
  373 + return $this->hasOne(User::className(), ['id' => 'user_id']);
  374 + }
  375 +
328 376 }
... ...
common/modules/comment/widgets/views/_project_comment_view.php
... ... @@ -10,13 +10,7 @@
10 10 * @var \yii\widgets\ListView $widget current ListView instance
11 11 * @var User $user
12 12 */
13   - $user = NULL;
14   - if(!empty( $model->user_id )) {
15   - $user = User::find()
16   - ->where([ 'id' => $model->user_id ])
17   - ->with('userInfo')
18   - ->one();
19   - }
  13 + $user = $model->user;
20 14 ?>
21 15 <div class="performer-vacancy-sidebar-left-wr">
22 16 <div class="performer-vacancy-sidebar-left">
... ... @@ -28,22 +22,22 @@
28 22 <ul>
29 23 <?php
30 24 if(!empty( $user->userInfo->social_fb )) {
31   - echo '<li>'.Html::a(Html::img('/images/ico-fb.png'), $user->userInfo->social_fb, ['target' => '_blank']).'</li>';
  25 + echo '<li>' . Html::a(Html::img('/images/ico-fb.png'), $user->userInfo->social_fb, [ 'target' => '_blank' ]) . '</li>';
32 26 }
33 27 ?>
34 28 <?php
35 29 if(!empty( $user->userInfo->social_t )) {
36   - echo '<li>'.Html::a(Html::img('/images/ico-tw.png'), $user->userInfo->social_t, ['target' => '_blank']).'</li>';
  30 + echo '<li>' . Html::a(Html::img('/images/ico-tw.png'), $user->userInfo->social_t, [ 'target' => '_blank' ]) . '</li>';
37 31 }
38 32 ?>
39 33 <?php
40 34 if(!empty( $user->userInfo->social_in )) {
41   - echo '<li>'.Html::a(Html::img('/images/ico-in.png'), $user->userInfo->social_in, ['target' => '_blank']).'</li>';
  35 + echo '<li>' . Html::a(Html::img('/images/ico-in.png'), $user->userInfo->social_in, [ 'target' => '_blank' ]) . '</li>';
42 36 }
43 37 ?>
44 38 <?php
45 39 if(!empty( $user->userInfo->social_vk )) {
46   - echo '<li>'.Html::a(Html::img('/images/ico-vk.png'), $user->userInfo->social_vk, ['target' => '_blank']).'</li>';
  40 + echo '<li>' . Html::a(Html::img('/images/ico-vk.png'), $user->userInfo->social_vk, [ 'target' => '_blank' ]) . '</li>';
47 41 }
48 42 ?>
49 43 </ul>
... ... @@ -54,60 +48,62 @@
54 48 <div class="sidebarvievstxt"><?= $user->userInfo->view_count ?></div>
55 49 </li>
56 50 <li><img src="/images/sidebar-ico/ico-9.png" alt="">
57   - <div class="sidebarvievstxt"><span class="sidebar-views-txt">Статус: </span><?= (empty($user->userInfo->busy)?'Свободен':'Занят') ?>
  51 + <div class="sidebarvievstxt">
  52 + <span class="sidebar-views-txt">Статус: </span><?= ( empty( $user->userInfo->busy ) ? 'Свободен' : 'Занят' ) ?>
58 53 </div>
59 54 </li>
60 55 <li><img src="/images/sidebar-ico/ico-2.png" alt="">
61 56 <div class="sidebarvievstxt">
62   - <span class="sidebar-views-txt">На сайте: </span>1г. 8 мес.
  57 + <span class="sidebar-views-txt">На сайте: </span><?= $user->liveTime ?>
63 58 </div>
64 59 </li>
65 60 <li><img src="/images/sidebar-ico/ico-3.png" alt="">
66   - <div class="sidebarvievstxt"><span class="sidebar-views-txt">Последний визит:<br></span>2 дня назад
  61 + <div class="sidebarvievstxt"><span class="sidebar-views-txt">Последний визит:<br></span><?= $user->lastVisit ?>
67 62 </div>
68 63 </li>
69 64 </ul>
70   - <a href="#" class="tender-see-profile style">Посмотреть профиль</a>
  65 + <?= Html::a('Посмотреть профиль', $user->link, [ 'class' => 'tender-see-profile style' ]) ?>
71 66 </div>
72 67 </div>
73 68 </div>
74 69 </div>
75 70 <div class="tender-offer-proj-block-right-wr">
76 71 <div class="tender-offer-proj-block-right">
77   - <div class="tender-offer-proj-min-blocks"><span>2000 грн</span></div>
78   - <div class="tender-offer-proj-min-blocks"><span>3 ДНЯ</span></div>
  72 + <div class="tender-offer-proj-min-blocks">
  73 + <span><?= $model->budget_from . '-' . $model->budget_to . ' ' . $model->currency->label ?></span>
  74 + </div>
  75 + <div class="tender-offer-proj-min-blocks">
  76 + <span><?= $model->term_from . '-' . $model->term_to ?> ДНЯ</span></div>
79 77 </div>
80 78 <div class="tender-offer-proj-block-left">
81 79 <div class="search-worker-blocks-title-wr">
82   - <div class="search-worker-blocks-title-title">Петер Цумтор</div>
  80 + <div class="search-worker-blocks-title-title"><?= $user->name ?></div>
83 81 <div class="rating-new">
84 82 <!--оценка-->
85   - <input type="hidden" class="val" value="4"/>
  83 + <input type="hidden" class="val" value="<?= $user->userInfo->rating ?>"/>
86 84 </div>
87   - <a href="#" class="link-to-comm">30 отзывов</a>
  85 + <?= Html::a(count($user->comments). ' отзывов', $user->getLink('review'), ['class' => 'link-to-comm']) ?>
88 86 </div>
89 87 <div class="tender-offer-proj-txt">
90   - <p>1.1 Строительная площадка расположена по адресу: г. Киев.</p>
91   - <p>1.2 Существующий объект представляет собой помещение общей площадью ориентировочно – 140 м2.</p>
92   - <p>1.3. Цель проекта состоит в проведении внутренних общестроительных и отделочных работ.</p>
93   - <p>1.4. При разработке методов строительства и выборе материалов, используемых в настоящем проекте, необходимо учитывать климатические условия, характерные для г. Киева.</p>
94   - <p>1.5. Требования к проектированию и производству работ определяются следующими документами:</p>
95   - <p>- Техническим заданием.</p>
96   - <p>- Строительными нормами и правилами.</p>
97   - <p>Все проектные решения и все разделы рабочего проекта должны быть согласованы с Заказчиком в объеме, необходимом для последующей сдачи инженерных систем и коммуникаций.</p>
  88 + <?= $model->text ?>
98 89 </div>
99 90 <ul class="download-list-files">
100   - <li>
101   - <span></span><a href="#" class="download-link-file">КП.doc</a><a href="#" class="download-link">Скачать</a>
102   - </li>
103   - <li>
104   - <span></span><a href="#" class="download-link-file">Резюме.txt</a><a href="#" class="download-link">Скачать</a>
105   - </li>
  91 + <?php
  92 + foreach($model->getFilesList() as $file) {
  93 + ?>
  94 + <li>
  95 + <span></span>
  96 + <?= Html::a($file->name, $file->dir, ['class' => 'download-link-file']) ?>
  97 + <?= Html::a('Скачать', $file->dir, ['class' => 'download-link', 'download' => 'download']) ?>
  98 + </li>
  99 + <?php
  100 + }
  101 + ?>
106 102 </ul>
107 103 </div>
108 104 <div class="tender-more-buttons-wr">
109   - <a class="get-project-new" href="#">Портфолио</a>
110   - <a class="get-list-new" href="#">Конаткты</a>
  105 + <?= Html::a('Портфолио', $user->getLink('portfolio'), ['class' => 'get-project-new']) ?>
  106 + <?= Html::a('Контакты', $user->link, ['class' => 'get-list-new']) ?>
111 107 </div>
112 108  
113 109 </div>
... ...
common/modules/comment/widgets/views/list-project-comment.php
... ... @@ -5,7 +5,7 @@
5 5 ?>
6 6 <div class="box-wr">
7 7 <div class="box-all">
8   - <div class="tender-offer-proj-title-all style">Предложения проектантов</div>
  8 + <div class="tender-offer-proj-title-all style">Предложения проектантов (<?=$dataProvider->getTotalCount()?>)</div>
9 9 <div class="tender-offer-proj-blocks-wr style">
10 10 <?php
11 11 echo \yii\widgets\ListView::widget([
... ...
frontend/views/search/project.php
... ... @@ -75,7 +75,7 @@
75 75 'options' => [ 'class' => 'blocks-check-list' ],
76 76 ])
77 77 ->label("<span></span>{$model->getAttributeLabel('contractual')}", ['class' => ''])
78   - ->checkbox([ 'uncheck' => NULL ], false) ?>
  78 + ->checkbox([ ], false) ?>
79 79 <?= $form->field($model, 'payment', [ 'template' => "{input}\n{error}" ])
80 80 ->checkboxList($payments, [
81 81 'item' => function($index, $label, $name, $checked, $value) {
... ...