Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- private $groupsManager;
- private $trainingsManager;
- private $walletsManager;
- public function __construct(GroupsManager $groupsManager, TrainingsManager $trainingsManager, WalletsManager $walletsManager)
- {
- $this->groupsManager = $groupsManager;
- $this->trainingsManager = $trainingsManager;
- $this->walletsManager = $walletsManager;
- }
- public function group(Request $request, string $slug = null, TranslatorInterface $translator): Response
- {
- // if (null === $slug) {
- // $group = new Group();
- // } else {
- // $group = $this->getDoctrine()->getRepository(Group::class)->findOneBy(['slug' => $slug]);
- // if (!$group) {
- // throw new Exception($translator->trans('Invalid group slug'));
- // }
- // }
- $group = $this->groupsManager->getGroupBySlug($slug);
- if(!$group) {
- throw new Exception($translator->trans('Invalid group slug'));
- }
- $form = $this->createForm(GroupType::class, $group);
- $form->handleRequest($request);
- if ($form->isSubmitted() && $form->isValid()) {
- // if (empty($group->getSlug())) {
- // $group->setSlug($group->getName());
- // }
- // $em = $this->getDoctrine()->getManager();
- // $em->persist($group);
- // $em->flush();
- $group = $this->groupsManager->updateGroup($group);
- if (null === $slug) {
- // Tworzenie treningów do grupy
- // $startDateGroup = $group->getStartDate();
- // $endDateGroup = $group->getEndDate();
- //
- // $endDateTraining = new \DateTime($group->getStartDate()->format('Y-m-d H:i:s'));
- // $endDateTraining->modify('+45 minutes');
- //
- // $trainingCount = 0;
- // while ($startDateGroup < $endDateGroup) {
- // $training = new Training();
- // $training->setStartDate($startDateGroup)
- // ->setEndDate($endDateTraining);
- //
- // $training->setGroup($group);
- // $training->setCoach($group->getCoach());
- //
- // foreach ($group->getStudents() as $student) {
- // $training->addStudent($student);
- // }
- //
- // $em->persist($training);
- // $em->flush();
- //
- // $startDateGroup->modify('+7 day');
- // $endDateTraining->modify('+7 day');
- //
- // ++$trainingCount;
- // }
- $this->trainingsManager->create($group);
- // Do każdego portfela studenta dodajemy koszt zajęć w grupie
- // portfel = portfel - (ilość_treningów * cena_jednych zajęć_w_grupie)
- // foreach ($group->getStudents() as $student) {
- // $student->setWallet($student->getWallet() - ($trainingCount * $group->getPrice()));
- // $em->persist($student);
- // $em->flush();
- // }
- $this->walletsManager->updateForGroup($group);
- }
- $this->addFlash('success', $translator->trans('Changes have been saved'));
- return $this->redirectToRoute('panel_groups');
- }
- // elseif ($form->isSubmitted() && false === $form->isValid()) {
- // $this->addFlash('error', $translator->trans('Corrects form'));
- // }
- return $this->render('backend/group/group.html.twig', [
- 'form' => $form->createView(),
- 'group' => $group,
- ]);
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement