/**
  * Returns a List of all notifications for the session user
  */
 public function actionIndex()
 {
     $pageSize = 10;
     $notifications = [];
     $filterForm = new FilterForm();
     $filterForm->initFilter();
     $filterForm->load(Yii::$app->request->get());
     $query = Notification::findGrouped();
     $query->andWhere(['user_id' => Yii::$app->user->id]);
     if ($filterForm->isExcludeFilter()) {
         $query->andFilterWhere(['not in', 'class', $filterForm->getExcludeClassFilter()]);
     } else {
         if ($filterForm->isActive()) {
             $query->andFilterWhere(['in', 'class', $filterForm->getIncludeClassFilter()]);
         } else {
             return $this->render('index', ['notificationEntries' => [], 'filterForm' => $filterForm, 'pagination' => null, 'notifications' => $notifications]);
         }
     }
     $countQuery = clone $query;
     $pagination = new \yii\data\Pagination(['totalCount' => $countQuery->count(), 'pageSize' => $pageSize]);
     //Reset pagegination after new filter set
     if (Yii::$app->request->post()) {
         $pagination->setPage(0);
     }
     $query->offset($pagination->offset)->limit($pagination->limit);
     foreach ($query->all() as $notificationRecord) {
         $notifications[] = $notificationRecord->getClass();
     }
     return $this->render('index', array('notifications' => $notifications, 'filterForm' => $filterForm, 'pagination' => $pagination));
 }
 /**
  * Returns a JSON which contains
  * - Number of new / unread notification
  * - Notification Output for new HTML5 Notifications
  *
  * @return string JSON String
  */
 public static function getUpdates()
 {
     $user = Yii::$app->user->getIdentity();
     $query = Notification::findGrouped()->andWhere(['seen' => 0])->orWhere(['IS', 'seen', new \yii\db\Expression('NULL')])->andWhere(['user_id' => $user->id]);
     $update['newNotifications'] = $query->count();
     $query->andWhere(['desktop_notified' => 0]);
     $update['notifications'] = array();
     foreach ($query->all() as $notification) {
         if (Yii::$app->getModule('notification')->settings->user()->get("enable_html5_desktop_notifications", Yii::$app->getModule('notification')->settings->get('enable_html5_desktop_notifications'))) {
             $update['notifications'][] = $notification->getClass()->render(BaseNotification::OUTPUT_TEXT);
         }
         $notification->desktop_notified = 1;
         $notification->update();
     }
     return $update;
 }
Exemple #3
0
 /**
  * Returns all notifications which should be send by e-mail to the given user
  * in the given interval
  *
  * @see \humhub\modules\content\components\MailUpdateSender
  * @param User $user
  * @param int $interval
  * @return components\BaseNotification[]
  */
 public function getMailNotifications(User $user, $interval)
 {
     $notifications = [];
     $receive_email_notifications = Yii::$app->getModule('notification')->settings->contentContainer($user)->get('receive_email_notifications');
     if ($receive_email_notifications === null) {
         // Use Default
         $receive_email_notifications = Yii::$app->getModule('notification')->settings->get('receive_email_notifications');
     }
     // Never receive notifications
     if ($receive_email_notifications == User::RECEIVE_EMAIL_NEVER) {
         return [];
     }
     // We are in hourly mode and user wants daily
     if ($interval == MailUpdateSender::INTERVAL_HOURY && $receive_email_notifications == User::RECEIVE_EMAIL_DAILY_SUMMARY) {
         return [];
     }
     // We are in daily mode and user dont wants daily reports
     if ($interval == MailUpdateSender::INTERVAL_DAILY && $receive_email_notifications != User::RECEIVE_EMAIL_DAILY_SUMMARY) {
         return [];
     }
     // User wants only when offline and is online
     if ($interval == MailUpdateSender::INTERVAL_HOURY) {
         $isOnline = count($user->httpSessions) > 0;
         if ($receive_email_notifications == User::RECEIVE_EMAIL_WHEN_OFFLINE && $isOnline) {
             return [];
         }
     }
     $query = Notification::findGrouped()->andWhere(['user_id' => $user->id])->andWhere(['!=', 'seen', 1])->andWhere(['!=', 'emailed', 1]);
     foreach ($query->all() as $notification) {
         $notifications[] = $notification->getClass();
         // Mark notifications as mailed
         $notification->emailed = 1;
         $notification->save();
     }
     return $notifications;
 }