コード例 #1
0
 public function postRead()
 {
     if (!Auth::check()) {
         return Response::json(array('status' => 'error', 'message' => trans(CLF_LANG_MESSAGE . 'require_signin')), 500);
     }
     $data = post();
     $valid['ids'] = isset($data['ids']) ? str_replace(',', '', $data['ids']) : '';
     $rules = ['ids' => 'required|numeric'];
     $validation = Validator::make($valid, $rules);
     if ($validation->fails()) {
         return Response::json(response_message(400, $validation->messages()->first()), 400);
     }
     $user = Auth::getUser();
     $ntfs = Notification::has_read($user, $data['ids']);
     return Response::json(response_message(200, $ntfs));
 }
コード例 #2
0
 public static function addThread($sender_id, $receiver_id, $message)
 {
     // Get max thread_id
     $thread_id = self::max('thread_id') + 1;
     if (empty($thread_id) || empty($sender_id) || empty($receiver_id) || empty($message)) {
         return;
     }
     DB::beginTransaction();
     try {
         // Insert sender to recipient table
         if (!MessageRecipients::addSender($thread_id, $sender_id)) {
             throw new \Exception('Can\'t sent message from user');
         }
         // Insert receiver to
         if (!MessageRecipients::addReceiver($thread_id, $receiver_id)) {
             throw new \Exception('Can\'t sent message to receiver');
         }
         // Insert new message thread
         $insert = new self();
         $insert->thread_id = $thread_id;
         $insert->sender_id = $sender_id;
         $insert->message = $message;
         $result = $insert->save();
         if (!$result) {
             throw new \Exception('Can\'t sent message');
         }
         // Add notifications
         $notify = Notification::add($receiver_id, $result->id, $sender_id, 'messages', 'new_message');
         if (!$notify) {
             throw new \Exception('Can\'t add message notification');
         }
     } catch (Exception $ex) {
         DB::rollback();
         throw $ex;
     }
     DB::commit();
 }