Exemplo n.º 1
0
 protected function readAll()
 {
     $user = \Auth::user();
     $this->notificationRepository->setAllNotifyRead($user->stu_id);
     $this->responseCode = 200;
     $this->responseData['status'] = "success";
     return $this->send_response();
 }
Exemplo n.º 2
0
 public function sendNotification($sender, $course, $content, $type)
 {
     $students = $course->students;
     $todayWeek = substr(Carbon::now()->format("l"), 0, 3);
     $courseDay = explode(",", $course->time1);
     $courseTime = explode(",", $course->time2);
     if (($index = array_search($todayWeek, $courseDay)) !== false) {
         $courseTime = $courseTime[$index];
         $courseStartTime = $this->course_start_map[min(str_split($courseTime))];
         $courseLatestTime = $this->course_end_map[max(str_split($courseTime))];
         if (Carbon::now()->between(Carbon::createFromFormat("H:i", $courseStartTime), Carbon::createFromFormat("H:i", $courseLatestTime))) {
             foreach ($students as $student) {
                 $sender_info = empty($sender->stu_id) ? 'Cyinf' : $sender->stu_id;
                 $notification = $this->notificationRepository->create($student->stu_id, $sender_info, $course->id, $content, $type);
                 if ($student->FB_conn && $this->checkConfig($student, $type)) {
                     $this->sendFBNotification($student, $notification);
                 }
             }
         } else {
             throw new \Exception("目前非上課時間");
         }
     } else {
         throw new \Exception("目前非上課時間");
     }
 }
 public function testGetNotificationById()
 {
     $user = $this->users->random();
     $stu_id = $user->stu_id;
     // default case
     $result = $this->repository->getLatest10Notification($stu_id);
     $this->assertEquals(10, $result->count());
     $first_id = $result->sortByDesc('id')->first()->id;
     $this->assertEquals($result->first()->id, $first_id);
     // id = 10 range = 5
     $result = $this->repository->getNotificationBack($stu_id, 10, 5);
     $this->assertEquals(5, $result->count());
     $first_id = $result->sortBy('id')->first()->id;
     $this->assertEquals($result->first()->id, $first_id);
     // id = 20 range = -7
     $result = $this->repository->getNotificationFront($stu_id, 20, 7);
     $this->assertEquals(7, $result->count());
     $first_id = $result->sortByDesc('id')->first()->id;
     $this->assertEquals($result->first()->id, $first_id);
 }