prepareActivityDirectory($exportDir, 'page', $moduleId); // Retrieve page data $pageData = $this->getData($activityId, $sectionId); // Generate XML files $this->createPageXml($pageData, $pageDir); $this->createModuleXml($pageData, $pageDir); $this->createGradesXml($pageData, $pageDir); $this->createFiltersXml($pageData, $pageDir); $this->createGradeHistoryXml($pageData, $pageDir); $this->createInforefXml($pageData, $pageDir); $this->createRolesXml($pageData, $pageDir); $this->createCommentsXml($pageData, $pageDir); $this->createCalendarXml($pageData, $pageDir); } /** * Get page data dynamically from the course. */ public function getData(int $pageId, int $sectionId): ?array { $pageResources = $this->course->resources[RESOURCE_DOCUMENT]; foreach ($pageResources as $page) { if ($page->source_id == $pageId) { $contextid = $this->course->info['real_id']; return [ 'id' => $page->source_id, 'moduleid' => $page->source_id, 'modulename' => 'page', 'contextid' => $contextid, 'name' => $page->title, 'intro' => $page->comment ?? '', 'content' => $this->getPageContent($page), 'sectionid' => $sectionId, 'sectionnumber' => 1, 'display' => 0, 'timemodified' => time(), 'users' => [], 'files' => [], ]; } } return null; } /** * Create the XML file for the page. */ private function createPageXml(array $pageData, string $pageDir): void { $xmlContent = ''.PHP_EOL; $xmlContent .= ''.PHP_EOL; $xmlContent .= ' '.PHP_EOL; $xmlContent .= ' '.htmlspecialchars($pageData['name']).''.PHP_EOL; $xmlContent .= ' '.htmlspecialchars($pageData['intro']).''.PHP_EOL; $xmlContent .= ' 1'.PHP_EOL; $xmlContent .= ' '.htmlspecialchars($pageData['content']).''.PHP_EOL; $xmlContent .= ' 1'.PHP_EOL; $xmlContent .= ' 0'.PHP_EOL; $xmlContent .= ' 5'.PHP_EOL; $xmlContent .= ' a:3:{s:12:"printheading";s:1:"1";s:10:"printintro";s:1:"0";s:17:"printlastmodified";s:1:"1";}'.PHP_EOL; $xmlContent .= ' 1'.PHP_EOL; $xmlContent .= ' '.$pageData['timemodified'].''.PHP_EOL; $xmlContent .= ' '.PHP_EOL; $xmlContent .= ''; $this->createXmlFile('page', $xmlContent, $pageDir); } /** * Retrieves the content of the page. */ private function getPageContent(object $page): string { if ($page->file_type === 'file') { return file_get_contents($this->course->path.$page->path); } return ''; } }