/** * 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); }