/** * @param $slug * @param $article_id * @param null $issue_id * @return \Symfony\Component\HttpFoundation\Response */ public function articlePageAction($slug, $article_id, $issue_id = null) { $journalService = $this->get('ojs.journal_service'); $em = $this->getDoctrine()->getManager(); $data['article'] = $em->getRepository('OjsJournalBundle:Article')->find($article_id); $this->throw404IfNotFound($data['article']); //log article view event $bibtex = new Bibtex(); $bibtex->_options['extractAuthors'] = true; $bibtex->_options['wordWrapWidth'] = 0; $bibtex->authorstring = 'VON LAST, JR, FIRST'; $createGetterFunction = 'get' . ucfirst('title'); $fieldTranslations = []; foreach ($data['article']->getTranslations() as $langCode => $translation) { if (!empty($translation->{$createGetterFunction}()) && $translation->{$createGetterFunction}() != '-') { $fieldTranslations[$langCode] = $translation->{$createGetterFunction}(); /* @article{seligman01impact, author = {Len Seligman and Arnon Rosenthal}, title = {{XML}'s Impact on Databases and Data Sharing}, journal = {Computer}, volume = {34}, number = {6}, year = {2001}, issn = {0018-9162}, pages = {59--67}, doi = {http://dx.doi.org/10.1109/2.928623}, publisher = {IEEE Computer Society Press}, address = {Los Alamitos, CA, USA}, } */ $addarray = array(); $addarray['entryType'] = $data['article']->getArticleType(); $addarray['journal'] = $data['article']->getJournal()->getTitle(); $addarray['issn'] = $data['article']->getJournal()->getIssn(); $addarray['address'] = $data['article']->getJournal()->getAddress(); $addarray['address'] = $data['article']->getJournal()->getPublisher()->getName(); $addarray['year'] = $data['article']->getJournal()->getFounded()->format('Y'); $addarray['volume'] = $data['article']->getIssue()->getVolume(); $addarray['pages'] = $data['article']->getFirstPage() . ' - ' . $data['article']->getLastPage(); $addarray['doi'] = $data['article']->getDoi(); $addarray['title'] = $translation->{$createGetterFunction}(); $addarray['language'] = $langCode; $addarray['cite'] = $data['article']->getJournal()->getSlug() . $data['article']->getId(); $addarray['key'] = 'cite'; foreach ($data['article']->getArticleAuthors() as $author) { $addarray['author'][$author->getAuthorOrder()]['first'] = $author->getAuthor()->getFirstName(); $addarray['author'][$author->getAuthorOrder()]['last'] = $author->getAuthor()->getLastName(); //$addarray['author'][]['jr'] = $author->getAuthor()->getMiddleName(); } arsort($addarray['author']); $bibtex->addEntry($addarray); unset($addarray); } } $data['bibtex'] = ltrim(rtrim(print_r($bibtex->bibTex(), 1))); $data['schemaMetaTag'] = '<link rel="schema.DC" href="http://purl.org/dc/elements/1.1/" />'; $data['meta'] = $this->get('ojs.article_service')->generateMetaTags($data['article']); $data['journal'] = $data['article']->getJournal(); $data['page'] = 'journals'; $data['blocks'] = $em->getRepository('OjsSiteBundle:Block')->journalBlocks($data['journal']); $data['journal']->setPublicURI($journalService->generateUrl($data['journal'])); $data['archive_uri'] = $this->generateUrl('ojs_archive_index', ['slug' => $data['journal']->getSlug(), 'publisher' => $data['journal']->getPublisher()->getSlug()], true); $data['token'] = $this->get('security.csrf.token_manager')->refreshToken('article_view'); return $this->render('OjsSiteBundle:Article:article_page.html.twig', $data); }
/** * Displays a results page to check the import status * * @return mixed Depending on validation redirects or view */ public function getConfirm() { // Check if files have been uploaded $store = Storage::disk('local'); $files = $store->files('bibtex'); if (count($files) <= 0) { return redirect('/references/import')->withErrors(['content' => 'Please upload something to import!']); } // Now loop through all found files and extract the notes $references = new Collection(); $bibtex = new Bibtex(); $omitted = []; foreach ($files as $file) { $filecontents = $store->get($file); $ret = $bibtex->loadString($store->get($file)); $bibtex->parse(); // Okay, the bibtex-data looks nice. So for now let's only fill the // already migrated fields: title, year, author_last, author_first, reference_type foreach ($bibtex->data as $index => $entry) { $ref = new Reference(); // Convert entryTypes if necessary switch ($entry['entryType']) { case "article": $entry['entryType'] = "journal article"; break; case "conference": $entry['entryType'] = "conference paper"; break; case "inbook": $entry['entryType'] = "book section"; break; case "masterthesis": $entry['entryType'] = "thesis"; break; case "phdthesis": $entry['entryType'] = "thesis"; break; case "techreport": $entry['entryType'] = "report"; break; } // Can we store this datatype? if (!$ref->typeAllowed($entry['entryType'])) { $omitted[$index]['reason'] = 'Entry type incompatible with database'; continue; } // Is anything empty? Then also omit if (!isset($entry['title']) || strlen($entry['title']) <= 0) { $omitted[$index]['reason'] = 'Title missing'; continue; } if (!isset($entry['year']) || strlen($entry['year']) <= 0) { $omitted[$index]['reason'] = 'Year missing'; continue; } if (!isset($entry['author']) || strlen($entry['author'][0]['last']) <= 0) { $omitted[$index]['reason'] = 'Author last name missing'; continue; } if (!isset($entry['author']) || strlen($entry['author'][0]['first']) <= 0) { $omitted[$index]['reason'] = 'Author first name missing'; continue; } $entry['title'] = str_replace(["{", "}"], "", $entry['title']); $bibtex->data[$index]['title'] = $entry['title']; $ref->title = $entry['title']; $ref->year = $entry['year']; $ref->author_last = $entry['author'][0]['last']; $ref->author_first = $entry['author'][0]['first']; $ref->reference_type = $ref->getTypeKey($entry['entryType']); // Create or, if it exists, omit Reference::firstOrCreate($ref->toArray()); /* * Accordding to the BibTex people these entries are allowed: * Everything with NULL hasn't been implemented yet * 'article', -> "journal article" * 'book', -> book * 'booklet', -> NULL * 'confernce', -> conference paper * 'inbook', -> book section * 'incollection', -> NULL * 'inproceedings', -> NULL * 'manual', -> NULL * 'mastersthesis', -> thesis * 'misc', -> NULL * 'phdthesis', -> thesis * 'proceedings', -> NULL * 'techreport', -> report * 'unpublished' -> NULL */ } } // Clear the uploaded files before exiting $store->delete($files); return view('references.confirm', ['bibtex' => $bibtex->data, 'omitted' => $omitted]); }