Exemplo n.º 1
0
 /**
  * @param Workshop|WorkshopCommandInterface $workshop
  * @return string
  */
 public function generate($workshop)
 {
     if ($workshop instanceof Workshop) {
         $params = [$workshop->getCity(), $workshop->getTitle()];
     } elseif ($workshop instanceof WorkshopCommandInterface) {
         /** @var CreateWorkshop|UpdateWorkshop $workshop */
         $firstLesson = current($workshop->lessons);
         $params = [$firstLesson->city, $workshop->title];
     }
     $i = 1;
     do {
         $slug = sprintf("%s-%d", implode("-", array_map(function ($el) {
             return strtolower(str_replace(" ", "-", $el));
         }, $params)), $i++);
     } while (!is_null($this->workshopRepository->findOneBySlug($slug)));
     return $slug;
 }
Exemplo n.º 2
0
 /**
  * UpdateWorkshop constructor.
  * @param Workshop $workshop
  */
 public function __construct(Workshop $workshop)
 {
     $this->id = $workshop->getId();
     $this->title = $workshop->getTitle();
     $this->description = $workshop->getDescription();
     $this->startDate = $workshop->getStartDate();
     $this->endDate = $workshop->getEndDate();
     $this->city = $workshop->getCity();
     $this->lessons = $this->convertLessons($workshop->getLessons());
     $this->phone = $workshop->getPhone();
     $this->url = $workshop->getUrl();
     $this->email = $workshop->getEmail();
 }
Exemplo n.º 3
0
 /**
  * @Route("/edit/{slug}", name="evento_edit")
  * @ParamConverter("workshop", class="AppBundle:Workshop")
  * @Template()
  * @param Request $request
  * @param Workshop $workshop
  * @return array
  */
 public function editAction(Request $request, Workshop $workshop)
 {
     $response = new Response(null, 200);
     $form = $this->createForm("register_workshops_form_type", new UpdateWorkshop($workshop), ["action" => $this->generateUrl("evento_edit", ["slug" => $workshop->getSlug()]), "method" => "POST"]);
     if ($request->isMethod("POST")) {
         $form->handleRequest($request);
         if ($form->isValid()) {
             $this->get("tactician.commandbus")->handle($form->getData());
             $this->addFlash("success", "Edycja się udała ;)");
             $this->redirectToRoute("evento_show", ["slug" => $workshop->getSlug()]);
         } else {
             $response->setStatusCode(400);
         }
     }
     return $this->render("AppBundle:Default:edit.html.twig", ["form" => $form->createView()], $response);
 }