Beispiel #1
0
 /**
  * Index action, listing all the users.
  * @return The show all users view
  */
 public function index()
 {
     $page = $this->view->getPage();
     $language = $this->view->getLanguage();
     try {
         if ($language !== null) {
             $users = $this->model->getAllUsers($page, "followers", $language);
         } else {
             if ($this->view->getSortBy() === "repos") {
                 $sortBy = $this->view->getSortBy();
                 $users = $this->model->getAllUsers($page, $sortBy);
             } else {
                 $users = $this->model->getAllUsers($page, "followers");
             }
         }
     } catch (HttpStatus404Exception $e) {
         return $this->errorView->showPageNotFound("/users/?page=" . $page);
     }
     $pages = $users["pages"];
     // RESPONSE FEL FRÅN GITHUB?
     // ^GITHUB SKICKAR BARA UT 1000 RESULTAT…
     /** @note
      * Twig is smart enough to figure out which getters are available
      * so Twig can get $user->login instead of $user->getLogin.
      * Both will work though, but if we remove the getter getLogin()
      * Twig cannot access $user->login, so the private field is'nt explosed,
      * Twig is just smart enough to use those getters.
      */
     $session = new Session();
     $auth = $session->get($this->auth->getTokenSessionName());
     if ($auth !== null) {
         $owner = $this->model->getLoggedInUser($auth)->getLogin();
         $followers = $this->followers->getFollowers($owner);
         $followerLogins = array_map(function ($item) {
             return $item["user"];
         }, $followers);
         // Check if the currently logged in user follow some users.
         foreach ($users[$this->view->getUsersField()] as $key => $value) {
             if (in_array($value->getLogin(), $followerLogins)) {
                 $value->setIsFollowed(true);
             }
         }
     }
     $context = array($this->view->getUsersField() => $users[$this->view->getUsersField()], $this->view->getPagesField() => $pages, $this->view->getAuthField() => $auth);
     return $this->view->showAllUsers($context);
 }