/** * @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 string * @throws PermissionRequiredException * @throws \Exception * @throws exceptions\LoginRequiredException * @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 KeywordRepository($this->db); $keyword = $repo->where('id', '=', $request->get('id'))->findSingle(); if (!$keyword) { throw new NotFoundException('keyword not found'); } $repo = new PublicationRepository($this->db); $publications = $repo->where('keyword_id', '=', $request->get('id'))->order('date_published', 'DESC')->find(); if ($request->get('m') === 'edit') { $view = new KeywordView($keyword, $publications, $this->errors, true); } else { $view = new KeywordView($keyword, $publications, $this->errors); } return $view->display(); }
/** * @param int $offset * * @return array */ private function fetchSets($offset = 0) { $repo = new KeywordRepository($this->db); $keywords = $repo->order('name', 'ASC')->limit($this->sets_per_request, $offset)->find(); $sets = array(); foreach ($keywords as $keyword) { $setSpec = str_replace(' ', '_', $keyword->getName()); $setSpec = strtolower($setSpec); $sets[] = array('setSpec' => $setSpec, 'setName' => $keyword->getName()); } return $sets; }