Ejemplo n.º 1
0
 /**
  * @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();
 }
Ejemplo n.º 2
0
 /**
  * @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();
 }
Ejemplo n.º 3
0
 /**
  * @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();
 }
Ejemplo n.º 4
0
 /**
  * @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();
         }
     }
     $repo = new AuthorRepository($this->db);
     $author = $repo->where('id', '=', $request->get('id'))->findSingle();
     if (!$author) {
         throw new NotFoundException('author not found');
     }
     $repo = new PublicationRepository($this->db);
     $publications = $repo->where('author_id', '=', $request->get('id'))->order('date_published', 'DESC')->find();
     /*
      * The configuration of the index parameters and the selection
      * of the requested indices is realized in the Config class of
      * Publin by using class constants. As class constants can't be
      * arrays below PHP 5.6, the configuration is done by using a
      * string with an array like syntax. The strings have to be
      * converted back to an array before calling e.g. the method
      * fetchIndices($requestedIndices).
      */
     if (!is_null(Config::INDICES_PARAMETERS)) {
         $parameters = IndexHelper::convertStringToArray(Config::INDICES_PARAMETERS, true);
     } else {
         $parameters = array();
     }
     if (!is_null(Config::INDICES_SELECTION)) {
         $requestedIndices = IndexHelper::convertStringToArray(Config::INDICES_SELECTION, false);
     } else {
         $requestedIndices = null;
     }
     $this->configureIndices($parameters, $request);
     $indices = $this->fetchIndices($requestedIndices);
     if ($request->get('m') === 'edit') {
         $view = new AuthorView($author, $publications, $indices, $this->errors, true);
     } else {
         $view = new AuthorView($author, $publications, $indices, $this->errors);
     }
     return $view->display();
 }
Ejemplo n.º 5
0
 /**
  * @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;
         }
     }
 }
Ejemplo n.º 6
0
 /**
  * @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();
 }
Ejemplo n.º 7
0
 /**
  * @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;
 }
Ejemplo n.º 8
0
 /**
  * @param $identifier
  * @param $metadataPrefix
  *
  * @return DOMDocument
  * @throws BadArgumentException
  * @throws CannotDisseminateFormatException
  * @throws IdDoesNotExistException
  */
 public function getRecord($identifier, $metadataPrefix)
 {
     if (!$identifier || !$metadataPrefix) {
         throw new BadArgumentException();
     }
     if (!array_key_exists($metadataPrefix, $this->metadataFormats)) {
         throw new CannotDisseminateFormatException();
     }
     $repo = new PublicationRepository($this->db);
     $identifier = explode(':', $identifier);
     if (!isset($identifier[2])) {
         throw new IdDoesNotExistException();
     }
     $identifier = $identifier[2];
     $publications = $repo->where('id', '=', $identifier)->find(true);
     if (count($publications) == 0) {
         throw new IdDoesNotExistException();
     }
     $publication = $publications[0];
     $xml = new DOMDocument('1.0', 'UTF-8');
     $request = array('verb' => 'GetRecord', 'identifier' => $identifier, 'metadataPrefix' => $metadataPrefix);
     $getRecord = $xml->createElement('GetRecord');
     $getRecord->appendChild($xml->importNode($this->createRecord($publication, $metadataPrefix), true));
     return $this->createResponse($request, $getRecord);
 }