Commit 1a3b0a63a6c6e0aed2c6612c216f476881cf2ac9
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 | 6 | use common\modules\comment\models\CommentProject; |
| 7 | 7 | use common\modules\fileloader\behaviors\FileloaderBehavior; |
| 8 | 8 | use Yii; |
| 9 | + use yii\base\ModelEvent; | |
| 10 | + use yii\behaviors\AttributeBehavior; | |
| 9 | 11 | use yii\behaviors\BlameableBehavior; |
| 10 | 12 | use yii\behaviors\TimestampBehavior; |
| 13 | + use yii\db\ActiveRecord; | |
| 11 | 14 | use yii\db\Expression; |
| 12 | 15 | |
| 13 | 16 | /** |
| ... | ... | @@ -68,6 +71,33 @@ |
| 68 | 71 | 'updatedAtAttribute' => false, |
| 69 | 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 | 101 | 'slug' => [ |
| 72 | 102 | 'class' => 'common\behaviors\Slug', |
| 73 | 103 | 'in_attribute' => 'name', |
| ... | ... | @@ -129,7 +159,6 @@ |
| 129 | 159 | [ |
| 130 | 160 | 'name', |
| 131 | 161 | 'link', |
| 132 | - 'budget', | |
| 133 | 162 | 'city', |
| 134 | 163 | 'street', |
| 135 | 164 | 'house', |
| ... | ... | @@ -138,6 +167,14 @@ |
| 138 | 167 | 'max' => 255, |
| 139 | 168 | ], |
| 140 | 169 | [ |
| 170 | + [ | |
| 171 | + 'budget', | |
| 172 | + ], | |
| 173 | + 'number', | |
| 174 | + 'skipOnEmpty' => true, | |
| 175 | + 'min' => 0, | |
| 176 | + ], | |
| 177 | + [ | |
| 141 | 178 | [ 'view_count' ], |
| 142 | 179 | 'default', |
| 143 | 180 | 'value' => 0, | ... | ... |
common/models/TenderSearch.php
| ... | ... | @@ -90,13 +90,13 @@ |
| 90 | 90 | public function attributeLabels() |
| 91 | 91 | { |
| 92 | 92 | return [ |
| 93 | - 'specialization' => Yii::t('app', 'specialization'), | |
| 93 | + 'specialization' => Yii::t('app', 'specialization'), | |
| 94 | 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 | 120 | { |
| 121 | 121 | $query = Project::find() |
| 122 | 122 | ->joinWith('projectSpecializations') |
| 123 | - ->joinWith('projectPayments'); | |
| 123 | + ->joinWith('projectPayments') | |
| 124 | + ->joinWith('user.companyInfo'); | |
| 124 | 125 | |
| 125 | 126 | $dataProvider = new ActiveDataProvider([ |
| 126 | 127 | 'query' => $query, |
| ... | ... | @@ -200,9 +201,32 @@ |
| 200 | 201 | 'city' => $this->city, |
| 201 | 202 | ]) |
| 202 | 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 | 231 | ->andWhere([ |
| 208 | 232 | 'project_payment.payment_id' => $this->payment, | ... | ... |