/** * @param string $permission * @param Lesson $lesson * * @throws AccessDeniedException */ protected function checkAccess($permission, Lesson $lesson) { $collection = new ResourceCollection(array($lesson->getResourceNode())); if (!$this->get('security.authorization_checker')->isGranted($permission, $collection)) { throw new AccessDeniedException($collection->getErrorsForDisplay()); } $logEvent = new LogResourceReadEvent($lesson->getResourceNode()); $this->get('event_dispatcher')->dispatch('log', $logEvent); }
public function onCopy(CopyResourceEvent $event) { $entityManager = $this->container->get('doctrine.orm.entity_manager'); $lesson = $event->getResource(); $newLesson = new Lesson(); $newLesson->setName($lesson->getResourceNode()->getName()); $entityManager->persist($newLesson); $entityManager->flush($newLesson); //$chapterRepository = $entityManager->getRepository('IcapLessonBundle:Chapter'); $chapter_manager = $this->container->get('icap.lesson.manager.chapter'); $chapter_manager->copyRoot($lesson->getRoot(), $newLesson->getRoot()); $event->setCopy($newLesson); $event->stopPropagation(); }
/** * 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 lesson($title, User $creator) { $lesson = new Lesson(); if (!$this->lessonType) { $this->lessonType = new ResourceType(); $this->lessonType->setName('icap_lesson'); $this->om->persist($this->lessonType); } $node = new ResourceNode(); $node->setName($title); $node->setCreator($creator); $node->setResourceType($this->lessonType); $node->setWorkspace($creator->getPersonalWorkspace()); $node->setClass('Icap\\LessonBundle\\Entity\\Lesson'); $node->setGuid(time()); $lesson->setResourceNode($node); $this->om->persist($lesson); $this->om->persist($node); $this->om->flush(); return $lesson; }
/** * @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); }
/** * @param Lesson $lesson * @param string $chaptername */ public function __construct(Lesson $lesson, $chaptername) { $details = array('chapter' => array('lesson' => $lesson->getId(), 'title' => $chaptername)); parent::__construct($lesson->getResourceNode(), $details); }
public function getFirstChapter(Lesson $lesson) { return $this->findOneBy(array('lesson' => $lesson, 'root' => $lesson->getRoot()->getId(), 'left' => 2)); }
/** * @param string $permission * @param Lesson $lesson * * @throws AccessDeniedException */ protected function apiCheckAccess($permission, Lesson $lesson) { $translator = $this->get('translator'); $collection = new ResourceCollection(array($lesson->getResourceNode())); if (!$this->get('security.authorization_checker')->isGranted($permission, $collection)) { throw new HttpException(401, $translator->trans('error_401', array(), 'icap_lesson')); } $logEvent = new LogResourceReadEvent($lesson->getResourceNode()); $this->get('event_dispatcher')->dispatch('log', $logEvent); }