Example #1
0
 public function getMailUpdate(User $user, $interval)
 {
     $output = "";
     foreach (Session::find()->where(['<', 'expire', time()])->all() as $session) {
         $session->delete();
     }
     $receive_email_notifications = $user->getSetting("receive_email_notifications", 'core', Setting::Get('receive_email_notifications', 'mailing'));
     // Never receive notifications
     if ($receive_email_notifications == User::RECEIVE_EMAIL_NEVER) {
         return "";
     }
     // We are in hourly mode and user wants daily
     if ($interval == CronController::EVENT_ON_HOURLY_RUN && $receive_email_notifications == User::RECEIVE_EMAIL_DAILY_SUMMARY) {
         return "";
     }
     // We are in daily mode and user dont wants daily reports
     if ($interval == CronController::EVENT_ON_DAILY_RUN && $receive_email_notifications != User::RECEIVE_EMAIL_DAILY_SUMMARY) {
         return "";
     }
     // User wants only when offline and is online
     if ($interval == CronController::EVENT_ON_HOURLY_RUN) {
         $isOnline = count($user->httpSessions) > 0;
         if ($receive_email_notifications == User::RECEIVE_EMAIL_WHEN_OFFLINE && $isOnline) {
             return "";
         }
     }
     $query = Notification::find()->where(['user_id' => $user->id])->andWhere(['!=', 'seen', 1])->andWhere(['!=', 'emailed', 1]);
     foreach ($query->all() as $notification) {
         $output .= $notification->getClass()->render(BaseNotification::OUTPUT_MAIL);
         $notification->emailed = 1;
         $notification->save();
     }
     return $output;
 }
Example #2
0
 public function getMailUpdate(User $user, $interval)
 {
     $output = ['html' => '', 'plaintext' => ''];
     $receive_email_activities = $user->getSetting("receive_email_activities", 'core', Setting::Get('receive_email_activities', 'mailing'));
     // User never wants activity content
     if ($receive_email_activities == User::RECEIVE_EMAIL_NEVER) {
         return "";
     }
     // We are in hourly mode and user wants receive a daily summary
     if ($interval == CronController::EVENT_ON_HOURLY_RUN && $receive_email_activities == User::RECEIVE_EMAIL_DAILY_SUMMARY) {
         return "";
     }
     // We are in daily mode and user wants receive not daily
     if ($interval == CronController::EVENT_ON_DAILY_RUN && $receive_email_activities != User::RECEIVE_EMAIL_DAILY_SUMMARY) {
         return "";
     }
     // User is online and want only receive when offline
     if ($interval == CronController::EVENT_ON_HOURLY_RUN) {
         $isOnline = count($user->httpSessions) > 0;
         if ($receive_email_activities == User::RECEIVE_EMAIL_WHEN_OFFLINE && $isOnline) {
             return "";
         }
     }
     $lastMailDate = $user->last_activity_email;
     if ($lastMailDate == "" || $lastMailDate == "0000-00-00 00:00:00") {
         $lastMailDate = new \yii\db\Expression('NOW() - INTERVAL 24 HOUR');
     }
     $stream = new \humhub\modules\dashboard\components\actions\DashboardStream('stream', Yii::$app->controller);
     $stream->limit = 50;
     $stream->mode = \humhub\modules\content\components\actions\Stream::MODE_ACTIVITY;
     $stream->user = $user;
     $stream->init();
     $stream->activeQuery->andWhere(['>', 'content.created_at', $lastMailDate]);
     foreach ($stream->getWallEntries() as $wallEntry) {
         try {
             $activity = $wallEntry->content->getPolymorphicRelation();
             $output['html'] .= $activity->getActivityBaseClass()->render(BaseActivity::OUTPUT_MAIL);
             $output['plaintext'] .= $activity->getActivityBaseClass()->render(BaseActivity::OUTPUT_MAIL_PLAINTEXT);
         } catch (\yii\base\Exception $ex) {
             \Yii::error($ex->getMessage());
         }
     }
     $user->last_activity_email = new \yii\db\Expression('NOW()');
     $user->save();
     return $output;
 }