plugins/importexport/nlm/NLMExportPlugin.inc.php

Go to the documentation of this file.
00001 <?php
00002 
00016 //$Id$
00017 
00018 import('classes.plugins.ImportExportPlugin');
00019 
00020 class NLMExportPlugin extends ImportExportPlugin {
00027    function register($category, $path) {
00028       $success = parent::register($category, $path);
00029       $this->addLocaleData();
00030       return $success;
00031    }
00032 
00038    function getName() {
00039       return 'NLMExportPlugin';
00040    }
00041 
00042    function getDisplayName() {
00043       return __('plugins.importexport.nlm.displayName');
00044    }
00045 
00046    function getDescription() {
00047       return __('plugins.importexport.nlm.description');
00048    }
00049 
00050    function display(&$args) {
00051       $templateMgr =& TemplateManager::getManager();
00052       parent::display($args);
00053 
00054       $conference =& Request::getConference();
00055 
00056       switch (array_shift($args)) {
00057          case 'exportPaper':
00058             $paperIds = array(array_shift($args));
00059 //          $result = array_shift(PaperSearch::formatResults($paperIds));
00060 //          $this->exportPaper($conference, $result['track'], $result['section'], $result['publishedPaper']);
00061             $result = PaperSearch::formatResults($paperIds);
00062             $this->exportPapers($result);
00063             break;
00064          case 'exportPapers':
00065             $paperIds = Request::getUserVar('paperId');
00066             if (!isset($paperIds)) $paperIds = array();
00067             else array_pop($paperIds);
00068             $results =& PaperSearch::formatResults($paperIds);
00069             $this->exportPapers($results);
00070             break;
00071          case 'papers':
00072             // Display a list of papers for export
00073             $this->setBreadcrumbs(array(), true);
00074             $publishedPaperDao =& DAORegistry::getDAO('PublishedPaperDAO');
00075             $rangeInfo = Handler::getRangeInfo('papers');
00076             $paperIds = $publishedPaperDao->getPublishedPaperIdsAlphabetizedBySchedConf($conference->getId());
00077             $totalPapers = count($paperIds);
00078             if ($rangeInfo->isValid()) $paperIds = array_slice($paperIds, $rangeInfo->getCount() * ($rangeInfo->getPage()-1), $rangeInfo->getCount());
00079             import('core.VirtualArrayIterator');
00080             $iterator = new VirtualArrayIterator(PaperSearch::formatResults($paperIds), $totalPapers, $rangeInfo->getPage(), $rangeInfo->getCount());
00081             $templateMgr->assign_by_ref('papers', $iterator);
00082             $templateMgr->display($this->getTemplatePath() . 'papers.tpl');
00083             break;
00084          default:
00085             $this->setBreadcrumbs();
00086             $templateMgr->display($this->getTemplatePath() . 'index.tpl');
00087       }
00088    }
00089 
00090    function exportPapers(&$results, $outputFile = null) {
00091       $this->import('NLMExportDom');
00092       $doc =& NLMExportDom::generateNLMDom();
00093       $paperSetNode =& NLMExportDom::generatePaperSetDom($doc);
00094 
00095       foreach ($results as $result) {
00096          $conference =& $result['conference'];
00097          $track =& $result['track'];
00098          $paper =& $result['publishedPaper'];
00099 
00100          $paperNode =& NLMExportDom::generatePaperDom($doc, $conference, $track, $paper);
00101          XMLCustomWriter::appendChild($paperSetNode, $paperNode);
00102       }
00103 
00104       if (!empty($outputFile)) {
00105          if (($h = fopen($outputFile, 'w'))===false) return false;
00106          fwrite($h, XMLCustomWriter::getXML($doc));
00107          fclose($h);
00108       } else {
00109          header("Content-Type: application/xml");
00110          header("Cache-Control: private");
00111          header("Content-Disposition: attachment; filename=\"nlm.xml\"");
00112          XMLCustomWriter::printXML($doc);
00113 //echo '<pre>'.htmlentities(preg_replace('/></', ">\n<", XMLCustomWriter::getXML($doc))).'</pre>';
00114       }
00115       return true;
00116    }
00117 
00122    function executeCLI($scriptName, &$args) {
00123 //    $command = array_shift($args);
00124       $xmlFile = array_shift($args);
00125       $conferencePath = array_shift($args);
00126 
00127       $conferenceDao =& DAORegistry::getDAO('ConferenceDAO');
00128       $userDao =& DAORegistry::getDAO('UserDAO');
00129       $publishedPaperDao =& DAORegistry::getDAO('PublishedPaperDAO');
00130 
00131       $conference =& $conferenceDao->getConferenceByPath($conferencePath);
00132 
00133       if (!$conference) {
00134          if ($conferencePath != '') {
00135             echo __('plugins.importexport.nlm.cliError') . "\n";
00136             echo __('plugins.importexport.nlm.export.error.unknownConference', array('conferencePath' => $conferencePath)) . "\n\n";
00137          }
00138          $this->usage($scriptName);
00139          return;
00140       }
00141 
00142       if ($xmlFile != '') switch (array_shift($args)) {
00143          case 'papers':
00144             $results =& PaperSearch::formatResults($args);
00145             if (!$this->exportPapers($results, $xmlFile)) {
00146                echo __('plugins.importexport.nlm.cliError') . "\n";
00147                echo __('plugins.importexport.nlm.export.error.couldNotWrite', array('fileName' => $xmlFile)) . "\n\n";
00148             }
00149             return;
00150       }
00151       $this->usage($scriptName);
00152 
00153    }
00154 
00158    function usage($scriptName) {
00159       echo __('plugins.importexport.nlm.cliUsage', array(
00160          'scriptName' => $scriptName,
00161          'pluginName' => $this->getName()
00162       )) . "\n";
00163    }
00164 }
00165 
00166 ?>

Generated on 25 Jul 2013 for Open Conference Systems by  doxygen 1.4.7