00001 <?php
00002
00015 import('classes.plugins.ImportExportPlugin');
00016 import('lib.pkp.classes.xml.XMLCustomWriter');
00017
00018 class Onix30ExportPlugin extends ImportExportPlugin {
00025 function register($category, $path) {
00026 $success = parent::register($category, $path);
00027 $this->addLocaleData();
00028 return $success;
00029 }
00030
00036 function getName() {
00037 return 'Onix30ExportPlugin';
00038 }
00039
00040 function getDisplayName() {
00041 return __('plugins.importexport.onix30.displayName');
00042 }
00043
00044 function getDescription() {
00045 return __('plugins.importexport.onix30.description');
00046 }
00047
00048 function display(&$args) {
00049 $templateMgr =& TemplateManager::getManager();
00050 parent::display($args);
00051
00052 $press =& Request::getPress();
00053 $templateMgr->assign_by_ref('press', $press);
00054
00055 switch (array_shift($args)) {
00056 case 'exportMonograph':
00057
00058 $publicationFormatId = (int) Request::getUserVar('publicationFormatId');
00059 $publicationFormatDao =& DAORegistry::getDAO('PublicationFormatDAO');
00060 $publicationFormat =& $publicationFormatDao->getById($publicationFormatId);
00061 if ($publicationFormat != null) {
00062 $monographId = $publicationFormat->getMonographId();
00063 $publishedMonographDao =& DAORegistry::getDAO('PublishedMonographDAO');
00064
00065
00066 $monograph =& $publishedMonographDao->getById($monographId, $press->getId());
00067 if ($monograph != null) {
00068 $this->exportMonograph($press, $monograph, $publicationFormat);
00069 }
00070 }
00071 break;
00072
00073 default:
00074
00075 AppLocale::requireComponents(LOCALE_COMPONENT_PKP_SUBMISSION);
00076 $publishedMonographDao =& DAORegistry::getDAO('PublishedMonographDAO');
00077 $rangeInfo = Handler::getRangeInfo('monographs');
00078 $monographs = $publishedMonographDao->getByPressId($press->getId())->toArray();
00079
00080 import('lib.pkp.classes.core.VirtualArrayIterator');
00081 $iterator = new VirtualArrayIterator($monographs, count($monographs), $rangeInfo->getPage(), $rangeInfo->getCount());
00082 $templateMgr->assign_by_ref('monographs', $iterator);
00083 $templateMgr->assign('urlPath', array('plugin', 'Onix30ExportPlugin', 'exportMonograph'));
00084 $templateMgr->display($this->getTemplatePath() . 'index.tpl');
00085 break;
00086 }
00087 }
00088
00089 function exportMonograph(&$press, &$monograph, $publicationFormat, $outputFile = null) {
00090 $this->import('Onix30ExportDom');
00091 $doc =& XMLCustomWriter::createDocument();
00092 $onix30ExportDom = new Onix30ExportDom();
00093
00094 $monographNode =& $onix30ExportDom->generateMonographDom($doc, $press, $monograph, $publicationFormat);
00095 XMLCustomWriter::appendChild($doc, $monographNode);
00096
00097 if (!empty($outputFile)) {
00098 if (($h = fopen($outputFile, 'wb'))===false) return false;
00099 fwrite($h, XMLCustomWriter::getXML($doc));
00100 fclose($h);
00101 } else {
00102 header('Content-Type: application/xml');
00103 header('Cache-Control: private');
00104 header('Content-Disposition: attachment; filename="onix30-' . $monograph->getId() . '-' . $publicationFormat->getId() . '.xml"');
00105 XMLCustomWriter::printXML($doc);
00106 }
00107 return true;
00108 }
00109
00114 function executeCLI($scriptName, &$args) {
00115 $xmlFile = array_shift($args);
00116 $pressPath = array_shift($args);
00117 $monographId = array_shift($args);
00118
00119 $pressDao =& DAORegistry::getDAO('PressDAO');
00120 $publishedMonographDao =& DAORegistry::getDAO('PublishedMonographDAO');
00121 $userDao =& DAORegistry::getDAO('UserDAO');
00122
00123 $press =& $pressDao->getByPath($pressPath);
00124
00125 if (!$press) {
00126 if ($pressPath != '') {
00127 echo __('plugins.importexport.onix30.cliError') . "\n";
00128 echo __('plugins.importexport.onix30.error.unknownPress', array('pressPath' => $pressPath)) . "\n\n";
00129 }
00130 $this->usage($scriptName);
00131 return;
00132 }
00133
00134 $monograph =& $publishedMonographDao->getById($monographId);
00135
00136 if ($monograph == null) {
00137 echo __('plugins.importexport.onix30.cliError') . "\n";
00138 echo __('plugins.importexport.onix30.export.error.monographNotFound', array('monographId' => $monographId)) . "\n\n";
00139 return;
00140 }
00141
00142 if (!$this->exportMonograph($press, $monograph, $xmlFile)) {
00143 echo __('plugins.importexport.onix30.cliError') . "\n";
00144 echo __('plugins.importexport.onix30.export.error.couldNotWrite', array('fileName' => $xmlFile)) . "\n\n";
00145 }
00146 }
00147
00151 function usage($scriptName) {
00152 echo __('plugins.importexport.onix30.cliUsage', array(
00153 'scriptName' => $scriptName,
00154 'pluginName' => $this->getName()
00155 )) . "\n";
00156 }
00157 }
00158
00159 ?>