예제 #1
0
 /**
  * Transfer the csl input data into a \Geissler\Converter\Model\Entries object.
  *
  * @param string $data
  * @return boolean
  */
 public function parse($data)
 {
     $json = json_decode($data, true);
     if (is_array($json) == true) {
         $this->entries = new Entries();
         $types = array('article' => 'setArticle', 'article-magazine' => 'setArticleMagazine', 'article-newspaper' => 'setArticleNewspaper', 'article-journal' => 'setArticleJournal', 'bill' => 'setBill', 'book' => 'setBook', 'broadcast' => 'setBroadcast', 'chapter' => 'setChapter', 'dataset' => 'setDataset', 'entry' => 'setEntry', 'entry-dictionary' => 'setEntryDictionary', 'entry-encyclopedia' => 'setEntryEncyclopedia', 'figure' => 'setFigure', 'graphic' => 'setGraphic', 'interview' => 'setInterview', 'legislation' => 'setLegislation', 'legal_case' => 'setLegalCase', 'manuscript' => 'setManuscript', 'map' => 'setMap', 'motion_picture' => 'setMotionPicture', 'musical_score' => 'setMusicalScore', 'pamphlet' => 'setPamphlet', 'paper-conference' => 'setPaperConference', 'patent' => 'setPatent', 'post' => 'setPost', 'post-weblog' => 'setPostWeblog', 'personal_communication' => 'setPersonalCommunication', 'report' => 'setReport', 'review' => 'setReview', 'review-book' => 'setReviewBook', 'song' => 'setSong', 'speech' => 'setSpeech', 'thesis' => 'setThesis', 'treaty' => 'setTreaty', 'webpage' => 'setWebpage');
         $persons = array('author' => 'getAuthor', 'collection-editor' => 'getCollectionEditor', 'container-author' => 'getContainerAuthor', 'director' => 'getDirector', 'editor' => 'getEditor', 'editorial-director' => 'getEditorialDirector', 'illustrator' => 'getIllustrator', 'interviewer' => 'getInterviewer', 'original-author' => 'getOriginalAuthor', 'recipient' => 'getRecipient', 'reviewed-author' => 'getReviewedAuthor', 'translator' => 'getTranslator');
         $dates = array('accessed' => 'getAccessed', 'event-date' => 'getEventDate', 'issued' => 'getIssued', 'original-date' => 'getOriginalDate', 'submitted' => 'getSubmitted');
         $fields = array('abstract' => 'setAbstract', 'annote' => 'setAnnote', 'archive' => 'setArchive', 'archive_location' => 'setArchiveLocation', 'archive-place' => 'setArchivePlace', 'authority' => 'setAuthority', 'call-number' => 'setCallNumber', 'citation-label' => 'setCitationLabel', 'collection-title' => 'setCollectionTitle', 'container-title' => 'setContainerTitle', 'container-title-short' => 'setContainerTitleShort', 'dimensions' => 'setDimensions', 'DOI' => 'setDOI', 'event' => 'setEvent', 'event-place' => 'setEventPlace', 'genre' => 'setGenre', 'ISBN' => 'setISBN', 'issn' => 'setISSN', 'ISSN' => 'setISSN', 'jurisdiction' => 'setJurisdiction', 'keyword' => 'setKeyword', 'medium' => 'setMedium', 'note' => 'setNote', 'original-publisher' => 'setOriginalPublisher', 'original-publisher-place' => 'setOriginalPublisherPlace', 'original-title' => 'setOriginalTitle', 'PMCID' => 'setPMCID', 'PMID' => 'setPMID', 'publisher' => 'setPublisher', 'publisher-place' => 'setPublisherPlace', 'references' => 'setReferences', 'reviewed-title' => 'setReviewedTitle', 'scale' => 'setScale', 'section' => 'setSection', 'source' => 'setSource', 'status' => 'setStatus', 'title' => 'setTitle', 'title-short' => 'setTitleShort', 'url' => 'setURL', 'version' => 'setVersion', 'yearSuffix' => 'setYearSuffix', 'pdf' => 'setPdf');
         foreach ($json as $record) {
             $this->entry = new Entry();
             if (isset($record['type']) == true) {
                 $method = $types[$record['type']];
                 $this->entry->getType()->{$method}();
             }
             // persons
             foreach ($persons as $field => $method) {
                 if (isset($record[$field]) == true) {
                     $this->createPerson($record[$field], $method);
                 }
             }
             // dates
             foreach ($dates as $field => $method) {
                 if (isset($record[$field]) == true) {
                     $this->createDate($record[$field], $method);
                 }
             }
             // pages
             if (isset($record['page']) == true) {
                 $this->entry->getPages()->setRange($record['page']);
             }
             if (isset($record['page-first']) == true) {
                 $this->entry->getPages()->setStart($record['page-first']);
             }
             // normal fields
             foreach ($fields as $field => $method) {
                 if (isset($record[$field]) == true) {
                     $this->entry->{$method}($record[$field]);
                 }
             }
             $this->entries->setEntry($this->entry);
         }
         return true;
     }
     return false;
 }
예제 #2
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);
     }
 }
예제 #3
0
 /**
  * Retrieve the type of record.
  *
  * @param \Geissler\Converter\Model\Entry $entry
  * @param  string                         $type
  * @return \Geissler\Converter\Model\Entry
  */
 private function getType(Entry $entry, $type)
 {
     switch ($type) {
         case 'ABST':
             $entry->getType()->setAbstract();
             break;
         case 'ADVS':
         case 'MPCT':
             $entry->getType()->setMotionPicture();
             break;
         case 'ART':
             $entry->getType()->setGraphic();
             break;
         case 'BILL':
         case 'UNBILl':
             $entry->getType()->setBill();
             break;
         case 'BOOK':
         case 'SER':
             $entry->getType()->setBook();
             break;
         case 'CASE':
             $entry->getType()->setLegalCase();
             break;
         case 'CHAP':
             $entry->getType()->setChapter();
             break;
         case 'JFULL':
         case 'JOUR':
             $entry->getType()->setArticleJournal();
             break;
         case 'CTLG':
             $entry->getType()->setCatalog();
             break;
         case 'DATA':
             $entry->getType()->setDataset();
             break;
         case 'ELEC':
             $entry->getType()->setWebpage();
             break;
         case 'MGZN':
             $entry->getType()->setArticleMagazine();
             break;
         case 'MUSIC':
         case 'SOUND':
             $entry->getType()->setMusicalScore();
             break;
         case 'NEWS':
             $entry->getType()->setArticleNewspaper();
             break;
         case 'PAMP':
             $entry->getType()->setPamphlet();
             break;
         case 'PCOMM':
             $entry->getType()->setPersonalCommunication();
             break;
         case 'RPRT':
             $entry->getType()->setReport();
             break;
         case 'THES':
             $entry->getType()->setThesis();
             break;
         case 'UNPB':
             $entry->getType()->setManuscript();
             break;
         case 'PAT':
             $entry->getType()->setPatent();
             break;
         case 'VIDEO':
             $entry->getType()->setVideo();
             break;
         case 'COMP':
             $entry->getType()->setSoftware();
             break;
         case 'MAP':
             $entry->getType()->setMap();
             break;
         case 'SLIDE':
             $entry->getType()->setSlide();
             break;
         default:
             $entry->getType()->setUnknown();
             break;
     }
     return $entry;
 }
예제 #4
0
 /**
  * Create the bibTeX "header".
  *
  * @param \Geissler\Converter\Model\Entry $entry
  * @return string
  */
 private function init(Entry $entry)
 {
     $type = $this->getType($entry->getType()->getType());
     $return = '@' . $type . '{';
     if ($entry->getCitationLabel() !== null) {
         $return .= $entry->getCitationLabel();
     } else {
         $return .= $type;
     }
     return $return;
 }