Skip to content

Commit a07cd40

Browse files
committed
refs #279
1 parent af247b5 commit a07cd40

1 file changed

Lines changed: 73 additions & 3 deletions

File tree

command/MigrateCoursewareCommand.php

Lines changed: 73 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -196,6 +196,10 @@ private function createNewCourseware($courseware, $output)
196196
$output->write('creating Courseware for: ' . $course->name . '(' . $course->id . ')' . '... ');
197197
$courseTeacher = $course->getMembersWithStatus('dozent')[0];
198198
$teacher = \User::find($courseTeacher->user_id);
199+
200+
$structural_element_counter = 0;
201+
$container_counter = 0;
202+
$block_counter = 0;
199203

200204
if ($teacher === null) {
201205
$output->write('<error>');
@@ -219,8 +223,14 @@ private function createNewCourseware($courseware, $output)
219223
]);
220224

221225
$root->store();
226+
$structural_element_counter++;
222227
}
223228

229+
$this->fillEmptyPage($root, $teacher, true, $output);
230+
$container_counter++;
231+
$block_counter++;
232+
$block_counter++;
233+
224234
//get courseware settings
225235
$instance = new Instance($root);
226236
if ($courseware['ui_block']->editing_permission === 'dozent') {
@@ -233,14 +243,18 @@ private function createNewCourseware($courseware, $output)
233243
$subchapter_map = [];
234244
$section_map = [];
235245
$new_link_blocks = [];
236-
$structural_element_counter = 0;
237-
$container_counter = 0;
238-
$block_counter = 0;
246+
239247
foreach ($courseware['children'] as $chapter) {
240248
$new_chapter = $this->createStructuralElement($chapter, $root->id, $teacher, $cid, $output);
249+
$this->fillEmptyPage($new_chapter, $teacher, false, $output);
250+
$container_counter++;
251+
$block_counter++;
241252
$structural_element_counter++;
242253
foreach ($chapter['children'] as $subchapter) {
243254
$new_subchapter = $this->createStructuralElement($subchapter, $new_chapter->id, $teacher, $cid, $output);
255+
$this->fillEmptyPage($new_subchapter, $teacher, false, $output);
256+
$container_counter++;
257+
$block_counter++;
244258
$structural_element_counter++;
245259
$subchapter_map[$subchapter['id']] = $new_subchapter->id;
246260
foreach ($subchapter['children'] as $section) {
@@ -919,6 +933,62 @@ private function createBlock($block, $container, $user, $cid, $courseware, $outp
919933
return array('new_block' => $new_block, 'link_target' => $link_target);
920934
}
921935

936+
private function fillEmptyPage($structural_element, $user, $headline = true, $output)
937+
{
938+
// add list container
939+
$new_container = $this->createContainer($structural_element->id, $user, $output);
940+
941+
if ($headline) {
942+
// add headline block
943+
$payload_headline = array(
944+
'title' => $structural_element->title,
945+
'subtitle' => '',
946+
'style' => 'bigicon_before',
947+
'height' => 'half',
948+
'background_color' => '#28497c',
949+
'background_image_id' => '',
950+
'background_type' => 'color',
951+
'text_color' => '#ffffff',
952+
'icon' => 'learnmodule',
953+
'icon_color' => 'white',
954+
);
955+
$new_headline_block = Block::build([
956+
'container_id' => $new_container->id,
957+
'owner_id' => $user->id,
958+
'editor_id' => $user->id,
959+
'edit_blocker_id' => null,
960+
'position' => $new_container->countBlocks(),
961+
'block_type' => 'headline',
962+
'payload' => json_encode($payload_headline),
963+
'visible' => true
964+
]);
965+
$new_headline_block->store();
966+
//add block to container payload
967+
$new_container->type->addBlock($new_headline_block);
968+
$new_container->store();
969+
}
970+
971+
// add toc block
972+
$payload_toc = array(
973+
'style' => 'list',
974+
'title' => '',
975+
);
976+
$new_toc_block = Block::build([
977+
'container_id' => $new_container->id,
978+
'owner_id' => $user->id,
979+
'editor_id' => $user->id,
980+
'edit_blocker_id' => null,
981+
'position' => $new_container->countBlocks(),
982+
'block_type' => 'table-of-contents',
983+
'payload' => json_encode($payload_toc),
984+
'visible' => true
985+
]);
986+
$new_toc_block->store();
987+
//add block to container payload
988+
$new_container->type->addBlock($new_toc_block);
989+
$new_container->store();
990+
}
991+
922992
private function convertCoursewareDate($date)
923993
{
924994
$new_date = date_create_from_format('Y-m-d H:i:s', $date);

0 commit comments

Comments
 (0)