/** * 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); }
/** * 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; }
/** * Get the list of users that likes the activity * * @param request $request * @return Response */ public function likerListAction(Request $request) { $viewer_id = $request->viewer_id; $type = $request->type; $type_id = $request->type_id; $error_msg = checkTypeId($type, $type_id); if ($error_msg) { return $error_msg; } $liker_list = Like::getLikerList($type, $type_id); $json_return[KeyParser::data] = array(); if ($liker_list) { foreach ($liker_list as $index => $liker) { $user_id = $liker->user_id; $user_data = Users::find($user_id); if ($user_data) { $array = ModelFormatter::userLongFormat($user_data); $array += array(KeyParser::follower_count => Follow::getCountByUserId($user_id, CONSTANTS::FOLLOW_FOLLOWER), KeyParser::review_count => Reviews::getCountByUserId($user_id), KeyParser::is_followed_by_viewer => Follow::isFollowed($viewer_id, $user_id)); $json_return[KeyParser::data][] = $array; unset($array); } // end of check $user_date } $json_return[KeyParser::like_count] = Like::getCount($type, $type_id); } $json_return[KeyParser::page] = array(KeyParser::current => $liker_list->currentPage(), KeyParser::number => $liker_list->lastPage()); return response()->json($json_return); }