Course import - Fix display order of items imported from sections - refs BT#20060

pull/4348/head
Christian 3 years ago
parent 5828c24804
commit 5de0d28bff
  1. 31
      main/inc/lib/MoodleImport.php
  2. 10
      main/lp/learnpath.class.php

@ -189,7 +189,7 @@ class MoodleImport
if ($debug) {
error_log('Loading activities: '.count($activities));
}
$n = 1;
foreach ($activities as $activity) {
if (empty($activity->childNodes->length)) {
continue;
@ -220,7 +220,8 @@ class MoodleImport
// It is added as item in Learnpath
if (!empty($currentItem['sectionid']) && !empty($assignId)) {
$lastLpItemId = $this->processSectionItem($sectionLpValues[$currentItem['sectionid']], 'student_publication', $assignId, $moduleValues['name']);
$lastLpItemId = $this->processSectionItem($sectionLpValues[$currentItem['sectionid']], 'student_publication', $assignId, $moduleValues['name'], $n);
$n++;
}
break;
case 'scorm':
@ -244,7 +245,8 @@ class MoodleImport
// It is added as item in Learnpath
if (!empty($currentItem['sectionid']) && !empty($documentId)) {
$lastLpItemId = $this->processSectionItem($sectionLpValues[$currentItem['sectionid']], 'document', $documentId, $moduleValues['name']);
$lastLpItemId = $this->processSectionItem($sectionLpValues[$currentItem['sectionid']], 'document', $documentId, $moduleValues['name'], $n);
$n++;
}
break;
case 'forum':
@ -272,7 +274,8 @@ class MoodleImport
$forumId = store_forum($forumValues, $courseInfo, true);
// It is added as item in Learnpath
if (!empty($currentItem['sectionid']) && !empty($forumId)) {
$lastLpItemId = $this->processSectionItem($sectionLpValues[$currentItem['sectionid']], 'forum', $forumId, $moduleValues['name']);
$lastLpItemId = $this->processSectionItem($sectionLpValues[$currentItem['sectionid']], 'forum', $forumId, $moduleValues['name'], $n);
$n++;
}
break;
case 'quiz':
@ -372,7 +375,8 @@ class MoodleImport
}
// It is added as item in Learnpath
if (!empty($currentItem['sectionid']) && !empty($exercise->iid)) {
$lastLpItemId = $this->processSectionItem($sectionLpValues[$currentItem['sectionid']], 'quiz', $exercise->iid, $title);
$lastLpItemId = $this->processSectionItem($sectionLpValues[$currentItem['sectionid']], 'quiz', $exercise->iid, $title, $n);
$n++;
}
break;
case 'resource':
@ -416,7 +420,8 @@ class MoodleImport
);
// It is added as item in Learnpath
if (!empty($currentItem['sectionid']) && !empty($documentData['iid'])) {
$lastLpItemId = $this->processSectionItem($sectionLpValues[$currentItem['sectionid']], 'document', $documentData['iid'], $fileInfo['title']);
$lastLpItemId = $this->processSectionItem($sectionLpValues[$currentItem['sectionid']], 'document', $documentData['iid'], $fileInfo['title'], $n);
$n++;
}
}
@ -435,7 +440,8 @@ class MoodleImport
$linkId = Link::addlinkcategory('link');
// It is added as item in Learnpath
if (!empty($currentItem['sectionid']) && !empty($linkId)) {
$lastLpItemId = $this->processSectionItem($sectionLpValues[$currentItem['sectionid']], 'link', $linkId, $moduleValues['name']);
$lastLpItemId = $this->processSectionItem($sectionLpValues[$currentItem['sectionid']], 'link', $linkId, $moduleValues['name'], $n);
$n++;
}
break;
}
@ -480,7 +486,7 @@ class MoodleImport
*
* @return int
*/
public function processSectionItem($lpId, $itemType, $itemId, $itemTitle)
public function processSectionItem($lpId, $itemType, $itemId, $itemTitle, $dspOrder = 0)
{
$lp = new \learnpath(
api_get_course_id(),
@ -494,7 +500,11 @@ class MoodleImport
$itemType,
$itemId,
$itemTitle,
''
'',
0,
0,
0,
$dspOrder
);
return $lpItemId;
@ -1073,9 +1083,6 @@ class MoodleImport
$dir = '/';
$extension = 'html';
if (file_exists($filepath.$filename.'.'.$extension)) {
return false;
}
$content = ('page' == $moduleName ? $moduleValues['content'] : $moduleValues['intro']);
$content = api_html_entity_decode($content);
$content = $this->replaceMoodleChamiloCoursePath($content);

@ -490,7 +490,8 @@ class learnpath
$description,
$prerequisites = 0,
$max_time_allowed = 0,
$userId = 0
$userId = 0,
$dspOrder = 0
) {
$course_id = $this->course_info['real_id'];
if (empty($course_id)) {
@ -578,6 +579,11 @@ class learnpath
$exercise->save();
}
$newDisplayOrder = $display_order + 1;
if (!empty($dspOrder)) {
$newDisplayOrder = (int) $dspOrder;
}
$params = [
'c_id' => $course_id,
'lp_id' => $this->get_id(),
@ -590,7 +596,7 @@ class learnpath
'parent_item_id' => $parent,
'previous_item_id' => $previous,
'next_item_id' => (int) $next,
'display_order' => $display_order + 1,
'display_order' => $newDisplayOrder,
'prerequisite' => $prerequisites,
'max_time_allowed' => $max_time_allowed,
'min_score' => 0,

Loading…
Cancel
Save