Example #1
0
 /**
  * Create entries based on the given standard from the \Geissler\Converter\Model\Entries object.
  *
  * @param \Geissler\Converter\Model\Entries $data
  * @return boolean
  */
 public function create(Entries $data)
 {
     // TODO: Implement create() method.
     if (count($data) > 0) {
         $this->enc = array();
         foreach ($data as $entry) {
             /** @var $entry \Geissler\Converter\Model\Entry */
             $record = array();
             $record['type'] = $entry->getType()->getOriginalType();
             $record['elaboratedtype'] = $entry->getType()->getType();
             $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');
             foreach ($persons as $field => $getter) {
                 $person = $this->createPerson($entry->{$getter}());
                 if (count($person) > 0) {
                     $record[$field] = $person;
                 }
             }
             $dates = array('accessed' => 'getAccessed', 'event-date' => 'getEventDate', 'issued' => 'getIssued', 'original-date' => 'getOriginalDate', 'submitted' => 'getSubmitted');
             foreach ($dates as $field => $getter) {
                 $date = $this->createDate($entry->{$getter}());
                 if (count($date) > 0) {
                     $record[$field] = $date;
                 }
             }
             // pages
             if ($entry->getPages()->getRange() !== null) {
                 $record['page'] = $entry->getPages()->getRange();
             } elseif ($entry->getPages()->getStart() !== null && $entry->getPages()->getEnd() !== null) {
                 $record['page'] = $entry->getPages()->getStart() . '-' . $entry->getPages()->getEnd();
             } elseif ($entry->getPages()->getStart() !== null) {
                 $record['page'] = $entry->getPages()->getStart();
             } elseif ($entry->getPages()->getEnd() !== null) {
                 $record['page'] = $entry->getPages()->getEnd();
             } elseif ($entry->getPages()->getTotal() !== null) {
                 $record['page'] = $entry->getPages()->getTotal();
             }
             if ($entry->getPages()->getStart() !== null) {
                 $record['page-first'] = $entry->getPages()->getStart();
             }
             $fields = array('abstract' => 'getAbstract', 'annote' => 'getAnnote', 'archive' => 'getArchive', 'archive_location' => 'getArchiveLocation', 'archive-place' => 'getArchivePlace', 'authority' => 'getAuthority', 'call-number' => 'getCallNumber', 'citation-label' => 'getCitationLabel', 'collection-title' => 'getCollectionTitle', 'container-title' => 'getContainerTitle', 'container-title-short' => 'getContainerTitleShort', 'dimensions' => 'getDimensions', 'DOI' => 'getDOI', 'event' => 'getEvent', 'event-place' => 'getEventPlace', 'genre' => 'getGenre', 'ISBN' => 'getISBN', 'ISSN' => 'getISSN', 'jurisdiction' => 'getJurisdiction', 'keyword' => 'getKeyword', 'medium' => 'getMedium', 'note' => 'getNote', 'original-publisher' => 'getOriginalPublisher', 'original-publisher-place' => 'getOriginalPublisherPlace', 'original-title' => 'getOriginalTitle', 'PMCID' => 'getPMCID', 'PMID' => 'getPMID', 'publisher' => 'getPublisher', 'publisher-place' => 'getPublisherPlace', 'references' => 'getReferences', 'reviewed-title' => 'getReviewedTitle', 'scale' => 'getScale', 'section' => 'getSection', 'source' => 'getSource', 'status' => 'getStatus', 'title' => 'getTitle', 'title-short' => 'getTitleShort', 'URL' => 'getURL', 'version' => 'getVersion', 'yearSuffix' => 'getYearSuffix', 'yearfiled' => 'getYearFiled', 'pdf' => 'getPdf', 'projectref' => 'getProjectRef');
             foreach ($fields as $field => $getter) {
                 $value = $entry->{$getter}();
                 if ($value != '' && $value !== null && (is_array($value) == true && count($value) > 0 || is_array($value) == false)) {
                     $record[$field] = $value;
                 }
             }
             $bibCreator = new \Geissler\Converter\Standard\BibTeX\Creator();
             $bib_entries = new Entries();
             $bib_entries->setEntry($entry);
             $bibCreated = $bibCreator->create($bib_entries);
             $record['bibtex_raw'] = $bibCreated ? $bibCreator->retrieve() : null;
             $this->enc[] = $record;
         }
         return true;
     }
     return false;
 }
Example #2
0
 /**
  * Transfer the data from a standard into a \Geissler\Converter\Model\Entries object.
  *
  * @param string $data
  * @return boolean
  */
 public function parse($data)
 {
     $reader = new \LibRIS\RISReader();
     $reader->parseString($data);
     $records = $reader->getRecords();
     if (is_array($records) === true && count($records) > 0) {
         $this->entries = new Entries();
         $authors = array('A1' => 'getAuthor', 'A2' => 'getEditor', 'A4' => 'getTranslator', 'AU' => 'getAuthor', 'TA' => 'getOriginalAuthor');
         $dates = array('Y1' => 'getIssued', 'PY' => 'getIssued', 'Y2' => 'getAccessed');
         $fields = array('N2' => 'setAbstract', 'ID ' => 'setCitationLabel', 'JA' => 'setCollectionTitle', 'JF' => 'setContainerTitle', 'JO' => 'setContainerTitleShort', 'J1' => 'setContainerTitleShort', 'J2' => 'setContainerTitleShort', 'SN' => 'setISBN', 'N1' => 'setNote', 'PB' => 'setPublisher', 'CY' => 'setPublisherPlace', 'T1' => 'setTitle', 'TI' => 'setTitle', 'TT' => 'setOriginalTitle', 'CT' => 'setTitle', 'UR' => 'setURL', 'VL' => 'setVolume', 'IS' => 'setIssue', 'T2' => 'setTitleSecondary', 'L1' => 'setPdf', 'L2 ' => 'setFullText', 'DB' => 'setDatabase', 'DO' => 'setDOI', 'ET' => 'setEdition', 'LA' => 'setLanguage', 'LB' => 'setLabel', 'NV' => 'setNumberOfVolumes', 'RI' => 'setReviewedTitle', 'SE' => 'setVersion', 'ST' => 'setTitleShort', 'RP' => 'setReprintEdition');
         foreach ($records as $record) {
             $entry = $this->getType(new Entry(), $record['TY'][0]);
             // authors
             foreach ($authors as $author => $method) {
                 if (isset($record[$author]) == true) {
                     foreach ($record[$author] as $value) {
                         $entry->{$method}()->setPerson($this->getPerson($value));
                     }
                 }
             }
             // pages
             if (isset($record['SP'][0]) == true) {
                 $entry->getPages()->setStart($record['SP'][0]);
             }
             if (isset($record['EP'][0]) == true) {
                 $entry->getPages()->setEnd($record['EP'][0]);
             }
             // dates
             foreach ($dates as $date => $method) {
                 if (isset($record[$date][0]) == true) {
                     $entry->{$method}()->setDate($this->getDate($record[$date][0]));
                 }
             }
             // keywords
             if (isset($record['KW']) == true) {
                 $entry->setKeyword(implode(', ', $record['KW']));
             }
             // fields
             foreach ($fields as $field => $setter) {
                 if (isset($record[$field][0]) == true && $record[$field][0] != '') {
                     $entry->{$setter}($record[$field][0]);
                 }
             }
             $this->entries->setEntry($entry);
         }
         return true;
     }
     return false;
 }
Example #3
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;
 }
Example #4
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);
     }
 }