/** * 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; }
/** * 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); }
/** * 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); }