/** * @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(); } } if ($request->get('file_id')) { $this->download($request); exit; } $repo = new PublicationRepository($this->db); $publication = $repo->where('id', '=', $request->get('id'))->findSingle(true); if (!$publication) { throw new NotFoundException('publication not found'); } if ($request->get('m') === 'edit') { // To add a citation all publication names are required $repo = new PublicationRepository($this->db); $all_publications = $repo->order('title', 'ASC')->find(); $view = new PublicationView($publication, $this->errors, true, $all_publications); } else { $view = new PublicationView($publication, $this->errors); } return $view->display(); }
/** * @param Request $request * * @return bool */ public function searchPublications(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 PublicationRepository($this->db); switch (true) { case $field === 'title': foreach ($search_words as $word) { $repo->where('title', 'LIKE', '%' . $word . '%'); } break; case $field === 'booktitle': foreach ($search_words as $word) { $repo->where('booktitle', 'LIKE', '%' . $word . '%'); } break; case $field === 'journal': foreach ($search_words as $word) { $repo->where('journal', 'LIKE', '%' . $word . '%'); } break; case $field === 'publisher': foreach ($search_words as $word) { $repo->where('publisher', 'LIKE', '%' . $word . '%'); } break; case $field === 'year': $repo->where('date_published', 'LIKE', $search, 'YEAR'); break; case $field === 'abstract': foreach ($search_words as $word) { $repo->where('abstract', 'LIKE', '%' . $word . '%'); } break; default: throw new UnexpectedValueException(); } $this->result = $repo->order('date_published', 'DESC')->find(); return true; }
/** * @param null $from * @param null $until * @param null $set * @param int $offset * * @return \publin\src\Publication[] */ private function fetchRecords($from = null, $until = null, $set = null, $offset = 0) { $repo = new PublicationRepository($this->db); if ($from) { $repo->where('date_added', '>=', $from . ' 00:00:00'); } if ($until) { $repo->where('date_added', '<=', $until . ' 23:59:59'); } if ($set) { $set = str_replace('_', ' ', $set); $repo->where('keyword_name', '=', $set); } $repo->order('date_added', 'DESC'); $repo->limit($this->records_per_request, (int) $offset); return $repo->find(true); }