Example #1
0
 /**
  * Search for users
  * @return Show search View
  */
 public function search()
 {
     $searchQuery = $this->view->getSearchBy();
     $users = null;
     if ($searchQuery) {
         $users = $this->model->searchUsers($searchQuery);
     }
     $session = new Session();
     $auth = $session->get($this->auth->getTokenSessionName());
     if ($auth !== null && $users !== 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 as $key => $value) {
             if (in_array($value->getLogin(), $followerLogins)) {
                 $value->setIsFollowed(true);
             }
         }
     }
     $context = array($this->view->getUsersField() => $users, $this->view->getAuthField() => $auth);
     return $this->view->showSearch($context);
 }
Example #2
0
 /**
  * Logged in action, get's the session, current user,
  * those the user follow and activity
  * @param String $accessToken
  * @return View showLoggedIn
  */
 public function loggedInUser($accessToken)
 {
     $user = $this->model->getLoggedInUser($accessToken);
     $session = new Session();
     // If we can't find the user, just destroy it.
     if ($user === null) {
         $session->destroy($this->token);
         return;
     }
     $auth = $session->get($this->token);
     $followers = $this->followers->getFollowers($user->getLogin());
     $events = null;
     // Get events
     if ($followers !== null) {
         foreach ($followers as $follower) {
             $events[] = $this->model->getUserActivity($follower["user"]);
         }
     }
     $context = array($this->view->getFollowersField() => $followers, $this->view->getUserField() => $user, $this->view->getEventField() => $events, $this->view->getAuthField() => $auth, $this->view->getSearchField() => $this->search->getSearchFieldName());
     return $this->view->showLoggedIn($context);
 }