Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 16 additions & 5 deletions main/inc/lib/moodleexport/FileExport.php
Original file line number Diff line number Diff line change
Expand Up @@ -186,12 +186,23 @@ private function createFileXmlEntry(array $file): string
*/
private function processDocument(array $filesData, object $document): array
{
if (
$document->file_type === 'file' &&
pathinfo($document->path, PATHINFO_EXTENSION) === 'html' &&
substr_count($document->path, '/') === 1
) {
return $filesData;
}

if ($document->file_type === 'file') {
$fileData = $this->getFileData($document);
$fileData['filepath'] = '/Documents/';
$fileData['contextid'] = 0;
$fileData['component'] = 'mod_folder';
$filesData['files'][] = $fileData;
$extension = pathinfo($document->path, PATHINFO_EXTENSION);
if (!in_array(strtolower($extension), ['html', 'htm'])) {
$fileData = $this->getFileData($document);
$fileData['filepath'] = '/Documents/';
$fileData['contextid'] = 0;
$fileData['component'] = 'mod_folder';
$filesData['files'][] = $fileData;
}
} elseif ($document->file_type === 'folder') {
$folderFiles = \DocumentManager::getAllDocumentsByParentId($this->course->info, $document->source_id);
foreach ($folderFiles as $file) {
Expand Down
6 changes: 4 additions & 2 deletions main/inc/lib/moodleexport/MoodleExport.php
Original file line number Diff line number Diff line change
Expand Up @@ -440,6 +440,7 @@ private function getActivities(): array
'title' => 'Documents',
];
$activities[] = $documentsFolder;
$htmlPageIds = [];
foreach ($this->course->resources as $resourceType => $resources) {
foreach ($resources as $resource) {
$exportClass = null;
Expand Down Expand Up @@ -479,13 +480,14 @@ private function getActivities(): array
// Handle documents (HTML pages)
elseif ($resourceType === RESOURCE_DOCUMENT && $resource->source_id > 0) {
$document = \DocumentManager::get_document_data_by_id($resource->source_id, $this->course->code);
if ('html' === pathinfo($document['path'], PATHINFO_EXTENSION)) {
if ('html' === pathinfo($document['path'], PATHINFO_EXTENSION) && substr_count($resource->path, '/') === 1) {
$exportClass = PageExport::class;
$moduleName = 'page';
$id = $resource->source_id;
$title = $document['title'];
$htmlPageIds[] = $id;
}
if ('file' === $resource->file_type) {
if ('file' === $resource->file_type && !in_array($resource->source_id, $htmlPageIds)) {
$resourceExport = new ResourceExport($this->course);
if ($resourceExport->getSectionIdForActivity($resource->source_id, $resourceType) > 0) {
$isRoot = substr_count($resource->path, '/') === 1;
Expand Down
17 changes: 11 additions & 6 deletions main/inc/lib/moodleexport/SectionExport.php
Original file line number Diff line number Diff line change
Expand Up @@ -273,19 +273,24 @@ private function addActivityToList(array $item, int $sectionId, array &$activiti
break;

case 'document':
if ($sectionId > 0) {
$documentId = (int) $item['path'];
$document = \DocumentManager::get_document_data_by_id($documentId, $this->course->code);
$documentId = (int) $item['path'];
$document = \DocumentManager::get_document_data_by_id($documentId, $this->course->code);

// Determine the type of document and get the corresponding export class
if ($document) {
$isRoot = substr_count($document['path'], '/') === 1;
$documentType = $this->getDocumentType($document['filetype'], $document['path']);
if ($documentType) {
if ($documentType === 'page' && $isRoot) {
$activityClass = $activityClassMap['page'];
$exportInstance = new $activityClass($this->course);
$activityData = $exportInstance->getData($item['path'], $sectionId);
}
elseif ($sectionId > 0 && $documentType && isset($activityClassMap[$documentType])) {
$activityClass = $activityClassMap[$documentType];
$exportInstance = new $activityClass($this->course);
$activityData = $exportInstance->getData($item['path'], $sectionId);
}
break;
}
break;
}

// Add the activity to the list if the data exists
Expand Down
Loading