/**
  * Returns restaurants recently viewed by a user
  *
  * @param $user_id
  * @return \Symfony\Component\HttpFoundation\Response
  */
 public function getAction($user_id)
 {
     $json_return = array();
     if (!$user_id) {
         return showErrorResponse('Invalid user_id');
     }
     $recently_viewed_data = LogRecentlyViewed::getByUserId($user_id);
     $recently_viewed_data = $recently_viewed_data->toArray();
     $page_data = $recently_viewed_data;
     unset($page_data['data']);
     $recently_viewed_data = $recently_viewed_data['data'];
     $recently_viewed = array();
     $restaurant = null;
     foreach ($recently_viewed_data as $rvd) {
         $restaurant = Restaurants::find($rvd['restaurant_id']);
         if ($restaurant) {
             $recently_viewed[] = ModelFormatter::restaurantFormat($restaurant);
         }
         $restaurant = null;
     }
     $json_return = array(KeyParser::data => $recently_viewed, KeyParser::page => array(KeyParser::current => $page_data['current_page'], KeyParser::number => $page_data['last_page']));
     return response()->json($json_return);
 }
Beispiel #2
0
 /**
  * Query the users, restaurant, bookmarks, checkins, reviews
  *
  * @param int activities
  * @return mixed
  */
 public static function activitiesQueries($activities)
 {
     $activities_array = array();
     if ($activities->count()) {
         foreach ($activities as $activity) {
             $data = array();
             $data[KeyParser::activity] = ModelFormatter::activityFormat($activity);
             //GetUserInfo
             $user = Users::find($activity->user_id);
             if ($user) {
                 $data[KeyParser::user] = ModelFormatter::userFormat($user);
             } else {
                 $data[KeyParser::user][KeyParser::error] = "No Information";
             }
             //end check user
             //GetRestaurantInfo
             $restaurant = Restaurants::where('status_verify', CONSTANTS::STATUS_VERIFIED)->find($activity->restaurant_id);
             if ($restaurant) {
                 $data[KeyParser::restaurant] = ModelFormatter::restaurantFormat($restaurant);
             } else {
                 $data[KeyParser::restaurant][KeyParser::error] = "No Information";
             }
             // end check restaurant
             $data += self::getActivityType($activity->type, $activity->type_id);
             $activities_array[] = $data;
             unset($data);
         }
         //end foreach
     }
     //end count
     return $activities_array;
 }