Ejemplo n.º 1
0
 /**
  * Checks if the provided publications data is correct.
  *
  * @param array $data Contains the data of all publications.
  *
  * @throws IndexDataException If $data doesn't contain valid
  * publications with the required attributes 'publicationId'
  * and 'citationCount'.
  */
 private function checkPublicationsData(array $data)
 {
     IndexHelper::checkArrayKeysExist(array_keys($this->dataFormat), $data, 0, 0);
     IndexHelper::checkDataTypesAreCorrect($this->dataFormat, $data, 3, 0, 0);
     IndexHelper::checkDataTypesAreCorrect(array('int'), $data, 1, 1, 0, array(0 => array('publications')));
     IndexHelper::checkDataTypesAreCorrect(array('array'), $data, 2, 1, 0, array(0 => array('publications')));
     IndexHelper::checkArrayKeysExist(array_keys($this->dataFormat['publications']['int']), $data, 2, 0, array(0 => array('publications')));
     IndexHelper::checkDataTypesAreCorrect($this->dataFormat['publications']['int'], $data, 3, 2, 0, array(0 => array('publications')));
 }
Ejemplo n.º 2
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.º 3
0
 /**
  * {@inheritdoc}
  */
 public function setParameters(array $parameters)
 {
     foreach ($parameters as $name => $value) {
         if (array_key_exists($name, $this->parameters)) {
             try {
                 IndexHelper::checkDataTypeIsCorrect($this->parameters[$name]['dataType'], $value);
             } catch (IndexDataException $e) {
                 throw new IndexParameterException('The parameter with the name ' . $name . ' should have the data type ' . $this->parameters[$name]['dataType'] . ' but has the data type ' . gettype($value));
             }
             if (in_array($this->parameters[$name]['dataType'], IndexHelper::getNumericDataTypes())) {
                 if (!($value >= $this->parameters[$name]['from'] && $value <= $this->parameters[$name]['to'])) {
                     throw new IndexParameterException('The parameter with the name ' . $name . ' is only defined in the range from ' . $this->parameters[$name]['from'] . ' to ' . $this->parameters[$name]['to'] . '. You provided the value ' . $value . '.');
                 }
             }
             $this->parameters[$name]['value'] = $value;
         } else {
             throw new IndexParameterException('The ' . $this->name . '
                 doesn\'t have a parameter with the name ' . $name . '.');
         }
     }
 }
Ejemplo n.º 4
0
 /**
  * Checks if the provided data of the colleagues of the
  * considered scientist is correct.
  *
  * @param array $data Contains the data of all colleagues.
  *
  * @throws IndexDataException If $data doesn't contain a valid
  * list of colleagues. This is e.g. the case if the colleague
  * array doesn't have timestamps as keys or if important
  * attributes to identify a colleague like the 'authorId'
  * are missing.
  */
 private function checkColleaguesData(array $data)
 {
     IndexHelper::checkDataTypesAreCorrect(array('int'), $data, 1, 2, 0, array(0 => array('author'), 1 => array('colleagues')));
     IndexHelper::checkDataTypesAreCorrect(array('array'), $data, 2, 2, 0, array(0 => array('author'), 1 => array('colleagues')));
     IndexHelper::checkDataTypesAreCorrect(array('int'), $data, 1, 3, 0, array(0 => array('author'), 1 => array('colleagues')));
     IndexHelper::checkDataTypesAreCorrect(array('array'), $data, 2, 3, 0, array(0 => array('author'), 1 => array('colleagues')));
     IndexHelper::checkArrayKeysExist(array_keys($this->dataFormat['author']['colleagues']['int']['int']), $data, 4, 0, array(0 => array('author'), 1 => array('colleagues')));
     IndexHelper::checkDataTypesAreCorrect($this->dataFormat['author']['colleagues']['int']['int'], $data, 3, 4, 0, array(0 => array('author'), 1 => array('colleagues')));
 }