Inheritance: extends Illuminate\Database\Eloquent\Model
 /**
  * Update stats in DB (like count & retweet count)
  *
  * @return void
  */
 public function updateTwitterStats()
 {
     $tweets = $this->twitterContent->fetchTwitterStats();
     foreach ($tweets as $key => $tweet) {
         if ($this->publishment->where('tweet_id', $tweet['id_str'])->exists()) {
             $publishment = $this->publishment->where('tweet_id', $tweet['id_str'])->first();
             $publishment->twitter_likes = $tweet['favorite_count'];
             $publishment->twitter_retweets = $tweet['retweet_count'];
             $publishment->save();
         }
     }
     $this->log->updateLog('publishments');
 }
 /**
  * Searches trough cases
  *
  * @param  Request $request
  *
  * @return bool|Builder
  */
 private function searchByKeywords(Request $request)
 {
     $keywords = $request->input('keywords');
     $contacts = $this->contact->where('name', 'LIKE', '%' . $keywords . '%')->get();
     if (is_numeric($keywords)) {
         $query = $this->case->where('id', $keywords);
     } else {
         if (strpos($keywords, self::TYPE_TWEET) !== false || strpos($keywords, 'twitter') !== false) {
             $query = $this->case->where('origin', 'Twitter mention')->orWhere('origin', 'Twitter direct');
         } else {
             if (strpos($keywords, 'fb') !== false || strpos($keywords, 'facebook') !== false || strpos($keywords, 'post') !== false) {
                 $query = $this->case->where('origin', 'Facebook post');
             }
         }
     }
     if (strtotime($keywords)) {
         $today = date("Y-m-d", strtotime("+0 hours", strtotime($keywords)));
         $tomorrow = date("Y-m-d", strtotime("+1 day", strtotime($keywords)));
         $query = $this->case->whereHas('messages', function ($q) use($today, $tomorrow) {
             $q->orderBy('id', 'ASC')->where('post_date', '>=', $today)->where('post_date', '<', $tomorrow);
         });
     }
     foreach ($contacts as $key => $contact) {
         $query = $contact->cases();
     }
     if (!isset($query)) {
         return false;
     }
     return $query;
 }
 /**
  * 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');
             }
         }
     }
 }
Beispiel #4
0
 /**
  * Check if contact exists, if not create a new user
  * @param  string  $type
  * @param  string  $id
  * @return collection
  */
 public function getContact($type, $id)
 {
     if ($type == 'twitter' && Contact::where('twitter_id', $id)->exists()) {
         return Contact::findByTwitterId($id);
     } else {
         if ($type == 'facebook' && Contact::where('facebook_id', $id)->exists()) {
             return Contact::findByFbId($id);
         }
     }
     return new Contact();
 }