Exemplo n.º 1
0
 /**
  * Report a comment, photo, restaurant, or review
  *
  * @param Request $request
  * @return Response
  */
 public function addAction(Request $request)
 {
     $json_return = array();
     $data = $request->json()->get('Report');
     if ($data['type'] == CONSTANTS::PHOTO) {
         $photo = Photos::find($data['type_id']);
         if (!$photo) {
             $message = 'Photo not found or already deleted';
             return showErrorResponse($message, HTTP_ACCEPTED, CONSTANTS::ERROR_CODE_PHOTO_MISSING);
         }
         $is_existing_photo_report = Reported::isExistingPhotoReport($data['type_id'], $data['user_id']);
         if ($is_existing_photo_report) {
             $message = 'You have already reported this photo';
             return showErrorResponse($message, HTTP_ACCEPTED, CONSTANTS::ERROR_CODE_REPORTED_ALREADY);
         }
     }
     try {
         $report = new Reported();
         $report_object = $report->addReport($data);
         $json_return[KeyParser::data] = ModelFormatter::reportFormat($report_object);
     } catch (\Exception $e) {
         return showErrorResponse($e->getMessage());
     }
     return response()->json($json_return);
 }
Exemplo n.º 2
0
 /**
  * Returns all notification data per user_id and status using lengthAwarePagination
  *
  * @param int $status
  * @param string $order
  * @param bool $user_id_to
  * @param int current_page
  * @param boolean $count_only
  * @return LengthAwarePaginator
  */
 public static function getNotificationByUserToCustomPaginate($status = CONSTANTS::NOTIFICATION_STATUS_DELETED, $order = CONSTANTS::ORDER_DESC, $user_id_to = false, $current_page = CONSTANTS::FIRST_PAGE, $count_only = false)
 {
     $notifications = self::where('status', '<=', $status);
     if ($user_id_to) {
         $notifications->where('user_id_to', $user_id_to);
     }
     $notifications = $notifications->orderBy('date_created', $order)->get();
     $data = array();
     $duplicate_activities = array();
     $notif_count = 0;
     foreach ($notifications as $notification) {
         $type_id = $notification->type_id;
         $type = $notification->type;
         $restaurant_id = $notification->restaurant_id;
         if ($restaurant_id != 0 && !Restaurants::isExists($restaurant_id)) {
             continue;
         }
         $from_user = Users::find($notification->user_id_from);
         if (!$count_only) {
             if ($notification->status == CONSTANTS::NOTIFICATION_STATUS_NEW) {
                 $notification->updateStatus(CONSTANTS::NOTIFICATION_STATUS_UNREAD);
             }
         }
         if ($from_user && isset($duplicate_activities[$type][$type_id])) {
             $date_diff = strtotime($duplicate_activities[$type][$type_id][KeyParser::date_created]) - strtotime($notification->date_created);
             if ($date_diff < CONSTANTS::DAY_SECOND_VALUE && $date_diff >= 0) {
                 $notif_index = $duplicate_activities[$type][$type_id][KeyParser::index];
                 $user_fullname = $from_user->getUserFullName();
                 if (!array_key_exists(KeyParser::usernames_from, $data[$notif_index][KeyParser::notification]) || !in_array($user_fullname, $data[$notif_index][KeyParser::notification][KeyParser::usernames_from])) {
                     $data[$notif_index][KeyParser::notification][KeyParser::usernames_from][] = $user_fullname;
                     $data[$notif_index][KeyParser::notification][KeyParser::users_from][] = $from_user->toArray();
                 }
                 continue;
             }
         }
         $data[$notif_count][KeyParser::notification] = ModelFormatter::notificationFormat($notification);
         $to_user = Users::find($notification->user_id_to);
         if ($to_user) {
             $data[$notif_count][KeyParser::notification] += array(KeyParser::facebook_id_to => $to_user->facebook_id);
         }
         if ($from_user) {
             $data[$notif_count][KeyParser::notification] += array(KeyParser::facebook_id_from => $from_user->facebook_id, KeyParser::usernames_from => array($from_user->getUserFullName()), KeyParser::users_from => array($from_user->toArray()));
         }
         $duplicate_activities[$type][$type_id] = array(KeyParser::date_created => $notification->date_created, KeyParser::index => $notif_count);
         $restaurant = Restaurants::find($notification->restaurant_id);
         if ($restaurant) {
             $data[$notif_count][KeyParser::notification] += array(KeyParser::restaurant_name => $restaurant->name);
         }
         $notif_count++;
     }
     if ($count_only) {
         return count($data);
     }
     $max_results = CONSTANTS::NOTIFICATIONS_VIEW_PAGINATION_LIMIT;
     $offset = $current_page * $max_results - $max_results;
     $notification_data = array_slice($data, $offset, $max_results);
     $paginated_data = new LengthAwarePaginator($notification_data, count($data), $max_results);
     return $paginated_data;
 }
Exemplo n.º 3
0
 /**
  * Returns array of categories based on restaurant ID
  *
  * @param $restaurant_id
  *
  * @return array
  */
 public static function getFormattedRestaurantCategories($restaurant_id)
 {
     $restaurant_categories = self::join('restaurants_category', 'categories.id', '=', 'restaurants_category.category_id')->where('restaurants_category.restaurant_id', $restaurant_id)->select('categories.id as id', 'categories.type as type', 'categories.name')->get();
     $category_data = array();
     foreach ($restaurant_categories as $category) {
         $category_data[] = ModelFormatter::categoryFormat($category);
     }
     return $category_data;
 }
Exemplo n.º 4
0
 public function readAction(Request $request)
 {
     $data = $request->json()->get('Notification');
     if (!$data) {
         return showErrorResponse('Incorrect request parameters', HTTP_UNPROCESSABLE_ENTITY);
     }
     $notification = Notification::find($data[CONSTANTS::KEY_ID]);
     if ($notification) {
         $notification = ModelFormatter::notificationFormat($notification->updateStatus(CONSTANTS::NOTIFICATION_STATUS_READ));
     }
     $json_return[KeyParser::data][KeyParser::notification] = $notification;
     return response()->json($json_return);
 }
 /**
  * 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);
 }
Exemplo n.º 6
0
 public static function restaurantSearch($params)
 {
     $longitude = isset($params['long']) ? $params['long'] : 0;
     $latitude = isset($params['lat']) ? $params['lat'] : 0;
     $review_count_query = "(SELECT COUNT(id) FROM reviews WHERE reviews.restaurant_id = restaurants.id)";
     $checkin_count_query = "(SELECT COUNT(id) FROM check_ins WHERE check_ins.restaurant_id = restaurants.id)";
     $restaurants = Restaurants::select('restaurants.*', DB::raw("{$review_count_query} AS review_count"), DB::raw("{$checkin_count_query} AS checkin_count"));
     if (isset($params['name'])) {
         $restaurants->where('restaurants.name', 'LIKE', '%' . substr($params['name'], 0, 30) . '%');
     }
     if (isset($params['address'])) {
         $restaurants->where('restaurants.address', 'LIKE', '%' . substr($params['address'], 0, 30) . '%');
     }
     if (isset($params['tag']) && $params['tag'] != '') {
         $tag = $params['tag'];
         $restaurants->leftJoin('restaurants_category', 'restaurants.id', '=', 'restaurants_category.restaurant_id')->where('restaurants_category.category_id', $tag);
     }
     $search_results = $restaurants->paginate(CONSTANTS::RESTAURANTS_PARTIAL_SEARCH_PAGINATION_LIMIT);
     $distances = array();
     $data = array();
     foreach ($search_results as $count => $restaurant) {
         if ($restaurant['id'] == NULL) {
             continue;
         }
         if ($longitude > 0 && $latitude > 0) {
             $restaurant->distance = 3956 * 2 * asin(sqrt(pow(sin(($latitude - $restaurant->latitude) * pi() / 180 / 2), 2) + cos($latitude * pi() / 180) * cos($restaurant->latitude * pi() / 180) * pow(sin(($longitude - $restaurant->longitude) * pi() / 180 / 2), 2)));
         } else {
             $restaurant->distance = 0;
         }
         $data[$count]['restaurant'] = ModelFormatter::restaurantSearchFormat($restaurant);
         $distances[$count] = $restaurant->distance;
         $data[$count][KeyParser::categories] = Categories::getFormattedRestaurantCategories($restaurant->id);
     }
     array_multisort($distances, SORT_ASC, $data);
     $page = array(KeyParser::current => $search_results->currentPage(), KeyParser::number => $search_results->lastPage());
     return array(KeyParser::data => $data, KeyParser::page => $page);
 }
Exemplo n.º 7
0
 /**
  * Construct the needed Array for Checkins User and Restaurant
  * action:
  *
  * @param $checkins
  * @return mixed
  */
 public static function checkinsQueries($checkins)
 {
     $checkins_array = array();
     if (!$checkins) {
         return $checkins_array;
     }
     foreach ($checkins as $checkin) {
         $restaurant = Restaurants::find($checkin->restaurant_id);
         if (!$restaurant) {
             continue;
         }
         $user = Users::find($checkin->user_id);
         $photos = Photos::getByType(CONSTANTS::CHECKIN, $checkin->id);
         $photos_array = Photos::convertPhotosToArray($photos);
         $checkins_array[] = array(KeyParser::checkin => ModelFormatter::checkinFormat($checkin), KeyParser::restaurant => ModelFormatter::restaurantLongFormat($restaurant), KeyParser::user => ModelFormatter::userLongFormat($user), KeyParser::photos => $photos_array);
         unset($restaurant);
         unset($user);
         unset($photos);
         unset($photos_array);
     }
     //end foreach
     return $checkins_array;
 }
Exemplo n.º 8
0
 /**
  * @param Request $request
  * @param $id
  * @return Response
  * @throws Exception
  */
 public function editAction(Request $request, $id)
 {
     /* Multipart Procedure
        $data = $request->only('json');
        $data_json = json_decode(file_get_contents($data['json']), true);
        */
     $data_json['CheckIn'] = $request->json()->get('CheckIn');
     if (!isset($data_json['CheckIn']) || !isset($data_json['CheckIn']['message'])) {
         $message = "Format should be: {'CheckIn': 'message': <string>}}";
         return showErrorResponse($message, HTTP_UNPROCESSABLE_ENTITY);
     }
     // check fo valid data
     // Check Ng Words
     $ng_words = NgWord::ngword_filter($data_json['CheckIn']['message']);
     if ($ng_words) {
         $message = "Bad word(s) found: " . implode(',', $ng_words);
         return showErrorResponse($message, HTTP_ACCEPTED, CONSTANTS::ERROR_CODE_BADWORDS_FOUND);
     }
     // check of Ng Words
     try {
         // Edit Review Data
         $checkin = new Checkins();
         $edit_checkin = $checkin->editCheckin($id, $data_json['CheckIn']);
         $photos = Photos::getByType(CONSTANTS::CHECKIN, $edit_checkin->id);
         $photos_array = Photos::convertPhotosToArray($photos);
         $restaurant = Restaurants::find($edit_checkin->restaurant_id);
         if (!$restaurant) {
             return showErrorResponse('Restaurant data not found', HTTP_ACCEPTED, CONSTANTS::ERROR_CODE_GENERAL);
         }
         $user = Users::find($edit_checkin->user_id);
         $json_return[KeyParser::data] = array(KeyParser::checkin => ModelFormatter::checkinFormat($edit_checkin), KeyParser::restaurant => ModelFormatter::restaurantLongFormat($restaurant), KeyParser::user => ModelFormatter::userLongFormat($user), KeyParser::photos => $photos_array);
         return response()->json($json_return);
     } catch (\Exception $e) {
         return showErrorResponse($e->getMessage());
     }
     // end catch
 }
Exemplo n.º 9
0
 /**
  * Update comment
  *
  * @param Request $request
  * @return Response
  */
 public function editCommentAction(Request $request)
 {
     $data = $request->json()->get('Comment');
     if (!isset($data['id']) || !isset($data['text']) || !isset($data['user_id'])) {
         $message = "Format should be: {'Comment': {'id': <int>, 'text': <string>, 'user_id': <int>}}";
         return showErrorResponse($message, HTTP_UNPROCESSABLE_ENTITY);
     }
     // Check Ng Words
     $ng_words = NgWord::ngword_filter($data['text']);
     if ($ng_words) {
         $message = "Bad word(s) found: " . implode(',', $ng_words);
         return showErrorResponse($message, HTTP_ACCEPTED, CONSTANTS::ERROR_CODE_BADWORDS_FOUND);
     }
     // check of Ng Words
     try {
         $comment = new Comments();
         $comment = $comment->editComment($data['id'], $data['user_id'], $data['text']);
         $comment = ModelFormatter::commentFormat($comment);
         $user = Users::find($data['user_id']);
         $user = ModelFormatter::userLongFormat($user);
         $json_return[KeyParser::data] = array(KeyParser::comment => $comment, KeyParser::user => $user);
     } catch (\Exception $e) {
         return showErrorResponse('Error Editing Comment');
     }
     return response()->json($json_return);
 }
Exemplo n.º 10
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);
 }
Exemplo n.º 11
0
 /**
  * Upload Photo Routine for Restaurant
  * route: photos/upload/restaurant
  *
  * @param Request $request
  * @return Mixed
  */
 public function photoUploadRestaurantAction(Request $request)
 {
     $data = $request->only('json', 'fileField');
     $data_photos = $data['fileField'];
     $data_json = json_decode(file_get_contents($data['json']), true);
     try {
         DB::beginTransaction();
         foreach ($data_json['Photos'] as $data_json_photo) {
             foreach ($data_photos as $key => $data_photo) {
                 $photo_text = "";
                 if (isset($data_json_photo['Photo']['text'])) {
                     $photo_text = $data_json_photo['Photo']['text'];
                     // Check Ng Words
                     $ng_words = NgWord::ngword_filter($photo_text);
                     if ($ng_words) {
                         $message = "Bad word(s) found: " . implode(' ', $ng_words);
                         return showErrorResponse($message, HTTP_ACCEPTED, CONSTANTS::ERROR_CODE_BADWORDS_FOUND);
                     }
                     // check of Ng Words
                 }
                 $data_photos[$key]->text = $photo_text;
             }
         }
         $restaurant_id = $data_json['Restaurant']['restaurant_id'];
         $user_id = $data_json['Restaurant']['user_id'];
         // Save and Upload Photo
         $photos_upload = new Photos();
         $success_photo = $photos_upload->saveUploadedPhotos($data_photos, $data_json['Restaurant'], CONSTANTS::RESTAURANT, $restaurant_id);
         $followers = Follow::getFollowerUsersAll($user_id);
         $notification = new Notification();
         //Add Activity
         foreach ($success_photo as $photo) {
             $activity = new Activities();
             $activity->addActivity(CONSTANTS::PHOTO_UPLOAD_RESTAURANT, $photo->id, $user_id, $restaurant_id);
             foreach ($followers as $follower) {
                 $notification->addNotificationNewPhoto($user_id, $follower->follower_user_id, $photo->id, $restaurant_id);
             }
         }
         $photos_array = Photos::convertPhotosToArray($success_photo);
         $restaurant = Restaurants::find($restaurant_id);
         $user = Users::find($user_id);
         $json_return[KeyParser::data] = array(KeyParser::activity => ModelFormatter::activityFormat($activity), KeyParser::restaurant => ModelFormatter::restaurantLongFormat($restaurant), KeyParser::user => ModelFormatter::userLongFormat($user), KeyParser::photos => $photos_array);
         DB::commit();
         return response()->json($json_return);
     } catch (\Exception $e) {
         return showErrorResponse($e->getMessage());
     }
     // end catch
 }
Exemplo n.º 12
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;
 }
Exemplo n.º 13
0
 /**
  * Returns a list of Twitter friends which you have not yet followed
  *
  * @param Request $request
  * @return Response
  * @throws Exception
  */
 public function followTwitterUsersAction(Request $request)
 {
     $json_return[KeyParser::data] = array(KeyParser::users => array(), Keyparser::is_private => CONSTANTS::TWITTER_PUBLIC);
     $user_id = $request->json()->get('User')['user_id'];
     $twitter_id = $request->json()->get('User')['twitter_id'];
     if (!$twitter_id || !$user_id) {
         return showErrorResponse('Failed to access Twitter account');
     }
     $settings = array('oauth_access_token' => Config::get('services.twitter.oauth_access_token'), 'oauth_access_token_secret' => Config::get('services.twitter.oauth_access_token_secret'), 'consumer_key' => Config::get('services.twitter.consumer_key'), 'consumer_secret' => Config::get('services.twitter.consumer_secret'));
     $url = 'https://api.twitter.com/1.1/friends/ids.json';
     $getfield = "?user_id={$twitter_id}";
     $requestMethod = 'GET';
     $twitter = new \TwitterAPIExchange($settings);
     $response = $twitter->setGetfield($getfield)->buildOauth($url, $requestMethod)->performRequest();
     $friends = json_decode($response);
     $twitter_friends = array();
     $followed_users = array();
     $friend_count = 0;
     if (isset($friends->error)) {
         $json_return[KeyParser::data][Keyparser::is_private] = CONSTANTS::TWITTER_PRIVATE;
     } else {
         foreach ($friends->ids as $friend_id) {
             $friend_user = Users::getByTwitterId($friend_id);
             if (!$friend_user) {
                 continue;
             }
             $is_followed = Follow::isFollowed($user_id, $friend_user->id);
             $follower_count = Follow::getCountByUserId($friend_user->id, CONSTANTS::FOLLOW_FOLLOWER);
             $review_count = Reviews::getCountByUserId($friend_user->id);
             if (!$is_followed && $friend_user->id != $user_id) {
                 $twitter_friends[$friend_count] = ModelFormatter::userFormat($friend_user);
                 $twitter_friends[$friend_count] += array(KeyParser::follower_count => $follower_count, KeyParser::review_count => $review_count, KeyParser::is_followed_by_viewer => $is_followed);
             } elseif ($is_followed && $friend_user->id != $user_id) {
                 $followed_users[$friend_count] = ModelFormatter::userFormat($friend_user);
                 $followed_users[$friend_count] += array(KeyParser::follower_count => $follower_count, KeyParser::review_count => $review_count, KeyParser::is_followed_by_viewer => $is_followed);
             }
             $friend_count++;
         }
         $twitter_friends = array_merge($twitter_friends, $followed_users);
         $json_return[KeyParser::data][KeyParser::users] = $twitter_friends;
     }
     return response()->json($json_return);
 }
Exemplo n.º 14
0
 /**
  * Create a new user
  *
  * @param Request $request
  * @return Response
  * @throws FacebookRequestException
  */
 public function addAction(Request $request)
 {
     $data = $request->json()->get('User');
     if (!$data) {
         return showErrorResponse('Incorrect request parameters', HTTP_UNPROCESSABLE_ENTITY);
     }
     try {
         $new_user = new Users();
         $new_user->addUser($data);
     } catch (\Exception $e) {
         return showErrorResponse($e->getMessage());
     }
     //Send push notifications to all Facebook friends who are using Masarap
     $fb_access_token = $data[CONSTANTS::KEY_FB_ACCESS_TOKEN];
     if (!$fb_access_token) {
         return showErrorResponse('Failed to access Facebook account');
     }
     FacebookSession::setDefaultApplication(Config::get('services.facebook.client_id'), Config::get('services.facebook.client_secret'));
     FacebookSession::enableAppSecretProof(false);
     $facebook_session = new FacebookSession($fb_access_token);
     $facebook_response = (new FacebookRequest($facebook_session, 'GET', '/me/friends/'))->execute();
     $friend_list = $facebook_response->getResponse();
     $failed_notifications = array();
     foreach ($friend_list->data as $friend) {
         $friend_user = Users::getByFbId($friend->id);
         if (!$friend_user) {
             continue;
         }
         $params = array(CONSTANTS::KEY_USER_ID_FROM => $new_user->id, CONSTANTS::KEY_USER_ID_TO => $friend_user->id, CONSTANTS::KEY_TYPE => CONSTANTS::NOTIFICATION_TYPE_FRIEND_JOIN, CONSTANTS::KEY_TYPE_ID => $new_user->id);
         try {
             $notification = new Notification();
             $notification->addGeneralNotification($params);
         } catch (\Exception $e) {
             $failed_notifications[] = $friend_user->id;
         }
     }
     $json_return[KeyParser::data] = array(KeyParser::user => ModelFormatter::userLongFormat($new_user), KeyParser::message => 'User successfully registered and push notifications are sent to Facebook friends', KeyParser::unsent_notifications => $failed_notifications);
     return response()->json($json_return);
 }
Exemplo n.º 15
0
 /**
  * Returns either review, checkin, or bookmark activity based on $type parameter.
  *
  * @param $type - activity type. Either 'checkin', 'review', or 'bookmark'
  * @param $type_id - ID for checkin/review/bookmark activity
  * @return mixed
  */
 public static function getActivityType($type, $type_id)
 {
     $arr = array();
     switch ($type) {
         case CONSTANTS::CHECKIN:
             $check_in = CheckIns::find($type_id);
             if ($check_in) {
                 $arr[KeyParser::checkin] = ModelFormatter::checkinFormat($check_in);
             } else {
                 $arr[KeyParser::checkin] = array();
             }
             $photos = Photos::getByType(CONSTANTS::CHECKIN, $type_id);
             $arr[KeyParser::photos] = Photos::convertPhotosToArray($photos);
             break;
         case CONSTANTS::REVIEW:
             $review = Reviews::find($type_id);
             if ($review) {
                 $arr[KeyParser::review] = ModelFormatter::reviewFormat($review);
             } else {
                 $arr[KeyParser::review] = array();
             }
             $photos = Photos::getByType(CONSTANTS::REVIEW, $type_id);
             $arr[KeyParser::photos] = Photos::convertPhotosToArray($photos);
             break;
         case CONSTANTS::PHOTO_UPLOAD_RESTAURANT:
             $photos = Photos::where('id', $type_id)->get();
             $arr[KeyParser::photos] = Photos::convertPhotosToArray($photos);
             break;
     }
     unset($photos_arr);
     return $arr;
 }
Exemplo n.º 16
0
 /**
  * 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;
 }
Exemplo n.º 17
0
 /**
  * Construct the needed Array for Reviews User and Restaurant
  * action: userAction, restaurantAction
  *
  * @param $reviews
  * @return mixed
  */
 public static function reviewsQueries($reviews)
 {
     $reviews_array = array();
     if (!$reviews) {
         return $reviews_array;
     }
     foreach ($reviews as $review) {
         $restaurant = Restaurants::find($review->restaurant_id);
         if (!$restaurant) {
             continue;
         }
         $user = Users::find($review->user_id);
         $photos = Photos::getByType(CONSTANTS::REVIEW, $review->id);
         $photos_array = Photos::convertPhotosToArray($photos);
         if ($user) {
             $reviews_array[] = array(KeyParser::review => ModelFormatter::reviewFormat($review), KeyParser::restaurant => ModelFormatter::restaurantLongFormat($restaurant), KeyParser::user => ModelFormatter::userLongFormat($user), KeyParser::photos => $photos_array);
         }
         //end of check user
         unset($restaurant);
         unset($user);
         unset($photos);
         unset($photos_array);
     }
     //end foreach
     return $reviews_array;
 }
Exemplo n.º 18
0
 /**
  * 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);
 }
Exemplo n.º 19
0
 public function getTagListAction()
 {
     $tags = Categories::getAllTags();
     $data[][KeyParser::category] = array(KeyParser::id => 0, KeyParser::type => CONSTANTS::CATEGORY_TAG, KeyParser::name => CONSTANTS::ALL_TAG_NAME, KeyParser::photo => CONSTANTS::ALL_TAG_PHOTO);
     foreach ($tags as $tag) {
         $data[][KeyParser::category] = ModelFormatter::categoryWithPhotoFormat($tag, CONSTANTS::CATEGORY_TAG);
     }
     $json_return[KeyParser::data] = $data;
     return response()->json($json_return);
 }
Exemplo n.º 20
0
 /**
  * Review View
  * route: reviews/view{id}
  *
  * @param $id
  * @optional ?viewer_id
  * @return Response
  */
 public function viewAction($id)
 {
     $json_return = array();
     $review = Reviews::find($id);
     if (!$review) {
         return showErrorResponse('Review not found', HTTP_ACCEPTED, CONSTANTS::ERROR_CODE_REVIEW_MISSING);
     }
     $restaurant = Restaurants::find($review->restaurant_id);
     if (!$restaurant) {
         return showErrorResponse('Restaurant data not found', HTTP_ACCEPTED, CONSTANTS::ERROR_CODE_GENERAL);
     }
     $user = Users::find($review->user_id);
     $photos = Photos::getByType(CONSTANTS::REVIEW, $review->id);
     $photos_array = Photos::convertPhotosToArray($photos);
     $comments = Comments::getByType(CONSTANTS::REVIEW, $review->id);
     $comments_array = array();
     if ($comments) {
         foreach ($comments as $comment) {
             $comments_array[] = ModelFormatter::commentFormat($comment);
         }
     }
     $json_return[KeyParser::data] = array(KeyParser::review => ModelFormatter::reviewFormat($review), KeyParser::restaurant => ModelFormatter::restaurantLongFormat($restaurant), KeyParser::user => ModelFormatter::userLongFormat($user), KeyParser::photos => $photos_array, KeyParser::comments => $comments_array);
     return response()->json($json_return);
 }