From 236a608c8a3acd7aa3cd3f4d96d5fe0e4a85babb Mon Sep 17 00:00:00 2001 From: Yarik Date: Tue, 17 May 2016 17:45:45 +0300 Subject: [PATCH] test --- common/models/User.php | 33 ++++++++++++++++++++++++++++++++- frontend/views/accounts/_portfolio_form.php | 3 +-- frontend/views/layouts/main.php | 29 ++++++++++++++++++----------- 3 files changed, 51 insertions(+), 14 deletions(-) diff --git a/common/models/User.php b/common/models/User.php index 03e3154..460b3df 100755 --- a/common/models/User.php +++ b/common/models/User.php @@ -101,7 +101,7 @@ { return [ [ - ['firstname'], + [ 'firstname' ], 'required', ], [ @@ -839,11 +839,42 @@ ->scalar(); } + public function getNewMessagesCount() + { + $chats = Chat::find() + ->select([ 'chat_id' ]) + ->where([ + 'or', + [ 'from_user' => $this->id ], + [ 'to_user' => $this->id ], + ]) + ->column(); + return Message::find()->select(['chat_id'])->distinct()->where(['chat_id' => $chats, 'status' => Message::NEW_MESSAGE])->andWhere(['not', ['user_id' => $this->id]])->count(); + } + public function getCommentProjects() { return $this->hasMany(CommentProject::className(), [ 'user_id' => 'id' ]); } + public function getCommentProjectsActive() + { + return $this->getCommentProjects() + ->where([ + 'between', + 'state', + CommentProject::STATE_NEW, + CommentProject::STATE_PERFORMER, + ]) + ->andWhere([ + 'status' => [ + CommentProject::STATUS_ACTIVE, + CommentProject::STATUS_ANONYMOUS, + CommentProject::STATUS_PERSONAL, + ], + ]); + } + public function getChat($user_id) { return Chat::find() diff --git a/frontend/views/accounts/_portfolio_form.php b/frontend/views/accounts/_portfolio_form.php index aa6f015..9a2be2f 100644 --- a/frontend/views/accounts/_portfolio_form.php +++ b/frontend/views/accounts/_portfolio_form.php @@ -288,12 +288,11 @@ $form->end(); $.post( "/accounts/gallery-cover", {gallery_id : gallery_id}, function(data) { - if(!($('#cover_old_img').val().length) && !($('#portfolio-cover').val().length)) + if(data.length && !($('#cover_old_img').val().length) && !($('#portfolio-cover').val().length)) { $('#portfolio-cover').val(data); var newimg = document.createElement("img"); newimg.setAttribute("src", data); - $('#cover_img_block .admin-avatar-pattern').append(newimg); } } diff --git a/frontend/views/layouts/main.php b/frontend/views/layouts/main.php index 023f632..f9f21a1 100755 --- a/frontend/views/layouts/main.php +++ b/frontend/views/layouts/main.php @@ -3,6 +3,7 @@ /* @var $this \yii\web\View */ /* @var $content string */ + use common\modules\comment\models\CommentProject; use yii\helpers\Html; use yii\helpers\Url; use yii\widgets\Menu; @@ -141,7 +142,7 @@
-
+ @@ -168,11 +169,11 @@ 'items' => [ [ 'url' => [ '/projects' ], - 'template' => '' . count(\Yii::$app->user->identity->commentProjects) . '', + 'template' => '' . count(\Yii::$app->user->identity->commentProjectsActive) . '', ], [ 'url' => [ 'chat/list' ], - 'template' => '' . \Yii::$app->user->identity->chatCount . '', + 'template' => '' . \Yii::$app->user->identity->newMessagesCount . '', ], [ 'url' => [ '/bookmarks' ], @@ -223,9 +224,9 @@ 'options' => [ 'class' => 'footer-menu', ], - 'items' => $items + 'items' => $items, ]); - unset($items); + unset( $items ); ?>
@@ -234,8 +235,11 @@ $items = [ [ 'label' => 'Рейтинг компаний', - 'url' => [ 'search/performer', 'SearchPerformerForm[type]' => 2 ], - ] + 'url' => [ + 'search/performer', + 'SearchPerformerForm[type]' => 2, + ], + ], ]; if(empty( \Yii::$app->user->id )) { array_unshift($items, [ @@ -249,7 +253,7 @@ ], 'items' => $items, ]); - unset($items); + unset( $items ); ?>