From 3f0c64495f91dfb6e27a888e2fc2a68230bd4539 Mon Sep 17 00:00:00 2001 From: Pierre Date: Sun, 13 May 2018 20:15:24 +0200 Subject: [PATCH] Can export user information --- RestControllers/accountController.php | 54 +++++++++++++++++++++++++ classes/components/AccountComponent.php | 40 ++++++++++++++++++ 2 files changed, 94 insertions(+) diff --git a/RestControllers/accountController.php b/RestControllers/accountController.php index 17a10e2..706a9fa 100644 --- a/RestControllers/accountController.php +++ b/RestControllers/accountController.php @@ -111,6 +111,60 @@ class accountController { ); } + /** + * Export all account data + * + * @url POST /account/export_data + */ + public function exportData(){ + + //Login & valid password required + user_login_required(); + check_post_password(userID, "password"); + + //Generate and get data set + $data = components()->account->export(userID); + + //Process data set + //Advanced user information + $data["advanced_info"] = userController::advancedUserToAPI($data["advanced_info"]); + + //Posts + foreach($data["posts"] as $num => $post) + $data["posts"][$num] = PostsController::PostToAPI($post); + + //Comments + foreach($data["comments"] as $num => $comment) + $data["comments"][$num] = CommentsController::commentToAPI($comment); + + //Likes + foreach($data["likes"] as $num => $like) + $data["likes"][$num] = LikesController::UserLikeToAPI($like); + + //Survey responses + foreach($data["survey_responses"] as $num => $response) + $data["survey_responses"][$num] = SurveysController::SurveyResponseToAPI($response); + + //Movies + foreach($data["movies"] as $num => $movie) + $data["movies"][$num] = MoviesController::MovieToAPI($movie); + + //Conversations messages + foreach($data["conversation_messages"] as $num => $message) + $data["conversation_messages"][$num] = ConversationsController::ConvMessageToAPI($message); + + //Conversations list + foreach($data["conversations_list"] as $num => $conversation) + $data["conversations_list"][$num] = ConversationsController::ConvInfoToAPI($conversation); + + //Friends list + foreach($data["friends_list"] as $num => $friend) + $data["friends_list"][$num] = friendsController::parseFriendAPI($friend); + + return $data; + + } + /** * Delete an account * diff --git a/classes/components/AccountComponent.php b/classes/components/AccountComponent.php index 7fac8da..2335bbb 100644 --- a/classes/components/AccountComponent.php +++ b/classes/components/AccountComponent.php @@ -277,6 +277,46 @@ class AccountComponent { return crypt(sha1($userPassword), sha1($userPassword)); } + /** + * Get user account data (full export) + * + * @param int $userID Target user ID + * @return array Information about the user + */ + public function export(int $userID) : array { + + $data = array(); + + //General account information + $data["advanced_info"] = components()->user->getUserAdvancedInfo($userID); + + //Posts list (with comments) + $data["posts"] = components()->posts->getUserEntirePostsList($userID, TRUE); + + //Comments list + $data["comments"] = components()->comments->getAllUser($userID); + + //Likes + $data["likes"] = components()->likes->get_all_user($userID); + + //Survey responses + $data["survey_responses"] = components()->survey->get_all_responses($userID); + + //User movies + $data["movies"] = components()->movies->get_list($userID); + + //Conversation messages + $data["conversation_messages"] = components()->conversations->getAllUserMessages($userID); + + //Conversations list + $data["conversations_list"] = components()->conversations->getList($userID); + + //Friend list + $data["friends_list"] = components()->friends->getList($userID); + + return $data; + } + /** * Delete user account *