/** * Update stats in DB * * @return void */ public function updateFbStats() { $posts = $this->publishment->orderBy('id', 'DESC')->where('fb_post_id', '!=', '')->get(); foreach ($posts as $key => $post) { $object = $this->facebookContent->fetchFbStats($post); if (isset($object->shares)) { $post->facebook_shares = $object->shares->count; } $post->facebook_likes = $object->likes->summary->total_count; $post->save(); } }
/** * Return all facebook posts (merges messages & publishments) * @return [type] [description] */ private function getPosts() { $collection = collect(); $messages = $this->message->with(['caseOverview' => function ($query) { $query->where('status', '!=', '2')->where('origin', 'Facebook post'); }])->where('fb_post_id', '!=', '')->where('fb_reply_id', '')->where('fb_private_id', '')->get(); $publishments = $this->publishment->facebookPosts(); foreach ($messages as $key => $message) { $collection->push($message); } foreach ($publishments as $key => $publishment) { $collection->push($publishment); } return $collection; }
/** * Insert publishment in DB * * @param string $type * @param array $publication * @param string $content */ private function insertPublishment($type, $publication, $content) { if ($this->publishment->double($content)->exists()) { $publishment = $this->publishment->double($content)->first(); } else { $publishment = new Publishment(); } $publishment->user_id = Auth::user()->id; $publishment->content = $content; if ($type == self::TYPE_TWITTER) { $publishment->tweet_id = $publication['id_str']; $publishment->post_date = changeDateFormat($publication['created_at']); } else { if ($type == self::TYPE_FACEBOOK) { $publishment->fb_post_id = $publication->id; $publishment->post_date = Carbon::now(); } } $publishment->save(); }