Exemplo n.º 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;
 }