Inheritance: extends Illuminate\Database\Eloquent\Model
Esempio n. 1
0
 /**
  * Handles media if sent with tweet
  * @param  integer $messageId
  * @param  string $message
  * @param  string $type
  * @return void
  */
 public function handleMedia($messageId, $message, $type = null)
 {
     $msg = Message::find($messageId);
     if ($type == 'innerComment') {
         $msg = InnerComment::find($messageId);
     }
     if (($type == 'twitter' || $type == 'twitter_reaction') && !empty($message['extended_entities']) && !empty($message['extended_entities']['media'])) {
         foreach ($message['extended_entities']['media'] as $key => $picture) {
             $media = new Media();
             if ($type == 'twitter_reaction') {
                 $media->reaction_id = $messageId;
             } else {
                 $media->message_id = $messageId;
             }
             $media->url = $picture['media_url'];
             $media->save();
         }
     } else {
         if (($type == 'twitter' || $type == 'twitter_reaction') && !empty($message['entities']) && !empty($message['entities']['media'])) {
             foreach ($message['entities']['media'] as $key => $picture) {
                 $media = new Media();
                 if ($type == 'twitter_reaction') {
                     $media->reaction_id = $messageId;
                 } else {
                     $media->message_id = $messageId;
                 }
                 $media->url = $picture['media_url'];
                 $media->save();
             }
         } else {
             if (($type == 'facebook_comment' || $type == 'facebook_innerComment' || $type == 'facebook_reactionInner') && isset($message->attachment->media->image->src)) {
                 $media = new Media();
                 if ($type == 'facebook_comment') {
                     $media->message_id = $messageId;
                 } else {
                     if ($type == 'facebook_innerComment') {
                         $media->inner_comment_id = $messageId;
                     } else {
                         $media->reaction_id = $messageId;
                     }
                 }
                 $media->url = $message->attachment->media->image->src;
                 $media->save();
             } else {
                 if ($type == 'facebook' && isset($message->full_picture)) {
                     $media = new Media();
                     $media->message_id = $messageId;
                     $media->url = $message->full_picture;
                     $media->save();
                 }
             }
         }
     }
 }
Esempio n. 2
0
 public function scopeLatestInnerCommentDate($query)
 {
     $messageId = $reactionId = Carbon::today();
     if (InnerComment::where('reaction_id', '0')->exists()) {
         $messageId = InnerComment::orderBy('post_date', 'DESC')->where('reaction_id', '0')->first()->post_date;
     }
     if (InnerComment::where('reaction_id', '!=', '0')->exists()) {
         $reactionId = InnerComment::orderBy('post_date', 'DESC')->where('reaction_id', '!=', '0')->first()->post_date;
     }
     return max($messageId, $reactionId);
 }
 /**
  * Gets all posts on Facebook
  * @return view
  */
 public function collectPosts()
 {
     $newestPost = $this->message->getNewestPostDate();
     $posts = $this->facebookContent->fetchPosts($newestPost);
     foreach ($posts->data as $key => $post) {
         $contact = $this->contact->createContact('facebook', $post);
         $case = $this->case->createCase('facebook_post', $post, $contact);
         $message = new Message();
         $message->contact_id = $contact->id;
         $message->fb_post_id = $post->id;
         $message->case_id = $case->id;
         if (isset($post->message)) {
             $message->message = $post->message;
         }
         $message->post_date = changeFbDateFormat($post->created_time);
         $message->save();
         $this->media->handleMedia($message->id, $post, 'facebook');
     }
     $newestComment = latestCommentDate();
     $newestInnerComment = $this->innerComment->LatestInnerCommentDate();
     $this->fetchComments($newestComment);
     $this->fetchInnerComments($newestInnerComment);
 }
 /**
  * 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();
 }
 /**
  * Fetch inner comments of facebook
  * @param  datetime $newest
  * @return void
  */
 private function fetchInnerComments($newest)
 {
     $messages = $this->getComments();
     foreach ($messages as $key => $message) {
         $comments = $this->facebookContent->fetchInnerComments($newest, $message['fb_post_id']);
         if ($comments == null) {
             continue;
         }
         foreach ($comments->data as $key => $comment) {
             if ($comment->from->id != config('crm-launcher.facebook_credentials.facebook_page_id') && new Datetime(changeFbDateFormat($comment->created_time)) > new Datetime($newest)) {
                 if (!$this->contact->findByFbId($comment->from->id)->exists()) {
                     $contact = $this->contact->createContact('facebook', $comment);
                 } else {
                     $contact = $this->contact->where('facebook_id', $comment->from->id)->first();
                 }
                 $innerComment = new InnerComment();
                 $innerComment->fb_reply_id = $message['fb_post_id'];
                 $innerComment->post_date = changeFbDateFormat($comment->created_time);
                 $innerComment->contact_id = $contact->id;
                 if (is_a($message, "Rubenwouters\\CrmLauncher\\Models\\Answer")) {
                     $innerComment->answer_id = $message['id'];
                 } else {
                     if (is_a($message, "Rubenwouters\\CrmLauncher\\Models\\Reaction")) {
                         $innerComment->reaction_id = $message['id'];
                     } else {
                         $innerComment->message_id = $message['id'];
                     }
                 }
                 $innerComment->fb_post_id = $comment->id;
                 $innerComment->message = $comment->message;
                 $innerComment->save();
                 $this->media->handleMedia($innerComment->id, $comment, 'facebook_innerComment');
             }
         }
     }
 }