From e25eff2d49f4cb0d772e8567a6bc0a4919dd97a6 Mon Sep 17 00:00:00 2001 From: Ryan Prather Date: Thu, 5 Dec 2024 01:05:35 -0500 Subject: [PATCH] Add referral source content --- src/Controller/ReferralSourceController.php | 120 ++++++++++++++++++ src/Entity/ReferralSource.php | 98 ++++++++++++++ src/Form/ReferralSourceFormType.php | 29 +++++ src/Repository/ReferralSourceRepository.php | 52 ++++++++ .../referral_source/add-source.html.twig | 66 ++++++++++ .../referral_source/edit-source.html.twig | 66 ++++++++++ .../list-referral-sources.html.twig | 78 ++++++++++++ 7 files changed, 509 insertions(+) create mode 100644 src/Controller/ReferralSourceController.php create mode 100644 src/Entity/ReferralSource.php create mode 100644 src/Form/ReferralSourceFormType.php create mode 100644 src/Repository/ReferralSourceRepository.php create mode 100644 templates/internal/admin/referral_source/add-source.html.twig create mode 100644 templates/internal/admin/referral_source/edit-source.html.twig create mode 100644 templates/internal/admin/referral_source/list-referral-sources.html.twig diff --git a/src/Controller/ReferralSourceController.php b/src/Controller/ReferralSourceController.php new file mode 100644 index 0000000..755c66b --- /dev/null +++ b/src/Controller/ReferralSourceController.php @@ -0,0 +1,120 @@ +navList = NavList::LIST; + } + + #[Route('/list-referral-sources', name: 'app_referral_source')] + public function listReferralSources(#[CurrentUser()] User $user): Response + { + $this->denyAccessUnlessGranted('ROLE_ADMIN'); + $this->navList['referral_sources'] = 'nav-link text-white active bg-gradient-dark'; + + $sources = $this->entityManager->getRepository(ReferralSource::class)->retrieveOrderedList(); + + return $this->render( + 'internal/admin/referral_source/list-referral-sources.html.twig', + array_merge( + $this->navList, + [ + 'sources' => $sources, + 'notifications' => $user->retrieveUnreadNotifications(), + 'breadcrumbs' => [ + 'Referral Sources' + ] + ] + ) + ); + } + + #[Route('/add-source', name: 'app_add_source')] + public function addSource(Request $request, #[CurrentUser()] User $user): Response + { + $this->denyAccessUnlessGranted('ROLE_ADMIN'); + $this->navList['referral_sources'] = 'nav-link text-white active bg-gradient-dark'; + + $rs = new ReferralSource(); + $form = $this->createForm(ReferralSourceFormType::class, $rs); + + $form->handleRequest($request); + + if ($form->isSubmitted() && $form->isValid()) { + $rs = $form->getData(); + + $this->entityManager->persist($rs); + $this->entityManager->flush(); + + return $this->redirectToRoute('app_referral_source'); + } + + return $this->render( + 'internal/admin/referral_source/add-source.html.twig', + array_merge( + $this->navList, + [ + 'form' => $form, + 'notifications' => $user->retrieveUnreadNotifications(), + 'breadcrumbs' => [ + 'Referral Sources', + 'Add Source' + ] + ] + ) + ); + } + + #[Route('/edit-source/{id}', name: 'app_edit_source')] + public function editSource(Request $request, #[CurrentUser()] User $user, string $id): Response + { + $this->denyAccessUnlessGranted('ROLE_ADMIN'); + $this->navList['referral_sources'] = 'nav-link text-white active bg-gradient-dark'; + + $rs = $this->entityManager->getRepository(ReferralSource::class)->find($id); + + $form = $this->createForm(ReferralSourceFormType::class, $rs); + + $form->handleRequest($request); + + if ($form->isSubmitted() && $form->isValid()) { + $rs = $form->getData(); + + $this->entityManager->persist($rs); + $this->entityManager->flush(); + + return $this->redirectToRoute('app_referral_source'); + } + + return $this->render( + 'internal/admin/referral_source/edit-source.html.twig', + array_merge( + $this->navList, + [ + 'form' => $form, + 'notifications' => $user->retrieveUnreadNotifications(), + 'breadcrumbs' => [ + 'Referral Sources', + 'Edit Source' + ] + ] + ) + ); + } +} diff --git a/src/Entity/ReferralSource.php b/src/Entity/ReferralSource.php new file mode 100644 index 0000000..db4563e --- /dev/null +++ b/src/Entity/ReferralSource.php @@ -0,0 +1,98 @@ +id; + } + + public function getAgency(): ?string + { + return $this->agency; + } + + public function setAgency(string $agency): static + { + $this->agency = $agency; + + return $this; + } + + public function getName(): ?string + { + return $this->name; + } + + public function setName(string $name): static + { + $this->name = $name; + + return $this; + } + + public function getEmail(): ?string + { + return $this->email; + } + + public function setEmail(string $email): static + { + $this->email = $email; + + return $this; + } + + public function getPhone(): ?string + { + return $this->phone; + } + + public function setPhone(?string $phone): static + { + $this->phone = $phone; + + return $this; + } + + public function getCounty(): ?string + { + return $this->county; + } + + public function setCounty(?string $county): static + { + $this->county = $county; + + return $this; + } +} diff --git a/src/Form/ReferralSourceFormType.php b/src/Form/ReferralSourceFormType.php new file mode 100644 index 0000000..3f2f6d2 --- /dev/null +++ b/src/Form/ReferralSourceFormType.php @@ -0,0 +1,29 @@ +add('agency') + ->add('name') + ->add('email') + ->add('phone') + ->add('county') + ; + } + + public function configureOptions(OptionsResolver $resolver): void + { + $resolver->setDefaults([ + 'data_class' => ReferralSource::class, + ]); + } +} diff --git a/src/Repository/ReferralSourceRepository.php b/src/Repository/ReferralSourceRepository.php new file mode 100644 index 0000000..b309571 --- /dev/null +++ b/src/Repository/ReferralSourceRepository.php @@ -0,0 +1,52 @@ + + */ +class ReferralSourceRepository extends ServiceEntityRepository +{ + public function __construct(ManagerRegistry $registry) + { + parent::__construct($registry, ReferralSource::class); + } + + public function retrieveOrderedList(): array + { + return $this->createQueryBuilder('r') + ->orderBy('r.name', 'ASC') + ->getQuery() + ->getResult() + ; + } + + // /** + // * @return ReferralSource[] Returns an array of ReferralSource objects + // */ + // public function findByExampleField($value): array + // { + // return $this->createQueryBuilder('r') + // ->andWhere('r.exampleField = :val') + // ->setParameter('val', $value) + // ->orderBy('r.id', 'ASC') + // ->setMaxResults(10) + // ->getQuery() + // ->getResult() + // ; + // } + + // public function findOneBySomeField($value): ?ReferralSource + // { + // return $this->createQueryBuilder('r') + // ->andWhere('r.exampleField = :val') + // ->setParameter('val', $value) + // ->getQuery() + // ->getOneOrNullResult() + // ; + // } +} diff --git a/templates/internal/admin/referral_source/add-source.html.twig b/templates/internal/admin/referral_source/add-source.html.twig new file mode 100644 index 0000000..6974553 --- /dev/null +++ b/templates/internal/admin/referral_source/add-source.html.twig @@ -0,0 +1,66 @@ +{% extends 'base.html.twig' %} + +{% block title %}Add Referral Source +{% endblock %} + +{% block body %} + {{ block('nav', 'internal/libs/nav.html.twig') }} + +
+ {{ block('topnav', 'internal/libs/top-nav.html.twig') }} + +
+
+
+ {% endblock %} diff --git a/templates/internal/admin/referral_source/edit-source.html.twig b/templates/internal/admin/referral_source/edit-source.html.twig new file mode 100644 index 0000000..db70c7a --- /dev/null +++ b/templates/internal/admin/referral_source/edit-source.html.twig @@ -0,0 +1,66 @@ +{% extends 'base.html.twig' %} + +{% block title %}Edit Referral Source +{% endblock %} + +{% block body %} + {{ block('nav', 'internal/libs/nav.html.twig') }} + +
+ {{ block('topnav', 'internal/libs/top-nav.html.twig') }} + +
+
+
+ {% endblock %} diff --git a/templates/internal/admin/referral_source/list-referral-sources.html.twig b/templates/internal/admin/referral_source/list-referral-sources.html.twig new file mode 100644 index 0000000..cca6765 --- /dev/null +++ b/templates/internal/admin/referral_source/list-referral-sources.html.twig @@ -0,0 +1,78 @@ +{% extends 'base.html.twig' %} + +{% block title %}Referral Source List +{% endblock %} + +{% block body %} + {{ block('nav', 'internal/libs/nav.html.twig') }} + +
+ {{ block('topnav', 'internal/libs/top-nav.html.twig') }} + +
+
+
+
+
+
+
+
Referral Source List
+
+
+ +
+
+
+
+
+ + + + + + + + + + + + {% for src in sources %} + + + + + + + + {% endfor %} + +
NameAgencyCountyPhone
+
+
+ {{ src.name }} +
+
+
{{ src.name }}
+

+ {{ src.email }} +

+
+
+
+

{{ src.agency }}

+
+

{{ src.county }}

+
+ {{ src.phone }} + + Edit +
+
+
+
+
+
+
+ +
+{% endblock %}