Ejemplo n.º 1
0
 /**
  * Write the data into Geissler\Converter\Model\Entry objects.
  *
  * @param array $data
  */
 private function create(array $data)
 {
     $this->entries = new Entries();
     $length = count($data);
     for ($i = 0; $i < $length; $i++) {
         $entry = new Entry();
         switch ($data[$i]['bibtexEntryType']) {
             case 'article':
                 $entry->getType()->setArticle();
                 break;
             case 'book':
             case 'manual':
                 $entry->getType()->setBook();
                 break;
             case 'conference':
                 $entry->getType()->setConference();
                 break;
             case 'inbook':
             case 'incollection':
                 $entry->getType()->setChapter();
                 break;
             case 'inproceedings':
             case 'proceedings':
                 $entry->getType()->setPaperConference();
                 break;
             case 'mastersthesis':
             case 'phdthesis':
                 $entry->getType()->setThesis();
                 break;
             case 'booklet':
                 $entry->getType()->setPamphlet();
                 break;
             case 'techreport':
                 $entry->getType()->setReport();
                 break;
             case 'unpublished':
                 $entry->getType()->setManuscript();
                 break;
             default:
                 $entry->getType()->setUnknown();
                 break;
         }
         // author
         if (isset($data[$i]['author']) == true) {
             $entry = $this->createPersons($entry, $data[$i]['author'], 'getAuthor');
         }
         // editor
         if (isset($data[$i]['editor']) == true) {
             $entry = $this->createPersons($entry, $data[$i]['editor'], 'getEditor');
         }
         // set dates as issued date
         $issued = new Date();
         if (isset($data[$i]['year']) == true) {
             $issued->setYear($data[$i]['year']);
         }
         if (isset($data[$i]['month']) == true) {
             if (is_array($data[$i]['month']) == true) {
                 // a date containing a month and a day is set
                 if ($data[$i]['month'][0] !== false) {
                     // two dates are used
                     $start = new Date();
                     $start->setYear($issued->getYear())->setMonth($data[$i]['month'][0]);
                     if ($data[$i]['month'][1] !== false) {
                         $start->setDay($data[$i]['month'][1]);
                     }
                     $entry->getIssued()->setDate($start);
                 }
                 // one date
                 if ($data[$i]['month'][2] !== false) {
                     $issued->setMonth($data[$i]['month'][2]);
                 } elseif ($data[$i]['month'][1] !== false) {
                     $issued->setMonth($data[$i]['month'][1]);
                 }
                 if ($data[$i]['month'][3] !== false) {
                     $issued->setDay($data[$i]['month'][3]);
                 }
             } else {
                 // only one number set
                 $issued->setMonth($data[$i]['month']);
             }
         }
         $entry->getIssued()->setDate($issued);
         // pages
         if (isset($data[$i]['pages']) == true) {
             if (is_array($data[$i]['pages']) == true) {
                 if (isset($data[$i]['pages'][0]) == true) {
                     $entry->getPages()->setStart($data[$i]['pages'][0]);
                 }
                 if (isset($data[$i]['pages'][1]) == true) {
                     $entry->getPages()->setEnd($data[$i]['pages'][1]);
                 }
             } elseif ($data[$i]['pages'] != '') {
                 $entry->getPages()->setTotal($data[$i]['pages']);
             }
         }
         $mapper = array('title' => 'setTitle', 'abstract' => 'setAbstract', 'volume' => 'setVolume', 'number' => 'setNumber', 'note' => 'setNote', 'publisher' => 'setPublisher', 'series' => 'setCollectionNumber', 'address' => 'setAddress', 'edition' => 'setEdition', 'isbn' => 'setISBN', 'organization' => 'setOrganization', 'chapter' => 'setChapterNumber', 'school' => 'setSchool', 'booktitle' => 'setContainerTitle', 'journal' => 'setJournal', 'bibtexCitation' => 'setCitationLabel', 'shorttitle' => 'setTitleShort', 'keywords' => 'setKeyword', 'LCCN' => 'setCallNumber');
         foreach ($mapper as $key => $method) {
             if (isset($data[$i][$key]) == true && $data[$i][$key] != '') {
                 $entry->{$method}($data[$i][$key]);
             }
         }
         $this->entries->setEntry($entry);
     }
 }
Ejemplo n.º 2
0
 /**
  * Transfer a \Geissler\Converter\Model\Date object into a date string.
  *
  * @param \Geissler\Converter\Model\Date $date
  * @return string|null
  */
 private function getDate(Date $date)
 {
     if ($date->getYear() == null) {
         return null;
     }
     $return = $date->getYear();
     if ($date->getDay() !== null && $date->getMonth() !== null) {
         $return .= '/' . $date->getMonth() . '/' . $date->getDay();
     } elseif ($date->getMonth() !== null) {
         $return .= '/' . $date->getMonth();
     }
     if ($date->getSeason() !== null) {
         $return .= '/';
         if ($date->getMonth() === null) {
             $return .= '/';
         }
         if ($date->getDay() == null) {
             $return .= '/';
         }
         return $return . $date->getSeason();
     }
     return $return;
 }
Ejemplo n.º 3
0
 /**
  * Create a date object for each csl date and inject it via the given getter-method.
  *
  * @param array $dates
  * @param       $method
  */
 private function createDate(array $dates, $method)
 {
     foreach ($dates['date-parts'] as $data) {
         $date = new Date();
         if (isset($data[0]) == true) {
             $date->setYear($data[0]);
         } elseif (isset($values['year']) == true) {
             $date->setYear($data['year']);
         }
         if (isset($data[1]) == true || isset($data['month']) == true) {
             $month = isset($data['month']) == true ? $data['month'] : $data[1];
             if (in_array($month, array(1, 2, 3, 4, 5, 5, 6, 7, 8, 9, 10, 11, 12)) == true) {
                 $date->setMonth($month);
             }
         }
         if (isset($data[2]) == true) {
             $date->setDay($data[2]);
         } elseif (isset($values['day']) == true) {
             $date->setDay($data['day']);
         }
         $this->entry->{$method}()->setDate($date);
     }
 }
Ejemplo n.º 4
0
 /**
  * Parse a date into a \Geissler\Converter\Model\Date object.
  *
  * @param string $data
  * @return \Geissler\Converter\Model\Date
  */
 private function getDate($data)
 {
     $date = new Date();
     if (preg_match('/^([0-9]){4}$/', $data) == 1) {
         $date->setYear($data);
     } elseif (preg_match('/^([0-9]{4})\\/([0-9][0-9])\\/([0-9][0-9])$/', $data, $match) == 1) {
         $date->setYear($match[1])->setMonth($match[2])->setDay($match[3]);
     } elseif (preg_match('/^([0-9]{4})\\/([0-9][0-9])\\/\\/$/', $data, $match) == 1) {
         $date->setYear($match[1])->setMonth($match[2]);
     }
     return $date;
 }