From be662d1f23f553ff03a40b893bc9d9b4afc46c16 Mon Sep 17 00:00:00 2001 From: Yarik Date: Tue, 15 Mar 2016 12:48:17 +0200 Subject: [PATCH] test --- common/models/Message.php | 2 -- common/models/TenderSearch.php | 7 +++++++ common/models/User.php | 85 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++--- common/modules/comment/models/CommentProject.php | 114 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++--------------------------------- common/modules/comment/widgets/views/_project_comment_view.php | 68 ++++++++++++++++++++++++++++++++------------------------------------ common/modules/comment/widgets/views/list-project-comment.php | 2 +- frontend/views/search/project.php | 2 +- 7 files changed, 204 insertions(+), 76 deletions(-) diff --git a/common/models/Message.php b/common/models/Message.php index 5a008da..d60c5e8 100644 --- a/common/models/Message.php +++ b/common/models/Message.php @@ -89,8 +89,6 @@ class Message extends \yii\db\ActiveRecord } - - public function isMy(){ if($this->user_id == \Yii::$app->user->id){ return true; diff --git a/common/models/TenderSearch.php b/common/models/TenderSearch.php index 67941a5..df6cb04 100644 --- a/common/models/TenderSearch.php +++ b/common/models/TenderSearch.php @@ -66,6 +66,13 @@ ], [ [ + 'contractual', + ], + 'default', + 'value' => 1, + ], + [ + [ 'budget_currency', ], 'default', diff --git a/common/models/User.php b/common/models/User.php index a632bf1..8e960dc 100755 --- a/common/models/User.php +++ b/common/models/User.php @@ -9,6 +9,7 @@ use yii\behaviors\TimestampBehavior; use yii\db\ActiveQuery; use yii\db\ActiveRecord; + use yii\helpers\Url; use yii\rbac\ManagerInterface; use yii\rbac\Role; use yii\web\IdentityInterface; @@ -28,6 +29,32 @@ * @property string $password write-only password * @property string $type * @property UserInfo $userInfo + * @property string $userName + * @property array[] $roles + * @property CompanyInfo $companyInfo + * @property array[] $phones + * @property array[] $site + * @property string $address + * @property string $liveTime + * @property Payment[] $payments + * @property integer[] $paymentInput + * @property Specialization[] $specializations + * @property integer[] $specializationInput + * @property Blog[] $blog + * @property Job[] $jobs + * @property Job $currentJob + * @property Portfolio[] $portfolios + * @property Project[] $projects + * @property Team[] $teams + * @property Vacancy[] $vacancies + * @property Gallery[] $galleries + * @property UserInfo|CompanyInfo $owner + * @property string $name + * @property Comment[] $comments + * @property Rating[] $commentRating + * @property int $ratingPG + * @property string $lastVisit + * @property string $link */ class User extends ActiveRecord implements IdentityInterface, UserRbacInterface { @@ -51,8 +78,6 @@ return '{{%user}}'; } - - /** * @inheritdoc */ @@ -60,7 +85,7 @@ { return [ [ - 'class' => 'common\behaviors\ShowImage', + 'class' => 'common\behaviors\ShowImage', ], TimestampBehavior::className(), ]; @@ -560,11 +585,21 @@ ->inverseOf('user'); } + /** + * Return all user's galleries + * + * @return ActiveQuery + */ public function getGalleries() { return $this->hasMany(Gallery::className(), [ 'user_id' => 'id' ]); } + /** + * Return company info or user info according to user type + * + * @return ActiveQuery + */ public function getOwner() { if($this->type == 2) { @@ -574,6 +609,11 @@ } } + /** + * Return company name or user firstname and lastname according to user type + * + * @return string + */ public function getName() { if($this->type == 2) { @@ -584,6 +624,8 @@ } /** + * Return all comments to user + * * @return ActiveQuery */ public function getComments() @@ -597,6 +639,8 @@ } /** + * Return all ratings to user + * * @return ActiveQuery */ public function getCommentRating() @@ -608,6 +652,13 @@ ]); } + /** + * Return user's rating
+ * Available only for PostgreSQL + * + * @return int + * @throws InvalidConfigException + */ public function getRatingPG() { if(\Yii::$app->db->driverName != 'pgsql') { @@ -622,6 +673,15 @@ ->scalar(); } + /** + * Recalculate rating and write it to db. + * + * Only for PostgreSQL + * + * @see \common\models\User::getRatingPG() + * + * @throws InvalidConfigException + */ public function updateRating() { if($rating = $this->getRatingPG()) { @@ -630,4 +690,23 @@ } } + public function getLastVisit() + { + return \Yii::$app->formatter->asRelativeTime($this->userInfo->date_visit); + } + + /** + * Return link to user personal page according to user type + * + * @return string + */ + public function getLink($page = 'common') + { + if($this->type == 2) { + return Url::to(['company/'.$page, 'company_id' => $this->id]); + } else { + return Url::to(['performer/'.$page, 'performer_id' => $this->id]); + } + } + } diff --git a/common/modules/comment/models/CommentProject.php b/common/modules/comment/models/CommentProject.php index 7cc3793..635bb3d 100644 --- a/common/modules/comment/models/CommentProject.php +++ b/common/modules/comment/models/CommentProject.php @@ -3,26 +3,29 @@ use common\models\Currency; use common\models\File; + use common\models\User; use yii\db\ActiveQuery; + use yii\db\ActiveRecord; use yii\web\UploadedFile; /** * Class Comment - * @property bool $guestComment - * @property integer $comment_id - * @property string $text - * @property int $user_id - * @property int $status - * @property string $date_add - * @property string $date_update - * @property string $date_delete - * @property string $model - * @property int $model_id - * @property string $files - * @property float $budget_from - * @property float $budget_to - * @property int $term_from - * @property int $term_to + * @property bool $guestComment + * @property integer $comment_id + * @property string $text + * @property int $user_id + * @property int $status + * @property string $date_add + * @property string $date_update + * @property string $date_delete + * @property string $model + * @property int $model_id + * @property string $files + * @property float $budget_from + * @property float $budget_to + * @property int $term_from + * @property int $term_to + * @property Currency $currency * @package common\modules\comment\models */ class CommentProject extends \yii\db\ActiveRecord @@ -42,6 +45,7 @@ * @var bool */ public $guestComment = false; + public $file; public function rules() @@ -84,7 +88,7 @@ [ [ 'budget_currency' ], 'exist', - 'targetClass' => Currency::className(), + 'targetClass' => Currency::className(), 'targetAttribute' => 'currency_id', ], [ @@ -118,7 +122,7 @@ 'term_to', 'file', ], - self::SCENARIO_GUEST => [ + self::SCENARIO_GUEST => [ ], ]; @@ -150,11 +154,11 @@ public function attributeLabels() { return [ - 'text' => \Yii::t('app', 'Текст ответа'), + 'text' => \Yii::t('app', 'Текст ответа'), 'budget_from' => \Yii::t('app', 'от'), - 'budget_to' => \Yii::t('app', 'до'), - 'term_from' => \Yii::t('app', 'от'), - 'term_to' => \Yii::t('app', 'до'), + 'budget_to' => \Yii::t('app', 'до'), + 'term_from' => \Yii::t('app', 'от'), + 'term_to' => \Yii::t('app', 'до'), ]; } @@ -163,10 +167,10 @@ return $this->guestComment; } -// public function setGuestComment($value) -// { -// $this->guestComment = $value; -// } + // public function setGuestComment($value) + // { + // $this->guestComment = $value; + // } /** * @param string $model @@ -181,27 +185,28 @@ 'comment_project.model' => $model, 'comment_project.model_id' => $model_id, 'comment_project.status' => 1, - ]); + ]) + ->with('currency', 'user', 'user.userInfo', 'user.companyInfo', 'user.comments'); } public function postComment() { if($this->checkCreate()) { - if(!empty(\Yii::$app->request->post($this->formName())['anonymous'])) { + if(!empty( \Yii::$app->request->post($this->formName())[ 'anonymous' ] )) { $this->status = self::STATUS_ANONYMOUS; } $this->file = UploadedFile::getInstances($this, 'file'); - if(!empty($this->file)) { - $file_id = []; - if(is_array($this->file)){ - foreach($this->file as $file){ - if($file instanceof UploadedFile){ + if(!empty( $this->file )) { + $file_id = [ ]; + if(is_array($this->file)) { + foreach($this->file as $file) { + if($file instanceof UploadedFile) { $file_model = new File(); $file_id[] = $file_model->saveFile($file); } } } else { - if($this->file instanceof UploadedFile){ + if($this->file instanceof UploadedFile) { $file_model = new File(); $file_id[] = $file_model->saveFile($this->file); } @@ -325,4 +330,47 @@ // } } + /** + * @return ActiveQuery + */ + public function getCurrency() + { + return $this->hasOne(Currency::className(), [ 'currency_id' => 'budget_currency' ]); + } + + /** + * @return File[] + */ + public function getFilesList() + { + $files = json_decode($this->files); + if(!empty( $files )) { + return File::findAll($files); + } else { + return [ ]; + } + } + + /** + * @return ActiveRecord + * @throws \TypeError + */ + public function getOwner() + { + $model = new $this->model(); + if($model instanceof ActiveRecord) { + return $model->findOne($this->model_id); + } else { + throw new \TypeError('Model must extends Active Record Class'); + } + } + + /** + * @return User + */ + public function getUser() + { + return $this->hasOne(User::className(), ['id' => 'user_id']); + } + } diff --git a/common/modules/comment/widgets/views/_project_comment_view.php b/common/modules/comment/widgets/views/_project_comment_view.php index 8e3c04f..1f68b07 100644 --- a/common/modules/comment/widgets/views/_project_comment_view.php +++ b/common/modules/comment/widgets/views/_project_comment_view.php @@ -10,13 +10,7 @@ * @var \yii\widgets\ListView $widget current ListView instance * @var User $user */ - $user = NULL; - if(!empty( $model->user_id )) { - $user = User::find() - ->where([ 'id' => $model->user_id ]) - ->with('userInfo') - ->one(); - } + $user = $model->user; ?>
@@ -28,22 +22,22 @@
    userInfo->social_fb )) { - echo '
  • '.Html::a(Html::img('/images/ico-fb.png'), $user->userInfo->social_fb, ['target' => '_blank']).'
  • '; + echo '
  • ' . Html::a(Html::img('/images/ico-fb.png'), $user->userInfo->social_fb, [ 'target' => '_blank' ]) . '
  • '; } ?> userInfo->social_t )) { - echo '
  • '.Html::a(Html::img('/images/ico-tw.png'), $user->userInfo->social_t, ['target' => '_blank']).'
  • '; + echo '
  • ' . Html::a(Html::img('/images/ico-tw.png'), $user->userInfo->social_t, [ 'target' => '_blank' ]) . '
  • '; } ?> userInfo->social_in )) { - echo '
  • '.Html::a(Html::img('/images/ico-in.png'), $user->userInfo->social_in, ['target' => '_blank']).'
  • '; + echo '
  • ' . Html::a(Html::img('/images/ico-in.png'), $user->userInfo->social_in, [ 'target' => '_blank' ]) . '
  • '; } ?> userInfo->social_vk )) { - echo '
  • '.Html::a(Html::img('/images/ico-vk.png'), $user->userInfo->social_vk, ['target' => '_blank']).'
  • '; + echo '
  • ' . Html::a(Html::img('/images/ico-vk.png'), $user->userInfo->social_vk, [ 'target' => '_blank' ]) . '
  • '; } ?>
@@ -54,60 +48,62 @@
userInfo->view_count ?>
  • -
    Статус: userInfo->busy)?'Свободен':'Занят') ?> +
    + Статус: userInfo->busy ) ? 'Свободен' : 'Занят' ) ?>
  • - На сайте: 1г. 8 мес. + На сайте: liveTime ?>
  • -
    Последний визит:
    2 дня назад +
    Последний визит:
    lastVisit ?>
  • - Посмотреть профиль + link, [ 'class' => 'tender-see-profile style' ]) ?>
    -
    2000 грн
    -
    3 ДНЯ
    +
    + budget_from . '-' . $model->budget_to . ' ' . $model->currency->label ?> +
    +
    + term_from . '-' . $model->term_to ?> ДНЯ
    -
    Петер Цумтор
    +
    name ?>
    - +
    - 30 отзывов + comments). ' отзывов', $user->getLink('review'), ['class' => 'link-to-comm']) ?>
    -

    1.1 Строительная площадка расположена по адресу: г. Киев.

    -

    1.2 Существующий объект представляет собой помещение общей площадью ориентировочно – 140 м2.

    -

    1.3. Цель проекта состоит в проведении внутренних общестроительных и отделочных работ.

    -

    1.4. При разработке методов строительства и выборе материалов, используемых в настоящем проекте, необходимо учитывать климатические условия, характерные для г. Киева.

    -

    1.5. Требования к проектированию и производству работ определяются следующими документами:

    -

    - Техническим заданием.

    -

    - Строительными нормами и правилами.

    -

    Все проектные решения и все разделы рабочего проекта должны быть согласованы с Заказчиком в объеме, необходимом для последующей сдачи инженерных систем и коммуникаций.

    + text ?>
    - Портфолио - Конаткты + getLink('portfolio'), ['class' => 'get-project-new']) ?> + link, ['class' => 'get-list-new']) ?>
    diff --git a/common/modules/comment/widgets/views/list-project-comment.php b/common/modules/comment/widgets/views/list-project-comment.php index f592675..ce045e5 100644 --- a/common/modules/comment/widgets/views/list-project-comment.php +++ b/common/modules/comment/widgets/views/list-project-comment.php @@ -5,7 +5,7 @@ ?>
    -
    Предложения проектантов
    +
    Предложения проектантов (getTotalCount()?>)
    [ 'class' => 'blocks-check-list' ], ]) ->label("{$model->getAttributeLabel('contractual')}", ['class' => '']) - ->checkbox([ 'uncheck' => NULL ], false) ?> + ->checkbox([ ], false) ?> field($model, 'payment', [ 'template' => "{input}\n{error}" ]) ->checkboxList($payments, [ 'item' => function($index, $label, $name, $checked, $value) { -- libgit2 0.21.4