Пример #1
0
 /**
  * Displays individual restaurant information
  * route: /restaurants/{restaurant_id}/{viewer_id?}
  *
  * @param id - restaurant ID
  * @param viewer_id - user ID of the viewer (Optional)
  * @return Response
  */
 public function viewAction($id)
 {
     $viewer_id = Input::get('viewer_id', null);
     $restaurant = Restaurants::find($id);
     $data = array();
     if ($restaurant) {
         $restaurant->view_count++;
         $restaurant->save();
         $restaurant_categories = RestaurantsCategory::getByRestaurantId($id);
         $photos = Photos::getByRestaurantId($id);
         $is_bookmarked = Bookmarks::isBookmarked($viewer_id, $restaurant->id);
         $data[KeyParser::restaurant] = ModelFormatter::restaurantViewFormat($restaurant, $is_bookmarked);
         foreach ($photos as $photo) {
             $data[KeyParser::photos][] = ModelFormatter::photosFormat($photo);
         }
         $data[KeyParser::categories] = Categories::getFormattedRestaurantCategories($restaurant->id);
         Categories::getFormattedRestaurantCategories($restaurant->id);
         $latest_activity = Activities::getLatestRestaurantActivity($id);
         if ($latest_activity) {
             $data[KeyParser::activity] = ModelFormatter::activityRestaurantViewFormat($latest_activity);
             $data[KeyParser::user] = Users::getStatistics($id);
             $data += Activities::getActivityType($latest_activity->type, $latest_activity->type_id);
         }
     }
     $recently_viewed = array();
     if ($viewer_id) {
         $where = array('user_id' => $viewer_id, 'restaurant_id' => $id);
         $rv = LogRecentlyViewed::where($where)->get()->first();
         if ($rv) {
             $rv->date_modified = date('Y-m-d H:i:s');
             $rv->save();
         }
         $rv = new LogRecentlyViewed();
         $rv->addNewLog($viewer_id, $id);
     }
     $json_return[KeyParser::data] = $data;
     return response()->json($json_return);
 }
Пример #2
0
function checkTypeId($type, $type_id)
{
    switch ($type) {
        case CONSTANTS::REVIEW:
            $object = Reviews::find($type_id);
            $message = "Review does not exist";
            $error_code = CONSTANTS::ERROR_CODE_REVIEW_MISSING;
            break;
        case CONSTANTS::CHECKIN:
            $object = CheckIns::find($type_id);
            $message = "Checkin does not exist";
            $error_code = CONSTANTS::ERROR_CODE_CHECKIN_MISSING;
            break;
        case CONSTANTS::BOOKMARK:
            $object = Bookmarks::find($type_id);
            $message = "Bookmark does not exist";
            $error_code = CONSTANTS::ERROR_CODE_GENERAL;
            break;
        case CONSTANTS::COMMENT:
            $object = Comments::find($type_id);
            $message = "Comment does not exist";
            $error_code = CONSTANTS::ERROR_CODE_GENERAL;
            break;
        case CONSTANTS::PHOTO:
            $object = Photos::find($type_id);
            $message = "Photo does not exist";
            $error_code = CONSTANTS::ERROR_CODE_PHOTO_MISSING;
            break;
        case CONSTANTS::RESTAURANT:
            $object = Restaurants::find($type_id);
            $message = "Restaurant does not exist";
            $error_code = CONSTANTS::ERROR_CODE_GENERAL;
            break;
        case 'user':
            $object = Users::find($type_id);
            $message = "User does not exist";
            $error_code = CONSTANTS::ERROR_CODE_GENERAL;
            break;
        default:
            return showErrorResponse('Invalid type', HTTP_ACCEPTED, CONSTANTS::ERROR_CODE_INVALID_TYPE);
    }
    if (!$object) {
        return showErrorResponse($message, HTTP_ACCEPTED, $error_code);
    }
    return false;
}
Пример #3
0
 /**
  * Delete a restaurant and all data associated with it
  *
  * @param Request $request
  * @return \Illuminate\Http\RedirectResponse
  */
 public function deleteAction(Request $request)
 {
     try {
         $errors = array();
         if (!$request->isMethod('POST')) {
             throw new Exception('Must be a POST request.');
         }
         $is_ajax = $request->ajax();
         $connection = DB::connection();
         $connection->beginTransaction();
         $restaurant_id = $request->input('id');
         $restaurant = Restaurants::find($restaurant_id);
         if (!$restaurant) {
             throw new Exception('Restaurant not found');
         }
         $bookmarks = Bookmarks::where('restaurant_id', $restaurant_id);
         if ($bookmarks->get()->count()) {
             $bookmarks->delete();
         }
         $check_ins = CheckIns::where('restaurant_id', $restaurant_id);
         if ($check_ins->get()->count()) {
             $check_ins->delete();
         }
         $photos = PhotosCms::where('restaurant_id', $restaurant_id);
         if ($photos->get()->count()) {
             $photos->delete();
         }
         $restaurants_category = RestaurantsCategory::where('restaurant_id', $restaurant_id);
         if ($restaurants_category->get()->count()) {
             $restaurants_category->delete();
         }
         $reviews = Reviews::where('restaurant_id', $restaurant_id);
         if ($reviews->get()->count()) {
             $reviews->delete();
         }
         $restaurant->delete();
         $connection->commit();
         if ($is_ajax) {
             header('Content-Type: application/json');
             $success[] = 'Restaurant ID ' . $restaurant_id . ' has been deleted';
             echo json_encode(array('success' => $success));
             exit;
         } else {
             $success[] = 'Restaurant ID ' . $restaurant_id . ' has been deleted';
             \Session::flush('success', $success);
             return redirect()->back();
         }
     } catch (Exception $e) {
         $connection->rollBack();
         if ($is_ajax) {
             header('Content-Type: application/json');
             $errors[] = $e->getMessage();
             \Session::flush('errors', $errors);
             echo json_encode(array('errors' => $e->getMessage()));
             exit;
         } else {
             $errors[] = $e->getMessage();
             \Session::flush('errors', $errors);
             return redirect()->back();
         }
     }
 }
Пример #4
0
 /**
  * Get the review, checkin, bookmark, follow, photos, comments, and notification data of a user
  *
  * @param $id
  * @param $viewer_id
  * @return array
  */
 public static function getStatistics($id, $viewer_id = false)
 {
     $user = self::find($id);
     if (!$user) {
         return array();
     }
     $user_array = ModelFormatter::userLongFormat($user);
     $user_array[KeyParser::review_count] = Reviews::getCountByUserId($id);
     $user_array[KeyParser::checkin_count] = CheckIns::getCountByUserId($id);
     $user_array[KeyParser::bookmark_count] = Bookmarks::getCountByUserId($id);
     $user_array[KeyParser::following_count] = Follow::getCountByUserId($id, CONSTANTS::FOLLOW_FOLLOWED);
     $user_array[KeyParser::follower_count] = Follow::getCountByUserId($id, CONSTANTS::FOLLOW_FOLLOWER);
     $user_array[KeyParser::photo_count] = Photos::getCountByUserId($id);
     $user_array[KeyParser::comment_count] = Comments::getCountByUserId($id);
     $user_array[KeyParser::unread_notification_count] = Notification::getNotificationByUserToCustomPaginate(CONSTANTS::NOTIFICATION_STATUS_UNREAD, CONSTANTS::ORDER_DESC, $id, null, true);
     $user_array[KeyParser::new_notification_count] = Notification::getNotificationByUserToCustomPaginate(CONSTANTS::NOTIFICATION_STATUS_NEW, CONSTANTS::ORDER_DESC, $id, null, true);
     if ($viewer_id) {
         $user_array[KeyParser::is_followed_by_viewer] = Follow::isFollowed($viewer_id, $id);
     }
     return $user_array;
 }
Пример #5
0
 /**
  * get all of the bookmarks of a user
  * /bookmarks/user/{user_id}
  *
  * @param $user_id
  * @return Response
  */
 public function userBookmarkListAction($user_id)
 {
     if (!is_numeric($user_id)) {
         return showErrorResponse('Incorrect User ID format');
     }
     $bookmark_list = Bookmarks::getBookmarkByUserId($user_id);
     $user_data = Users::find($user_id);
     $json_return[KeyParser::data] = array();
     if ($bookmark_list) {
         foreach ($bookmark_list as $bookmark) {
             $restaurant_data = Restaurants::find($bookmark->restaurant_id);
             if ($restaurant_data) {
                 $json_return[KeyParser::data][] = array(KeyParser::bookmark => ModelFormatter::bookmarkFormat($bookmark), KeyParser::user => ModelFormatter::userFormat($user_data), KeyParser::restaurant => ModelFormatter::restaurantBookmarkListViewFormat($restaurant_data), KeyParser::categories => Categories::getFormattedRestaurantCategories($bookmark->restaurant_id));
             }
         }
     }
     $json_return[KeyParser::page] = array(KeyParser::current => $bookmark_list->currentPage(), KeyParser::number => $bookmark_list->lastPage());
     return response()->json($json_return);
 }