<?php

class ProfileController extends Controller
{
    /**
     * Construct this object by extending the basic Controller class
     */
    public function __construct()
    {
        parent::__construct();
    }

    /**
     * This method controls what happens when you move to /overview/index in your app.
     * Shows a list of all users.
     */
    public function index()
    {
        $all_users = UserModel::getPublicProfilesOfAllUsers();
        
        // Remove current user from the list
        $current_user_id = Session::get('user_id');
        if ($current_user_id && isset($all_users[$current_user_id])) {
            unset($all_users[$current_user_id]);
        }
        
        $this->View->render('profile/index', array(
            'users' => $all_users)
        );
    }

    /**
     * This method controls what happens when you move to /overview/showProfile in your app.
     * Shows the (public) details of the selected user.
     * @param $user_id int id the the user
     */
    public function showProfile($user_id)
    {
        if (isset($user_id)) {
            $this->View->render('profile/showProfile', array(
                'user' => UserModel::getPublicProfileOfUser($user_id))
            );
        } else {
            Redirect::home();
        }
    }
}
