Exemplo n.º 1
0
 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();
 }
Exemplo n.º 2
0
 /**
  * @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);
 }