예제 #1
0
 public static function customCreate(CreateConversationRequest $request)
 {
     $conv = new Conversation();
     $conv->Title = $request->Title;
     // if nothing specified in the request
     if (!$request->has('user_id')) {
         // if we are not even logged ( happen while seeding base)
         if (!\Auth::check()) {
             $conv->user_id = User::first()->id;
         } else {
             $conv->user_id = \Auth::id();
         }
     }
     // if Pending status is specified we take it, if not default value will be applied (false)
     if (!$request->has('Pending')) {
         $conv->Pending = $request->Pending;
     }
     $conv->created_at = Carbon::now();
     $conv->save();
     // When conversation is settled the Thread can be created
     $thread = new Thread();
     $thread->user_id = $conv->user_id;
     $thread->Content = $request->Content;
     $thread->conversation_id = $conv->id;
     $thread->created_at = Carbon::now();
     $thread->Pending = $conv->Pending;
     $thread->save();
     return true;
 }
 /**
  * Display the specified resource.
  *
  * @param  int  $id
  * @return \Illuminate\Http\Response
  */
 public function show($id)
 {
     $conversation = \App\Conversation::with(['messages' => function ($query) {
         $query->with('user')->orderBy('created_at', 'DESC');
     }])->findOrFail($id);
     return $conversation;
 }
예제 #3
0
 public function createNewConversasion()
 {
     if (\Request::ajax()) {
         $conv = new Conversation();
         $conv->user_one = Input::get('user-two');
         $conv->user_two = Input::get('user-one');
         $conv->save();
         $msg = new ChatMessages();
         $msg->conversation_id = $conv->id;
         $msg->sender_id = $conv->user_one;
         $msg->message = Input::get('message');
         $msg->read = false;
         $msg->save();
         echo json_encode(array('conversation' => $conv));
     }
 }
예제 #4
0
 public function run()
 {
     Model::unguard();
     DB::table('conversations')->delete();
     for ($i = 0; $i < 80; $i++) {
         $request = new CreateConversationRequest();
         $request->Title = "Conversation {$i} level contain title";
         $request->Content = "Thread from conversation {$i}";
         $request->Pending = false;
         Conversation::customCreate($request);
     }
     /* roughly equivalent to the following instructions without selection the first user available
     		// Take the first ID in the table
     		$user=User::first()->id;
     		// We create the conversation
     		$aConv=Conversation::create(['Title'=> "Demonstration: Conversation level contain title",
     							  'user_id'=> $user,
     							  'Pending'=>false]);
     							  
     		// We create the first Thread of the Conversation		
     		Thread::create(['Content'=> "Demonstration: Thread level contain content",
     							  'user_id'=> $user,
     							  'Pending'=>false,
     							  'conversation_id'=>$aConv->id]);
     		*/
 }
예제 #5
0
 /**
  * Execute the job.
  *
  * @return void
  */
 public function handle()
 {
     // Someone triggered the conversation without mentioning the target user
     if (is_null($this->tweet['in_reply_to_user_id'])) {
         return;
     }
     $conversation = Conversation::create(['trigger_tweet_id' => $this->tweet['id_str'], 'sniper_user_id' => $this->tweet['user']['id_str'], 'sniper_user_screen_name' => $this->tweet['user']['screen_name'], 'sniper_user_utc_offset' => $this->tweet['user']['utc_offset'], 'target_user_id' => $this->tweet['in_reply_to_user_id_str'], 'target_user_screen_name' => $this->tweet['in_reply_to_screen_name'], 'story_id' => Story::random()->id]);
     $this->dispatch(new AnnoyTheTarget($conversation));
 }
예제 #6
0
 public function handle(Request $request, $id)
 {
     $conversation = Conversation::where(['from' => Auth::user()->id, 'to' => $id])->orWhere(['to' => Auth::user()->id, 'from' => $id])->first();
     if (count($conversation) == 0) {
         $conversation = Conversation::create(['from' => Auth::user()->id, 'to' => $id]);
     }
     if ($request->get('content') != "" && Message::create(['from' => Auth::user()->id, 'to' => $id, 'content' => htmlentities($request->get('content')), 'conversation_id' => $conversation->id])) {
         $conversation->updated_at = date("Y-m-d H:i:s");
         $conversation->save();
         return json_encode(['error' => 0, 'message' => htmlentities($request->get('content')), 'reciever' => $id, 'avatar_url' => Auth::user()->getProfilePictureUrl(), 'type' => 0]);
     }
     return json_encode(['error' => 1, 'message' => 'Can not send message!', 'type' => -1]);
 }
예제 #7
0
 /**
  * Execute the job.
  *
  * @return void
  */
 public function handle()
 {
     // If not a reply, do nothing.
     if (is_null($this->tweet['in_reply_to_status_id'])) {
         return;
     }
     // Find the Trigger Tweet's ID
     $triggerTweetId = $this->twitter->find($this->tweet['in_reply_to_status_id'])['in_reply_to_status_id'];
     // If no trigger tweet found, do nothing.
     if (is_null($triggerTweetId)) {
         return;
     }
     // Close the conversation
     echo 'Closing conversation with Trigger Tweet ID: ' . $triggerTweetId;
     Conversation::closeByTriggerTweetId($triggerTweetId, $this->tweet);
 }
예제 #8
0
 /**
  * Execute the console command.
  *
  * @return mixed
  */
 public function handle()
 {
     $this->info('Beginning at: ' . Carbon::now() . PHP_EOL);
     $conversations = Conversation::open()->get();
     $this->info('Total open conversations: ' . $conversations->count() . PHP_EOL);
     foreach ($conversations as $conversation) {
         $this->info('Working for conversation with ID: ' . $conversation->id . PHP_EOL);
         $closingTweet = $this->findClosingTweet($conversation);
         if (is_null($closingTweet)) {
             $this->info('Annoying conversation with ID: ' . $conversation->id . PHP_EOL);
             $this->dispatch(new AnnoyTheTarget($conversation));
         } else {
             $this->info('Closing conversation with ID: ' . $conversation->id . PHP_EOL);
             $conversation->close($closingTweet);
         }
     }
 }
 public function store(Request $request, $id)
 {
     //
     //
     $conversation = Conversation::find($id);
     $conversation->touch();
     $input = Request::all();
     $input['published_at'] = Carbon::now();
     $input['author_id'] = Auth::id();
     $input['conversation_id'] = $id;
     Message::create($input);
     $to_users = ConversationUser::where('conversation_id', $id)->where('user_id', '!=', Auth::id())->get(['user_id']);
     foreach ($to_users as $_user) {
         $user = User::find($_user->user_id);
         $user->newNotification()->withType('message')->withSender(Auth::id())->withSubject($conversation->title)->withBody($input['body'])->regarding($conversation)->deliver();
     }
     return redirect('/messages/' . $id);
 }
예제 #10
0
 public function getShowProject($projectid, $userid)
 {
     $project = Project::find($projectid);
     $project_status = \DB::table('project')->where('project.id', '=', $projectid)->leftJoin('project_status', 'status_id', '=', 'project_status.id')->leftJoin('project_budget', 'project_budget.id', '=', 'project.project_budget')->get(array('status_sign', 'budget'));
     $user = User::find($project->freelancer_id);
     $exists = \DB::table('bids')->where("project_id", "=", $projectid)->where("user_id", "=", $userid)->count();
     $bids = \DB::table('bids')->leftJoin('users', 'users.id', '=', 'bids.user_id')->where("project_id", "=", $projectid)->get();
     $conversationsExists = array();
     foreach ($bids as $bid) {
         $results = Conversation::where(function ($query) use($bid) {
             $query->where('user_one', '=', $bid->user_id)->orWhere('user_two', '=', $bid->user_id);
         })->where(function ($query) use($project) {
             $query->where('user_one', '=', $project->user_id)->orWhere('user_two', '=', $project->user_id);
         })->count();
         array_push($conversationsExists, $results);
     }
     $bid = Bid::where('project_id', '=', $projectid)->where('user_id', '=', $project->freelancer_id)->get();
     $milesstone = ProjectMilestones::where('project_id', '=', $projectid)->get();
     $files = \DB::table('project_files')->where('project_id', '=', $projectid)->get();
     return view('showproject')->with('project', $project)->with('exists', $exists)->with('bids', $bids)->with('project_status', $project_status)->with('freelancer', $user)->with('bid', $bid)->with('milesstone', $milesstone)->with('files', $files)->with('conversationsExists', $conversationsExists);
 }
예제 #11
0
파일: routes.php 프로젝트: yves01/dashboard
|
*/
Route::get('/', function () {
    return view('messages');
});
Route::get('home', 'DashboardController@index');
Route::get('messages', function (Request $request) {
    // we recover all the data sent by the ajax request
    $keys = $request::all();
    $query = "";
    // test of the query parameter
    if ($keys['query'] != "") {
        $query = Conversation::where("Title", "like", "%" . $keys['query'] . "%");
        //->skip($keys['offset']);//->get();
    } else {
        $query = Conversation::select("*");
    }
    //test of the offset parameter
    if ($keys['offset'] != 0) {
        $query = $query->take($keys['limit'])->skip($keys['offset'])->get();
    } else {
        $query = $query->get();
    }
    //else
    //{	// cannot use offset alone, so we take a limit very high
    //	$query=Conversation::select("*")->take(9999999)->skip($keys['offset'])->get();
    // we do not want so much be we still need to know how much answer we get
    //}
    $i = 0;
    $response = array();
    foreach ($query as $qry) {
예제 #12
0
 /**
  * Set messages from a specific conversation as read.
  */
 private function markReadMessages($id)
 {
     $messagesUnread = Conversation::where('id', $id)->with(['messages' => function ($query) {
         $query->where('user_id', '!=', \Auth::id())->where('read', '=', 0);
     }])->first();
     foreach ($messagesUnread->messages as $message) {
         $message->read = true;
         $message->save();
     }
 }
 public function saveConversations(ConversationRequest $request)
 {
     $patient = User::find($request->doctorID);
     $conversation = new Conversation();
     $conversation->message = $request->message;
     $conversation->doctor_id = auth()->user()->id;
     $conversation->patient_id = $patient->id;
     $conversation->report_id = $request->reportId;
     $conversation->doctor_name = $patient->name;
     $conversation->sender = auth()->user()->id;
     $conversation->save();
     return redirect()->back();
 }
 /**
  * Show the form for creating a new resource.
  *
  * @return \Illuminate\Http\Response
  */
 public static function createPrivateConversation($user1, $user2)
 {
     //
     $newPrivateConversation = new Conversation();
     $newPrivateConversation->touch();
     $newPrivateConversation->save();
     $user1relation = new ConversationUser();
     $user1relation->conversation_id = $newPrivateConversation->id;
     $user1relation->user_id = $user1;
     $user1relation->touch();
     $user1relation->save();
     $user2relation = new ConversationUser();
     $user2relation->conversation_id = $newPrivateConversation->id;
     $user2relation->user_id = $user2;
     $user2relation->touch();
     $user2relation->save();
     return $newPrivateConversation->id;
 }
예제 #15
0
 /**
  * Update the specified resource in storage.
  *
  * @param  int  $id
  * @return Response
  */
 public function update($id, Request $request)
 {
     $aConv = Conversation::findOrFail($id);
     $aThread = Thread::select("*")->where("conversation_id", '=', $id)->firstOrFail();
     if ($request->has('Content')) {
         $aConv->update($request->all());
         session()->flash('flash_message', 'Conversation updated');
     } else {
         // by definition if the conversation is validated the first thread also is
         if ($aConv->Pending == 1) {
             $aConv->Pending = 0;
             $aThread->Pending = 0;
             session()->flash('flash_message', 'Conversation is now published');
         } else {
             $aConv->Pending = 1;
             $aThread->Pending = 1;
             session()->flash('flash_message', 'Conversation is now unpublished');
         }
     }
     $aConv->save();
     $aThread->save();
     return redirect('dashboard');
 }