Add referral source content

This commit is contained in:
Ryan Prather 2024-12-05 01:05:35 -05:00
parent a38e63add9
commit e25eff2d49
7 changed files with 509 additions and 0 deletions

View File

@ -0,0 +1,120 @@
<?php
namespace App\Controller;
use App\Entity\ReferralSource;
use App\Entity\User;
use App\Form\ReferralSourceFormType;
use App\Libs\NavList;
use Doctrine\ORM\EntityManagerInterface;
use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
use Symfony\Component\HttpFoundation\Request;
use Symfony\Component\HttpFoundation\Response;
use Symfony\Component\Routing\Attribute\Route;
use Symfony\Component\Security\Http\Attribute\CurrentUser;
class ReferralSourceController extends AbstractController
{
public function __construct(
private EntityManagerInterface $entityManager,
private array $navList = []
) {
$this->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'
]
]
)
);
}
}

View File

@ -0,0 +1,98 @@
<?php
namespace App\Entity;
use App\Repository\ReferralSourceRepository;
use Doctrine\ORM\Mapping as ORM;
use Symfony\Bridge\Doctrine\Types\UuidType;
use Symfony\Component\Uid\Uuid;
#[ORM\Entity(repositoryClass: ReferralSourceRepository::class)]
class ReferralSource
{
#[ORM\Id]
#[ORM\Column(type: UuidType::NAME, unique: true)]
#[ORM\GeneratedValue(strategy: 'CUSTOM')]
#[ORM\CustomIdGenerator(class: 'doctrine.uuid_generator')]
private ?Uuid $id = null;
#[ORM\Column(length: 10)]
private ?string $agency = null;
#[ORM\Column(length: 255)]
private ?string $name = null;
#[ORM\Column(length: 255)]
private ?string $email = null;
#[ORM\Column(length: 15, nullable: true)]
private ?string $phone = null;
#[ORM\Column(length: 100, nullable: true)]
private ?string $county = null;
public function getId(): ?Uuid
{
return $this->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;
}
}

View File

@ -0,0 +1,29 @@
<?php
namespace App\Form;
use App\Entity\ReferralSource;
use Symfony\Component\Form\AbstractType;
use Symfony\Component\Form\FormBuilderInterface;
use Symfony\Component\OptionsResolver\OptionsResolver;
class ReferralSourceFormType extends AbstractType
{
public function buildForm(FormBuilderInterface $builder, array $options): void
{
$builder
->add('agency')
->add('name')
->add('email')
->add('phone')
->add('county')
;
}
public function configureOptions(OptionsResolver $resolver): void
{
$resolver->setDefaults([
'data_class' => ReferralSource::class,
]);
}
}

View File

@ -0,0 +1,52 @@
<?php
namespace App\Repository;
use App\Entity\ReferralSource;
use Doctrine\Bundle\DoctrineBundle\Repository\ServiceEntityRepository;
use Doctrine\Persistence\ManagerRegistry;
/**
* @extends ServiceEntityRepository<ReferralSource>
*/
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()
// ;
// }
}

View File

@ -0,0 +1,66 @@
{% extends 'base.html.twig' %}
{% block title %}Add Referral Source
{% endblock %}
{% block body %}
{{ block('nav', 'internal/libs/nav.html.twig') }}
<main class="main-content position-relative max-height-vh-100 h-100 border-radius-lg ">
{{ block('topnav', 'internal/libs/top-nav.html.twig') }}
<section>
<div class='page-header min-vh-100'>
<div class='container'>
<div class="row">
<div class="col-6 d-lg-flex d-none h-100 my-auto pe-0 position-absolute top-0 start-0 text-center justify-content-center flex-column">
<div class="position-relative bg-gradient-primary h-100 m-3 px-7 border-radius-lg d-flex flex-column justify-content-center" style="background-image: url('/assets/img/illustrations/illustration-signup.jpg'); background-size: cover;"></div>
</div>
<div class="col-xl-4 col-lg-5 col-md-7 d-flex flex-column ms-auto me-auto ms-lg-auto me-lg-5">
<div class="card card-plain">
<div class="card-header">
<h4 class="font-weight-bolder">Add Referral Source</h4>
<p class="mb-0">Add a source of receiving referrals</p>
</div>
<div class="card-body">
{{ form_errors(form) }}
{{ form_start(form) }}
<div class='input-group input-group-outline mb-3'>
<label for='ref_src_name' class='form-label'>Name</label>
<input type='text' name='{{ field_name(form.name) }}' id='ref_src_name' placeholder='' class='form-control' required='required'/>
</div>
<div class='input-group input-group-outline mb-3'>
<label for='ref_src_agency' class='form-label'>Agency</label>
<input type='text' name='{{ field_name(form.agency) }}' id='ref_src_agency' placeholder='' class='form-control' required='required'/>
</div>
<div class='input-group input-group-outline mb-3'>
<label for='ref_src_email' class='form-label'>Email</label>
<input type='email' name='{{ field_name(form.email) }}' id='ref_src_email' placeholder='' class='form-control' required='required'/>
</div>
<div class='input-group input-group-outline mb-3'>
<label for='ref_src_phone' class='form-label'>Phone</label>
<input type='phone' name='{{ field_name(form.phone) }}' id='ref_src_phone' placeholder='' class='form-control'/>
</div>
<div class='input-group input-group-outline mb-3'>
<label for='ref_src_county' class='form-label'>County</label>
<input type='text' name='{{ field_name(form.county) }}' id='ref_src_county' placeholder='' class='form-control'/>
</div>
<div class='text-center'>
<button type='submit' class='btn btn-lg bg-gradient-dark btn-lg w-100 mt-4 mb-0'>Add Source</button>
</div>
{{ form_end(form) }}
</div>
</div>
</div>
</div>
</div>
</section>
</main>
{% endblock %}

View File

@ -0,0 +1,66 @@
{% extends 'base.html.twig' %}
{% block title %}Edit Referral Source
{% endblock %}
{% block body %}
{{ block('nav', 'internal/libs/nav.html.twig') }}
<main class="main-content position-relative max-height-vh-100 h-100 border-radius-lg ">
{{ block('topnav', 'internal/libs/top-nav.html.twig') }}
<section>
<div class='page-header min-vh-100'>
<div class='container'>
<div class="row">
<div class="col-6 d-lg-flex d-none h-100 my-auto pe-0 position-absolute top-0 start-0 text-center justify-content-center flex-column">
<div class="position-relative bg-gradient-primary h-100 m-3 px-7 border-radius-lg d-flex flex-column justify-content-center" style="background-image: url('/assets/img/illustrations/illustration-signup.jpg'); background-size: cover;"></div>
</div>
<div class="col-xl-4 col-lg-5 col-md-7 d-flex flex-column ms-auto me-auto ms-lg-auto me-lg-5">
<div class="card card-plain">
<div class="card-header">
<h4 class="font-weight-bolder">Add Referral Source</h4>
<p class="mb-0">Add a source of receiving referrals</p>
</div>
<div class="card-body">
{{ form_errors(form) }}
{{ form_start(form) }}
<div class='input-group input-group-outline mb-3 is-filled'>
<label for='ref_src_name' class='form-label'>Name</label>
<input type='text' name='{{ field_name(form.name) }}' value='{{ field_value(form.name) }}' id='ref_src_name' class='form-control' required='required'/>
</div>
<div class='input-group input-group-outline mb-3 is-filled'>
<label for='ref_src_agency' class='form-label'>Agency</label>
<input type='text' name='{{ field_name(form.agency) }}' value='{{ field_value(form.agency) }}' id='ref_src_agency' class='form-control' required='required'/>
</div>
<div class='input-group input-group-outline mb-3 is-filled'>
<label for='ref_src_email' class='form-label'>Email</label>
<input type='email' name='{{ field_name(form.email) }}' value='{{ field_value(form.email) }}' id='ref_src_email' class='form-control' required='required'/>
</div>
<div class='input-group input-group-outline mb-3 {% if field_value(form.phone) %}is-filled{% endif %}'>
<label for='ref_src_phone' class='form-label'>Phone</label>
<input type='phone' name='{{ field_name(form.phone) }}' value='{{ field_value(form.phone) }}' id='ref_src_phone' class='form-control'/>
</div>
<div class='input-group input-group-outline mb-3 is-filled'>
<label for='ref_src_county' class='form-label'>County</label>
<input type='text' name='{{ field_name(form.county) }}' value='{{ field_value(form.county) }}' id='ref_src_county' class='form-control'/>
</div>
<div class='text-center'>
<button type='submit' class='btn btn-lg bg-gradient-dark btn-lg w-100 mt-4 mb-0'>Save Source</button>
</div>
{{ form_end(form) }}
</div>
</div>
</div>
</div>
</div>
</section>
</main>
{% endblock %}

View File

@ -0,0 +1,78 @@
{% extends 'base.html.twig' %}
{% block title %}Referral Source List
{% endblock %}
{% block body %}
{{ block('nav', 'internal/libs/nav.html.twig') }}
<main class="main-content position-relative max-height-vh-100 h-100 border-radius-lg ">
{{ block('topnav', 'internal/libs/top-nav.html.twig') }}
<div class="container-fluid py-2">
<div class="row">
<div class="col-12">
<div class="card my-4">
<div class="card-header p-0 position-relative mt-n4 mx-3 z-index-2">
<div class="d-flex justify-content-between bg-gradient-dark shadow-dark border-radius-lg pt-4 pb-3 ps-3 p-2">
<div>
<h6 class="text-white text-capitalize ps-3">Referral Source List</h6>
</div>
<div>
<button type="button" class="btn btn-block btn-light mb-3" onclick="window.open('/index.php/add-source', '_self')">Add Source</button>
</div>
</div>
</div>
<div class="card-body px-0 pb-2">
<div class="table-responsive p-0">
<table class="table align-items-center mb-0">
<thead>
<tr>
<th class="text-uppercase text-secondary text-xxs font-weight-bolder opacity-7">Name</th>
<th class="text-uppercase text-secondary text-xxs font-weight-bolder opacity-7 ps-2">Agency</th>
<th class='text-center text-uppercase text-secondary text-xxs font-weight-bolder opacity-7'>County</th>
<th class="text-center text-uppercase text-secondary text-xxs font-weight-bolder opacity-7">Phone</th>
<th class="text-secondary opacity-7"></th>
</tr>
</thead>
<tbody>
{% for src in sources %}
<tr>
<td>
<div class='d-flex px-2 py-1'>
<div>
<img src='' class='avatar avatar-sm me-3 border-radius-large' alt='{{ src.name }}'>
</div>
<div class='d-flex flex-column justify-content-center'>
<h6 class='mb-0 text-small'>{{ src.name }}</h6>
<p class='text-xs text-secondary mb-0'>
<a href='mailto:{{ src.email }}'>{{ src.email }}</a>
</p>
</div>
</div>
</td>
<td>
<p class='text-xs font-weight-bold mb-0'>{{ src.agency }}</p>
</td>
<td>
<p class='text-xs font-weight-bold mb-0'>{{ src.county }}</p>
</td>
<td class='align-middle text-center text-xs'>
{{ src.phone }}
</td>
<td class='align-middle'>
<a href='/index.php/edit-source/{{ src.id }}' class='text-secondary font-weight-bold text-xs' data-toggle='tooltip' data-original-title='Edit Source'>Edit</a>
</td>
</tr>
{% endfor %}
</tbody>
</table>
</div>
</div>
</div>
</div>
</div>
</div>
</main>
{% endblock %}