/** * @param Request $request * * @return string * @throws NotFoundException * @throws \Exception */ public function run(Request $request) { $repo = new TypeRepository($this->db); $type = $repo->where('id', '=', $request->get('id'))->findSingle(); if (!$type) { throw new NotFoundException('type not found'); } $repo = new PublicationRepository($this->db); $publications = $repo->where('type_id', '=', $request->get('id'))->order('date_published', 'DESC')->find(); $view = new TypeView($type, $publications); 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 $id * @param array $data * * @return int */ public function update($id, array $data) { /* Fetches the type */ if (isset($data['type'])) { $repo = new TypeRepository($this->db); $type = $repo->where('name', '=', $data['type'])->findSingle(); $data['type_id'] = $type->getId(); unset($data['type']); } /* Fetches the study field */ if (isset($data['study_field'])) { $repo = new StudyFieldRepository($this->db); $type = $repo->where('name', '=', $data['study_field'])->findSingle(); $data['study_field_id'] = $type->getId(); unset($data['study_field']); } /* If checkbox is unchecked, we do not get a value */ if (!isset($data['foreign'])) { $data['foreign'] = 0; } $old_db = new OldDatabase(); return $old_db->updateData('publications', array('id' => $id), $data); }