Commit 1a3b0a63a6c6e0aed2c6612c216f476881cf2ac9

Authored by Yarik
1 parent 4920d7a3

Commit

Showing 2 changed files with 72 additions and 11 deletions   Show diff stats
common/models/Project.php
@@ -6,8 +6,11 @@ @@ -6,8 +6,11 @@
6 use common\modules\comment\models\CommentProject; 6 use common\modules\comment\models\CommentProject;
7 use common\modules\fileloader\behaviors\FileloaderBehavior; 7 use common\modules\fileloader\behaviors\FileloaderBehavior;
8 use Yii; 8 use Yii;
  9 + use yii\base\ModelEvent;
  10 + use yii\behaviors\AttributeBehavior;
9 use yii\behaviors\BlameableBehavior; 11 use yii\behaviors\BlameableBehavior;
10 use yii\behaviors\TimestampBehavior; 12 use yii\behaviors\TimestampBehavior;
  13 + use yii\db\ActiveRecord;
11 use yii\db\Expression; 14 use yii\db\Expression;
12 15
13 /** 16 /**
@@ -68,6 +71,33 @@ @@ -68,6 +71,33 @@
68 'updatedAtAttribute' => false, 71 'updatedAtAttribute' => false,
69 'value' => new Expression('NOW()'), 72 'value' => new Expression('NOW()'),
70 ], 73 ],
  74 + [
  75 + 'class' => AttributeBehavior::className(),
  76 + 'attributes' => [
  77 + ActiveRecord::EVENT_BEFORE_INSERT => 'total_budget',
  78 + ActiveRecord::EVENT_BEFORE_UPDATE => 'total_budget',
  79 + ],
  80 + 'value' => function($event) {
  81 + /**
  82 + * @var ModelEvent $event
  83 + * @var Project $sender
  84 + */
  85 + $total_budget = 0;
  86 + $sender = $event->sender;
  87 + if($sender->budget > 0) {
  88 + $currencies = Currency::find()
  89 + ->select([
  90 + 'rate',
  91 + 'currency_id',
  92 + ])
  93 + ->asArray()
  94 + ->indexBy('currency_id')
  95 + ->column();
  96 + $total_budget = $sender->budget * $currencies[$sender->budget_currency];
  97 + }
  98 + return $total_budget;
  99 + },
  100 + ],
71 'slug' => [ 101 'slug' => [
72 'class' => 'common\behaviors\Slug', 102 'class' => 'common\behaviors\Slug',
73 'in_attribute' => 'name', 103 'in_attribute' => 'name',
@@ -129,7 +159,6 @@ @@ -129,7 +159,6 @@
129 [ 159 [
130 'name', 160 'name',
131 'link', 161 'link',
132 - 'budget',  
133 'city', 162 'city',
134 'street', 163 'street',
135 'house', 164 'house',
@@ -138,6 +167,14 @@ @@ -138,6 +167,14 @@
138 'max' => 255, 167 'max' => 255,
139 ], 168 ],
140 [ 169 [
  170 + [
  171 + 'budget',
  172 + ],
  173 + 'number',
  174 + 'skipOnEmpty' => true,
  175 + 'min' => 0,
  176 + ],
  177 + [
141 [ 'view_count' ], 178 [ 'view_count' ],
142 'default', 179 'default',
143 'value' => 0, 180 'value' => 0,
common/models/TenderSearch.php
@@ -90,13 +90,13 @@ @@ -90,13 +90,13 @@
90 public function attributeLabels() 90 public function attributeLabels()
91 { 91 {
92 return [ 92 return [
93 - 'specialization' => Yii::t('app', 'specialization'), 93 + 'specialization' => Yii::t('app', 'specialization'),
94 'budget_currency' => Yii::t('app', 'budget_currency'), 94 'budget_currency' => Yii::t('app', 'budget_currency'),
95 - 'contractual' => Yii::t('app', 'contractual'),  
96 - 'city' => Yii::t('app', 'city'),  
97 - 'payment' => Yii::t('app', 'payment'),  
98 - 'budget_from' => Yii::t('app', 'budget_from'),  
99 - 'budget_to' => Yii::t('app', 'budget_to'), 95 + 'contractual' => Yii::t('app', 'contractual'),
  96 + 'city' => Yii::t('app', 'city'),
  97 + 'payment' => Yii::t('app', 'payment'),
  98 + 'budget_from' => Yii::t('app', 'budget_from'),
  99 + 'budget_to' => Yii::t('app', 'budget_to'),
100 ]; 100 ];
101 } 101 }
102 102
@@ -120,7 +120,8 @@ @@ -120,7 +120,8 @@
120 { 120 {
121 $query = Project::find() 121 $query = Project::find()
122 ->joinWith('projectSpecializations') 122 ->joinWith('projectSpecializations')
123 - ->joinWith('projectPayments'); 123 + ->joinWith('projectPayments')
  124 + ->joinWith('user.companyInfo');
124 125
125 $dataProvider = new ActiveDataProvider([ 126 $dataProvider = new ActiveDataProvider([
126 'query' => $query, 127 'query' => $query,
@@ -200,9 +201,32 @@ @@ -200,9 +201,32 @@
200 'city' => $this->city, 201 'city' => $this->city,
201 ]) 202 ])
202 ->andFilterWhere([ 203 ->andFilterWhere([
203 - 'like',  
204 - 'LOWER(project.name)',  
205 - mb_strtolower($this->info), 204 + 'or',
  205 + [
  206 + 'like',
  207 + 'LOWER(project.name)',
  208 + mb_strtolower($this->info),
  209 + ],
  210 + [
  211 + 'like',
  212 + 'LOWER(project.description)',
  213 + mb_strtolower($this->info),
  214 + ],
  215 + [
  216 + 'like',
  217 + 'LOWER("user".firstname)',
  218 + mb_strtolower($this->info),
  219 + ],
  220 + [
  221 + 'like',
  222 + 'LOWER("user".lastname)',
  223 + mb_strtolower($this->info),
  224 + ],
  225 + [
  226 + 'like',
  227 + 'LOWER(company_info.name)',
  228 + mb_strtolower($this->info),
  229 + ],
206 ]) 230 ])
207 ->andWhere([ 231 ->andWhere([
208 'project_payment.payment_id' => $this->payment, 232 'project_payment.payment_id' => $this->payment,