ProfileController.php

This handles user profile information, including fetching and updating user profiles, and retrieving counts of bookmarks, published maps, and maps associated with a user.

getUserProfile

public function getUserProfile(Request $request)
{
    // Get the user ID from the request input
    $userId = $request->input('userId');
    // Retrieve the user profile using the User ID from the UserProfile model
    $userProfile = UserProfile::where('user_id', $userId)
        ->first();
    // Retrieve the user account using the User ID from the UserAccount model
    $userAccount = UserAccount::where('id', $userId)
        ->first();
    // Check if both user profile and user account exist
    if (isset($userProfile) && isset($userAccount)) {
        // If both exist, create a success response with user information
        $response = [
            'SUCCESS' => 1,
            'USERNAME' => $userAccount->username,
            'NAME' => $userProfile->name,
            'EMAIL' => $userAccount->email,
            'COMPANY' => $userProfile->company,
        ];
        return $response;
    } else {
        // If either user profile or user account is not found, create a failure response
        $response = [
            'SUCCESS' => 0,
        ];
        return $response;
    }
}

To explain what this getUserProfile method does:

  1. Method Declaration:

    • Declares the function getUserProfile in the ProfileController class.

  2. Request Handling:

    • Accepts a Request object to handle HTTP requests.

    • Retrieves the user ID from the request.

  3. Retrieve User Profile:

    • Uses the UserProfile model to fetch the user profile based on the provided user ID.

  4. Retrieve User Account:

    • Uses the UserAccount model to fetch the user account based on the same user ID.

  5. Check if Both Exist:

    • Checks if both the user profile and user account exist.

  6. Create Success Response:

    • If both exist, creates a success response with user information.

  7. Return the Response:

    • Returns the response containing user information.

  8. Handle Case Where Either Profile or Account is Not Found:

    • If either the user profile or user account is not found, creates a failure response.

updateUserProfile

To explain what this updateUserProfile method does:

  1. Method Declaration:

    • Declares the function updateUserProfile in the ProfileController class.

  2. Request Handling:

    • Accepts a Request object to handle HTTP requests.

    • Retrieves user ID, name, and company from the request input.

  3. Retrieve User Profile:

    • Uses the UserProfile model to fetch the user profile based on the provided user ID.

  4. Update User Profile Information:

    • Updates the user profile information with the provided name and company.

  5. Create Success Response:

    • Creates a success response indicating that the user profile has been updated.

  6. Return the Response:

    • Returns the success response.

getUserInfo

To explain what this getUserInfo method does:

  1. Method Declaration:

    • Declares the function getUserInfo in the ProfileController class.

  2. Request Handling:

    • Accepts a Request object to handle HTTP requests.

    • Retrieves the user ID from the request input.

  3. Bookmark Handling:

    • Defines a directory named 'Bookmark' and constructs the file path for the user's bookmark file.

    • Reads the content of the bookmark file, decodes it as JSON, and counts the number of bookmarks.

  4. PublishedMap Handling:

    • Defines a directory named 'PublishedMap' and gets a list of files.

    • Reads the content of each file, decodes it as JSON, and counts the number of published maps associated with the user.

  5. Map Handling:

    • Defines a directory named 'Map' and constructs the file path for the user's map file.

    • Reads the content of the map file, decodes it as JSON, and counts the number of maps.

  6. Create Response:

    • Creates a response with counts of bookmarks, published maps, and maps.

  7. Return the Response:

    • Returns the response containing counts of bookmarks, published maps, and maps.

Last updated