Browse Source

Notification widget fix zero count

master
Egorka 6 years ago
parent
commit
d115294956
  1. 5
      backend/widgets/NotificationCountWidget.php
  2. 2
      backend/widgets/views/notification-count.php
  3. 1
      common/modules/banners/widgets/BannerWidget.php

5
backend/widgets/NotificationCountWidget.php

@ -14,12 +14,15 @@ class NotificationCountWidget extends Widget
public function run() public function run()
{ {
$count = 0; $count = 0;
if (isset(\Yii::$app->params['notifications'])) {
foreach ( \Yii::$app->params['notifications'] as $notification ) { foreach ( \Yii::$app->params['notifications'] as $notification ) {
$count += $notification['count']; $count += $notification['count'];
} }
}
return $this->render('notification-count', [ return $this->render('notification-count', [
'notifications' => \Yii::$app->params['notifications'], 'notifications' => isset(\Yii::$app->params['notifications']) ? \Yii::$app->params['notifications'] : [],
'count' => $count, 'count' => $count,
]); ]);
} }

2
backend/widgets/views/notification-count.php

@ -17,7 +17,9 @@ use yii\helpers\Url;
<li class="dropdown notifications-menu"> <li class="dropdown notifications-menu">
<a href="#" class="dropdown-toggle" data-toggle="dropdown"> <a href="#" class="dropdown-toggle" data-toggle="dropdown">
<i class="fa fa-bell-o"></i> <i class="fa fa-bell-o"></i>
<?php if ($count > 0): ?>
<span class="label label-warning"><?= $count ?></span> <span class="label label-warning"><?= $count ?></span>
<?php endif; ?>
</a> </a>
<ul class="dropdown-menu"> <ul class="dropdown-menu">
<li class="header"><?= Yii::t('main', 'You have {count} notifications', ['count' => $count]) ?></li> <li class="header"><?= Yii::t('main', 'You have {count} notifications', ['count' => $count]) ?></li>

1
common/modules/banners/widgets/BannerWidget.php

@ -8,7 +8,6 @@ namespace common\modules\banners\widgets;
use common\modules\banners\entities\Banner; use common\modules\banners\entities\Banner;
use common\modules\banners\entities\BannerPlace; use common\modules\banners\entities\BannerPlace;
use common\modules\banners\helpers\BannerHelper;
use yii\base\Widget; use yii\base\Widget;
class BannerWidget extends Widget class BannerWidget extends Widget

Loading…
Cancel
Save