Example #1
0
 /**
  * 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]);
 }