src/Front/Modules/OnlineService/Controller/CreatorController.php line 25
<?phpnamespace App\Front\Modules\OnlineService\Controller;use Symfony\Component\HttpFoundation\Request;use Symfony\Component\HttpFoundation\JsonResponse;use App\Admin\Modules\OnlineService\Service\CreatorService as AdminCreatorService;use App\UserPanel\Modules\OnlineService\Form\CreatorType as UserPanelCreatorType;use App\Front\Controller\BaseController;use App\Front\Modules\Cart\Service\CartService;class CreatorController extends BaseController{private $_adminCreatorService;private $_cartService;public function __construct(AdminCreatorService $adminCreatorService,CartService $cartService){$this->_adminCreatorService = $adminCreatorService;$this->_cartService = $cartService;}public function index(Request $request, $categoryId){$creator = $this->_adminCreatorService->getCreator();if ($creator && count($creator->getCategories())){$categories = array();foreach($creator->getCategories() as $category){if (count($category->getItems()))$categories[] = $category;}if ($categories){if ($categoryId){$category = null;foreach($categories as $_category){if ($_category->getId() == $categoryId){$category = $_category;break;}}if (!$category)throw $this->createNotFoundException();}else$category = $categories[0];$form = $this->createForm(UserPanelCreatorType::class, null, ['category' => $category]);$form->handleRequest($request);if ($form->isSubmitted() && $form->isValid()){if ($form['items']->getData()){foreach($form['items']->getData() as $item)$this->_cartService->addItem($item);$this->addFlash('success', 'Wybrane usługi zostały dodane do koszyka.');return $this->redirectToRoute('front_online_service_creator_index', ['categoryId' => $category->getId()]);}}}}return $this->render('Front/Modules/OnlineService/Templates/Creator/index.html.twig', ['formType' => !empty($form) ? $form->getConfig()->getType()->getInnerType() : null,'form' => !empty($form) ? $form->createView() : null,'categories' => $categories ?? []]);}public function updateFormAjax(Request $request, $categoryId){$creator = $this->_adminCreatorService->getCreator();if (!$creator)$this->throwHttpError400();$category = null;foreach($creator->getCategories() as $_category){if ($_category->getId() == $categoryId){$category = $_category;break;}}if (!$category)throw $this->throwHttpError400();$form = $this->createForm(UserPanelCreatorType::class, null, ['category' => $category, 'validation_groups' => false]);$form->handleRequest($request);return new JsonResponse(array('html' => $this->renderView('UserPanel/Modules/OnlineService/Templates/Creator/partials/form.html.twig', array('formType' => !empty($form) ? $form->getConfig()->getType()->getInnerType() : null,'form' => $form->createView()))));}}