/**
  * Loads the profile page
  *
  * @param int $userId
  * @return string
  */
 public function profile($userId)
 {
     try {
         //Get user for who this profile belongs
         $profileOwner = app('UserRepo')->getUser($userId, 'student');
         //Student profile was not found
         if ($profileOwner == false) {
             //Show 404 page
             throw new Exception('Student profile not found', '404');
         }
         //Get Posts
         $posts = $this->postsRepo->paginateUserPosts($profileOwner);
         //Get next page url
         $nextPageUrl = generate_next_page_url($posts);
         //This is a normal request
         if (!$this->input->is_ajax_request()) {
             //Load Student profile
             $this->load->view('student-profile/timeline', ['title' => $profileOwner->full_name, 'profileOwner' => $profileOwner, 'posts' => $posts, 'nextPageUrl' => $nextPageUrl, 'profileMenu' => 1]);
         } else {
             //Return json encoded data
             echo json_encode(['error' => false, 'grid' => $this->load->view('partials/_posts-grid', ['posts' => $posts], true), 'nextPageUrl' => $nextPageUrl]);
         }
     } catch (Exception $e) {
         //Unexpected error
         //This is a normal request
         if (!$this->input->is_ajax_request()) {
             show_error($e->getMessage(), $e->getCode());
         } else {
             //Return error json
             echo json_encode(['error' => true, 'message' => $e->getMessage()]);
         }
     }
 }