@@ -13,78 +13,78 @@ |
||
| 13 | 13 | |
| 14 | 14 | class CreateAdminCommand extends Command |
| 15 | 15 | { |
| 16 | - /** @var EntityManagerInterface */ |
|
| 17 | - private $em; |
|
| 16 | + /** @var EntityManagerInterface */ |
|
| 17 | + private $em; |
|
| 18 | 18 | |
| 19 | - /** @var UserPasswordEncoderInterface */ |
|
| 20 | - private $passwordEncoder; |
|
| 19 | + /** @var UserPasswordEncoderInterface */ |
|
| 20 | + private $passwordEncoder; |
|
| 21 | 21 | |
| 22 | - /** |
|
| 23 | - * CreateAdminCommand constructor. |
|
| 24 | - * @param EntityManagerInterface $em |
|
| 25 | - * @param UserPasswordEncoderInterface $passwordEncoder |
|
| 26 | - * @param string|null $name |
|
| 27 | - */ |
|
| 28 | - public function __construct(EntityManagerInterface $em, UserPasswordEncoderInterface $passwordEncoder, string $name = null) |
|
| 29 | - { |
|
| 30 | - parent::__construct($name); |
|
| 31 | - $this->em = $em; |
|
| 32 | - $this->passwordEncoder = $passwordEncoder; |
|
| 33 | - } |
|
| 22 | + /** |
|
| 23 | + * CreateAdminCommand constructor. |
|
| 24 | + * @param EntityManagerInterface $em |
|
| 25 | + * @param UserPasswordEncoderInterface $passwordEncoder |
|
| 26 | + * @param string|null $name |
|
| 27 | + */ |
|
| 28 | + public function __construct(EntityManagerInterface $em, UserPasswordEncoderInterface $passwordEncoder, string $name = null) |
|
| 29 | + { |
|
| 30 | + parent::__construct($name); |
|
| 31 | + $this->em = $em; |
|
| 32 | + $this->passwordEncoder = $passwordEncoder; |
|
| 33 | + } |
|
| 34 | 34 | |
| 35 | - protected function configure() |
|
| 36 | - { |
|
| 37 | - $this |
|
| 38 | - ->setName('ribsadmin:create-admin') |
|
| 39 | - ->setDescription('Create an admin in ribs admin') |
|
| 40 | - ->addArgument( |
|
| 41 | - 'firstname', |
|
| 42 | - InputArgument::REQUIRED, |
|
| 43 | - 'Firstname of admin to create' |
|
| 44 | - ) |
|
| 45 | - ->addArgument( |
|
| 46 | - 'lastname', |
|
| 47 | - InputArgument::REQUIRED, |
|
| 48 | - 'Lastname of admin to create' |
|
| 49 | - ) |
|
| 50 | - ->addArgument( |
|
| 51 | - 'email', |
|
| 52 | - InputArgument::REQUIRED, |
|
| 53 | - 'email of admin to create' |
|
| 54 | - ) |
|
| 55 | - ->addArgument( |
|
| 56 | - 'password', |
|
| 57 | - InputArgument::REQUIRED, |
|
| 58 | - 'password of admin to create' |
|
| 59 | - ) |
|
| 60 | - ; |
|
| 61 | - } |
|
| 35 | + protected function configure() |
|
| 36 | + { |
|
| 37 | + $this |
|
| 38 | + ->setName('ribsadmin:create-admin') |
|
| 39 | + ->setDescription('Create an admin in ribs admin') |
|
| 40 | + ->addArgument( |
|
| 41 | + 'firstname', |
|
| 42 | + InputArgument::REQUIRED, |
|
| 43 | + 'Firstname of admin to create' |
|
| 44 | + ) |
|
| 45 | + ->addArgument( |
|
| 46 | + 'lastname', |
|
| 47 | + InputArgument::REQUIRED, |
|
| 48 | + 'Lastname of admin to create' |
|
| 49 | + ) |
|
| 50 | + ->addArgument( |
|
| 51 | + 'email', |
|
| 52 | + InputArgument::REQUIRED, |
|
| 53 | + 'email of admin to create' |
|
| 54 | + ) |
|
| 55 | + ->addArgument( |
|
| 56 | + 'password', |
|
| 57 | + InputArgument::REQUIRED, |
|
| 58 | + 'password of admin to create' |
|
| 59 | + ) |
|
| 60 | + ; |
|
| 61 | + } |
|
| 62 | 62 | |
| 63 | - protected function execute(InputInterface $input, OutputInterface $output) |
|
| 64 | - { |
|
| 65 | - $firstname = $input->getArgument('firstname'); |
|
| 66 | - $lastname = $input->getArgument('lastname'); |
|
| 67 | - $email = $input->getArgument('email'); |
|
| 68 | - $password = $input->getArgument('password'); |
|
| 63 | + protected function execute(InputInterface $input, OutputInterface $output) |
|
| 64 | + { |
|
| 65 | + $firstname = $input->getArgument('firstname'); |
|
| 66 | + $lastname = $input->getArgument('lastname'); |
|
| 67 | + $email = $input->getArgument('email'); |
|
| 68 | + $password = $input->getArgument('password'); |
|
| 69 | 69 | |
| 70 | - $output->writeln("Create admin " . $firstname . " " . $lastname); |
|
| 70 | + $output->writeln("Create admin " . $firstname . " " . $lastname); |
|
| 71 | 71 | |
| 72 | - $user = new User(); |
|
| 73 | - $user->setFirstname($firstname); |
|
| 74 | - $user->setLastname($lastname); |
|
| 75 | - $user->setAccessRights("*"); |
|
| 76 | - $this->em->persist($user); |
|
| 72 | + $user = new User(); |
|
| 73 | + $user->setFirstname($firstname); |
|
| 74 | + $user->setLastname($lastname); |
|
| 75 | + $user->setAccessRights("*"); |
|
| 76 | + $this->em->persist($user); |
|
| 77 | 77 | |
| 78 | - $account = new Account(); |
|
| 79 | - $temp_password = $this->passwordEncoder->encodePassword($account, $password); |
|
| 80 | - $account->setPassword($temp_password); |
|
| 81 | - $account->setUser($user); |
|
| 82 | - $account->setEmail($email); |
|
| 83 | - $account->setUsername(substr($firstname, 0, 1).".".$lastname); |
|
| 84 | - $this->em->persist($account); |
|
| 78 | + $account = new Account(); |
|
| 79 | + $temp_password = $this->passwordEncoder->encodePassword($account, $password); |
|
| 80 | + $account->setPassword($temp_password); |
|
| 81 | + $account->setUser($user); |
|
| 82 | + $account->setEmail($email); |
|
| 83 | + $account->setUsername(substr($firstname, 0, 1).".".$lastname); |
|
| 84 | + $this->em->persist($account); |
|
| 85 | 85 | |
| 86 | - $this->em->flush(); |
|
| 86 | + $this->em->flush(); |
|
| 87 | 87 | |
| 88 | - $output->writeln("End Create admin " . $firstname . " " . $lastname); |
|
| 89 | - } |
|
| 88 | + $output->writeln("End Create admin " . $firstname . " " . $lastname); |
|
| 89 | + } |
|
| 90 | 90 | } |
@@ -80,7 +80,7 @@ |
||
| 80 | 80 | $account->setPassword($temp_password); |
| 81 | 81 | $account->setUser($user); |
| 82 | 82 | $account->setEmail($email); |
| 83 | - $account->setUsername(substr($firstname, 0, 1).".".$lastname); |
|
| 83 | + $account->setUsername(substr($firstname, 0, 1) . "." . $lastname); |
|
| 84 | 84 | $this->em->persist($account); |
| 85 | 85 | |
| 86 | 86 | $this->em->flush(); |
@@ -11,83 +11,83 @@ |
||
| 11 | 11 | |
| 12 | 12 | class ModuleController extends AbstractController |
| 13 | 13 | { |
| 14 | - /** |
|
| 15 | - * @Route("/modules/", name="ribsadmin_modules") |
|
| 16 | - * @return Response |
|
| 17 | - * function that return a list of all modules |
|
| 18 | - */ |
|
| 19 | - public function List(): Response |
|
| 20 | - { |
|
| 21 | - $em = $this->getDoctrine()->getManager(); |
|
| 14 | + /** |
|
| 15 | + * @Route("/modules/", name="ribsadmin_modules") |
|
| 16 | + * @return Response |
|
| 17 | + * function that return a list of all modules |
|
| 18 | + */ |
|
| 19 | + public function List(): Response |
|
| 20 | + { |
|
| 21 | + $em = $this->getDoctrine()->getManager(); |
|
| 22 | 22 | |
| 23 | - $modules = $em->getRepository(Module::class)->findBy([], ['titleTag' => 'ASC']); |
|
| 23 | + $modules = $em->getRepository(Module::class)->findBy([], ['titleTag' => 'ASC']); |
|
| 24 | 24 | |
| 25 | - return $this->render('@RibsAdmin/modules/list.html.twig', [ |
|
| 26 | - "modules" => $modules, |
|
| 27 | - ]); |
|
| 28 | - } |
|
| 25 | + return $this->render('@RibsAdmin/modules/list.html.twig', [ |
|
| 26 | + "modules" => $modules, |
|
| 27 | + ]); |
|
| 28 | + } |
|
| 29 | 29 | |
| 30 | - /** |
|
| 31 | - * @Route("/modules/create/", name="ribsadmin_modules_create") |
|
| 32 | - * @Route("/modules/edit/{id}", name="ribsadmin_modules_edit") |
|
| 33 | - * @param Request $request |
|
| 34 | - * @param int|null $id |
|
| 35 | - * @return Response |
|
| 36 | - * method to edit a module |
|
| 37 | - */ |
|
| 38 | - public function edit(Request $request, int $id = null): Response |
|
| 39 | - { |
|
| 40 | - $em = $this->getDoctrine()->getManager(); |
|
| 30 | + /** |
|
| 31 | + * @Route("/modules/create/", name="ribsadmin_modules_create") |
|
| 32 | + * @Route("/modules/edit/{id}", name="ribsadmin_modules_edit") |
|
| 33 | + * @param Request $request |
|
| 34 | + * @param int|null $id |
|
| 35 | + * @return Response |
|
| 36 | + * method to edit a module |
|
| 37 | + */ |
|
| 38 | + public function edit(Request $request, int $id = null): Response |
|
| 39 | + { |
|
| 40 | + $em = $this->getDoctrine()->getManager(); |
|
| 41 | 41 | |
| 42 | - if (!$id) { |
|
| 43 | - $module = new Module(); |
|
| 44 | - $text = "created"; |
|
| 45 | - } else { |
|
| 46 | - $module = $em->getRepository(Module::class)->findOneBy(["id" => $id]); |
|
| 47 | - $text = "edited"; |
|
| 48 | - } |
|
| 42 | + if (!$id) { |
|
| 43 | + $module = new Module(); |
|
| 44 | + $text = "created"; |
|
| 45 | + } else { |
|
| 46 | + $module = $em->getRepository(Module::class)->findOneBy(["id" => $id]); |
|
| 47 | + $text = "edited"; |
|
| 48 | + } |
|
| 49 | 49 | |
| 50 | - $form = $this->createForm(\PiouPiou\RibsAdminBundle\Form\Module::class, $module); |
|
| 51 | - $form->handleRequest($request); |
|
| 50 | + $form = $this->createForm(\PiouPiou\RibsAdminBundle\Form\Module::class, $module); |
|
| 51 | + $form->handleRequest($request); |
|
| 52 | 52 | |
| 53 | - if ($form->isSubmitted() && $form->isValid()) { |
|
| 54 | - /** @var Module $data */ |
|
| 55 | - $data = $form->getData(); |
|
| 56 | - $em->persist($data); |
|
| 57 | - $em->flush(); |
|
| 58 | - $this->addFlash("success-flash", "Module ". $data->getTitleTag() . " was " . $text); |
|
| 53 | + if ($form->isSubmitted() && $form->isValid()) { |
|
| 54 | + /** @var Module $data */ |
|
| 55 | + $data = $form->getData(); |
|
| 56 | + $em->persist($data); |
|
| 57 | + $em->flush(); |
|
| 58 | + $this->addFlash("success-flash", "Module ". $data->getTitleTag() . " was " . $text); |
|
| 59 | 59 | |
| 60 | - return $this->redirectToRoute("ribsadmin_modules"); |
|
| 61 | - } |
|
| 60 | + return $this->redirectToRoute("ribsadmin_modules"); |
|
| 61 | + } |
|
| 62 | 62 | |
| 63 | - return $this->render("@RibsAdmin/modules/edit.html.twig", [ |
|
| 64 | - "form" => $form->createView(), |
|
| 65 | - "form_errors" => $form->getErrors(), |
|
| 66 | - "module" => $module |
|
| 67 | - ]); |
|
| 68 | - } |
|
| 63 | + return $this->render("@RibsAdmin/modules/edit.html.twig", [ |
|
| 64 | + "form" => $form->createView(), |
|
| 65 | + "form_errors" => $form->getErrors(), |
|
| 66 | + "module" => $module |
|
| 67 | + ]); |
|
| 68 | + } |
|
| 69 | 69 | |
| 70 | - /** |
|
| 71 | - * @Route("/modules/delete/{id}", name="ribsadmin_modules_delete") |
|
| 72 | - * @param Request $request |
|
| 73 | - * @param int $id |
|
| 74 | - * @return RedirectResponse |
|
| 75 | - * method to delete a module |
|
| 76 | - */ |
|
| 77 | - public function delete(Request $request, int $id): RedirectResponse |
|
| 78 | - { |
|
| 79 | - $em = $this->getDoctrine()->getManager(); |
|
| 80 | - $module = $em->getRepository(Module::class)->findOneBy(["id" => $id]); |
|
| 70 | + /** |
|
| 71 | + * @Route("/modules/delete/{id}", name="ribsadmin_modules_delete") |
|
| 72 | + * @param Request $request |
|
| 73 | + * @param int $id |
|
| 74 | + * @return RedirectResponse |
|
| 75 | + * method to delete a module |
|
| 76 | + */ |
|
| 77 | + public function delete(Request $request, int $id): RedirectResponse |
|
| 78 | + { |
|
| 79 | + $em = $this->getDoctrine()->getManager(); |
|
| 80 | + $module = $em->getRepository(Module::class)->findOneBy(["id" => $id]); |
|
| 81 | 81 | |
| 82 | - if ($module) { |
|
| 83 | - $name = $module->getTitle(); |
|
| 84 | - $em->remove($module); |
|
| 85 | - $em->flush(); |
|
| 86 | - $this->addFlash("success-flash", "Module " . $name . " was deleted"); |
|
| 87 | - } else { |
|
| 88 | - $this->addFlash("error-flash", "An error occured, module doesn't found"); |
|
| 89 | - } |
|
| 82 | + if ($module) { |
|
| 83 | + $name = $module->getTitle(); |
|
| 84 | + $em->remove($module); |
|
| 85 | + $em->flush(); |
|
| 86 | + $this->addFlash("success-flash", "Module " . $name . " was deleted"); |
|
| 87 | + } else { |
|
| 88 | + $this->addFlash("error-flash", "An error occured, module doesn't found"); |
|
| 89 | + } |
|
| 90 | 90 | |
| 91 | - return $this->redirectToRoute("ribsadmin_modules"); |
|
| 92 | - } |
|
| 91 | + return $this->redirectToRoute("ribsadmin_modules"); |
|
| 92 | + } |
|
| 93 | 93 | } |
@@ -55,7 +55,7 @@ |
||
| 55 | 55 | $data = $form->getData(); |
| 56 | 56 | $em->persist($data); |
| 57 | 57 | $em->flush(); |
| 58 | - $this->addFlash("success-flash", "Module ". $data->getTitleTag() . " was " . $text); |
|
| 58 | + $this->addFlash("success-flash", "Module " . $data->getTitleTag() . " was " . $text); |
|
| 59 | 59 | |
| 60 | 60 | return $this->redirectToRoute("ribsadmin_modules"); |
| 61 | 61 | } |