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