/** * @param Season $season * @param array $ignore */ public function buildFromPlanning(Season $season, array $ignore) { // Existing lessons $lessons = new ArrayCollection(); foreach ($this->em->getRepository('AppBundle:Lesson')->findBySeason($season) as $l) { $lessons->add($l->getDate()->format('Y-m-d') . '-' . $l->getStart()->format('H-i') . '-' . $l->getLevel()->getId()); } // Periods to ignore $ignorePeriods = new ArrayCollection(); foreach ($ignore as $i) { foreach (new \DatePeriod($i['start'], new \DateInterval('P1D'), $i['stop']) as $d) { $ignorePeriods->add($d->format('Y-m-d')); } $ignorePeriods->add($i['stop']->format('Y-m-d')); } // Planning $planning = $this->em->getRepository('AppBundle:Planning')->findAll(); foreach ($planning as $p) { $start = new \DateTime($season->getStart()->format('Y-m-d') . ' 00:00:00'); $start->modify('+' . ($p->getWeekday() - $start->format('N')) . ' day'); $stop = new \DateTime($season->getStop()->format('Y-m-d') . ' 23:59:59'); foreach (new \DatePeriod($start, new \DateInterval('P1W'), $stop) as $date) { if ($ignorePeriods->contains($date->format('Y-m-d'))) { continue; } if ($lessons->contains($date->format('Y-m-d') . '-' . $p->getStart()->format('H-i') . '-' . $p->getLevel()->getId())) { continue; } $l = new Lesson(); $l->setDate($date)->setDuration($p->getDuration())->setLevel($p->getLevel())->setStart($p->getStart()); $this->em->persist($l); } } $this->em->flush(); }
public function load(ObjectManager $manager) { $lessonConfigurator = $this->configureLessons(); foreach ($lessonConfigurator as $configuration) { $lesson = new Lesson(); $lesson->setName($configuration['name'])->setCourse($this->getReference($configuration['course']))->setImagePath($configuration['image'])->setLevel($configuration['level']); $manager->persist($lesson); } $manager->flush(); }
/** * @param ObjectManager $manager */ public function load(ObjectManager $manager) { $lesson = new Lesson(); $lesson->setActive(true)->setDate(new \DateTime('2015-09-08'))->setDuration(60)->setLevel($this->getReference('level1'))->setStart(new \DateTime('18:15:00')); $manager->persist($lesson); $lesson = new Lesson(); $lesson->setActive(true)->setDate(new \DateTime('2015-09-15'))->setDuration(60)->setLevel($this->getReference('level1'))->setStart(new \DateTime('18:15:00')); $manager->persist($lesson); $lesson = new Lesson(); $lesson->setActive(true)->setDate(new \DateTime('2015-09-29'))->setDuration(60)->setLevel($this->getReference('level2'))->setStart(new \DateTime('18:15:00')); $manager->persist($lesson); $lesson = new Lesson(); $lesson->setActive(true)->setDate(new \DateTime('2015-09-17'))->setDuration(90)->setLevel($this->getReference('level3'))->setStart(new \DateTime('19:00:00')); $manager->persist($lesson); $manager->flush(); }
/** * @param Lesson $lesson * @return CreateLesson|UpdateLesson */ static function createUpdateCommand(Lesson $lesson) { $command = new UpdateLesson(); $command->id = $lesson->getId(); $command->title = $lesson->getTitle(); $command->description = $lesson->getDescription(); $command->address = $lesson->getAddress(); $command->city = $lesson->getCity(); $command->workshop = $lesson->getWorkshop(); $command->startDate = $lesson->getStartDate(); $command->endDate = $lesson->getEndDate(); return $command; }
/** * @param Request $request * @param \DateTime $day * @return \Symfony\Component\HttpFoundation\RedirectResponse|Response * * @Route("/lesson/add/{day}", * name="app_lesson_add", * methods={"GET","POST"}, * requirements={"day"="[0-9]{4}-[0-9]{2}-[0-9]{2}"}) */ public function addAction(Request $request, \DateTime $day) { // Lesson manager $lm = $this->get('app.lesson_manager'); // Edit form $lesson = new Lesson(); $lesson->setDate($day); $formEdit = $this->createForm(LessonType::class, $lesson); $formEdit->handleRequest($request); if ($formEdit->isSubmitted() && $formEdit->isValid()) { // Save data $lm->updateLesson($lesson); // Flash message $this->addFlash('success', $this->get('translator')->trans('lesson_add.success.added', [], 'lesson')); // Redirect return $this->redirectToRoute('app_lesson_day', ['day' => $lesson->getDate()->format('Y-m-d')]); } // Render return $this->render('lesson/add.html.twig', ['day' => $day, 'formEdit' => $formEdit->createView()]); }
public function load(ObjectManager $manager) { for ($i = 0; $i < 6; $i++) { /** @var Instrument $instrument */ $instrument = $this->getReference('instrument-' . $i); for ($j = 0; $j < 3; $j++) { /** @var Level $level */ $level = $this->getReference('level-' . $j); $lesson = new Lesson(); $lesson->setName($instrument->getName() . ' ' . $level->getName()); $lesson->setInstrument($instrument); $lesson->setLevel($level); $lesson->setImageUrl('img/lessons/' . ($j + 1 + 3 * $i) . '.png'); $lesson->setDescription("Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum."); $manager->persist($lesson); } } $manager->flush(); }
/** * @Route("/api/lessons", name="create_lesson") * @Method({"POST"}) * @ApiDoc( * resource=true, * description="Create a new lesson", * ) * @param ParamFetcher $paramFetcher Paramfetcher * @RequestParam(name="name", nullable=false, strict=true, description="Lesson name.") * @RequestParam(name="description", nullable=true, strict=true, description="Lesson description.") * @RequestParam(name="image_url", nullable=true, strict=true, description="Lesson image.") * @RequestParam(name="instrument", nullable=true, strict=true, description="Lesson instrument.") * @RequestParam(name="level", nullable=true, strict=true, description="Lesson level.") * @return JsonResponse|Response $response List of lessons */ public function createLessonAction(ParamFetcher $paramFetcher) { $em = $this->getDoctrine()->getManager(); $level = $em->getRepository('AppBundle:Level')->findOneBy(['slug' => $paramFetcher->get('level')]); if (!$level) { throw new NotFoundHttpException('Level not found'); } $instrument = $em->getRepository('AppBundle:Instrument')->findOneBy(['slug' => $paramFetcher->get('instrument')]); if (!$instrument) { throw new NotFoundHttpException('Instrument not found'); } $lesson = new Lesson(); $lesson->setName($paramFetcher->get('name')); $lesson->setDescription($paramFetcher->get('description')); $lesson->setImageUrl($paramFetcher->get('image_url')); $lesson->setInstrument($instrument); $lesson->setLevel($level); $em->persist($lesson); $em->flush(); $serializer = SerializerBuilder::create()->build(); $json = $serializer->serialize($lesson, 'json', SerializationContext::create()->enableMaxDepthChecks()); return new Response($json); }
/** * @param Lesson $lesson */ public function addLesson(Lesson $lesson) { $lesson->setWorkshop($this); $this->lessons->add($lesson); }
/** * {@inheritDoc} */ public function __toString() { $this->__initializer__ && $this->__initializer__->__invoke($this, '__toString', array()); return parent::__toString(); }