예제 #1
0
 /**
  * View Photos By Type
  * type: restaurant, review, checkin, user, photo
  * route: /photos/{type}/{type_id}
  *
  * @param int $type
  * @param int $type_id
  * @return Response
  */
 public function viewPhotosByTypeAction($type, $type_id)
 {
     $json_return = array('data' => array());
     $photos = Photos::getByTypePagination($type, $type_id);
     if ($photos->count()) {
         foreach ($photos as $photo) {
             $photo_object = array(KeyParser::photo => ModelFormatter::photosFormat($photo), KeyParser::user => Users::find($photo->user_id), KeyParser::restaurant => Restaurants::find($photo->restaurant_id));
             if ($type == 'photo') {
                 $photo_object += array(KeyParser::like_count => Like::getCount(CONSTANTS::PHOTO, $photo->id));
             }
             $json_return[KeyParser::data][] = $photo_object;
             unset($photo_object);
         }
         // end foreach
     } elseif ($type == 'photo') {
         return showErrorResponse('Photo not found', HTTP_ACCEPTED, CONSTANTS::ERROR_CODE_PHOTO_MISSING);
     }
     $json_return[KeyParser::page] = array(KeyParser::current => $photos->currentPage(), KeyParser::number => $photos->lastPage());
     return response()->json($json_return);
 }
예제 #2
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);
 }
예제 #3
0
파일: Photos.php 프로젝트: jigen7/laravel5
 /**
  * Convert Photos Object to Array of Datas
  *
  * @param $photos
  * @return array
  */
 public static function convertPhotosToArray($photos)
 {
     $photos_array = array();
     if (!$photos) {
         return $photos_array;
     }
     foreach ($photos as $photo) {
         $photos_array[] = ModelFormatter::photosFormat($photo);
     }
     return $photos_array;
 }