Example #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);
 }
Example #2
0
 /**
  * Unfollow a user
  *
  * @param Request $request
  * @return Response
  */
 public function unfollowAction(Request $request)
 {
     $data = $request->json()->get('Follow');
     if (!validateParameters($data)) {
         return showErrorResponse("Format should be: {'Follow': {'follower_id': <int>, 'following_id: <int>}}", HTTP_UNPROCESSABLE_ENTITY);
     }
     if (isset($data['follower_id'])) {
         $follower_id = $data['follower_id'];
     } else {
         $follower_id = convertFbIdToId($data['follower_fb_id']);
     }
     if (isset($data['following_id'])) {
         $following_id = $data['following_id'];
     } else {
         $following_id = convertFbIdToId($data['following_fb_id']);
     }
     if ($follower_id === false || $following_id === false) {
         return showErrorResponse('No such user', HTTP_ACCEPTED, CONSTANTS::ERROR_CODE_GENERAL);
     }
     try {
         $follow_data = new Follow();
         $follow_data->unfollowUser($follower_id, $following_id);
         // TODO: Add Notification::deleteByFromToUserIds() here
     } catch (\Exception $e) {
         return showErrorResponse($e->getMessage());
     }
     $json_return[KeyParser::data] = array(KeyParser::user => Users::getStatistics($following_id), KeyParser::message => 'Success');
     return response()->json($json_return);
 }
Example #3
0
 /**
  * Get list of users with the most number of activities
  * Prioritize users that are not being followed yet
  *
  * @param $user_id
  * @return Response
  */
 public function viewFeaturedUsersAction($user_id)
 {
     $followed_users = array();
     $featured_users = array();
     $json_return[KeyParser::data] = array();
     $users = Users::getUsersWithMostActivities()->toArray();
     $all_followed_users = Follow::getFollowedUserIds($user_id);
     foreach ($users as $user) {
         $is_followed = in_array($user['id'], $all_followed_users);
         if ($user['id'] != $user_id) {
             if ($is_followed) {
                 $followed_users[] = $user['id'];
             } else {
                 $featured_users[] = $user['id'];
             }
         }
     }
     $featured_users = array_merge($featured_users, $followed_users);
     $featured_users = array_slice($featured_users, 0, 20);
     foreach ($featured_users as $index => $featured_user) {
         $json_return[KeyParser::data][KeyParser::users][$index] = Users::getStatistics($featured_user, $user_id);
     }
     return response()->json($json_return);
 }