/** * Exports a Lesson resource * according to the description found in LessonImporter. * * @param Workspace $workspace * @param array $files * @param Lesson $object * * @return array */ public function exportLesson(Workspace $workspace, array &$files, Lesson $object) { $data = ['chapters' => []]; // Getting all sections and building array $rootChapter = $object->getRoot(); $chapters = $this->chapterRepository->children($rootChapter); array_unshift($chapters, $rootChapter); foreach ($chapters as $chapter) { $uid = uniqid() . '.txt'; $tmpPath = $this->ch->getParameter('tmp_dir') . DIRECTORY_SEPARATOR . $uid; file_put_contents($tmpPath, $chapter->getText()); $files[$uid] = $tmpPath; $chapterArray = ['id' => $chapter->getId(), 'parent_id' => $chapter->getParent() !== null ? $chapter->getParent()->getId() : null, 'is_root' => $chapter->getId() === $rootChapter->getId(), 'title' => $chapter->getTitle(), 'path' => $uid]; $data['chapters'][] = $chapterArray; } return $data; }
public function getFirstChapter(Lesson $lesson) { return $this->findOneBy(array('lesson' => $lesson, 'root' => $lesson->getRoot()->getId(), 'left' => 2)); }