diff --git a/common/models/Project.php b/common/models/Project.php index b08e196..75fb2bd 100755 --- a/common/models/Project.php +++ b/common/models/Project.php @@ -6,8 +6,11 @@ use common\modules\comment\models\CommentProject; use common\modules\fileloader\behaviors\FileloaderBehavior; use Yii; + use yii\base\ModelEvent; + use yii\behaviors\AttributeBehavior; use yii\behaviors\BlameableBehavior; use yii\behaviors\TimestampBehavior; + use yii\db\ActiveRecord; use yii\db\Expression; /** @@ -68,6 +71,33 @@ 'updatedAtAttribute' => false, 'value' => new Expression('NOW()'), ], + [ + 'class' => AttributeBehavior::className(), + 'attributes' => [ + ActiveRecord::EVENT_BEFORE_INSERT => 'total_budget', + ActiveRecord::EVENT_BEFORE_UPDATE => 'total_budget', + ], + 'value' => function($event) { + /** + * @var ModelEvent $event + * @var Project $sender + */ + $total_budget = 0; + $sender = $event->sender; + if($sender->budget > 0) { + $currencies = Currency::find() + ->select([ + 'rate', + 'currency_id', + ]) + ->asArray() + ->indexBy('currency_id') + ->column(); + $total_budget = $sender->budget * $currencies[$sender->budget_currency]; + } + return $total_budget; + }, + ], 'slug' => [ 'class' => 'common\behaviors\Slug', 'in_attribute' => 'name', @@ -129,7 +159,6 @@ [ 'name', 'link', - 'budget', 'city', 'street', 'house', @@ -138,6 +167,14 @@ 'max' => 255, ], [ + [ + 'budget', + ], + 'number', + 'skipOnEmpty' => true, + 'min' => 0, + ], + [ [ 'view_count' ], 'default', 'value' => 0, diff --git a/common/models/TenderSearch.php b/common/models/TenderSearch.php index 4e08e75..7c0831e 100755 --- a/common/models/TenderSearch.php +++ b/common/models/TenderSearch.php @@ -90,13 +90,13 @@ public function attributeLabels() { return [ - 'specialization' => Yii::t('app', 'specialization'), + 'specialization' => Yii::t('app', 'specialization'), 'budget_currency' => Yii::t('app', 'budget_currency'), - 'contractual' => Yii::t('app', 'contractual'), - 'city' => Yii::t('app', 'city'), - 'payment' => Yii::t('app', 'payment'), - 'budget_from' => Yii::t('app', 'budget_from'), - 'budget_to' => Yii::t('app', 'budget_to'), + 'contractual' => Yii::t('app', 'contractual'), + 'city' => Yii::t('app', 'city'), + 'payment' => Yii::t('app', 'payment'), + 'budget_from' => Yii::t('app', 'budget_from'), + 'budget_to' => Yii::t('app', 'budget_to'), ]; } @@ -120,7 +120,8 @@ { $query = Project::find() ->joinWith('projectSpecializations') - ->joinWith('projectPayments'); + ->joinWith('projectPayments') + ->joinWith('user.companyInfo'); $dataProvider = new ActiveDataProvider([ 'query' => $query, @@ -200,9 +201,32 @@ 'city' => $this->city, ]) ->andFilterWhere([ - 'like', - 'LOWER(project.name)', - mb_strtolower($this->info), + 'or', + [ + 'like', + 'LOWER(project.name)', + mb_strtolower($this->info), + ], + [ + 'like', + 'LOWER(project.description)', + mb_strtolower($this->info), + ], + [ + 'like', + 'LOWER("user".firstname)', + mb_strtolower($this->info), + ], + [ + 'like', + 'LOWER("user".lastname)', + mb_strtolower($this->info), + ], + [ + 'like', + 'LOWER(company_info.name)', + mb_strtolower($this->info), + ], ]) ->andWhere([ 'project_payment.payment_id' => $this->payment, -- libgit2 0.21.4