/** * @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 Request $request * * @return string * @throws NotFoundException * @throws \Exception */ public function run(Request $request) { $repo = new StudyFieldRepository($this->db); $study_field = $repo->where('id', '=', $request->get('id'))->findSingle(); if (!$study_field) { throw new NotFoundException('study field not found'); } $repo = new PublicationRepository($this->db); $publications = $repo->where('study_field_id', '=', $request->get('id'))->order('date_published', 'DESC')->find(); $view = new StudyFieldView($study_field, $publications); return $view->display(); }
/** * @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; }
/** @noinspection PhpUnusedPrivateMethodInspection * @param Request $request * * @return string * @throws Exception * @throws NotFoundException */ private function browse(Request $request) { $model = new BrowseModel($this->db); $model->handle($request->get('by'), $request->get('id')); $view = new BrowseView($model); return $view->display(); }
/** @noinspection PhpUnusedPrivateMethodInspection * @param Request $request * * @return bool|mixed * @throws PermissionRequiredException * @throws exceptions\LoginRequiredException */ private function addUrl(Request $request) { if (!$this->auth->checkPermission(Auth::EDIT_PUBLICATION)) { throw new PermissionRequiredException(Auth::EDIT_PUBLICATION); } $id = Validator::sanitizeNumber($request->get('id')); if (!$id) { throw new UnexpectedValueException(); } $url_model = new UrlModel($this->db); $validator = $url_model->getValidator(); if ($validator->validate($request->post())) { $data = $validator->getSanitizedResult(); $url = new Url($data); try { return $url_model->store($url, $id); } catch (DBDuplicateEntryException $e) { $this->errors[] = 'This url is already assigned to this publication'; return false; } } else { $this->errors = array_merge($this->errors, $validator->getErrors()); return false; } }
/** @noinspection PhpUnusedPrivateMethodInspection * @param Request $request * * @return bool|int * @throws PermissionRequiredException * @throws exceptions\LoginRequiredException */ private function edit(Request $request) { if (!$this->auth->checkPermission(Auth::EDIT_KEYWORD)) { throw new PermissionRequiredException(Auth::EDIT_KEYWORD); } $id = Validator::sanitizeNumber($request->get('id')); if (!$id) { throw new UnexpectedValueException(); } $validator = $this->model->getValidator(); if ($validator->validate($request->post())) { $input = $validator->getSanitizedResult(); $this->model->update($id, $input); return true; } else { $this->errors = array_merge($this->errors, $validator->getErrors()); return false; } }
/** * @param Request $request * * @return string */ public function run(Request $request) { try { $this->clearResumptionTokens(); $verb = $request->get('verb') ? $request->get('verb') : $request->post('verb'); $resumptionToken = $request->get('resumptionToken') ? $request->get('resumptionToken') : $request->post('resumptionToken'); $metadataPrefix = $request->get('metadataPrefix') ? $request->get('metadataPrefix') : $request->post('metadataPrefix'); $from = $request->get('from') ? $request->get('from') : $request->post('from'); $until = $request->get('until') ? $request->get('until') : $request->post('until'); $set = $request->get('set') ? $request->get('set') : $request->post('set'); $identifier = $request->get('identifier') ? $request->get('identifier') : $request->post('identifier'); switch (true) { case $verb === 'Identify': $xml = $this->identify(); break; case $verb === 'ListMetadataFormats': $xml = $this->listMetadataFormats(); break; case $verb === 'ListSets': $xml = $this->listSets($resumptionToken); break; case $verb === 'ListIdentifiers': $xml = $this->listIdentifiers($metadataPrefix, $from, $until, $set, $resumptionToken); break; case $verb === 'ListRecords': $xml = $this->listRecords($metadataPrefix, $from, $until, $set, $resumptionToken); break; case $verb === 'GetRecord': $xml = $this->getRecord($identifier, $metadataPrefix); break; default: throw new BadVerbException(); break; } } catch (BadArgumentException $e) { $xml = $this->createErrorResponse('badArgument'); } catch (BadResumptionTokenException $e) { $xml = $this->createErrorResponse('badResumptionToken'); } catch (BadVerbException $e) { $xml = $this->createErrorResponse('badVerb'); } catch (CannotDisseminateFormatException $e) { $xml = $this->createErrorResponse('cannotDisseminateFormat'); } catch (IdDoesNotExistException $e) { $xml = $this->createErrorResponse('idDoesNotExist'); } catch (NoMetadataFormatsException $e) { $xml = $this->createErrorResponse('noMetadataFormats'); } catch (NoRecordsMatchException $e) { $xml = $this->createErrorResponse('noRecordsMatch'); } catch (NoSetHierarchyException $e) { $xml = $this->createErrorResponse('noSetHierarchy'); } $xml->preserveWhiteSpace = false; $xml->formatOutput = true; return $xml->saveXML(); }