Beispiel #1
0
 /**
  * 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;
 }
 /**
  * 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');
             }
         }
     }
 }