/** * Construct the needed Array for Reviews User and Restaurant * action: userAction, restaurantAction * * @param $reviews * @return mixed */ public static function reviewsQueries($reviews) { $reviews_array = array(); if (!$reviews) { return $reviews_array; } foreach ($reviews as $review) { $restaurant = Restaurants::find($review->restaurant_id); if (!$restaurant) { continue; } $user = Users::find($review->user_id); $photos = Photos::getByType(CONSTANTS::REVIEW, $review->id); $photos_array = Photos::convertPhotosToArray($photos); if ($user) { $reviews_array[] = array(KeyParser::review => ModelFormatter::reviewFormat($review), KeyParser::restaurant => ModelFormatter::restaurantLongFormat($restaurant), KeyParser::user => ModelFormatter::userLongFormat($user), KeyParser::photos => $photos_array); } //end of check user unset($restaurant); unset($user); unset($photos); unset($photos_array); } //end foreach return $reviews_array; }
/** * Construct the needed Array for Checkins User and Restaurant * action: * * @param $checkins * @return mixed */ public static function checkinsQueries($checkins) { $checkins_array = array(); if (!$checkins) { return $checkins_array; } foreach ($checkins as $checkin) { $restaurant = Restaurants::find($checkin->restaurant_id); if (!$restaurant) { continue; } $user = Users::find($checkin->user_id); $photos = Photos::getByType(CONSTANTS::CHECKIN, $checkin->id); $photos_array = Photos::convertPhotosToArray($photos); $checkins_array[] = array(KeyParser::checkin => ModelFormatter::checkinFormat($checkin), KeyParser::restaurant => ModelFormatter::restaurantLongFormat($restaurant), KeyParser::user => ModelFormatter::userLongFormat($user), KeyParser::photos => $photos_array); unset($restaurant); unset($user); unset($photos); unset($photos_array); } //end foreach return $checkins_array; }
/** * Returns either review, checkin, or bookmark activity based on $type parameter. * * @param $type - activity type. Either 'checkin', 'review', or 'bookmark' * @param $type_id - ID for checkin/review/bookmark activity * @return mixed */ public static function getActivityType($type, $type_id) { $arr = array(); switch ($type) { case CONSTANTS::CHECKIN: $check_in = CheckIns::find($type_id); if ($check_in) { $arr[KeyParser::checkin] = ModelFormatter::checkinFormat($check_in); } else { $arr[KeyParser::checkin] = array(); } $photos = Photos::getByType(CONSTANTS::CHECKIN, $type_id); $arr[KeyParser::photos] = Photos::convertPhotosToArray($photos); break; case CONSTANTS::REVIEW: $review = Reviews::find($type_id); if ($review) { $arr[KeyParser::review] = ModelFormatter::reviewFormat($review); } else { $arr[KeyParser::review] = array(); } $photos = Photos::getByType(CONSTANTS::REVIEW, $type_id); $arr[KeyParser::photos] = Photos::convertPhotosToArray($photos); break; case CONSTANTS::PHOTO_UPLOAD_RESTAURANT: $photos = Photos::where('id', $type_id)->get(); $arr[KeyParser::photos] = Photos::convertPhotosToArray($photos); break; } unset($photos_arr); return $arr; }
/** * @param Request $request * @param $id * @return Response * @throws Exception */ public function editAction(Request $request, $id) { /* Multipart Procedure $data = $request->only('json'); $data_json = json_decode(file_get_contents($data['json']), true); */ $data_json['CheckIn'] = $request->json()->get('CheckIn'); if (!isset($data_json['CheckIn']) || !isset($data_json['CheckIn']['message'])) { $message = "Format should be: {'CheckIn': 'message': <string>}}"; return showErrorResponse($message, HTTP_UNPROCESSABLE_ENTITY); } // check fo valid data // Check Ng Words $ng_words = NgWord::ngword_filter($data_json['CheckIn']['message']); 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 { // Edit Review Data $checkin = new Checkins(); $edit_checkin = $checkin->editCheckin($id, $data_json['CheckIn']); $photos = Photos::getByType(CONSTANTS::CHECKIN, $edit_checkin->id); $photos_array = Photos::convertPhotosToArray($photos); $restaurant = Restaurants::find($edit_checkin->restaurant_id); if (!$restaurant) { return showErrorResponse('Restaurant data not found', HTTP_ACCEPTED, CONSTANTS::ERROR_CODE_GENERAL); } $user = Users::find($edit_checkin->user_id); $json_return[KeyParser::data] = array(KeyParser::checkin => ModelFormatter::checkinFormat($edit_checkin), KeyParser::restaurant => ModelFormatter::restaurantLongFormat($restaurant), KeyParser::user => ModelFormatter::userLongFormat($user), KeyParser::photos => $photos_array); return response()->json($json_return); } catch (\Exception $e) { return showErrorResponse($e->getMessage()); } // end catch }
/** * Review View * route: reviews/view{id} * * @param $id * @optional ?viewer_id * @return Response */ public function viewAction($id) { $json_return = array(); $review = Reviews::find($id); if (!$review) { return showErrorResponse('Review not found', HTTP_ACCEPTED, CONSTANTS::ERROR_CODE_REVIEW_MISSING); } $restaurant = Restaurants::find($review->restaurant_id); if (!$restaurant) { return showErrorResponse('Restaurant data not found', HTTP_ACCEPTED, CONSTANTS::ERROR_CODE_GENERAL); } $user = Users::find($review->user_id); $photos = Photos::getByType(CONSTANTS::REVIEW, $review->id); $photos_array = Photos::convertPhotosToArray($photos); $comments = Comments::getByType(CONSTANTS::REVIEW, $review->id); $comments_array = array(); if ($comments) { foreach ($comments as $comment) { $comments_array[] = ModelFormatter::commentFormat($comment); } } $json_return[KeyParser::data] = array(KeyParser::review => ModelFormatter::reviewFormat($review), KeyParser::restaurant => ModelFormatter::restaurantLongFormat($restaurant), KeyParser::user => ModelFormatter::userLongFormat($user), KeyParser::photos => $photos_array, KeyParser::comments => $comments_array); return response()->json($json_return); }