Add referral source content
This commit is contained in:
120
src/Controller/ReferralSourceController.php
Normal file
120
src/Controller/ReferralSourceController.php
Normal 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'
|
||||
]
|
||||
]
|
||||
)
|
||||
);
|
||||
}
|
||||
}
|
98
src/Entity/ReferralSource.php
Normal file
98
src/Entity/ReferralSource.php
Normal 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;
|
||||
}
|
||||
}
|
29
src/Form/ReferralSourceFormType.php
Normal file
29
src/Form/ReferralSourceFormType.php
Normal 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,
|
||||
]);
|
||||
}
|
||||
}
|
52
src/Repository/ReferralSourceRepository.php
Normal file
52
src/Repository/ReferralSourceRepository.php
Normal 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()
|
||||
// ;
|
||||
// }
|
||||
}
|
Reference in New Issue
Block a user