Example #1
0
 /**
  * View Checkin by Id
  * route: /checkins/view/{id}
  *
  * @param @id
  * @return Response
  */
 public function viewAction($id)
 {
     $json_return = array();
     $checkin = CheckIns::find($id);
     if (!$checkin) {
         return showErrorResponse('Checkin not found', HTTP_ACCEPTED, CONSTANTS::ERROR_CODE_CHECKIN_MISSING);
     }
     $restaurant = Restaurants::find($checkin->restaurant_id);
     if (!$restaurant) {
         return showErrorResponse('Restaurant data not found', HTTP_ACCEPTED, CONSTANTS::ERROR_CODE_GENERAL);
     }
     $user = Users::find($checkin->user_id);
     $photos = Photos::getByType(CONSTANTS::CHECKIN, $checkin->id);
     $photos_array = Photos::convertPhotosToArray($photos);
     $comments = Comments::getByType(CONSTANTS::REVIEW, $checkin->id);
     $comments_array = array();
     if ($comments) {
         foreach ($comments as $comment) {
             $comments_array[] = ModelFormatter::commentFormat($comment);
         }
     }
     $json_return[KeyParser::data] = array(KeyParser::checkin => ModelFormatter::checkinFormat($checkin), KeyParser::restaurant => ModelFormatter::restaurantLongFormat($restaurant), KeyParser::user => ModelFormatter::userLongFormat($user), KeyParser::photos => $photos_array);
     return response()->json($json_return);
 }
Example #2
0
 /**
  * Update comment
  *
  * @param Request $request
  * @return Response
  */
 public function editCommentAction(Request $request)
 {
     $data = $request->json()->get('Comment');
     if (!isset($data['id']) || !isset($data['text']) || !isset($data['user_id'])) {
         $message = "Format should be: {'Comment': {'id': <int>, 'text': <string>, 'user_id': <int>}}";
         return showErrorResponse($message, HTTP_UNPROCESSABLE_ENTITY);
     }
     // Check Ng Words
     $ng_words = NgWord::ngword_filter($data['text']);
     if ($ng_words) {
         $message = "Bad word(s) found: " . implode(',', $ng_words);
         return showErrorResponse($message, HTTP_ACCEPTED, CONSTANTS::ERROR_CODE_BADWORDS_FOUND);
     }
     // check of Ng Words
     try {
         $comment = new Comments();
         $comment = $comment->editComment($data['id'], $data['user_id'], $data['text']);
         $comment = ModelFormatter::commentFormat($comment);
         $user = Users::find($data['user_id']);
         $user = ModelFormatter::userLongFormat($user);
         $json_return[KeyParser::data] = array(KeyParser::comment => $comment, KeyParser::user => $user);
     } catch (\Exception $e) {
         return showErrorResponse('Error Editing Comment');
     }
     return response()->json($json_return);
 }