<?php use yii\bootstrap\Nav; use yii\bootstrap\NavBar; use yii\helpers\Url; use app\models\Notification; use yii\helpers\Html; use yii\widgets\ActiveForm; use kartik\icons\Icon; $events = Notification::getUserNotifications('event'); $journals = Notification::getUserNotifications('journal'); $messages = Notification::getUserNotifications('message'); $global = Notification::getGlobalNotifications(); //var_dump($journals); die(); $number_new_events = count($events); $number_new_journals = count($journals); $number_messages = count($messages); $number_global = Notification::notificationCount($global, true); ?> <!-- Main Header --> <header class="main-header"> <!-- Header Navbar --> <nav class="navbar navbar-static-top" role="navigation"> <!-- Logo --> <a href="<?php echo Yii::$app->homeUrl; ?> " class="logo"> <!-- mini logo for sidebar mini 50x50 pixels --> <span class="logo-mini"><b>K</b>C</span>
/** * API GET Route to get viable User notifications and notification statuses for current user. * * @param User $user * * @return Response::json * * @todo I'm sure this can be simplified... */ public function getNotifications(User $user) { if (Auth::user()->id !== $user->id) { return Response::json($this->growlMessage("You do not have permission to view this user's notification settings", "error"), 401); } //Retrieve all valid user notifications as associative array (event => description) $validNotifications = Notification::getUserNotifications(); //Filter out event keys $events = array_keys($validNotifications); //Retreive all User Events for the current user $currentNotifications = Notification::select('event')->where('user_id', '=', $user->id)->whereIn('event', $events)->get(); //Filter out event names from selected notifications $currentNotifications = $currentNotifications->toArray(); $selectedEvents = array(); foreach ($currentNotifications as $notification) { array_push($selectedEvents, $notification['event']); } //Build array of notifications and their selected status $toReturn = array(); foreach ($validNotifications as $event => $description) { $notification = array(); $notification['event'] = $event; $notification['description'] = $description; $notification['selected'] = in_array($event, $selectedEvents) ? true : false; array_push($toReturn, $notification); } return Response::json($toReturn); }
<?php use yii\bootstrap\Nav; use yii\bootstrap\NavBar; use yii\helpers\Url; use app\models\Notification; use yii\helpers\Html; use yii\widgets\ActiveForm; $events = Notification::getUserNotifications('event'); $journals = Notification::getUserNotifications('journal'); $messages = app\models\Contact::getMessages(); $global = Notification::getGlobalNotifications(); //var_dump($journals); die(); $number_new_events = count($events); $number_new_journals = count($journals); $number_messages = count($messages); $number_global = Notification::notificationCount($global, true); ?> <!-- Main Header --> <header class="main-header"> <!-- Header Navbar --> <nav class="navbar navbar-static-top" role="navigation"> <!-- Logo --> <a href="<?php echo Yii::$app->homeUrl; ?> " class="logo"> <!-- mini logo for sidebar mini 50x50 pixels --> <span class="logo-mini"><b>K</b>C</span> <!-- logo for regular state and mobile devices -->