public function unreadQueryThreads($assignment)
 {
     $unreadThreads = [];
     if ($threads = Thread::where('subject', 'LIKE', '%query-' . $assignment->id . '%')->get()) {
         foreach ($threads as $thread) {
             if ($thread->isUnread(Authorizer::getResourceOwnerId())) {
                 array_push($unreadThreads, $thread->subject);
             }
         }
     }
     return $unreadThreads;
 }
 public function createNewThread()
 {
     if (Thread::where('subject', Input::get('subject'))->first() == null) {
         $thread = Thread::create(['subject' => Input::get('subject')]);
         Participant::create(['thread_id' => $thread->id, 'user_id' => Authorizer::getResourceOwnerId(), 'last_read' => new Carbon()]);
         $thread->addParticipants([Input::get('participant_id')]);
         return $thread;
     }
     return Thread::where('subject', Input::get('subject'))->first()->get();
 }
示例#3
0
 /**
  * Retrieves a specific innovation with its related data
  * @param $id
  * @param ConversationRepository $conversationRepository
  * @return \Illuminate\View\View
  */
 public function show($id, ConversationRepository $conversationRepository)
 {
     $innovation = $this->repo->retrieve($id);
     $check_chat = $conversationRepository->chatExists($id);
     $currentUserId = Auth::user()->id;
     $chatWithInnovator = $conversationRepository->checkChatWithInnovator($id);
     $mother = User::where('id', '=', $innovation->moderator_id)->first();
     $users = User::where('userCategory', '=', 3)->get();
     $investors = User::where('userCategory', '=', 2)->get();
     // All threads that user is participating in
     $threads = Thread::forUser($currentUserId)->where('innovation_id', '=', $id)->get();
     $threads_count = $threads->count();
     if (\Auth::user()->isInvestor()) {
         if (Thread::where('innovation_id', '=', $id)->where('user_id', '=', \Auth::user()->id)->exists() == true) {
             $thread = Thread::where('innovation_id', '=', $id)->where('user_id', '=', \Auth::user()->id)->first();
         }
     }
     if (\Auth::user()->isMother()) {
         if (Thread::where('innovation_id', '=', $id)->where('user_id', '=', \Auth::user()->id)->exists() == true) {
             $thread_mother = Thread::where('innovation_id', '=', $id)->where('user_id', '=', \Auth::user()->id)->first();
         } else {
             $thread_mother = null;
         }
     }
     $funds = $this->repo->getPortfolio($id);
     $totalNeeded = $this->repo->getInnovationFund($id);
     return view('innovation.show', compact('totalNeeded', 'funds', 'thread_mother', 'thread', 'investors', 'mother', 'users', 'chatWithInnovator', 'innovation', 'id', 'check_chat', 'message', 'threads', 'threads_count', 'currentUserId'));
 }
示例#4
0
 /**
  * Update a thread
  * @param $id
  * @param MessagesRequest $request
  * @param $unique_id
  * @return \Illuminate\Http\JsonResponse|\Illuminate\Http\RedirectResponse|\Illuminate\Routing\Redirector
  */
 public function update($id, MessagesRequest $request, $unique_id)
 {
     $input = $request;
     try {
         $thread = Thread::where('innovation_id', '=', $id)->where('unique_id', '=', $unique_id)->first();
     } catch (ModelNotFoundException $e) {
         Session::flash('error_message', 'The thread with ID: ' . $id . ' was not found.');
         return redirect('messages');
     }
     $thread->activateAllParticipants();
     // Message
     $message = Message::create(['thread_id' => $thread->id, 'user_id' => Auth::user()->id, 'body' => htmlentities($input->message)]);
     // Add replier as a participant
     $participant = Participant::firstOrCreate(['thread_id' => $thread->id, 'user_id' => Auth::user()->id]);
     $participant->last_read = new Carbon();
     $participant->save();
     // Recipients
     if (Input::has('recipients')) {
         $thread->addParticipants(Input::get('recipients'));
     }
     $this->oooPushIt($message);
     return response()->json(['id' => $message->id]);
 }