00001 <?php
00002
00015
00016
00017
00018 import('xml.XMLCustomWriter');
00019
00020 class MetsExportDom {
00021
00025 function generateStructMap(&$doc, &$root, &$journal , &$issues) {
00026 $structMap = &XMLCustomWriter::createElement($doc, 'METS:structMap');
00027 XMLCustomWriter::setAttribute($structMap, 'TYPE', 'logical');
00028 $sDiv = &XMLCustomWriter::createElement($doc, 'METS:div');
00029 XMLCustomWriter::setAttribute($sDiv, 'TYPE', 'journal');
00030 XMLCustomWriter::setAttribute($sDiv, 'DMDID', 'J-'.$journal->getJournalId());
00031 foreach ($issues as $issue) {
00032 MetsExportDom::generateIssueDiv($doc, $sDiv, $issue);
00033 }
00034 XMLCustomWriter::appendChild($structMap, $sDiv);
00035 XMLCustomWriter::appendChild($root, $structMap);
00036 }
00037
00038 function generateIssueDiv(&$doc, &$root, &$issue) {
00039 $pDiv = &XMLCustomWriter::createElement($doc, 'METS:div');
00040 XMLCustomWriter::setAttribute($pDiv, 'TYPE', 'issue');
00041 XMLCustomWriter::setAttribute($pDiv, 'DMDID', 'I-'.$issue->getIssueId());
00042 $SectionDAO = &DAORegistry::getDAO('SectionDAO');
00043 $SectionArray = &$SectionDAO->getSectionsForIssue($issue->getIssueId());
00044 $i = 0;
00045 while ($i < sizeof($SectionArray)) {
00046 MetsExportDom::generateSectionDiv($doc, $pDiv, $SectionArray[$i], $issue);
00047 $i++;
00048 }
00049 XMLCustomWriter::appendChild($root, $pDiv);
00050 }
00051
00052 function generateSectionDiv(&$doc, &$root, &$section, &$issue) {
00053 $pDiv = &XMLCustomWriter::createElement($doc, 'METS:div');
00054 XMLCustomWriter::setAttribute($pDiv, 'TYPE', 'section');
00055 XMLCustomWriter::setAttribute($pDiv, 'DMDID', 'S-'.$section->getSectionId());
00056 $publishedArticleDao = &DAORegistry::getDAO('PublishedArticleDAO');
00057 $publishedArticleArray = &$publishedArticleDao->getPublishedArticlesBySectionId($section->getSectionId(),$issue->getIssueId());
00058 $i = 0;
00059 while ($i < sizeof($publishedArticleArray)) {
00060 MetsExportDom::generateArticleDiv($doc, $pDiv, $publishedArticleArray[$i], $issue);
00061 $i++;
00062 }
00063 XMLCustomWriter::appendChild($root, $pDiv);
00064 }
00065
00069 function generateArticleDiv(&$doc, &$root, &$article, &$issue) {
00070 $pDiv = &XMLCustomWriter::createElement($doc, 'METS:div');
00071 XMLCustomWriter::setAttribute($pDiv, 'TYPE', 'article');
00072 XMLCustomWriter::setAttribute($pDiv, 'DMDID', 'A-'.$article->getArticleId());
00073 $ArticleGalleyDAO = &DAORegistry::getDAO('ArticleGalleyDAO');
00074 $i = 0;
00075 $GalleysArray = &$ArticleGalleyDAO->getGalleysByArticle($article->getArticleId());
00076 while ($i < sizeof($GalleysArray)) {
00077 MetsExportDom::generateArticleFileDiv($doc, $pDiv, $GalleysArray[$i]);
00078 if($GalleysArray[$i]->isHTMLGalley()){
00079 $images = $GalleysArray[$i]->getImageFiles();
00080 foreach ($images as $image) {
00081 MetsExportDom::generateArticleHtmlGalleyImageFileDiv($doc, $pDiv, $image, $article);
00082 }
00083 }
00084 $i++;
00085 }
00086 $SuppFileDAO = &DAORegistry::getDAO('SuppFileDAO');
00087 $suppFilesArray = &$SuppFileDAO->getSuppFilesByArticle($article->getArticleId());
00088 $i = 0;
00089 while ($i < sizeof($suppFilesArray)) {
00090 MetsExportDom::generateArticleSuppFilesDiv($doc, $pDiv, $suppFilesArray[$i]);
00091 $i++;
00092 }
00093 XMLCustomWriter::appendChild($root, $pDiv);
00094 }
00095
00099 function generateArticleFileDiv(&$doc, &$root, $File) {
00100 $fDiv = &XMLCustomWriter::createElement($doc, 'METS:fptr');
00101 XMLCustomWriter::setAttribute($fDiv, 'FILEID', 'F'.$File->getFileId().'-A'.$File->getArticleId());
00102 XMLCustomWriter::appendChild($root, $fDiv);
00103 }
00104
00105 function generateArticleHtmlGalleyImageFileDiv(&$doc, &$root, &$imageFile, &$article){
00106 $fDiv = &XMLCustomWriter::createElement($doc, 'METS:fptr');
00107 XMLCustomWriter::setAttribute($fDiv, 'FILEID', 'F'.$imageFile->getFileId().'-A'.$article->getArticleId());
00108 XMLCustomWriter::appendChild($root, $fDiv);
00109 }
00110
00114 function generateArticleSuppFilesDiv(&$doc, &$root, $SuppFile) {
00115 $sDiv = &XMLCustomWriter::createElement($doc, 'METS:div');
00116 XMLCustomWriter::setAttribute($sDiv, 'TYPE', 'additional_material');
00117 XMLCustomWriter::setAttribute($sDiv, 'DMDID', 'DMD-SF'.$SuppFile->getFileId().'-A'.$SuppFile->getArticleId());
00118 $fDiv = &XMLCustomWriter::createElement($doc, 'METS:fptr');
00119 XMLCustomWriter::setAttribute($fDiv, 'FILEID', 'SF'.$SuppFile->getFileId().'-A'.$SuppFile->getArticleId());
00120 XMLCustomWriter::appendChild($sDiv, $fDiv);
00121 XMLCustomWriter::appendChild($root, $sDiv);
00122 }
00123
00127 function generateJournalDmdSecDom(&$doc, $root, &$journal) {
00128 $dmdSec = &XMLCustomWriter::createElement($doc, 'METS:dmdSec');
00129 XMLCustomWriter::setAttribute($dmdSec, 'ID', 'J-'.$journal->getJournalId());
00130 $mdWrap = &XMLCustomWriter::createElement($doc, 'METS:mdWrap');
00131 $xmlData = &XMLCustomWriter::createElement($doc, 'METS:xmlData');
00132 XMLCustomWriter::setAttribute($mdWrap, 'MDTYPE', 'MODS');
00133 $mods = &XMLCustomWriter::createElement($doc, 'mods:mods');
00134 XMLCustomWriter::setAttribute($mods, 'xmlns:mods', 'http://www.loc.gov/mods/v3');
00135 XMLCustomWriter::setAttribute($root, 'xsi:schemaLocation', str_replace(' http://www.loc.gov/mods/v3 http://www.loc.gov/standards/mods/v3/mods-3-0.xsd', '', $root->getAttribute('xsi:schemaLocation')) . ' http://www.loc.gov/mods/v3 http://www.loc.gov/standards/mods/v3/mods-3-0.xsd');
00136 $titleInfo = &XMLCustomWriter::createElement($doc, 'mods:titleInfo');
00137 XMLCustomWriter::createChildWithText($doc, $titleInfo, 'mods:title', $journal->getJournalTitle());
00138 XMLCustomWriter::appendChild($mods, $titleInfo);
00139 XMLCustomWriter::createChildWithText($doc, $mods, 'mods:genre', 'journal');
00140 XMLCustomWriter::appendChild($xmlData, $mods);
00141 XMLCustomWriter::appendChild($dmdSec, $mdWrap);
00142 XMLCustomWriter::appendChild($mdWrap,$xmlData);
00143 XMLCustomWriter::appendChild($root, $dmdSec);
00144 }
00145
00149 function generateIssueDmdSecDom(&$doc, &$root, &$issue, &$journal) {
00150 $dmdSec = &XMLCustomWriter::createElement($doc, 'METS:dmdSec');
00151 XMLCustomWriter::setAttribute($dmdSec, 'ID', 'I-'.$issue->getIssueId());
00152 $mdWrap = &XMLCustomWriter::createElement($doc, 'METS:mdWrap');
00153 $xmlData = &XMLCustomWriter::createElement($doc, 'METS:xmlData');
00154 XMLCustomWriter::setAttribute($mdWrap, 'MDTYPE', 'MODS');
00155 $mods = &XMLCustomWriter::createElement($doc, 'mods:mods');
00156 XMLCustomWriter::setAttribute($mods, 'xmlns:mods', 'http://www.loc.gov/mods/v3');
00157 XMLCustomWriter::setAttribute($root, 'xsi:schemaLocation', str_replace(' http://www.loc.gov/mods/v3 http://www.loc.gov/standards/mods/v3/mods-3-0.xsd', '', $root->getAttribute('xsi:schemaLocation')) . ' http://www.loc.gov/mods/v3 http://www.loc.gov/standards/mods/v3/mods-3-0.xsd');
00158 $titleInfo = &XMLCustomWriter::createElement($doc, 'mods:titleInfo');
00159 XMLCustomWriter::createChildWithText($doc, $titleInfo, 'mods:title', $issue->getIssueTitle());
00160 XMLCustomWriter::appendChild($mods, $titleInfo);
00161
00162 if($issue->getIssueDescription() != ''){
00163 $modsAbstract = XMLCustomWriter::createChildWithText($doc, $titleInfo, 'mods:abstract', $issue->getIssueDescription());
00164 XMLCustomWriter::appendChild($mods, $modsAbstract);
00165 }
00166
00167 XMLCustomWriter::createChildWithText($doc, $mods, 'mods:genre', 'issue');
00168 import('classes.config.Config');
00169 $base_url = &Config::getVar('general','base_url');
00170 $url = $base_url.'/index.php/'.$journal->getPath().'/issue/view/'.$issue->getIssueId();
00171 $modsIdentifier = XMLCustomWriter::createChildWithText($doc, $mods, 'mods:identifier', $url);
00172 XMLCustomWriter::setAttribute($modsIdentifier, 'type', 'uri');
00173 $modsOriginInfo = &XMLCustomWriter::createElement($doc, 'mods:originInfo');
00174 $timeIssued = date(DATE_W3C, strtotime($issue->getDatePublished()));
00175 $modsDateIssued = XMLCustomWriter::createChildWithText($doc, $modsOriginInfo, 'mods:dateIssued', $timeIssued);
00176 XMLCustomWriter::appendChild($mods, $modsOriginInfo);
00177 $modsRelatedItem = &XMLCustomWriter::createElement($doc, 'mods:relatedItem');
00178 XMLCustomWriter::setAttribute($modsRelatedItem, 'type', 'host');
00179 $modsTitleInfo = &XMLCustomWriter::createElement($doc, 'mods:titleInfo');
00180 $modsIdentifier = XMLCustomWriter::createChildWithText($doc, $modsTitleInfo, 'mods:title', $journal->getJournalTitle());
00181 XMLCustomWriter::appendChild($modsRelatedItem, $modsTitleInfo);
00182 $url = $base_url.'/index.php/'.$journal->getPath();
00183 $modsIdentifier = XMLCustomWriter::createChildWithText($doc, $modsRelatedItem, 'mods:identifier', $url);
00184 XMLCustomWriter::setAttribute($modsIdentifier, 'type', 'uri');
00185 $modsPart = &XMLCustomWriter::createElement($doc, 'mods:part');
00186 $modsVolumDetail = &XMLCustomWriter::createElement($doc, 'mods:detail');
00187 XMLCustomWriter::setAttribute($modsVolumDetail, 'type', 'volume');
00188 XMLCustomWriter::createChildWithText($doc, $modsVolumDetail, 'mods:number', $issue->getVolume());
00189 $modsIssueDetail = &XMLCustomWriter::createElement($doc, 'mods:detail');
00190 XMLCustomWriter::setAttribute($modsIssueDetail, 'type', 'issue');
00191 XMLCustomWriter::createChildWithText($doc, $modsIssueDetail, 'mods:number', $issue->getNumber());
00192 XMLCustomWriter::appendChild($modsPart, $modsVolumDetail);
00193 XMLCustomWriter::appendChild($modsPart, $modsIssueDetail);
00194 XMLCustomWriter::createChildWithText($doc, $modsPart, 'mods:date', $issue->getYear());
00195 XMLCustomWriter::appendChild($modsRelatedItem, $modsPart);
00196 XMLCustomWriter::appendChild($mods, $modsRelatedItem);
00197 XMLCustomWriter::appendChild($xmlData, $mods);
00198 XMLCustomWriter::appendChild($dmdSec, $mdWrap);
00199 XMLCustomWriter::appendChild($mdWrap,$xmlData);
00200 XMLCustomWriter::appendChild($root, $dmdSec);
00201 $SectionDAO = &DAORegistry::getDAO('SectionDAO');
00202 $SectionArray = &$SectionDAO->getSectionsForIssue($issue->getIssueId());
00203 $i = 0;
00204 while ($i < sizeof($SectionArray)) {
00205 MetsExportDom::generateSectionDmdSecDom($doc, $root, $SectionArray[$i], $issue);
00206 $i++;
00207 }
00208 }
00209
00213 function generateSectionDmdSecDom(&$doc, &$root, &$section, &$issue) {
00214 $dmdSec = &XMLCustomWriter::createElement($doc, 'METS:dmdSec');
00215 XMLCustomWriter::setAttribute($dmdSec, 'ID', 'S-'.$section->getSectionId());
00216 $mdWrap = &XMLCustomWriter::createElement($doc, 'METS:mdWrap');
00217 $xmlData = &XMLCustomWriter::createElement($doc, 'METS:xmlData');
00218 XMLCustomWriter::setAttribute($mdWrap, 'MDTYPE', 'MODS');
00219 $mods = &XMLCustomWriter::createElement($doc, 'mods:mods');
00220 XMLCustomWriter::setAttribute($mods, 'xmlns:mods', 'http://www.loc.gov/mods/v3');
00221 XMLCustomWriter::setAttribute($root, 'xsi:schemaLocation', str_replace(' http://www.loc.gov/mods/v3 http://www.loc.gov/standards/mods/v3/mods-3-0.xsd', '', $root->getAttribute('xsi:schemaLocation')) . ' http://www.loc.gov/mods/v3 http://www.loc.gov/standards/mods/v3/mods-3-0.xsd');
00222 $titleInfo = &XMLCustomWriter::createElement($doc, 'mods:titleInfo');
00223 XMLCustomWriter::createChildWithText($doc, $titleInfo, 'mods:title', $section->getSectionTitle());
00224 XMLCustomWriter::appendChild($mods, $titleInfo);
00225 if($section->getSectionAbbrev() != ''){
00226 $titleInfoAlt1 = &XMLCustomWriter::createElement($doc, 'mods:titleInfo');
00227 XMLCustomWriter::createChildWithText($doc, $titleInfoAlt1, 'mods:title', $section->getSectionAbbrev());
00228 XMLCustomWriter::setAttribute($titleInfoAlt1, 'type', 'abbreviated');
00229 XMLCustomWriter::appendChild($mods, $titleInfoAlt1);
00230 }
00231 XMLCustomWriter::createChildWithText($doc, $mods, 'mods:genre', 'section');
00232 XMLCustomWriter::appendChild($xmlData, $mods);
00233 XMLCustomWriter::appendChild($dmdSec, $mdWrap);
00234 XMLCustomWriter::appendChild($mdWrap,$xmlData);
00235 XMLCustomWriter::appendChild($root, $dmdSec);
00236 $publishedArticleDao = &DAORegistry::getDAO('PublishedArticleDAO');
00237 $publishedArticleArray = &$publishedArticleDao->getPublishedArticlesBySectionId($section->getSectionId(),$issue->getIssueId());
00238 $i = 0;
00239 $i = 0;
00240 while ($i < sizeof($publishedArticleArray)) {
00241 MetsExportDom::generateArticleDmdSecDom($doc, $root, $publishedArticleArray[$i], $issue);
00242 $i++;
00243 }
00244 }
00245
00249 function generateArticleDmdSecDom(&$doc, &$root, &$article, &$issue) {
00250 $dmdSec = &XMLCustomWriter::createElement($doc, 'METS:dmdSec');
00251 XMLCustomWriter::setAttribute($dmdSec, 'ID', 'A-'.$article->getArticleId());
00252 $mdWrap = &XMLCustomWriter::createElement($doc, 'METS:mdWrap');
00253 $xmlData = &XMLCustomWriter::createElement($doc, 'METS:xmlData');
00254 XMLCustomWriter::setAttribute($mdWrap, 'MDTYPE', 'MODS');
00255 $mods = &XMLCustomWriter::createElement($doc, 'mods:mods');
00256 XMLCustomWriter::setAttribute($mods, 'xmlns:mods', 'http://www.loc.gov/mods/v3');
00257 XMLCustomWriter::setAttribute($root, 'xsi:schemaLocation', str_replace(' http://www.loc.gov/mods/v3 http://www.loc.gov/standards/mods/v3/mods-3-0.xsd', '', $root->getAttribute('xsi:schemaLocation')) . ' http://www.loc.gov/mods/v3 http://www.loc.gov/standards/mods/v3/mods-3-0.xsd');
00258 $titleInfo = &XMLCustomWriter::createElement($doc, 'mods:titleInfo');
00259 XMLCustomWriter::createChildWithText($doc, $titleInfo, 'mods:title', $article->getArticleTitle());
00260 XMLCustomWriter::appendChild($mods, $titleInfo);
00261
00262
00263
00264
00265
00266
00267
00268
00269
00270
00271
00272
00273
00274
00275
00276 if($article->getArticleAbstract() != '')
00277 XMLCustomWriter::createChildWithText($doc, $mods, 'mods:abstract', $article->getArticleAbstract());
00278
00279
00280
00281
00282
00283
00284
00285 $i = 0;
00286 $authorsArray = &$article->getAuthors();
00287 while ($i < sizeof($authorsArray)) {
00288 $PresenterNode = &MetsExportDom::generateAuthorDom($doc, $authorsArray[$i]);
00289 XMLCustomWriter::appendChild($mods, $PresenterNode);
00290 $i++;
00291 }
00292 XMLCustomWriter::createChildWithText($doc, $mods, 'mods:genre', 'article');
00293 if($issue->getDatePublished() != ''){
00294 $timeIssued = date(DATE_W3C, strtotime($issue->getDatePublished()));
00295 $originInfo = &XMLCustomWriter::createElement($doc, 'mods:originInfo');
00296 $sDate = XMLCustomWriter::createChildWithText($doc, $originInfo, 'mods:dateIssued', $timeIssued);
00297 XMLCustomWriter::appendChild($mods, $originInfo);
00298 }
00299 if($article->getArticleDiscipline() != ''){
00300 $modsSubject = &XMLCustomWriter::createElement($doc, 'mods:subject');
00301 $DisciplineArray = explode(";", $article->getArticleDiscipline());
00302 $i = 0;
00303 while ($i < sizeof($DisciplineArray)) {
00304 XMLCustomWriter::createChildWithText($doc, $modsSubject, 'mods:topic', $DisciplineArray[$i] );
00305 $i++;
00306 }
00307 XMLCustomWriter::appendChild($mods, $modsSubject);
00308 }
00309 if($article->getArticleSubject() != ''){
00310 $modsSubject = &XMLCustomWriter::createElement($doc, 'mods:subject');
00311 $modsTopic = XMLCustomWriter::createChildWithText($doc, $modsSubject, 'mods:topic', $article->getArticleSubject());
00312 if($article->getSubjectClass() != '')
00313 XMLCustomWriter::setAttribute($modsSubject, 'authority', $article->getSubjectClass());
00314 XMLCustomWriter::appendChild($mods, $modsSubject);
00315 }
00316 if($article->getArticleCoverageGeo() != ''){
00317 $modsSubject = &XMLCustomWriter::createElement($doc, 'mods:subject');
00318 $coverageArray = explode(";", $article->getArticleCoverageGeo());
00319 $i = 0;
00320 while ($i < sizeof($coverageArray)) {
00321 XMLCustomWriter::createChildWithText($doc, $modsSubject, 'mods:geographic', $coverageArray[$i] );
00322 $i++;
00323 }
00324 XMLCustomWriter::appendChild($mods, $modsSubject);
00325 }
00326 if($article->getArticleCoverageChron() != ''){
00327 $modsSubject = &XMLCustomWriter::createElement($doc, 'mods:subject');
00328 $coverageArray = explode(";", $article->getArticleCoverageChron());
00329 $i = 0;
00330 while ($i < sizeof($coverageArray)) {
00331 XMLCustomWriter::createChildWithText($doc, $modsSubject, 'mods:temporal', $coverageArray[$i] );
00332 $i++;
00333 }
00334 XMLCustomWriter::appendChild($mods, $modsSubject);
00335 }
00336 if($article->getArticleType() != ''){
00337 $modsSubject = &XMLCustomWriter::createElement($doc, 'mods:subject');
00338 XMLCustomWriter::createChildWithText($doc, $modsSubject, 'mods:genre', $article->getArticleType());
00339 XMLCustomWriter::appendChild($mods, $modsSubject);
00340 }
00341 if($article->getArticleSponsor() != ''){
00342 $PresenterNode = &XMLCustomWriter::createElement($doc, 'mods:name');
00343 XMLCustomWriter::setAttribute($PresenterNode, 'type', 'corporate');
00344 $fNameNode =&XMLCustomWriter::createChildWithText($doc, $PresenterNode, 'mods:namePart', $article->getArticleSponsor());
00345 $role = &XMLCustomWriter::createElement($doc, 'mods:role');
00346 $roleTerm =&XMLCustomWriter::createChildWithText($doc, $role, 'mods:roleTerm', 'sponsor');
00347 XMLCustomWriter::setAttribute($roleTerm, 'type', 'text');
00348 XMLCustomWriter::appendChild($PresenterNode, $role);
00349 XMLCustomWriter::appendChild($mods, $PresenterNode);
00350 }
00351 if($article->getLanguage() != '')
00352 XMLCustomWriter::createChildWithText($doc, $mods, 'mods:language', $article->getLanguage());
00353 XMLCustomWriter::appendChild($xmlData, $mods);
00354 XMLCustomWriter::appendChild($dmdSec, $mdWrap);
00355 XMLCustomWriter::appendChild($mdWrap,$xmlData);
00356 XMLCustomWriter::appendChild($root, $dmdSec);
00357 $SuppFileDAO = &DAORegistry::getDAO('SuppFileDAO');
00358 $suppFilesArray = &$SuppFileDAO->getSuppFilesByArticle($article->getArticleId());
00359 $i = 0;
00360 while ($i < sizeof($suppFilesArray)) {
00361 MetsExportDom::generateArticleSuppFilesDmdSecDom($doc, $root, $suppFilesArray[$i]);
00362 $i++;
00363 }
00364 }
00365
00369 function generateArticleSuppFilesDmdSecDom(&$doc, &$root, $suppFile) {
00370 $dmdSec = &XMLCustomWriter::createElement($doc, 'METS:dmdSec');
00371 XMLCustomWriter::setAttribute($dmdSec, 'ID', 'DMD-SF'.$suppFile->getFileId().'-A'.$suppFile->getArticleId());
00372 $mdWrap = &XMLCustomWriter::createElement($doc, 'METS:mdWrap');
00373 $xmlData = &XMLCustomWriter::createElement($doc, 'METS:xmlData');
00374 XMLCustomWriter::setAttribute($mdWrap, 'MDTYPE', 'MODS');
00375 $mods = &XMLCustomWriter::createElement($doc, 'mods:mods');
00376 XMLCustomWriter::setAttribute($mods, 'xmlns:mods', 'http://www.loc.gov/mods/v3');
00377 XMLCustomWriter::setAttribute($root, 'xsi:schemaLocation', str_replace(' http://www.loc.gov/mods/v3 http://www.loc.gov/standards/mods/v3/mods-3-0.xsd', '', $root->getAttribute('xsi:schemaLocation')) . ' http://www.loc.gov/mods/v3 http://www.loc.gov/standards/mods/v3/mods-3-0.xsd');
00378 $titleInfo = &XMLCustomWriter::createElement($doc, 'mods:titleInfo');
00379 XMLCustomWriter::createChildWithText($doc, $titleInfo, 'mods:title', $suppFile->getTitle());
00380 XMLCustomWriter::appendChild($mods, $titleInfo);
00381 if($suppFile->getCreator() != ''){
00382 $creatorNode = &XMLCustomWriter::createElement($doc, 'mods:name');
00383 XMLCustomWriter::setAttribute($creatorNode, 'type', 'personal');
00384 $nameNode =&XMLCustomWriter::createChildWithText($doc, $creatorNode, 'mods:namePart', $suppFile->getCreator());
00385 $role = &XMLCustomWriter::createElement($doc, 'mods:role');
00386 $roleTerm =&XMLCustomWriter::createChildWithText($doc, $role, 'mods:roleTerm', 'creator');
00387 XMLCustomWriter::setAttribute($roleTerm, 'type', 'text');
00388 XMLCustomWriter::appendChild($creatorNode, $role);
00389 XMLCustomWriter::appendChild($mods, $creatorNode);
00390 }
00391 if($suppFile->getDescription() != '')
00392 XMLCustomWriter::createChildWithText($doc, $mods, 'mods:abstract', $suppFile->getDescription());
00393 if($suppFile->getDateCreated() != ''){
00394 $originInfo = &XMLCustomWriter::createElement($doc, 'mods:originInfo');
00395 $timeIssued = date(DATE_W3C, strtotime($suppFile->getDateCreated()));
00396 $sDate = XMLCustomWriter::createChildWithText($doc, $originInfo, 'mods:dateCreated', $timeIssued);
00397 XMLCustomWriter::appendChild($mods, $originInfo);
00398 }
00399 XMLCustomWriter::createChildWithText($doc, $mods, 'mods:genre', 'additional material');
00400 if($suppFile->getType() != '')
00401 XMLCustomWriter::createChildWithText($doc, $mods, 'mods:genre', $suppFile->getType());
00402 if($suppFile->getTypeOther() != '')
00403 XMLCustomWriter::createChildWithText($doc, $mods, 'mods:genre', $suppFile->getTypeOther());
00404 if($suppFile->getSubject() != ''){
00405 $subjNode = &XMLCustomWriter::createElement($doc, 'mods:subject');
00406 XMLCustomWriter::createChildWithText($doc, $subjNode, 'mods:topic', $suppFile->getSubject());
00407 XMLCustomWriter::appendChild($mods, $subjNode);
00408 }
00409 if($suppFile->getSponsor() != ''){
00410 $PresenterNode = &XMLCustomWriter::createElement($doc, 'mods:name');
00411 XMLCustomWriter::setAttribute($PresenterNode, 'type', 'corporate');
00412 $fNameNode =&XMLCustomWriter::createChildWithText($doc, $PresenterNode, 'mods:namePart', $suppFile->getSponsor());
00413 $role = &XMLCustomWriter::createElement($doc, 'mods:role');
00414 $roleTerm =&XMLCustomWriter::createChildWithText($doc, $role, 'mods:roleTerm', 'sponsor');
00415 XMLCustomWriter::setAttribute($roleTerm, 'type', 'text');
00416 XMLCustomWriter::appendChild($PresenterNode, $role);
00417 XMLCustomWriter::appendChild($mods, $PresenterNode);
00418 }
00419 if($suppFile->getPublisher() != ''){
00420 $PresenterNode = &XMLCustomWriter::createElement($doc, 'mods:name');
00421 XMLCustomWriter::setAttribute($PresenterNode, 'type', 'corporate');
00422 $fNameNode =&XMLCustomWriter::createChildWithText($doc, $PresenterNode, 'mods:namePart', $suppFile->getPublisher());
00423 $role = &XMLCustomWriter::createElement($doc, 'mods:role');
00424 $roleTerm =&XMLCustomWriter::createChildWithText($doc, $role, 'mods:roleTerm', 'publisher');
00425 XMLCustomWriter::setAttribute($roleTerm, 'type', 'text');
00426 XMLCustomWriter::appendChild($PresenterNode, $role);
00427 XMLCustomWriter::appendChild($mods, $PresenterNode);
00428 }
00429 if($suppFile->getLanguage() != '')
00430 XMLCustomWriter::createChildWithText($doc, $mods, 'mods:language', $suppFile->getLanguage());
00431 XMLCustomWriter::appendChild($xmlData, $mods);
00432 XMLCustomWriter::appendChild($dmdSec, $mdWrap);
00433 XMLCustomWriter::appendChild($mdWrap,$xmlData);
00434 XMLCustomWriter::appendChild($root, $dmdSec);
00435 }
00436
00441 function generateIssueFileSecDom(&$doc, &$root, &$issue) {
00442 $publishedArticleDao = &DAORegistry::getDAO('PublishedArticleDAO');
00443 $publishedArticleArray = $publishedArticleDao->getPublishedArticles($issue->getIssueId());
00444 $i = 0;
00445 while ($i < sizeof($publishedArticleArray)) {
00446 MetsExportDom::generateArticleFilesDom($doc, $root, $publishedArticleArray[$i], $issue);
00447 $i++;
00448 }
00449 }
00450
00451 function generateIssueHtmlGalleyFileSecDom(&$doc, &$root, &$issue) {
00452 $publishedArticleDao = &DAORegistry::getDAO('PublishedArticleDAO');
00453 $publishedArticleArray = $publishedArticleDao->getPublishedArticles($issue->getIssueId());
00454 $i = 0;
00455 while ($i < sizeof($publishedArticleArray)) {
00456 MetsExportDom::generateArticleHtmlGalleyFilesDom($doc, $root, $publishedArticleArray[$i], $issue);
00457 $i++;
00458 }
00459 }
00460
00464 function generateArticleFilesDom(&$doc, $root, $article, &$issue) {
00465 $ArticleGalleyDAO = &DAORegistry::getDAO('ArticleGalleyDAO');
00466 $i = 0;
00467 $GalleysArray = &$ArticleGalleyDAO->getGalleysByArticle($article->getArticleId());
00468 while ($i < sizeof($GalleysArray)) {
00469 if(!$GalleysArray[$i]->isHTMLGalley())
00470 MetsExportDom::generateArticleFileDom($doc, $root, $article, $GalleysArray[$i], null);
00471 $i++;
00472 }
00473 $SuppFileDAO = &DAORegistry::getDAO('SuppFileDAO');
00474 $suppFilesArray = &$SuppFileDAO->getSuppFilesByArticle($article->getArticleId());
00475 $i = 0;
00476 while ($i < sizeof($suppFilesArray)) {
00477 MetsExportDom::generateArticleSuppFileDom($doc, $root, $article, $suppFilesArray[$i]);
00478 $i++;
00479 }
00480 }
00481
00482 function generateArticleHtmlGalleyFilesDom(&$doc, $root, $article, &$issue) {
00483 $ArticleGalleyDAO = &DAORegistry::getDAO('ArticleGalleyDAO');
00484 $i = 0;
00485 $GalleysArray = &$ArticleGalleyDAO->getGalleysByArticle($article->getArticleId());
00486 while ($i < sizeof($GalleysArray)) {
00487 if($GalleysArray[$i]->isHTMLGalley()){
00488 MetsExportDom::generateArticleFileDom($doc, $root, $article, $GalleysArray[$i], 'html');
00489 $images = $GalleysArray[$i]->getImageFiles();
00490 foreach ($images as $image) {
00491 MetsExportDom::generateArticleHtmlGalleyImageFileDom($doc, $root, $article, $GalleysArray[$i], $image, 'html');
00492 }
00493 }
00494 $i++;
00495 }
00496 }
00497
00498 function generateArticleHtmlGalleyImageFileDom(&$doc, &$root, $article, $galley, $imageFile, $useAttribute) {
00499 import('classes.file.PublicFileManager');
00500 import('classes.file.FileManager');
00501 $contentWrapper = &Request::getUserVar('contentWrapper');
00502 $mfile = &XMLCustomWriter::createElement($doc, 'METS:file');
00503 $filePath = MetsExportDom::getPublicFilePath($imageFile , '/public/');
00504
00505 $journalDao =& DAORegistry::getDAO('JournalDAO');
00506 $journal =& $journalDao->getJournal($article->getJournalId());
00507
00508 $chkmd5return = md5_file($filePath);
00509 XMLCustomWriter::setAttribute($mfile, 'ID', 'F'.$imageFile->getFileId().'-A'.$article->getArticleId());
00510 if($useAttribute != null)
00511 XMLCustomWriter::setAttribute($mfile, 'USE', $useAttribute);
00512 XMLCustomWriter::setAttribute($mfile, 'SIZE', $imageFile->getFileSize());
00513 XMLCustomWriter::setAttribute($mfile, 'MIMETYPE', $imageFile->getFileType());
00514 XMLCustomWriter::setAttribute($mfile, 'OWNERID', $imageFile->getOriginalFileName());
00515 XMLCustomWriter::setAttribute($mfile, 'CHECKSUM', $chkmd5return);
00516 XMLCustomWriter::setAttribute($mfile, 'CHECKSUMTYPE', 'MD5');
00517 if($contentWrapper == 'FContent'){
00518 $FileContent = &FileManager::readFile($filePath);
00519 $FContent = &XMLCustomWriter::createElement($doc, 'METS:FContent');
00520 $fNameNode =&XMLCustomWriter::createChildWithText($doc, $FContent, 'METS:binData',base64_encode($FileContent));
00521 XMLCustomWriter::appendChild($mfile, $FContent);
00522 }
00523 else{
00524 $fLocat = &XMLCustomWriter::createElement($doc, 'METS:FLocat');
00525 $fileUrl = Request::url(null, 'article', 'viewFile', array($article->getArticleId(), $galley->getBestGalleyId($journal), $imageFile->getFileId()));
00526 XMLCustomWriter::setAttribute($fLocat, 'xlink:href', $fileUrl);
00527 XMLCustomWriter::setAttribute($fLocat, 'LOCTYPE', 'URL');
00528 XMLCustomWriter::appendChild($mfile, $fLocat);
00529 }
00530 XMLCustomWriter::appendChild($root, $mfile);
00531 }
00532
00537 function generateArticleFileDom(&$doc, &$root, $article, &$galleyFile, $useAttribute) {
00538 import('classes.file.PublicFileManager');
00539 import('classes.file.FileManager');
00540 $contentWrapper = &Request::getUserVar('contentWrapper');
00541 $mfile = &XMLCustomWriter::createElement($doc, 'METS:file');
00542 $filePath = MetsExportDom::getPublicFilePath($galleyFile , '/public/');
00543 $chkmd5return = md5_file($filePath);
00544 XMLCustomWriter::setAttribute($mfile, 'ID', 'F'.$galleyFile->getFileId().'-A'.$galleyFile->getArticleId());
00545 if($useAttribute != null)
00546 XMLCustomWriter::setAttribute($mfile, 'USE', $useAttribute);
00547 XMLCustomWriter::setAttribute($mfile, 'SIZE', $galleyFile->getFileSize());
00548 XMLCustomWriter::setAttribute($mfile, 'MIMETYPE', $galleyFile->getFileType());
00549 XMLCustomWriter::setAttribute($mfile, 'OWNERID', $galleyFile->getFileName());
00550 XMLCustomWriter::setAttribute($mfile, 'CHECKSUM', $chkmd5return);
00551 XMLCustomWriter::setAttribute($mfile, 'CHECKSUMTYPE', 'MD5');
00552 if($contentWrapper == 'FContent'){
00553 $FileContent = &FileManager::readFile($filePath);
00554 $FContent = &XMLCustomWriter::createElement($doc, 'METS:FContent');
00555 $fNameNode =&XMLCustomWriter::createChildWithText($doc, $FContent, 'METS:binData',base64_encode($FileContent));
00556 XMLCustomWriter::appendChild($mfile, $FContent);
00557 }
00558 else{
00559 $fLocat = &XMLCustomWriter::createElement($doc, 'METS:FLocat');
00560 $fileUrl = MetsExportDom::getPublicFileUrl($galleyFile);
00561 XMLCustomWriter::setAttribute($fLocat, 'xlink:href', $fileUrl);
00562 XMLCustomWriter::setAttribute($fLocat, 'LOCTYPE', 'URL');
00563 XMLCustomWriter::appendChild($mfile, $fLocat);
00564 }
00565 XMLCustomWriter::appendChild($root, $mfile);
00566 }
00567
00572 function generateArticleSuppFileDom(&$doc, &$root, $article, &$SuppFile) {
00573 import('classes.file.PublicFileManager');
00574 import('classes.file.FileManager');
00575 $contentWrapper = &Request::getUserVar('contentWrapper');
00576 $mfile = &XMLCustomWriter::createElement($doc, 'METS:file');
00577 $filePath = MetsExportDom::getPublicFilePath($SuppFile , '/supp/');;
00578 $chkmd5return = md5_file($filePath);
00579 XMLCustomWriter::setAttribute($mfile, 'ID', 'SF'.$SuppFile->getFileId().'-A'.$SuppFile->getArticleId());
00580 XMLCustomWriter::setAttribute($mfile, 'SIZE', $SuppFile->getFileSize());
00581 XMLCustomWriter::setAttribute($mfile, 'MIMETYPE', $SuppFile->getFileType());
00582 XMLCustomWriter::setAttribute($mfile, 'OWNERID', $SuppFile->getFileName());
00583 XMLCustomWriter::setAttribute($mfile, 'CHECKSUM', $chkmd5return);
00584 XMLCustomWriter::setAttribute($mfile, 'CHECKSUMTYPE', 'MD5');
00585 if($contentWrapper == 'FContent'){
00586 $FileContent = &FileManager::readFile($filePath);
00587 $FContent = &XMLCustomWriter::createElement($doc, 'METS:FContent');
00588 $fNameNode =&XMLCustomWriter::createChildWithText($doc, $FContent, 'METS:binData',base64_encode($FileContent));
00589 XMLCustomWriter::appendChild($mfile, $FContent);
00590 }
00591 else{
00592 $fLocat = &XMLCustomWriter::createElement($doc, 'METS:FLocat');
00593 $fileUrl = MetsExportDom::getPublicSuppFileUrl($SuppFile);
00594 XMLCustomWriter::setAttribute($fLocat, 'xlink:href', $fileUrl);
00595 XMLCustomWriter::setAttribute($fLocat, 'LOCTYPE', 'URL');
00596 XMLCustomWriter::appendChild($mfile, $fLocat);
00597 }
00598 XMLCustomWriter::appendChild($root, $mfile);
00599 }
00600
00604 function &generateAuthorDom(&$doc, $author) {
00605 $PresenterNode = &XMLCustomWriter::createElement($doc, 'mods:name');
00606 XMLCustomWriter::setAttribute($PresenterNode, 'type', 'personal');
00607 $fNameNode =&XMLCustomWriter::createChildWithText($doc, $PresenterNode, 'mods:namePart', $author->getFirstName().' '.$author->getMiddleName());
00608 XMLCustomWriter::setAttribute($fNameNode, 'type', 'given');
00609 $lNameNode =&XMLCustomWriter::createChildWithText($doc, $PresenterNode, 'mods:namePart', $author->getLastName());
00610 XMLCustomWriter::setAttribute($lNameNode, 'type', 'family');
00611 $role = &XMLCustomWriter::createElement($doc, 'mods:role');
00612 $roleTerm =&XMLCustomWriter::createChildWithText($doc, $role, 'mods:roleTerm', 'author');
00613 XMLCustomWriter::setAttribute($roleTerm, 'type', 'text');
00614 XMLCustomWriter::appendChild($PresenterNode, $role);
00615 return $PresenterNode;
00616 }
00617
00621 function createmetsamdSec($doc, &$root, &$journal)
00622 {
00623 $amdSec = &XMLCustomWriter::createElement($doc, 'METS:amdSec');
00624 $techMD = &XMLCustomWriter::createElement($doc, 'METS:techMD');
00625 XMLCustomWriter::setAttribute($techMD, 'ID', 'A-'.$journal->getJournalId());
00626 $mdWrap = &XMLCustomWriter::createElement($doc, 'METS:mdWrap');
00627 XMLCustomWriter::setAttribute($mdWrap, 'MDTYPE', 'PREMIS');
00628 $xmlData = &XMLCustomWriter::createElement($doc, 'METS:xmlData');
00629 $pObject = &XMLCustomWriter::createElement($doc, 'premis:object');
00630 XMLCustomWriter::setAttribute($pObject, 'xmlns:premis', 'http://www.loc.gov/standards/premis/v1');
00631 XMLCustomWriter::setAttribute($root, 'xsi:schemaLocation', str_replace(' http://www.loc.gov/standards/premis/v1 http://www.loc.gov/standards/premis/v1/PREMIS-v1-1.xsd', '', $root->getAttribute('xsi:schemaLocation')) . ' http://www.loc.gov/standards/premis/v1 http://www.loc.gov/standards/premis/v1/PREMIS-v1-1.xsd');
00632 $objectIdentifier = &XMLCustomWriter::createElement($doc, 'premis:objectIdentifier');
00633 XMLCustomWriter::createChildWithText($doc, $objectIdentifier, 'premis:objectIdentifierType', 'internal');
00634 XMLCustomWriter::createChildWithText($doc, $objectIdentifier, 'premis:objectIdentifierValue', 'J-'.$journal->getJournalId());
00635 XMLCustomWriter::appendChild($pObject, $objectIdentifier);
00636 $preservationLevel = &Request::getUserVar('preservationLevel');
00637 if($preservationLevel == ''){
00638 $preservationLevel = '1';
00639 }
00640 XMLCustomWriter::createChildWithText($doc, $pObject, 'premis:preservationLevel', 'level '.$preservationLevel);
00641 XMLCustomWriter::createChildWithText($doc, $pObject, 'premis:objectCategory', 'Representation');
00642 XMLCustomWriter::appendChild($xmlData, $pObject);
00643 XMLCustomWriter::appendChild($mdWrap, $xmlData);
00644 XMLCustomWriter::appendChild($techMD ,$mdWrap);
00645 XMLCustomWriter::appendChild($amdSec, $techMD);
00646 return $amdSec;
00647 }
00648
00652 function createmetsHdr($doc)
00653 {
00654 $root = &XMLCustomWriter::createElement($doc, 'METS:metsHdr');
00655 XMLCustomWriter::setAttribute($root, 'CREATEDATE', date('c'));
00656 XMLCustomWriter::setAttribute($root, 'LASTMODDATE', date('c'));
00657 $agentNode = &XMLCustomWriter::createElement($doc, 'METS:agent');
00658 XMLCustomWriter::setAttribute($agentNode, 'ROLE', 'DISSEMINATOR');
00659 XMLCustomWriter::setAttribute($agentNode, 'TYPE', 'ORGANIZATION');
00660 $organization = &Request::getUserVar('organization');
00661 if($organization == ''){
00662 $siteDao = &DAORegistry::getDAO('SiteDAO');
00663 $site = $siteDao->getSite();
00664 $organization = $site->getSiteTitle();
00665 }
00666 XMLCustomWriter::createChildWithText($doc, $agentNode, 'METS:name', $organization, false);
00667 XMLCustomWriter::appendChild($root, $agentNode);
00668 $agentNode2 = &XMLCustomWriter::createElement($doc, 'METS:agent');
00669 XMLCustomWriter::setAttribute($agentNode2, 'ROLE', 'CREATOR');
00670 XMLCustomWriter::setAttribute($agentNode2, 'TYPE', 'OTHER');
00671 XMLCustomWriter::createChildWithText($doc, $agentNode2, 'METS:name', MetsExportDom::getCreatorString(), false);
00672 XMLCustomWriter::appendChild($root, $agentNode2);
00673 return $root;
00674 }
00675
00679 function getCreatorString() {
00680 $versionDAO = &DAORegistry::getDAO('VersionDAO');
00681 $cVersion = $versionDAO->getCurrentVersion();
00682 return sprintf('Open Journal Systems v%d.%d.%d build %d', $cVersion->getMajor(), $cVersion->getMinor(), $cVersion->getRevision(), $cVersion->getBuild());
00683 }
00684
00689 function getPublicFilePath(&$File, $pathComponent) {
00690 $articleId = $File->getArticleId();
00691 $articleDao = &DAORegistry::getDAO('ArticleDAO');
00692 $article = &$articleDao->getArticle($articleId);
00693 $journalId = $article->getJournalId();
00694 return Config::getVar('files', 'files_dir') . '/journals/' . $journalId .
00695 '/articles/' . $File->getArticleId() . '/' . $pathComponent . '/' . $File->getFileName();
00696 }
00697
00701 function getPublicFileUrl(&$File) {
00702 import('classes.config.Config');
00703 $base_url = &Config::getVar('general','base_url');
00704 $articleDao = &DAORegistry::getDAO('ArticleDAO');
00705 $article = &$articleDao->getArticle($File->getArticleId());
00706 $JournalDAO = &DAORegistry::getDAO('JournalDAO');
00707 $journal = $JournalDAO->getJournal($article->getJournalId());
00708 $base_url = &Config::getVar('general','base_url');
00709 $url = $base_url.'/index.php/'.$journal->getPath().'/article/download/'.$File->getArticleId().'/'.$File->getBestGalleyId($journal);
00710 return $url;
00711 }
00712
00716 function getPublicSuppFileUrl(&$File) {
00717 import('classes.config.Config');
00718 $base_url = &Config::getVar('general','base_url');
00719 $articleDao = &DAORegistry::getDAO('ArticleDAO');
00720 $article = &$articleDao->getArticle($File->getArticleId());
00721 $JournalDAO = &DAORegistry::getDAO('JournalDAO');
00722 $journal = $JournalDAO->getJournal($article->getJournalId());
00723 $base_url = &Config::getVar('general','base_url');
00724 $url = $base_url.'/index.php/'.$journal->getPath().'/article/downloadSuppFile/'.$File->getArticleId().'/'.$File->getSuppFileId();
00725 return $url;
00726 }
00727
00728 }
00729
00730 ?>