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