Advertisement
Guest User

Untitled

a guest
May 21st, 2019
153
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 3.69 KB | None | 0 0
  1.     private $groupsManager;
  2.  
  3.     private $trainingsManager;
  4.  
  5.     private $walletsManager;
  6.  
  7.     public function __construct(GroupsManager $groupsManager, TrainingsManager $trainingsManager, WalletsManager $walletsManager)
  8.     {
  9.         $this->groupsManager = $groupsManager;
  10.         $this->trainingsManager = $trainingsManager;
  11.         $this->walletsManager = $walletsManager;
  12.     }
  13.  
  14.     public function group(Request $request, string $slug = null, TranslatorInterface $translator): Response
  15.     {
  16. //        if (null === $slug) {
  17. //            $group = new Group();
  18. //        } else {
  19. //            $group = $this->getDoctrine()->getRepository(Group::class)->findOneBy(['slug' => $slug]);
  20. //            if (!$group) {
  21. //                throw new Exception($translator->trans('Invalid group slug'));
  22. //            }
  23. //        }
  24.  
  25.         $group = $this->groupsManager->getGroupBySlug($slug);
  26.  
  27.         if(!$group) {
  28.             throw new Exception($translator->trans('Invalid group slug'));
  29.         }
  30.  
  31.         $form = $this->createForm(GroupType::class, $group);
  32.         $form->handleRequest($request);
  33.  
  34.         if ($form->isSubmitted() && $form->isValid()) {
  35. //            if (empty($group->getSlug())) {
  36. //                $group->setSlug($group->getName());
  37. //            }
  38. //            $em = $this->getDoctrine()->getManager();
  39. //            $em->persist($group);
  40. //            $em->flush();
  41.             $group = $this->groupsManager->updateGroup($group);
  42.  
  43.             if (null === $slug) {
  44.                 // Tworzenie treningów do grupy
  45. //                $startDateGroup = $group->getStartDate();
  46. //                $endDateGroup = $group->getEndDate();
  47. //
  48. //                $endDateTraining = new \DateTime($group->getStartDate()->format('Y-m-d H:i:s'));
  49. //                $endDateTraining->modify('+45 minutes');
  50. //
  51. //                $trainingCount = 0;
  52. //                while ($startDateGroup < $endDateGroup) {
  53. //                    $training = new Training();
  54. //                    $training->setStartDate($startDateGroup)
  55. //                        ->setEndDate($endDateTraining);
  56. //
  57. //                    $training->setGroup($group);
  58. //                    $training->setCoach($group->getCoach());
  59. //
  60. //                    foreach ($group->getStudents() as $student) {
  61. //                        $training->addStudent($student);
  62. //                    }
  63. //
  64. //                    $em->persist($training);
  65. //                    $em->flush();
  66. //
  67. //                    $startDateGroup->modify('+7 day');
  68. //                    $endDateTraining->modify('+7 day');
  69. //
  70. //                    ++$trainingCount;
  71. //                }
  72.                 $this->trainingsManager->create($group);
  73.  
  74.                 // Do każdego portfela studenta dodajemy koszt zajęć w grupie
  75.                 // portfel = portfel - (ilość_treningów * cena_jednych zajęć_w_grupie)
  76. //                foreach ($group->getStudents() as $student) {
  77. //                    $student->setWallet($student->getWallet() - ($trainingCount * $group->getPrice()));
  78. //                    $em->persist($student);
  79. //                    $em->flush();
  80. //                }
  81.                 $this->walletsManager->updateForGroup($group);
  82.             }
  83.  
  84.             $this->addFlash('success', $translator->trans('Changes have been saved'));
  85.  
  86.             return $this->redirectToRoute('panel_groups');
  87.         }
  88. //        elseif ($form->isSubmitted() && false === $form->isValid()) {
  89. //            $this->addFlash('error', $translator->trans('Corrects form'));
  90. //        }
  91.  
  92.         return $this->render('backend/group/group.html.twig', [
  93.             'form' => $form->createView(),
  94.             'group' => $group,
  95.         ]);
  96.     }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement