Ejemplo n.º 1
0
 public function listnode($id = 0)
 {
     if (!$id) {
         throw new \Exception('Node ID is undefined');
     }
     $current_page = page::find((int) $id);
     //var_dump($current_page);
     $items = $current_page->node;
     if ($items) {
         $nodes_array = $items->toArray();
     } else {
         $nodes_array = [];
     }
     return response()->json($nodes_array);
 }
Ejemplo n.º 2
0
 public function comment($page_id, $post_id)
 {
     $data = array();
     $user_data = $this->getUserInfo();
     $post_data = array();
     $comment_data = array();
     $sentiment_data = array();
     $num_sent_data = array();
     $user_model = App\user::where('user_id', $user_data['user_id'])->first();
     $page_model = App\page::where('page_id', $page_id)->first();
     if (is_null($page_model)) {
         // if page data is not found in database
         $page_model = new App\page();
         $graphObject = $this->getPage($page_id);
         $pageName = $graphObject->getProperty('name');
         $page_model->page_id = $page_id;
         $page_model->page_name = $pageName;
         $page_model->save();
         $post_model = new App\post();
         $graphObject = $this->getPost($post_id);
         if (null !== $graphObject->getProperty('message')) {
             $postMsg = $graphObject->getProperty('message');
         } else {
             $postMsg = $graphObject->getProperty('story');
         }
         $postTime = $graphObject->getProperty('created_time');
         $post_model->post_id = $post_id;
         $post_model->content = $postMsg;
         $post_model->created_time = $postTime;
         $page_model = App\page::where('page_id', $page_id)->first();
         $page_model->posts()->save($post_model);
         $comment_data = $this->getComment($post_id);
         $sentiment_data = $this->sentiment($comment_data);
         $post_model = App\post::where('post_id', $post_id)->first();
         $count = 0;
         foreach ($comment_data as $comment) {
             $comment_model = new App\comment();
             $comment_model->comment = $comment['comment'];
             $comment_model->commenter = $comment['commenter'];
             $comment_model->commenter_id = $comment['commenter_id'];
             $comment_model->comment_datetime = $comment['comment_datetime'];
             $post_model->comments()->save($comment_model);
             $sentiment_model = new App\commentSentiment();
             $sentiment_model->joy = $sentiment_data[$count]['joy'];
             $sentiment_model->sadness = $sentiment_data[$count]['sadness'];
             $sentiment_model->trust = $sentiment_data[$count]['trust'];
             $sentiment_model->disgust = $sentiment_data[$count]['disgust'];
             $sentiment_model->fear = $sentiment_data[$count]['fear'];
             $sentiment_model->anger = $sentiment_data[$count]['anger'];
             $sentiment_model->surprise = $sentiment_data[$count]['surprise'];
             $sentiment_model->anticipation = $sentiment_data[$count]['anticipation'];
             $sentiment_model->result = $sentiment_data[$count]['result'];
             $comment_model->sentiment()->save($sentiment_model);
             $count++;
         }
     } else {
         //if page data is already been saved in database
         $post_model = $page_model->posts()->where('post_id', $post_id)->first();
         if (is_null($post_model)) {
             $post_model = new App\post();
             $graphObject = $this->getPost($post_id);
             $postMsg = $graphObject->getProperty('message');
             $postTime = $graphObject->getProperty('created_time');
             $post_model->post_id = $post_id;
             $post_model->content = $postMsg;
             $post_model->created_time = $postTime;
             $page_model->posts()->save($post_model);
             $post_model = $page_model->posts()->where('post_id', $post_id)->first();
             $comment_data = $this->getComment($post_id);
             $sentiment_data = $this->sentiment($comment_data);
             $count = 0;
             foreach ($comment_data as $comment) {
                 $comment_model = new App\comment();
                 $comment_model->comment = $comment['comment'];
                 $comment_model->commenter = $comment['commenter'];
                 $comment_model->commenter_id = $comment['commenter_id'];
                 $comment_model->comment_datetime = $comment['comment_datetime'];
                 $post_model->comments()->save($comment_model);
                 $sentiment_model = new App\commentSentiment();
                 $sentiment_model->joy = $sentiment_data[$count]['joy'];
                 $sentiment_model->sadness = $sentiment_data[$count]['sadness'];
                 $sentiment_model->trust = $sentiment_data[$count]['trust'];
                 $sentiment_model->disgust = $sentiment_data[$count]['disgust'];
                 $sentiment_model->fear = $sentiment_data[$count]['fear'];
                 $sentiment_model->anger = $sentiment_data[$count]['anger'];
                 $sentiment_model->surprise = $sentiment_data[$count]['surprise'];
                 $sentiment_model->anticipation = $sentiment_data[$count]['anticipation'];
                 $sentiment_model->result = $sentiment_data[$count]['result'];
                 $comment_model->sentiment()->save($sentiment_model);
                 $count++;
             }
         } else {
             $comment_data = $post_model->comments->toArray();
             foreach ($comment_data as $comment) {
                 $sentiment_data[] = App\comment::where('comment_id', $comment['comment_id'])->first()->sentiment->toArray();
             }
         }
     }
     $post_data['post_id'] = $post_model->post_id;
     $post_data['post_content'] = $post_model->content;
     $post_data['post_time'] = $post_model->created_time;
     $pivot_model = App\post_user::where(['user_id' => $user_data['user_id'], 'post_id' => $post_id])->first();
     if (is_null($pivot_model)) {
         $user_model = App\user::where('user_id', $user_data['user_id'])->first();
         $user_model->posts()->attach($post_id);
     }
     $data = $user_data;
     $data['post'] = $post_data;
     $data['comments'] = $comment_data;
     $data['sentiment'] = $sentiment_data;
     $num_sent_data = $this->count_sentiment($sentiment_data);
     $data['num_sentiment'] = $num_sent_data;
     return view('post.comments', $data);
 }