Deprecated: Return type of Google\Model::offsetExists($offset) should either be compatible with ArrayAccess::offsetExists(mixed $offset): bool, or the #[\ReturnTypeWillChange] attribute should be used to temporarily suppress the notice in /var/www/html/sanralsmme/vendor/google/apiclient/src/Model.php on line 256

Deprecated: Return type of Google\Model::offsetGet($offset) should either be compatible with ArrayAccess::offsetGet(mixed $offset): mixed, or the #[\ReturnTypeWillChange] attribute should be used to temporarily suppress the notice in /var/www/html/sanralsmme/vendor/google/apiclient/src/Model.php on line 261

Deprecated: Return type of Google\Model::offsetSet($offset, $value) should either be compatible with ArrayAccess::offsetSet(mixed $offset, mixed $value): void, or the #[\ReturnTypeWillChange] attribute should be used to temporarily suppress the notice in /var/www/html/sanralsmme/vendor/google/apiclient/src/Model.php on line 268

Deprecated: Return type of Google\Model::offsetUnset($offset) should either be compatible with ArrayAccess::offsetUnset(mixed $offset): void, or the #[\ReturnTypeWillChange] attribute should be used to temporarily suppress the notice in /var/www/html/sanralsmme/vendor/google/apiclient/src/Model.php on line 278

Deprecated: Return type of Google\Collection::current() should either be compatible with Iterator::current(): mixed, or the #[\ReturnTypeWillChange] attribute should be used to temporarily suppress the notice in /var/www/html/sanralsmme/vendor/google/apiclient/src/Collection.php on line 22

Deprecated: Return type of Google\Collection::next() should either be compatible with Iterator::next(): void, or the #[\ReturnTypeWillChange] attribute should be used to temporarily suppress the notice in /var/www/html/sanralsmme/vendor/google/apiclient/src/Collection.php on line 38

Deprecated: Return type of Google\Collection::key() should either be compatible with Iterator::key(): mixed, or the #[\ReturnTypeWillChange] attribute should be used to temporarily suppress the notice in /var/www/html/sanralsmme/vendor/google/apiclient/src/Collection.php on line 30

Deprecated: Return type of Google\Collection::valid() should either be compatible with Iterator::valid(): bool, or the #[\ReturnTypeWillChange] attribute should be used to temporarily suppress the notice in /var/www/html/sanralsmme/vendor/google/apiclient/src/Collection.php on line 43

Deprecated: Return type of Google\Collection::rewind() should either be compatible with Iterator::rewind(): void, or the #[\ReturnTypeWillChange] attribute should be used to temporarily suppress the notice in /var/www/html/sanralsmme/vendor/google/apiclient/src/Collection.php on line 14

Deprecated: Return type of Google\Collection::count() should either be compatible with Countable::count(): int, or the #[\ReturnTypeWillChange] attribute should be used to temporarily suppress the notice in /var/www/html/sanralsmme/vendor/google/apiclient/src/Collection.php on line 49
Symfony Profiler

src/Controller/HomeController.php line 123

Open in your IDE?
  1. <?php
  2. namespace App\Controller;
  3. use App\Entity\Entrants;
  4. use App\Entity\MailingList;
  5. use App\Entity\Regions;
  6. use App\Entity\Tenders;
  7. use App\Entity\Categories;
  8. use App\Entity\Content;
  9. use App\Form\Type\MailListFormType;
  10. use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
  11. use Symfony\Component\Mailer\MailerInterface;
  12. use Symfony\Component\Mime\Email;
  13. use Symfony\Component\Routing\Annotation\Route;
  14. use Symfony\Component\HttpFoundation\Request;
  15. class HomeController extends AbstractController {
  16.     /**
  17.      * @Route("/", name="homepage")
  18.      */
  19.     public function indexAction(\Symfony\Component\HttpFoundation\Request $request){
  20.         $repo_regions $this->getDoctrine()->getRepository(Regions::class)->findAll();
  21.         $repo_content $this->getDoctrine()->getRepository(Content::class)->findOneBy(['page' => 'home-page']);
  22.         $repo_tenders $this->getDoctrine()->getRepository(Tenders::class);
  23.         $closing_soon $repo_tenders->getTendersClosing();
  24.         $repo_entrants $this->getDoctrine()->getRepository(Entrants::class)->findAll();
  25.         if(count($repo_regions) > 0){
  26.             $tenders = [];
  27.             foreach($repo_regions as $region){
  28.                 $tenders_repo $repo_tenders->getTenders(1$region->getId());
  29.                 $arr = [];
  30.                 for($i=0;$i<count($tenders_repo);$i++) {
  31.                     $repo_cat $this->getDoctrine()->getRepository(Categories::class)->findOneBy(['id' => $tenders_repo[$i]->getCategory()]);
  32.                     $arr[] = [
  33.                         'id' => $tenders_repo[$i]->getId(),
  34.                         'closingDate' => $tenders_repo[$i]->getClosingDate(),
  35.                         'projectNumber' => $tenders_repo[$i]->getProjectNumber(),
  36.                         'contractDescription' => $tenders_repo[$i]->getContractDescription(),
  37.                         'category' => $repo_cat->getCategory(),
  38.                         'region' => $region->getRegion(),
  39.                         'thumbnail' => $region->getThumbnail(),
  40.                         ];
  41.                 }
  42.                 $tenders[]['region'] = [
  43.                     'regionId' => $region->getId(),
  44.                     'regionName' => $region->getRegion(),
  45.                     'thumb' => $region->getThumbnail(),
  46.                     'data' => $arr
  47.                 ];
  48.             }
  49.         }
  50.         return $this->render('frontend/index.html.twig',
  51.             [
  52.                 'copy' => $repo_content->getCopy(),
  53.                 'regions' => $tenders,
  54.                 'page' => 'home',
  55.                 'closing_soon' => $closing_soon,
  56.                 'entrants' => $repo_entrants,
  57.                 'subscribed' => 0
  58.             ]);
  59.     }
  60.     /**
  61.      * @Route("/subscribe/thank-you", name="subscribe_page")
  62.      */
  63.     public function getSubscribeForm(MailerInterface $mailerRequest $request)
  64.     {
  65.         $repo_regions $this->getDoctrine()->getRepository(Regions::class)->findAll();
  66.         $repo_content $this->getDoctrine()->getRepository(Content::class)->findOneBy(['page' => 'home-page']);
  67.         $repo_tenders $this->getDoctrine()->getRepository(Tenders::class);
  68.         $closing_soon $repo_tenders->getTendersClosing();
  69.         $repo_entrants $this->getDoctrine()->getRepository(Entrants::class)->findAll();
  70.         if(count($repo_regions) > 0){
  71.             $tenders = [];
  72.             foreach($repo_regions as $region){
  73.                 $tenders_repo $repo_tenders->getTenders(1$region->getId());
  74.                 $arr = [];
  75.                 for($i=0;$i<count($tenders_repo);$i++) {
  76.                     $repo_cat $this->getDoctrine()->getRepository(Categories::class)->findOneBy(['id' => $tenders_repo[$i]->getCategory()]);
  77.                     $arr[] = [
  78.                         'id' => $tenders_repo[$i]->getId(),
  79.                         'closingDate' => $tenders_repo[$i]->getClosingDate(),
  80.                         'projectNumber' => $tenders_repo[$i]->getProjectNumber(),
  81.                         'contractDescription' => $tenders_repo[$i]->getContractDescription(),
  82.                         'category' => $repo_cat->getCategory(),
  83.                         'region' => $region->getRegion(),
  84.                         'thumbnail' => $region->getThumbnail(),
  85.                     ];
  86.                 }
  87.                 $tenders[]['region'] = [
  88.                     'regionId' => $region->getId(),
  89.                     'regionName' => $region->getRegion(),
  90.                     'thumb' => $region->getThumbnail(),
  91.                     'data' => $arr
  92.                 ];
  93.             }
  94.         }
  95.         $form $this->createSubscribeForm();
  96.         $now = new \DateTime();
  97.         $form->handleRequest($request);
  98.         if ($form->isSubmitted() && $form->isValid()) {
  99.             // data is an array with "name", "email", and "message" keys
  100.             $data $form->getData();
  101.             $mailing_lists = new MailingList();
  102.             $mailing_lists->setRegion($data->getRegion());
  103.             $mailing_lists->setCompanyName($data->getCompanyName());
  104.             $mailing_lists->setFullName($data->getFullName());
  105.             $mailing_lists->setEmail($data->getEmail());
  106.             $mailing_lists->setMobile($data->getMobile());
  107.             $mailing_lists->setDesignation($data->getDesignation());
  108.             $mailing_lists->setIsSubscribed(1);
  109.             $mailing_lists->setModified($now->format('Y-m-d H:i:s'));
  110.             $mailing_lists->setCreated($now->format('Y-m-d'));
  111.             $em $this->getDoctrine()->getManager();
  112.             $em->persist($mailing_lists);
  113.             $em->flush();
  114.             // Send Email
  115.             $body '<table style="padding: 8px; border-collapse: collapse; border: none; font-family: arial">';
  116.             $body .= '<tr><td colspan="2"><img src="https://huguenottunnel.nerdw.com/images/sanral-preferred-logo_cmyk.png"></td></tr>';
  117.             $body .= '<tr><td colspan="2">&nbsp;</td></tr>';
  118.             $body .= '<tr><td colspan="2">Thank you for submitting your details.</td></tr>';
  119.             $body .= '<tr><td colspan="2">&nbsp;</td></tr>';
  120.             $body .= '    <td><b>Contact Name</b></td>';
  121.             $body .= '    <td>'$data->getFullName() .'</td>';
  122.             $body .= '</tr>';
  123.             $body .= '<tr>';
  124.             $body .= '    <td><b>Email</b></td>';
  125.             $body .= '    <td>'$data->getEmail() .'</td>';
  126.             $body .= '</tr>';
  127.             if(!empty($data->getMobile())) {
  128.                 $body .= '<tr>';
  129.                 $body .= '    <td><b>Telephone</b></td>';
  130.                 $body .= '    <td>' $data->getMobile() . '</td>';
  131.                 $body .= '</tr>';
  132.             }
  133.             $body .= '<tr>';
  134.             $body .= '    <td><b>Company Name</b></td>';
  135.             $body .= '    <td>'$data->getCompanyName() .'</td>';
  136.             $body .= '</tr>';
  137.             $body .= '<tr>';
  138.             $body .= '<tr>';
  139.             $body .= '    <td><b>Designation</b></td>';
  140.             $body .= '    <td>'$data->getDesignation() .'</td>';
  141.             $body .= '</tr>';
  142.             $body .= '<tr>';
  143.             if(!empty($data->getRegion())) {
  144.                 $body .= '<tr>';
  145.                 $body .= '    <td><b>Province</b></td>';
  146.                 $body .= '    <td>' $data->getRegion() . '</td>';
  147.                 $body .= '</tr>';
  148.             }
  149.             $body .= '</table>';
  150.             $email = (new Email())
  151.                 ->from($data->getEmail())
  152.                 ->addTo('SANRAL <karsten@nerdw.com>')
  153.                 ->subject('New Subscription')
  154.                 ->html($body);
  155.             $mailer->send($email);
  156.             return $this->render('frontend/index.html.twig',
  157.                 [
  158.                     'copy' => $repo_content->getCopy(),
  159.                     'form' => $form->createView(),
  160.                     'regions' => $tenders,
  161.                     'page' => 'home',
  162.                     'closing_soon' => $closing_soon,
  163.                     'entrants' => $repo_entrants,
  164.                     'subscribed' => 1
  165.                 ]);
  166.         }
  167.         return $this->render('frontend/mailing_list_form.html.twig',
  168.             [
  169.                 'copy' => $repo_content->getCopy(),
  170.                 'form' => $form->createView(),
  171.                 'modified' => $now->format('Y-m-d')
  172.             ]
  173.         );
  174.     }
  175.     protected function createSubscribeForm()
  176.     {
  177.         $mailing_list = new MailingList();
  178.         return $this->createForm(MailListFormType::class,
  179.             $mailing_list,
  180.             [
  181.                 'method' => 'POST',
  182.                 'action' => $this->generateUrl('subscribe_page')
  183.             ]
  184.         );
  185.     }
  186. }