コード例 #1
0
ファイル: NativeImportDom.inc.php プロジェクト: jalperin/ocs
 function importPaper(&$conference, &$schedConf, &$node, &$track, &$paper, &$errors, &$user, $isCommandLine)
 {
     $dependentItems = array();
     $result = NativeImportDom::handlePaperNode(&$conference, $schedConf, $node, $track, $paper, $publishedPaper, $errors, $user, $isCommandLine, $dependentItems);
     if (!$result) {
         NativeImportDom::cleanupFailure($dependentItems);
     }
     return $result;
 }
コード例 #2
0
 function importIssue(&$journal, &$issueNode, &$issue, &$errors, &$user, $isCommandLine, &$dependentItems, $cleanupErrors = true)
 {
     $errors = array();
     $issue = null;
     $hasErrors = false;
     $issueDao =& DAORegistry::getDAO('IssueDAO');
     $issue = new Issue();
     $issue->setJournalId($journal->getId());
     $journalSupportedLocales = array_keys($journal->getSupportedLocaleNames());
     // => journal locales must be set up before
     $journalPrimaryLocale = $journal->getPrimaryLocale();
     /* --- Set title, description, volume, number, and year --- */
     $titleExists = false;
     for ($index = 0; $node = $issueNode->getChildByName('title', $index); $index++) {
         $locale = $node->getAttribute('locale');
         if ($locale == '') {
             $locale = $journalPrimaryLocale;
         } elseif (!in_array($locale, $journalSupportedLocales)) {
             $errors[] = array('plugins.importexport.native.import.error.issueTitleLocaleUnsupported', array('issueTitle' => $node->getValue(), 'locale' => $locale));
             $hasErrors = true;
             continue;
         }
         $issue->setTitle($node->getValue(), $locale);
         $titleExists = true;
     }
     for ($index = 0; $node = $issueNode->getChildByName('description', $index); $index++) {
         $locale = $node->getAttribute('locale');
         if ($locale == '') {
             $locale = $journalPrimaryLocale;
         } elseif (!in_array($locale, $journalSupportedLocales)) {
             $errors[] = array('plugins.importexport.native.import.error.issueDescriptionLocaleUnsupported', array('issueTitle' => $issue->getLocalizedTitle(), 'locale' => $locale));
             $hasErrors = true;
             continue;
         }
         $issue->setDescription($node->getValue(), $locale);
     }
     if ($node = $issueNode->getChildByName('volume')) {
         $issue->setVolume($node->getValue());
     }
     if ($node = $issueNode->getChildByName('number')) {
         $issue->setNumber($node->getValue());
     }
     if ($node = $issueNode->getChildByName('year')) {
         $issue->setYear($node->getValue());
     }
     /* --- Set date published --- */
     if ($node = $issueNode->getChildByName('date_published')) {
         $publishedDate = strtotime($node->getValue());
         if ($publishedDate === -1) {
             $errors[] = array('plugins.importexport.native.import.error.invalidDate', array('value' => $node->getValue()));
             if ($cleanupErrors) {
                 NativeImportDom::cleanupFailure($dependentItems);
             }
             return false;
         } else {
             $issue->setDatePublished($publishedDate);
         }
     }
     /* --- Set attributes: Identification type, published, current, public ID --- */
     switch ($value = $issueNode->getAttribute('identification')) {
         case 'num_vol_year':
             $issue->setShowVolume(1);
             $issue->setShowNumber(1);
             $issue->setShowYear(1);
             $issue->setShowTitle(0);
             break;
         case 'vol_year':
             $issue->setShowVolume(1);
             $issue->setShowNumber(0);
             $issue->setShowYear(1);
             $issue->setShowTitle(0);
             break;
         case 'vol':
             $issue->setShowVolume(1);
             $issue->setShowNumber(0);
             $issue->setShowYear(0);
             $issue->setShowTitle(0);
             break;
         case 'year':
             $issue->setShowVolume(0);
             $issue->setShowNumber(0);
             $issue->setShowYear(1);
             $issue->setShowTitle(0);
             break;
         case 'title':
         case '':
         case null:
             $issue->setShowVolume(0);
             $issue->setShowNumber(0);
             $issue->setShowYear(0);
             $issue->setShowTitle(1);
             break;
         default:
             $errors[] = array('plugins.importexport.native.import.error.unknownIdentificationType', array('identificationType' => $value, 'issueTitle' => $issue->getLocalizedTitle()));
             $hasErrors = true;
             break;
     }
     if (($issueNode->getAttribute('identification') == 'title' || $issueNode->getAttribute('identification') == '') && !$titleExists) {
         $errors[] = array('plugins.importexport.native.import.error.titleMissing', array());
         // Set a placeholder title so that further errors are
         // somewhat meaningful; this placeholder will not be
         // inserted into the database.
         $issue->setTitle(__('plugins.importexport.native.import.error.defaultTitle'), $journalPrimaryLocale);
         $hasErrors = true;
     }
     switch ($value = $issueNode->getAttribute('published')) {
         case 'true':
             $issue->setPublished(1);
             break;
         case 'false':
         case '':
         case null:
             $issue->setPublished(0);
             break;
         default:
             $errors[] = array('plugins.importexport.native.import.error.invalidBooleanValue', array('value' => $value));
             $hasErrors = true;
             break;
     }
     switch ($value = $issueNode->getAttribute('current')) {
         case 'true':
             $issue->setCurrent(1);
             break;
         case 'false':
         case '':
         case null:
             $issue->setCurrent(0);
             break;
         default:
             $errors[] = array('plugins.importexport.native.import.error.invalidBooleanValue', array('value' => $value));
             $hasErrors = true;
             break;
     }
     if (($value = $issueNode->getAttribute('public_id')) != '') {
         $anotherIssue = $issueDao->getIssueByPublicIssueId($value, $journal->getId());
         if ($anotherIssue) {
             $errors[] = array('plugins.importexport.native.import.error.duplicatePublicId', array('issueTitle' => $issue->getIssueIdentification(), 'otherIssueTitle' => $anotherIssue->getIssueIdentification()));
             $hasErrors = true;
         } else {
             $issue->setPublicIssueId($value);
         }
     }
     /* --- Access Status --- */
     $node = $issueNode->getChildByName('open_access');
     $issue->setAccessStatus($node ? ISSUE_ACCESS_OPEN : ISSUE_ACCESS_SUBSCRIPTION);
     if ($node = $issueNode->getChildByName('access_date')) {
         $accessDate = strtotime($node->getValue());
         if ($accessDate === -1) {
             $errors[] = array('plugins.importexport.native.import.error.invalidDate', array('value' => $node->getValue()));
             $hasErrors = true;
         } else {
             $issue->setOpenAccessDate($accessDate);
         }
     }
     /* --- All processing that does not require an inserted issue ID
        --- has been performed by this point. If there were no errors
        --- then insert the issue and carry on. If there were errors,
        --- then abort without performing the insertion. */
     if ($hasErrors) {
         $issue = null;
         if ($cleanupErrors) {
             NativeImportDom::cleanupFailure($dependentItems);
         }
         return false;
     } else {
         if ($issue->getCurrent()) {
             $issueDao->updateCurrentIssue($journal->getId());
         }
         $issue->setIssueId($issueDao->insertIssue($issue));
         $dependentItems[] = array('issue', $issue);
     }
     /* --- Handle cover --- */
     for ($index = 0; $node = $issueNode->getChildByName('cover', $index); $index++) {
         if (!NativeImportDom::handleCoverNode($journal, $node, $issue, $coverErrors, $isCommandLine)) {
             $errors = array_merge($errors, $coverErrors);
             $hasErrors = true;
         }
     }
     /* --- Handle sections --- */
     for ($index = 0; $node = $issueNode->getChildByName('section', $index); $index++) {
         if (!NativeImportDom::handleSectionNode($journal, $node, $issue, $sectionErrors, $user, $isCommandLine, $dependentItems, $index)) {
             $errors = array_merge($errors, $sectionErrors);
             $hasErrors = true;
         }
     }
     /* --- See if any errors occurred since last time we checked.
        --- If so, delete the created issue and return failure.
        --- Otherwise, the whole process was successful. */
     if ($hasErrors) {
         $issue = null;
         // Don't pass back a reference to a dead issue
         if ($cleanupErrors) {
             NativeImportDom::cleanupFailure($dependentItems);
         }
         return false;
     }
     $issueDao->updateIssue($issue);
     return true;
 }