Skip to content

Commit 70e791e

Browse files
committed
Improved importer lesson description
1 parent 0c31d09 commit 70e791e

File tree

2 files changed

+19
-20
lines changed

2 files changed

+19
-20
lines changed

Manager/LessonManager.php

Lines changed: 9 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -55,27 +55,26 @@ public function importLesson(array $data, $rootPath)
5555
$lessonData = $data['data'];
5656

5757
$chaptersMap = array();
58-
foreach ($lessonData as $chapter) {
59-
$chapterData = $chapter['chapter'];
58+
foreach ($lessonData['chapters'] as $chapter) {
6059
$entityChapter = new Chapter();
6160
$entityChapter->setLesson($lesson);
62-
$entityChapter->setTitle($chapterData['title']);
61+
$entityChapter->setTitle($chapter['title']);
6362
$text = file_get_contents(
64-
$rootPath . DIRECTORY_SEPARATOR . $chapterData['path']
63+
$rootPath . DIRECTORY_SEPARATOR . $chapter['path']
6564
);
6665
$entityChapter->setText($text);
67-
if ($chapterData['is_root']) {
66+
if ($chapter['is_root']) {
6867
$lesson->setRoot($entityChapter);
6968
}
7069
$parentChapter = null;
71-
if ($chapterData['parent_id'] !== null) {
72-
$parentChapter = $chaptersMap[$chapterData['parent_id']];
70+
if ($chapter['parent_id'] !== null) {
71+
$parentChapter = $chaptersMap[$chapter['parent_id']];
7372
$entityChapter->setParent($parentChapter);
7473
$this->chapterRepository->persistAsLastChildOf($entityChapter, $parentChapter);
7574
} else {
7675
$this->chapterRepository->persistAsFirstChild($entityChapter);
7776
}
78-
$chaptersMap[$chapterData['id']] = $entityChapter;
77+
$chaptersMap[$chapter['id']] = $entityChapter;
7978
}
8079
}
8180

@@ -93,7 +92,7 @@ public function importLesson(array $data, $rootPath)
9392
*/
9493
public function exportLesson(Workspace $workspace, array &$files, Lesson $object)
9594
{
96-
$data = array();
95+
$data = array('chapters' => array());
9796

9897
// Getting all sections and building array
9998
$rootChapter = $object->getRoot();
@@ -113,9 +112,7 @@ public function exportLesson(Workspace $workspace, array &$files, Lesson $object
113112
'path' => $uid
114113
);
115114

116-
$data[] = array(
117-
'chapter' => $chapterArray
118-
);
115+
$data['chapters'][] = $chapterArray;
119116
}
120117

121118
return $data;

Transfert/LessonImporter.php

Lines changed: 10 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -60,13 +60,15 @@ public function addLessonDescription($rootNode)
6060
$rootPath = $this->getRootPath();
6161
$rootNode
6262
->children()
63-
->arrayNode('chapter')
64-
->children()
65-
->scalarNode('id')->end()
66-
->scalarNode('parent_id')->end()
67-
->booleanNode('is_root')->defaultFalse()->end()
68-
->scalarNode('title')->end()
69-
->scalarNode('path')->end()
63+
->arrayNode('chapters')
64+
->prototype('array')
65+
->children()
66+
->scalarNode('id')->end()
67+
->scalarNode('parent_id')->end()
68+
->booleanNode('is_root')->defaultFalse()->end()
69+
->scalarNode('title')->end()
70+
->scalarNode('path')->end()
71+
->end()
7072
->end()
7173
->end()
7274
->end()
@@ -76,7 +78,7 @@ public function addLessonDescription($rootNode)
7678
public function validate(array $data)
7779
{
7880
$processor = new Processor();
79-
$result = $processor->processConfiguration($this, $data);
81+
$result = $processor->processConfiguration($this, ['data' => $data]);
8082
}
8183

8284
public function import(array $data)

0 commit comments

Comments
 (0)