Exemplo n.º 1
0
 /**
  * Delete comment
  *
  * @param $id
  * @return Response
  */
 public function deleteCommentAction($id)
 {
     $comment = Comments::find($id);
     if (!$comment) {
         return showErrorResponse('Comment not found');
     }
     $comment_type = $comment->type;
     $comment_type_id = $comment->type_id;
     try {
         $comment->deleteComment();
         $json_return[KeyParser::data] = array(KeyParser::id => $id, KeyParser::is_success => CONSTANTS::DELETE_SUCCESS);
     } catch (\Exception $e) {
         return showErrorResponse($e->getMessage());
     }
     $comments = Comments::getByTypePaginate($comment_type, $comment_type_id);
     foreach ($comments as $comment) {
         $user = Users::find($comment->user_id);
         $json_return[KeyParser::comments][] = array(KeyParser::comment => ModelFormatter::commentFormat($comment), KeyParser::user => ModelFormatter::userFormat($user));
     }
     $json_return[KeyParser::comment_count] = Comments::getCountByType($comment_type, $comment_type_id);
     $json_return[KeyParser::page] = array(KeyParser::current => $comments->currentPage(), KeyParser::number => $comments->lastPage());
     return response()->json($json_return);
 }
Exemplo n.º 2
0
 /**
  * Returns an array of photo data
  *
  * @param Photos $data
  * @return array
  */
 public static function photosFormat(Photos $data)
 {
     $viewer_id = Input::get('viewer_id');
     $short_photo_url = route('short_photo_view', ['id' => $data->id]);
     $arr = array();
     $arr[KeyParser::id] = $data->id;
     $arr[KeyParser::short_url] = $short_photo_url;
     $arr[KeyParser::restaurant_id] = $data->restaurant_id;
     $arr[KeyParser::type] = $data->type;
     $arr[KeyParser::type_id] = $data->type_id;
     $arr[KeyParser::user_id] = $data->user_id;
     $arr[KeyParser::text] = $data->text;
     $arr[KeyParser::url] = $data->url;
     $arr[KeyParser::date_uploaded] = elapsedTime($data->date_uploaded);
     $arr[KeyParser::status] = $data->status;
     $arr[KeyParser::comment_count] = Comments::getCountByType(CONSTANTS::PHOTO, $data->id);
     $arr[KeyParser::like_count] = Like::getCount(CONSTANTS::PHOTO, $data->id);
     if ($viewer_id) {
         $arr[KeyParser::is_liked] = Like::isLiked($viewer_id, CONSTANTS::PHOTO, $data->id);
     }
     return $arr;
 }