/** * Delete comment * * @param $id * @return Response */ public function deleteCommentAction($id) { $comment = Comments::find($id); if (!$comment) { return showErrorResponse('Comment not found'); } $comment_type = $comment->type; $comment_type_id = $comment->type_id; try { $comment->deleteComment(); $json_return[KeyParser::data] = array(KeyParser::id => $id, KeyParser::is_success => CONSTANTS::DELETE_SUCCESS); } catch (\Exception $e) { return showErrorResponse($e->getMessage()); } $comments = Comments::getByTypePaginate($comment_type, $comment_type_id); foreach ($comments as $comment) { $user = Users::find($comment->user_id); $json_return[KeyParser::comments][] = array(KeyParser::comment => ModelFormatter::commentFormat($comment), KeyParser::user => ModelFormatter::userFormat($user)); } $json_return[KeyParser::comment_count] = Comments::getCountByType($comment_type, $comment_type_id); $json_return[KeyParser::page] = array(KeyParser::current => $comments->currentPage(), KeyParser::number => $comments->lastPage()); return response()->json($json_return); }
/** * 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; }
/** * 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); }
/** * 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); }