Exemple #1
0
 /**
  * Cleanup tables as scheduled action
  */
 public static function cleanupTablesSchedule()
 {
     // calculate date (now - 1week) for sql query
     $date = (new \DateTime('now'))->modify('-1 week')->format('Y-m-d');
     UserNotification::where('created_at', '<=', $date)->delete();
     UserLog::where('created_at', '<=', $date)->delete();
 }
Exemple #2
0
 /**
  * Get user p.m and notifications count
  * @return string
  * @throws ForbiddenException
  */
 public function actionNotifications()
 {
     // check if authed
     if (!App::$User->isAuth()) {
         throw new ForbiddenException('Auth required');
     }
     $this->setJsonHeader();
     // get user object
     $user = App::$User->identity();
     // get messages count
     $messagesCount = Message::where('target_id', '=', $user->id)->where('readed', '=', 0)->count();
     // get notifications count
     $notificationsCount = UserNotification::where('user_id', '=', $user->id)->where('readed', '=', 0)->count();
     return json_encode(['status' => 1, 'notify' => $notificationsCount, 'messages' => $messagesCount, 'summary' => $notificationsCount + $messagesCount]);
 }