Inheritance: extends Illuminate\Database\Eloquent\Model
コード例 #1
0
ファイル: Message.php プロジェクト: rubenwouters/crm-launcher
 public function getNewestMessageDate()
 {
     if (Message::where('fb_private_id', '!=', '')->exists()) {
         return Message::where('fb_private_id', '!=', '')->orderBy('post_date', 'DESC')->first()->post_date;
     }
     return 0;
 }
コード例 #2
0
ファイル: Media.php プロジェクト: rubenwouters/crm-launcher
 /**
  * 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();
                 }
             }
         }
     }
 }
コード例 #3
0
ファイル: Kernel.php プロジェクト: rubenwouters/crm-launcher
 /**
  * Define the application's command schedule.
  *
  * @param  \Illuminate\Console\Scheduling\Schedule  $schedule
  * @return void
  */
 protected function schedule(Schedule $schedule)
 {
     parent::schedule($schedule);
     $schedule->command('crm-launcher:updateCases')->everyMinute()->when(function () {
         return Message::exists();
     });
     $schedule->command('crm-launcher:activity')->everyMinute()->when(function () {
         return Message::exists();
     });
     $schedule->command('crm-launcher:updateDashboardStats')->everyFiveMinutes();
     $schedule->command('crm-launcher:updatePublishmentStats')->everyFiveMinutes();
     $schedule->command('crm-launcher::resetNotified')->daily();
 }
コード例 #4
0
 /**
  * Insert inner comment in DB
  *
  * @param  Request $request
  * @param  integer $messageId
  * @param  object $reply
  *
  * @return void
  */
 private function insertInnerComment($request, $messageId, $reply)
 {
     $innerComment = new InnerComment();
     if ($this->message->where('fb_post_id', $messageId)->exists()) {
         $message = $this->message->where('fb_post_id', $messageId)->first();
         $innerComment->message_id = $message->id;
     } else {
         $answer = $this->answer->where('fb_post_id', $messageId)->first();
         $innerComment->answer_id = $answer->id;
     }
     $innerComment->user_id = Auth::user()->id;
     $innerComment->fb_post_id = $reply->id;
     $innerComment->fb_reply_id = $messageId;
     $innerComment->message = $request->input('answer_specific');
     $innerComment->post_date = Carbon::now();
     $innerComment->save();
 }
コード例 #5
0
 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;
 }
コード例 #6
0
ファイル: helpers.php プロジェクト: rubenwouters/crm-launcher
/**
 * 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);
}
コード例 #7
0
 /**
  * Remember that a notification is sent today
  * @return void
  */
 private function toggleSentNotification()
 {
     $config = $this->config->first();
     $config->notified_today = 1;
     $config->save();
 }
コード例 #8
0
 /**
  * Get most recent id's for Twitter & Facebook
  *
  * @return void
  */
 private function initIds()
 {
     $message = new Message();
     if (isTwitterLinked()) {
         $mentionId = $this->twitterContent->newestMentionId();
         $directId = $this->twitterContent->newestDirectId();
         if ($mentionId) {
             $message->tweet_id = $mentionId;
         }
         if ($directId) {
             $message->direct_id = $directId;
         }
     }
     if (isFacebookLinked()) {
         $postId = $this->facebookContent->newestPostId();
         $conversationId = $this->facebookContent->newestConversationId();
         if ($postId) {
             $message->fb_post_id = $postId;
         }
         if ($conversationId) {
             $message->fb_private_id = $conversationId;
         }
     }
     $message->post_date = Carbon::now();
     $message->save();
     $this->log->updateLog('fetching');
 }
コード例 #9
0
 /**
  * Fetch comments on post form Facebook
  * @param  \Datetime $newest
  * @return return collection
  */
 private function fetchComments($newest)
 {
     $messages = $this->getPosts();
     foreach ($messages as $key => $message) {
         if ($message->fb_post_id != 0) {
             $comments = $this->facebookContent->fetchComments($newest, $message);
             if (!empty($comments->data)) {
                 foreach ($comments->data as $key => $comment) {
                     if ($comment->from->id != config('crm-launcher.facebook_credentials.facebook_page_id') && (!$newest || new Datetime(changeFbDateFormat($comment->created_time)) > new Datetime($newest))) {
                         if ($this->contact->FindByFbId($comment->from->id)->exists()) {
                             $contact = $this->contact->where('facebook_id', $comment->from->id)->first();
                         } else {
                             $contact = $this->contact->createContact('facebook', $comment);
                         }
                         if ($this->publishment->where('fb_post_id', $message->fb_post_id)->exists()) {
                             $id = $this->publishment->where('fb_post_id', $message->fb_post_id)->first()->id;
                             $reaction = $this->reaction->insertReaction('facebook', $comment, $id);
                             $this->media->handleMedia($reaction->id, $comment, 'facebook_reactionInner');
                         } else {
                             $msg = new Message();
                             $msg->fb_reply_id = $message->fb_post_id;
                             $msg->post_date = changeFbDateFormat($comment->created_time);
                             $msg->contact_id = $contact->id;
                             $msg->fb_post_id = $comment->id;
                             $msg->case_id = $message->case_id;
                             $msg->message = $comment->message;
                             $msg->save();
                             $this->media->handleMedia($msg->id, $comment, 'facebook_comment');
                             $this->updateCase($message->case_id, 'facebook', $comment->id);
                         }
                     }
                 }
             }
         }
     }
 }