/**
  * Show all notifications
  *
  * @return string
  */
 public function index()
 {
     try {
         //Get the notifications for the currently logged in user
         $notifications = $this->userRepo->paginateNotifications($this->auth->user());
         //Get next Page url
         $nextPageUrl = generate_next_page_url($notifications);
         //This is not an ajax request
         if (!$this->input->is_ajax_request()) {
             //Load view with data
             $this->load->view('pages/notifications', compact('notifications', 'nextPageUrl'));
         } else {
             //Is an ajax request
             echo json_encode(['error' => false, 'grid' => $this->load->view('pages/partials/_notifications-grid', compact('notifications'), true), 'nextPageUrl' => $nextPageUrl]);
         }
     } catch (Exception $e) {
         //This is not an ajax request
         if (!$this->input->is_ajax_request()) {
             //Show error page
             show_404();
         } else {
             //Is an ajax request
             echo json_encode(['error' => true, 'message' => $e->getMessage()]);
         }
     }
 }
 /**
  * Loads user friends page
  *
  * @param int $userId
  * @return string
  */
 public function friends($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 Friends
         $friends = app('UserRepo')->paginateFriends($profileOwner, 10);
         //Get next page url
         $nextPageUrl = generate_next_page_url($friends);
         //This is a normal request
         if (!$this->input->is_ajax_request()) {
             //Load friends page
             $this->load->view('student-profile/friends', ['title' => $profileOwner->full_name, 'profileOwner' => $profileOwner, 'friends' => $friends, 'nextPageUrl' => $nextPageUrl, 'profileMenu' => 3]);
         } else {
             //Return json encoded data
             echo json_encode(['error' => false, 'grid' => $this->load->view('partials/_friends-grid', ['friends' => $friends], true), 'nextPageUrl' => $nextPageUrl]);
         }
     } catch (Exception $e) {
         //Unexpected error
         show_404();
     }
 }
 /**
  * Search for users
  *
  * @return string
  */
 public function getSearchUsers()
 {
     try {
         //Get search results
         $results = $this->userRepo->searchUsers($this->input->get('srch-term'));
     } catch (Exception $e) {
         //Unexpected error
         $results = null;
     }
     //Get next page url
     $nextPageUrl = generate_next_page_url($results);
     //This is a normal request
     if (!$this->input->is_ajax_request()) {
         //Load view with results
         $this->load->view('pages/search-users-results', ['results' => $results, 'nextPageUrl' => $nextPageUrl]);
     } else {
         //Return json encoded data
         echo json_encode(['error' => false, 'grid' => $this->load->view('partials/_users-grid', ['users' => $results], true), 'nextPageUrl' => $nextPageUrl]);
     }
 }