/** * Imports lesson object from array * (see LessonImporter for structure and description). * * @param array $data * @param $rootPath * * @return Lesson */ public function importLesson(array $data, $rootPath) { $lesson = new Lesson(); if (isset($data['data'])) { $lessonData = $data['data']; $chaptersMap = []; foreach ($lessonData['chapters'] as $chapter) { $entityChapter = new Chapter(); $entityChapter->setLesson($lesson); $entityChapter->setTitle($chapter['title']); $text = file_get_contents($rootPath . DIRECTORY_SEPARATOR . $chapter['path']); $entityChapter->setText($text); if ($chapter['is_root']) { $lesson->setRoot($entityChapter); } $parentChapter = null; if ($chapter['parent_id'] !== null) { $parentChapter = $chaptersMap[$chapter['parent_id']]; $entityChapter->setParent($parentChapter); $this->chapterRepository->persistAsLastChildOf($entityChapter, $parentChapter); } else { $this->chapterRepository->persistAsFirstChild($entityChapter); } $chaptersMap[$chapter['id']] = $entityChapter; } } return $lesson; }
public function prePersist(Chapter $chapter, LifecycleEventArgs $event) { if ($chapter->getText() != null) { $userPicker = new UserPickerContent($chapter->getText()); $chapter->setUserPicker($userPicker); $chapter->setText($userPicker->getFinalText()); } }
public function getNextChapter(Chapter $chapter) { try { $qb = $this->_em->createQueryBuilder(); return $this->_em->createQueryBuilder()->add('select', 'c')->add('from', 'Icap\\LessonBundle\\Entity\\Chapter c')->innerJoin('c.lesson', ' l')->where($qb->expr()->andx($qb->expr()->gt('c.left', '?1'), $qb->expr()->eq('l.id', '?2')))->orderBy('c.left', 'ASC')->setParameter(1, $chapter->getLeft())->setParameter(2, $chapter->getLesson())->setFirstResult(0)->setMaxResults(1)->getQuery()->getSingleResult(); } catch (\Doctrine\Orm\NoResultException $e) { return; } }
public function chapter($title, $text, $lesson, $root) { $chapter = new Chapter(); $chapter->setTitle($title); $chapter->setText($text); $chapter->setLesson($lesson); $this->om->persist($chapter); $this->om->flush(); return $chapter; }
/** * Copy chapter_org subchapters into provided chapter_copy * @param Chapter $chapter_org * @param Chapter $parent * @param boolean $copy_children * @param Lesson $copyName * * @return Chapter $chapter_copy */ public function copyChapter(Chapter $chapter_org, Chapter $parent, $copy_children, $copyName = null) { $chapter_copy = new Chapter(); if (!$copyName) { $copyName = $chapter_org->getTitle(); } $chapter_copy->setTitle($copyName); $chapter_copy->setText($chapter_org->getText()); $chapter_copy->setLesson($parent->getLesson()); $this->insertChapter($chapter_copy, $parent); if ($copy_children) { $this->copyChildren($chapter_org, $chapter_copy, $copy_children); } return $chapter_copy; }
/** * @ORM\PostPersist */ public function createRoot(LifecycleEventArgs $event) { if ($this->getRoot() == null) { $em = $event->getEntityManager(); $rootLesson = $this->getRoot(); if ($rootLesson == null) { $rootLesson = new Chapter(); $rootLesson->setLesson($this); $rootLesson->setTitle("root_" . $this->getId()); $this->setRoot($rootLesson); $em->getRepository('IcapLessonBundle:Chapter')->persistAsFirstChild($rootLesson); $em->flush(); } } }
/** * @param Lesson $lesson * @param Chapter $chapter */ public function __construct(Lesson $lesson, Chapter $chapter) { $this->lesson = $lesson; $this->details = array('chapter' => array('lesson' => $lesson->getId(), 'chapter' => $chapter->getId(), 'title' => $chapter->getTitle())); parent::__construct($lesson->getResourceNode(), $this->details); }
/** * @param Lesson $lesson * @param Chapter $chapter * @param Chapter $oldparent * @param Chapter $newparent */ public function __construct(Lesson $lesson, Chapter $chapter, Chapter $oldparent, Chapter $newparent) { $details = array('chapter' => array('lesson' => $lesson->getId(), 'chapter' => $chapter->getId(), 'title' => $chapter->getTitle(), 'old_parent' => $oldparent->getTitle(), 'new_parent' => $newparent->getTitle())); parent::__construct($lesson->getResourceNode(), $details); }
/** * @Delete("/chapters/{lesson}/{chapter}", * requirements={"lesson" = "\d+"}) * @ParamConverter("lesson", class="IcapLessonBundle:Lesson") * @ParamConverter("chapter", class="IcapLessonBundle:Chapter", options={"mapping": {"chapter": "slug"}}) */ public function deleteChapterAction(Lesson $lesson, Chapter $chapter) { // CHECK ACCESS $this->apiCheckAccess('EDIT', $lesson); $translator = $this->get('translator'); $message = null; $chapterTitle = $chapter->getTitle(); // DELETE request doesn't allow to send body params, so we have to rely on a query param instead $deleteChildren = $this->request->query->get('deleteChildren'); $em = $this->getDoctrine()->getManager(); $repo = $em->getRepository('IcapLessonBundle:Chapter'); if ($deleteChildren == 'true') { $em->remove($chapter); $message = $translator->trans('Your chapter has been deleted', array(), 'icap_lesson'); } else { $repo->removeFromTree($chapter); $message = $translator->trans('Your chapter has been deleted but no subchapter', array(), 'icap_lesson'); } $em->flush(); $this->dispatchChapterDeleteEvent($lesson, $chapterTitle); return array('message' => $message); }