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
27 changes: 17 additions & 10 deletions main/inc/lib/moodleexport/FolderExport.php
Original file line number Diff line number Diff line change
Expand Up @@ -42,19 +42,26 @@ public function export($activityId, $exportDir, $moduleId, $sectionId): void
/**
* Get folder data dynamically from the course.
*/
public function getData(int $folderId, int $sectionId): array
public function getData(int $folderId, int $sectionId): ?array
{
$folder = $this->course->resources['document'][$folderId];

return [
'id' => $folderId,
'moduleid' => $folder->source_id,
'modulename' => 'folder',
'contextid' => $folder->source_id,
'name' => $folder->title,
'sectionid' => $sectionId,
'timemodified' => time(),
];
$folderPath = $folder->path . '/';
foreach ($this->course->resources['document'] as $resource) {
if ($resource->path !== $folder->path && str_starts_with($resource->path, $folderPath)) {
return [
'id' => $folderId,
'moduleid' => $folder->source_id,
'modulename' => 'folder',
'contextid' => $folder->source_id,
'name' => $folder->title,
'sectionid' => $sectionId,
'timemodified' => time(),
];
}
}

return null;
}

/**
Expand Down
34 changes: 26 additions & 8 deletions main/inc/lib/moodleexport/MoodleExport.php
Original file line number Diff line number Diff line change
Expand Up @@ -404,15 +404,33 @@ private function getActivities(): array
$id = $resource->source_id;
$title = $document['title'];
} elseif ('file' === $resource->file_type) {
$exportClass = ResourceExport::class;
$moduleName = 'resource';
$id = $resource->source_id;
$title = $resource->title;
$isRoot = substr_count($resource->path, '/') === 1;

if ($isRoot) {
$exportClass = ResourceExport::class;
$moduleName = 'resource';
$id = $resource->source_id;
$title = $resource->title;
}
} elseif ('folder' === $resource->file_type) {
$exportClass = FolderExport::class;
$moduleName = 'folder';
$id = $resource->source_id;
$title = $resource->title;
$isEmpty = true;
$folderPath = $resource->path . '/';

foreach ($this->course->resources['document'] as $childResource) {
if (str_starts_with($childResource->path, $folderPath) && $childResource->path !== $resource->path) {
$isEmpty = false;
break;
}
}

$isRoot = substr_count($resource->path, '/') === 1;

if (!$isEmpty && $isRoot) {
$exportClass = FolderExport::class;
$moduleName = 'folder';
$id = $resource->source_id;
$title = $resource->title;
}
}
}
// Handle assignments (work)
Expand Down
Loading