/** * Generate the export DOM tree for a given journal. * @param $doc object DOM object * @param $journal object Journal to export * @param $selectedObjects array */ function generateJournalDom($doc, $journal, $selectedObjects) { $issueDao = DAORegistry::getDAO('IssueDAO'); $sectionDao = DAORegistry::getDAO('SectionDAO'); $pubArticleDao = DAORegistry::getDAO('PublishedArticleDAO'); $articleDao = DAORegistry::getDAO('ArticleDAO'); $journalId = $journal->getId(); // Records node contains all articles, each called a record $records = XMLCustomWriter::createElement($doc, 'records'); // retrieve selected issues $selectedIssues = array(); if (isset($selectedObjects[DOAJ_EXPORT_ISSUES])) { $selectedIssues = $selectedObjects[DOAJ_EXPORT_ISSUES]; // make sure the selected issues belong to the current journal foreach ($selectedIssues as $key => $selectedIssueId) { $selectedIssue = $issueDao->getIssueById($selectedIssueId, $journalId); if (!$selectedIssue) { unset($selectedIssues[$key]); } } } // retrieve selected articles $selectedArticles = array(); if (isset($selectedObjects[DOAJ_EXPORT_ARTICLES])) { $selectedArticles = $selectedObjects[DOAJ_EXPORT_ARTICLES]; // make sure the selected articles belong to the current journal foreach ($selectedArticles as $key => $selectedArticleId) { $selectedArticle = $articleDao->getArticle($selectedArticleId, $journalId); if (!$selectedArticle) { unset($selectedArticles[$key]); } } } $pubArticles = $pubArticleDao->getPublishedArticlesByJournalId($journalId); while ($pubArticle = $pubArticles->next()) { // check for selected issues: $issueId = $pubArticle->getIssueId(); if (!empty($selectedIssues) && !in_array($issueId, $selectedIssues)) { continue; } $issue = $issueDao->getIssueById($issueId); if (!$issue) { continue; } // check for selected articles: $articleId = $pubArticle->getArticleId(); if (!empty($selectedArticles) && !in_array($articleId, $selectedArticles)) { continue; } $section = $sectionDao->getSection($pubArticle->getSectionId()); $articleNode = DOAJExportDom::generateArticleDom($doc, $journal, $issue, $section, $pubArticle); XMLCustomWriter::appendChild($records, $articleNode); unset($issue, $section, $articleNode); } return $records; }
/** * Generate the export DOM tree for a given journal. * @param $doc object DOM object * @param $journal object Journal to export */ function &generateJournalDom(&$doc, &$journal) { $issueDao = DAORegistry::getDAO('IssueDAO'); $sectionDao = DAORegistry::getDAO('SectionDAO'); $pubArticleDao = DAORegistry::getDAO('PublishedArticleDAO'); // Records node contains all articles, each called a record $records = XMLCustomWriter::createElement($doc, 'records'); $pubArticles = $pubArticleDao->getPublishedArticlesByJournalId($journal->getId()); while ($pubArticle = $pubArticles->next()) { $issue = $issueDao->getById($pubArticle->getIssueId()); if (!$issue) { continue; } $section = $sectionDao->getById($pubArticle->getSectionId()); $articleNode = DOAJExportDom::generateArticleDom($doc, $journal, $issue, $section, $pubArticle); XMLCustomWriter::appendChild($records, $articleNode); } return $records; }