/** * Insert reaction in DB (eiter from a Facebook post or Tweet) * @param string $type * @param object $mention * @param integer $id * @param string $answer * * @return Reaction */ public function insertReaction($type, $mention, $id, $answer = null) { $reaction = new Reaction(); $reaction->publishment_id = $id; if ($answer != null) { $reaction->user_id = Auth::user()->id; } if ($type == 'twitter') { if ($mention['user']['id_str'] != Configuration::twitterId()) { $reaction->user_id = $mention['user']['id_str']; } $reaction->screen_name = $mention['user']['screen_name']; $reaction->tweet_id = $mention['id_str']; $reaction->tweet_reply_id = $mention['in_reply_to_status_id_str']; $reaction->message = $mention['text']; $reaction->post_date = changeDateFormat($mention['created_at']); } else { $reaction->fb_post_id = $mention->id; if ($answer == null) { $reaction->screen_name = $mention->from->name; $reaction->message = $mention->message; $reaction->post_date = changeFbDateFormat($mention->created_time); } else { $reaction->message = $answer; $reaction->post_date = Carbon::now(); } } $reaction->save(); return $reaction; }
/** * Insert inner comment in DB * @param integer $id * @param Request $request * @param integer $messageId * @param object $reply * @return void */ private function insertInnerComment($id, $request, $messageId, $reply) { $innerComment = new InnerComment(); if ($this->reaction->where('fb_post_id', $messageId)->exists()) { $innerComment->reaction_id = $this->reaction->where('fb_post_id', $messageId)->first()->id; } $innerComment->user_id = Auth::user()->id; $innerComment->fb_post_id = $reply->id; $innerComment->fb_reply_id = $messageId; $innerComment->message = $request->input('answer'); $innerComment->post_date = Carbon::now(); $innerComment->save(); }
private function getComments() { $collection = collect(); $messages = $this->message->where('fb_post_id', '!=', '')->get(); $answers = $this->answer->where('fb_post_id', '!=', '')->get(); $reactions = $this->reaction->where('fb_post_id', '!=', '')->get(); foreach ($messages as $key => $message) { $collection->push($message); } foreach ($answers as $key => $answer) { $collection->push($answer); } foreach ($reactions as $key => $reaction) { $collection->push($reaction); } return $collection; }
/** * Get latest comment date (Facebook) * @return datetime */ function latestCommentDate() { $messageId = $reactionId = false; if (Message::where('fb_reply_id', '!=', '')->exists()) { $messageId = Message::where('fb_reply_id', '!=', '')->orderBy('post_date', 'DESC')->first()->post_date; } if (Reaction::where('fb_post_id', '!=', '')->exists()) { $reactionId = Reaction::where('fb_post_id', '!=', '')->orderBy('post_date', 'DESC')->first()->post_date; } return max($messageId, $reactionId); }