Commit 236a608c8a3acd7aa3cd3f4d96d5fe0e4a85babb

Authored by Yarik
1 parent e82beebc

test

common/models/User.php
... ... @@ -101,7 +101,7 @@
101 101 {
102 102 return [
103 103 [
104   - ['firstname'],
  104 + [ 'firstname' ],
105 105 'required',
106 106 ],
107 107 [
... ... @@ -839,11 +839,42 @@
839 839 ->scalar();
840 840 }
841 841  
  842 + public function getNewMessagesCount()
  843 + {
  844 + $chats = Chat::find()
  845 + ->select([ 'chat_id' ])
  846 + ->where([
  847 + 'or',
  848 + [ 'from_user' => $this->id ],
  849 + [ 'to_user' => $this->id ],
  850 + ])
  851 + ->column();
  852 + return Message::find()->select(['chat_id'])->distinct()->where(['chat_id' => $chats, 'status' => Message::NEW_MESSAGE])->andWhere(['not', ['user_id' => $this->id]])->count();
  853 + }
  854 +
842 855 public function getCommentProjects()
843 856 {
844 857 return $this->hasMany(CommentProject::className(), [ 'user_id' => 'id' ]);
845 858 }
846 859  
  860 + public function getCommentProjectsActive()
  861 + {
  862 + return $this->getCommentProjects()
  863 + ->where([
  864 + 'between',
  865 + 'state',
  866 + CommentProject::STATE_NEW,
  867 + CommentProject::STATE_PERFORMER,
  868 + ])
  869 + ->andWhere([
  870 + 'status' => [
  871 + CommentProject::STATUS_ACTIVE,
  872 + CommentProject::STATUS_ANONYMOUS,
  873 + CommentProject::STATUS_PERSONAL,
  874 + ],
  875 + ]);
  876 + }
  877 +
847 878 public function getChat($user_id)
848 879 {
849 880 return Chat::find()
... ...
frontend/views/accounts/_portfolio_form.php
... ... @@ -288,12 +288,11 @@ $form->end();
288 288 $.post(
289 289 "/accounts/gallery-cover", {gallery_id : gallery_id}, function(data)
290 290 {
291   - if(!($('#cover_old_img').val().length) && !($('#portfolio-cover').val().length))
  291 + if(data.length && !($('#cover_old_img').val().length) && !($('#portfolio-cover').val().length))
292 292 {
293 293 $('#portfolio-cover').val(data);
294 294 var newimg = document.createElement("img");
295 295 newimg.setAttribute("src", data);
296   -
297 296 $('#cover_img_block .admin-avatar-pattern').append(newimg);
298 297 }
299 298 }
... ...
frontend/views/layouts/main.php
... ... @@ -3,6 +3,7 @@
3 3 /* @var $this \yii\web\View */
4 4 /* @var $content string */
5 5  
  6 + use common\modules\comment\models\CommentProject;
6 7 use yii\helpers\Html;
7 8 use yii\helpers\Url;
8 9 use yii\widgets\Menu;
... ... @@ -141,7 +142,7 @@
141 142 </ul>
142 143  
143 144 <div class="search-main-menu">
144   - <form action="<?=Url::to(['search/common'])?>" method="get">
  145 + <form action="<?= Url::to([ 'search/common' ]) ?>" method="get">
145 146 <input value="" name="query" type="text"/>
146 147 <input type="hidden" value="1" name="action"/>
147 148 <button type="submit" value=""></button>
... ... @@ -168,11 +169,11 @@
168 169 'items' => [
169 170 [
170 171 'url' => [ '/projects' ],
171   - 'template' => '<a href="{url}" class="main-menu-icons-home"><span>' . count(\Yii::$app->user->identity->commentProjects) . '</span></a>',
  172 + 'template' => '<a href="{url}" class="main-menu-icons-home"><span>' . count(\Yii::$app->user->identity->commentProjectsActive) . '</span></a>',
172 173 ],
173 174 [
174 175 'url' => [ 'chat/list' ],
175   - 'template' => '<a href="{url}" class="main-menu-icons-edit"><span>' . \Yii::$app->user->identity->chatCount . '</span></a>',
  176 + 'template' => '<a href="{url}" class="main-menu-icons-edit"><span>' . \Yii::$app->user->identity->newMessagesCount . '</span></a>',
176 177 ],
177 178 [
178 179 'url' => [ '/bookmarks' ],
... ... @@ -223,9 +224,9 @@
223 224 'options' => [
224 225 'class' => 'footer-menu',
225 226 ],
226   - 'items' => $items
  227 + 'items' => $items,
227 228 ]);
228   - unset($items);
  229 + unset( $items );
229 230 ?>
230 231 </div>
231 232  
... ... @@ -234,8 +235,11 @@
234 235 $items = [
235 236 [
236 237 'label' => 'Рейтинг компаний',
237   - 'url' => [ 'search/performer', 'SearchPerformerForm[type]' => 2 ],
238   - ]
  238 + 'url' => [
  239 + 'search/performer',
  240 + 'SearchPerformerForm[type]' => 2,
  241 + ],
  242 + ],
239 243 ];
240 244 if(empty( \Yii::$app->user->id )) {
241 245 array_unshift($items, [
... ... @@ -249,7 +253,7 @@
249 253 ],
250 254 'items' => $items,
251 255 ]);
252   - unset($items);
  256 + unset( $items );
253 257 ?>
254 258 <div class="footer-menu-project">
255 259 <?php
... ... @@ -284,7 +288,10 @@
284 288 $items = [
285 289 [
286 290 'label' => 'Рейтинг компаний',
287   - 'url' => [ 'search/performer', 'SearchPerformerForm[type]' => 2 ],
  291 + 'url' => [
  292 + 'search/performer',
  293 + 'SearchPerformerForm[type]' => 2,
  294 + ],
288 295 ],
289 296 ];
290 297 if(empty( \Yii::$app->user->id )) {
... ... @@ -297,9 +304,9 @@
297 304 'options' => [
298 305 'class' => 'footer-menu',
299 306 ],
300   - 'items' => $items
  307 + 'items' => $items,
301 308 ]);
302   - unset($items);
  309 + unset( $items );
303 310 ?>
304 311 <div class="footer-menu-project-two">
305 312 <?php
... ...