/** * @param Request $request * * @return string * @throws \Exception * @throws exceptions\NotFoundException */ public function run(Request $request) { if ($request->post('action')) { $method = $request->post('action'); if (method_exists($this, $method)) { $this->{$method}($request); } else { throw new BadMethodCallException(); } } $repo = new AuthorRepository($this->db); $author = $repo->where('id', '=', $request->get('id'))->findSingle(); if (!$author) { throw new NotFoundException('author not found'); } $repo = new PublicationRepository($this->db); $publications = $repo->where('author_id', '=', $request->get('id'))->order('date_published', 'DESC')->find(); /* * The configuration of the index parameters and the selection * of the requested indices is realized in the Config class of * Publin by using class constants. As class constants can't be * arrays below PHP 5.6, the configuration is done by using a * string with an array like syntax. The strings have to be * converted back to an array before calling e.g. the method * fetchIndices($requestedIndices). */ if (!is_null(Config::INDICES_PARAMETERS)) { $parameters = IndexHelper::convertStringToArray(Config::INDICES_PARAMETERS, true); } else { $parameters = array(); } if (!is_null(Config::INDICES_SELECTION)) { $requestedIndices = IndexHelper::convertStringToArray(Config::INDICES_SELECTION, false); } else { $requestedIndices = null; } $this->configureIndices($parameters, $request); $indices = $this->fetchIndices($requestedIndices); if ($request->get('m') === 'edit') { $view = new AuthorView($author, $publications, $indices, $this->errors, true); } else { $view = new AuthorView($author, $publications, $indices, $this->errors); } return $view->display(); }
/** * @param $type * @param $id * * @throws Exception */ public function handle($type, $id) { if (!empty($type)) { $this->browse_type = $type; switch ($type) { case 'recent': $this->is_result = true; $repo = new PublicationRepository($this->db); $this->result = $repo->where('foreign', '=', 0)->order('date_added', 'DESC')->limit(20)->find(); break; case 'author': $repo = new AuthorRepository($this->db); $this->browse_list = $repo->order('family', 'ASC')->find(); break; case 'keyword': $repo = new KeywordRepository($this->db); $this->browse_list = $repo->order('name', 'ASC')->find(); break; case 'study_field': $repo = new StudyFieldRepository($this->db); $this->browse_list = $repo->order('name', 'ASC')->find(); break; case 'type': $repo = new TypeRepository($this->db); $this->browse_list = $repo->order('name', 'ASC')->find(); break; case 'year': if ($id > 0) { $this->is_result = true; $repo = new PublicationRepository($this->db); $this->result = $repo->where('date_published', '=', $id, 'YEAR')->order('date_published', 'DESC')->find(); } else { $this->browse_list = $this->fetchYears(); } break; default: throw new Exception('unknown browse type "' . $type . '"'); break; } } }
/** * @param Request $request * * @return bool */ public function searchAuthors(Request $request) { $field = Validator::sanitizeText($request->get('field')); $search = Validator::sanitizeText($request->get('search')); if (!$search) { $this->errors[] = 'Your search input is invalid'; return false; } $search_words = explode(' ', $search); $repo = new AuthorRepository($this->db); switch (true) { case $field === 'given': foreach ($search_words as $word) { $repo->where('given', 'LIKE', '%' . $word . '%'); } break; case $field === 'family': foreach ($search_words as $word) { $repo->where('family', 'LIKE', '%' . $word . '%'); } break; case $field === 'about': foreach ($search_words as $word) { $repo->where('about', 'LIKE', '%' . $word . '%'); } break; default: throw new UnexpectedValueException(); } $this->result = $repo->order('family', 'ASC')->find(); return true; }