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/TendersController.php line 263

Open in your IDE?
  1. <?php
  2. namespace App\Controller;
  3. use App\Entity\Documents;
  4. use App\Entity\TenderSubmissions;
  5. use App\Entity\Tenders;
  6. use App\Entity\Regions;
  7. use App\Entity\Categories;
  8. use App\Entity\TenderRecipient;
  9. use App\Form\Type\TenderSubmissionFormType;
  10. use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
  11. use Symfony\Component\Form\Extension\Core\Type\EmailType;
  12. use Symfony\Component\Form\Extension\Core\Type\HiddenType;
  13. use Symfony\Component\Form\Extension\Core\Type\SubmitType;
  14. use Symfony\Component\Form\Extension\Core\Type\TextType;
  15. use Symfony\Component\HttpFoundation\BinaryFileResponse;
  16. use Symfony\Component\HttpFoundation\Request;
  17. use Symfony\Component\HttpFoundation\Response;
  18. use Symfony\Component\HttpFoundation\ResponseHeaderBag;
  19. use Symfony\Component\Mailer\MailerInterface;
  20. use Symfony\Component\Mime\Email;
  21. use Symfony\Component\Routing\Annotation\Route;
  22. use buildClient;
  23. class TendersController extends AbstractController {
  24.     /**
  25.      * @Route("/tender/{id}", name="tenders_page")
  26.      */
  27.     public function getTenders(Request $request){
  28.         $tenders $this->getDoctrine()->getRepository(Tenders::class)->findBy(['id' => $request->get('id')]);
  29.         $region $this->getDoctrine()->getRepository(Regions::class)->findBy(['id' => $tenders[0]->getRegion()]);
  30.         $category $this->getDoctrine()->getRepository(Categories::class)->findBy(['id' => $tenders[0]->getCategory()]);
  31.         $documents count($this->getDoctrine()->getRepository(Documents::class)->findBy(['tender' => $request->get('id')]));
  32.         $tender_recipient $this->getDoctrine()->getRepository(TenderRecipient::class)->findBy(['id' => $request->get('id')]);
  33.         return $this->render('frontend/tenders.html.twig',
  34.             [
  35.                 'tender' => $tenders[0],
  36.                 'region' => $region[0],
  37.                 'category' => $category[0],
  38.                 'documents' => $documents
  39.             ]
  40.         );
  41.     }
  42.     /**
  43.      * @Route("/tender-recipient-search/{status}/{status_id}",name="tender_recipient_search")
  44.      */
  45.     public function getAwardedTenders(Request $request)
  46.     {
  47.         $repo_tenders $this->getDoctrine()->getRepository(Tenders::class);
  48.         $tenders_repo $repo_tenders->getTendersByStatus($request->get('status_id'));
  49.         $tenders = [];
  50.         $search_criteria '';
  51.         if(count($tenders_repo) > 0){
  52.             for ($i 0$i count($tenders_repo); $i++) {
  53.                 $region $this->getDoctrine()->getRepository(Regions::class)->findBy(['id' => $tenders_repo[$i]->getRegion()]);
  54.                 $category $this->getDoctrine()->getRepository(Categories::class)->findBy(['id' => $tenders_repo[$i]->getCategory()]);
  55.                 $tenders[] = [
  56.                     'id' => $tenders_repo[$i]->getId(),
  57.                     'closingDate' => $tenders_repo[$i]->getClosingDate(),
  58.                     'closingTime'=> $tenders_repo[$i]->getClosingTime(),
  59.                     'projectNumber' => $tenders_repo[$i]->getProjectNumber(),
  60.                     'contractDescription' => $tenders_repo[$i]->getContractDescription(),
  61.                     'region' => $region[0]->getRegion(),
  62.                     'thumbnail' => $region[0]->getThumbnail(),
  63.                     'category' => $category[0]->getCategory(),
  64.                     'created' => $tenders_repo[$i]->getCreated(),
  65.                     'status' => $request->get('status'),
  66.                 ];
  67.             }
  68.         }
  69.         return $this->render('frontend/tender-recipient-search.html.twig',
  70.         [
  71.             'tenders' => $tenders,
  72.             'search_criteria' => $request->get('status'),
  73.             'tender' => [],
  74.             'region' => $request->get('status'),
  75.         ]);
  76.     }
  77.     /**
  78.      * @Route("/tender-recipient/{id}",name="tender_recipients")
  79.      */
  80.     public function getTenderRecipients(Request $request)
  81.     {
  82.        
  83.         $tenders $this->getDoctrine()->getRepository(Tenders::class)->findBy(['id' => $request->get('id')]);
  84.         $region $this->getDoctrine()->getRepository(Regions::class)->findBy(['id' => $tenders[0]->getRegion()]);
  85.         $category $this->getDoctrine()->getRepository(Categories::class)->findBy(['id' => $tenders[0]->getCategory()]);
  86.         $documents count($this->getDoctrine()->getRepository(Documents::class)->findBy(['tender' => $request->get('id')]));
  87.         $tender_recipients $this->getDoctrine()->getRepository(TenderRecipient::class)->getTenderRecipient([$request->get('id')]);
  88.         return $this->render('frontend/tender_recipients.html.twig',[
  89.             'tender' => $tenders[0],
  90.             'region' => $region[0],
  91.             'category' => $category[0],
  92.             'documents' => $documents,
  93.             'tender_recipient'=>$tender_recipients
  94.         ]);
  95.     }
  96.     /**
  97.      * @Route("/tender/thank-you/{id}/{submission_id}", name="tender_thank_you_page")
  98.      */
  99.     public function getTenderThankYou(Request $request){
  100.         $download $this->getDoctrine()->getRepository(TenderSubmissions::class)->findBy(['id' => $request->get('submission_id')]);
  101.         $tenders $this->getDoctrine()->getRepository(Tenders::class)->findBy(['id' => $request->get('id')]);
  102.         $region $this->getDoctrine()->getRepository(Regions::class)->findBy(['id' => $tenders[0]->getRegion()]);
  103.         $category $this->getDoctrine()->getRepository(Categories::class)->findBy(['id' => $tenders[0]->getCategory()]);
  104.         $documents count($this->getDoctrine()->getRepository(Documents::class)->findBy(['tender' => $request->get('id')]));
  105.         return $this->render('tenders_download_thank_you.html.twig',
  106.             [
  107.                 'tender' => $tenders[0],
  108.                 'region' => $region[0],
  109.                 'category' => $category[0],
  110.                 'documents' => $download[0]->getZip()
  111.             ]
  112.         );
  113.     }
  114.     /**
  115.      * @Route("/download-form/{id}", name="download_form_page")
  116.      */
  117.     public function getDownloadForm(MailerInterface $mailerRequest $request)
  118.     {
  119.         $tender $this->getDoctrine()->getRepository(Tenders::class)->findBy(['id' => $request->get('id')]);
  120.         $tenders $this->getDoctrine()->getRepository(Tenders::class)->findBy(['id' => $request->get('id')]);
  121.         $region $this->getDoctrine()->getRepository(Regions::class)->findBy(['id' => $tenders[0]->getRegion()]);
  122.         $category $this->getDoctrine()->getRepository(Categories::class)->findBy(['id' => $tenders[0]->getCategory()]);
  123.         $documents count($this->getDoctrine()->getRepository(Documents::class)->findBy(['tender' => $request->get('id')]));
  124.         $form $this->createDownloadForm($request->get('id'));
  125.         $form->handleRequest($request);
  126.         if ($form->isSubmitted() && $form->isValid()) {
  127.             // data is an array with "name", "email", and "message" keys
  128.             $data $form->getData();
  129.             // Create zip file with docs
  130.             $zip $this->createDocuments($tender[0]->getId());
  131.             $tender_submission = new TenderSubmissions();
  132.             $tender_submission->setTenderId($data->getTenderId());
  133.             $tender_submission->setProvince($data->getProvince());
  134.             $tender_submission->setCompanyName($data->getCompanyName());
  135.             $tender_submission->setContactName($data->getContactName());
  136.             $tender_submission->setEmail($data->getEmail());
  137.             $tender_submission->setTelephone($data->getTelephone());
  138.             $tender_submission->setZip($zip);
  139.             $tender_submission->setCreated($data->getCreated());
  140.             $em $this->getDoctrine()->getManager();
  141.             $em->persist($tender_submission);
  142.             $em->flush();
  143.             // Send Email
  144.             $body '<table style="padding: 8px; border-collapse: collapse; border: none; font-family: arial">';
  145.             $body .= '<tr><td colspan="2"><img src="https://huguenottunnel.nerdw.com/images/sanral-preferred-logo_cmyk.png"></td></tr>';
  146.             $body .= '<tr><td colspan="2">&nbsp;</td></tr>';
  147.             $body .= '<tr><td colspan="2">Thank you for submitting your details.</td></tr>';
  148.             $body .= '<tr><td colspan="2">&nbsp;</td></tr>';
  149.             if(!empty($data->getProvince())) {
  150.                 $body .= '<tr>';
  151.                 $body .= '    <td><b>Province</b></td>';
  152.                 $body .= '    <td>' $data->getProvince() . '</td>';
  153.                 $body .= '</tr>';
  154.             }
  155.             $body .= '<tr>';
  156.             $body .= '    <td><b>Company Name</b></td>';
  157.             $body .= '    <td>'$data->getCompanyName() .'</td>';
  158.             $body .= '</tr>';
  159.             $body .= '<tr>';
  160.             $body .= '    <td><b>Contact Name</b></td>';
  161.             $body .= '    <td>'$data->getContactName() .'</td>';
  162.             $body .= '</tr>';
  163.             $body .= '<tr>';
  164.             $body .= '    <td><b>Email</b></td>';
  165.             $body .= '    <td>'$data->getEmail() .'</td>';
  166.             $body .= '</tr>';
  167.             if(!empty($data->getTelephone())) {
  168.                 $body .= '<tr>';
  169.                 $body .= '    <td><b>Telephone</b></td>';
  170.                 $body .= '    <td>' $data->getTelephone() . '</td>';
  171.                 $body .= '</tr>';
  172.             }
  173.             $body .= '<tr>';
  174.             $body .= '    <td colspan="2">&nbsp;</td>';
  175.             $body .= '</tr>';
  176.             $body .= '<tr>';
  177.             $body .= '    <td colspan="2">Your files are ready to <a href="'$zip .'" style="text-decoration: underline">Download</a></td>';
  178.             $body .= '</tr>';
  179.             $body .= '</table>';
  180.             $email = (new Email())
  181.                 ->from($data->getEmail())
  182.                 ->addTo('SANRAL <karsten@nerdw.com>')
  183.                 ->subject('Tender Download')
  184.                 ->html($body);
  185.             $mailer->send($email);
  186.             return $this->render('frontend/tenders_download_thank_you.html.twig',
  187.                 [
  188.                     'tender' => $tender[0],
  189.                     'form' => $form->createView(),
  190.                     'tender' => $tenders[0],
  191.                     'region' => $region[0],
  192.                     'category' => $category[0],
  193.                     'documents' => basename($zip)
  194.                 ]);
  195.         }
  196.         return $this->render('frontend/tender_download_form.html.twig',
  197.             [
  198.                 'tender' => $tender[0],
  199.                 'form' => $form->createView(),
  200.                 'created' => date('Y-m-d H:i:s'),
  201.                 'message' => 0
  202.             ]);
  203.     }
  204.     protected function createDownloadForm($id)
  205.     {
  206.         $tender_submissions = new TenderSubmissions();
  207.         return  $this->createForm(TenderSubmissionFormType::class,
  208.             $tender_submissions,
  209.             [
  210.                 'method' => 'POST',
  211.                 'action' => $this->generateUrl('download_form_page',
  212.                     [
  213.                         'id' => $id
  214.                     ]
  215.                 ),
  216.             ]
  217.         );
  218.     }
  219.     /**
  220.      * @Route("/tender-search/{status}/{status_id}", name="tender_search_page")
  221.      */
  222.     public function getTenderSearch(Request $request)
  223.     {
  224.         $repo_tenders $this->getDoctrine()->getRepository(Tenders::class);
  225.         $tenders_repo $repo_tenders->getTendersByStatus($request->get('status_id'));
  226.         $tenders = [];
  227.         $search_criteria '';
  228.         if(count($tenders_repo) > 0){
  229.             for ($i 0$i count($tenders_repo); $i++) {
  230.                 $region $this->getDoctrine()->getRepository(Regions::class)->findBy(['id' => $tenders_repo[$i]->getRegion()]);
  231.                 $category $this->getDoctrine()->getRepository(Categories::class)->findBy(['id' => $tenders_repo[$i]->getCategory()]);
  232.                 $tenders[] = [
  233.                     'id' => $tenders_repo[$i]->getId(),
  234.                     'closingDate' => $tenders_repo[$i]->getClosingDate(),
  235.                     'closingTime'=> $tenders_repo[$i]->getClosingTime(),
  236.                     'projectNumber' => $tenders_repo[$i]->getProjectNumber(),
  237.                     'contractDescription' => $tenders_repo[$i]->getContractDescription(),
  238.                     'region' => $region[0]->getRegion(),
  239.                     'thumbnail' => $region[0]->getThumbnail(),
  240.                     'category' => $category[0]->getCategory(),
  241.                     'created' => $tenders_repo[$i]->getCreated(),
  242.                     'status' => $request->get('status'),
  243.                 ];
  244.             }
  245.         }
  246.         return $this->render('frontend/tender-search.html.twig',
  247.         [
  248.             'tenders' => $tenders,
  249.             'search_criteria' => $request->get('status'),
  250.             'tender' => [],
  251.             'region' => $request->get('status'),
  252.         ]);
  253.     }
  254.     /**
  255.      * @Route("/tender-region/{region}/{region_id}", name="tender_region_page")
  256.      */
  257.     public function getTenderRegion(Request $request)
  258.     {
  259.         $repo_tenders $this->getDoctrine()->getRepository(Tenders::class);
  260.         $tenders_repo $repo_tenders->getTendersByRegion($request->get('region_id'));
  261.         $tenders = [];
  262.         for($i=0;$i<count($tenders_repo);$i++) {
  263.             $region $this->getDoctrine()->getRepository(Regions::class)->findBy(['id' => $request->get('region_id')]);
  264.             $category $this->getDoctrine()->getRepository(Categories::class)->findBy(['id' => $tenders_repo[$i]->getCategory()]);
  265.             $tenders[] = [
  266.                 'id' => $tenders_repo[$i]->getId(),
  267.                 'closingTime'=>$tenders_repo[$i]->getClosingTime(),
  268.                 'closingDate' => $tenders_repo[$i]->getClosingDate(),
  269.                 'projectNumber' => $tenders_repo[$i]->getProjectNumber(),
  270.                 'contractDescription' => $tenders_repo[$i]->getContractDescription(),
  271.                 'region' => $region[0]->getRegion(),
  272.                 'thumbnail' => $region[0]->getThumbnail(),
  273.                 'category' => $category[0]->getCategory(),
  274.                 'created' => $tenders_repo[$i]->getCreated(),
  275.                 'status' => $request->get('status'),
  276.             ];
  277.         }
  278.         $form $this->getSearchForm();
  279.         if(count($tenders) == 0){
  280.             $tenders = [
  281.                 'status' => $request->get('status'),
  282.             ];
  283.             return $this->render('frontend/tender-search.html.twig',
  284.                 [
  285.                     'tender' => $tenders,
  286.                     'tenders' => [],
  287.                     'form' => $form,
  288.                 ]);
  289.         }
  290.         return $this->render('frontend/tender-search.html.twig',
  291.             [
  292.                 'tenders' => $tenders,
  293.                 'tender' => [],
  294.                 'form' => $form,
  295.                 'region' => $request->get('region')
  296.             ]);
  297.     }
  298.     /**
  299.      * @Route("/tender-search-results", name="tender_search_results_page")
  300.      * methods={"GET","POST"}
  301.      */
  302.     public function getTenderSearchResults(Request $request)
  303.     {
  304.         $repo_tenders $this->getDoctrine()->getRepository(Tenders::class);
  305.         $tenders $repo_tenders->getTenderSearchResults($request->get('region'), $request->get('category'), $request->get('status'));
  306.         $search_criteria '';
  307.         if(count($tenders) == 0) {
  308.             if (!empty($request->get('region'))) {
  309.                 $repo_region $this->getDoctrine()->getRepository(Regions::class)->find($request->get('region'));
  310.                 $search_criteria .= $repo_region->getRegion() . ' -> ';
  311.             }
  312.             if (!empty($request->get('category'))) {
  313.                 $repo_category $this->getDoctrine()->getRepository(Categories::class)->find($request->get('category'));
  314.                 $search_criteria .= $repo_category->getCategory() . ' -> ';
  315.             }
  316.             if (!empty($request->get('status'))) {
  317.                 if($request->get('status') == 1){
  318.                     $status 'Advertised';
  319.                 }
  320.                 if($request->get('status') == 2){
  321.                     $status 'Awarded';
  322.                 }
  323.                 if($request->get('status') == 3){
  324.                     $status 'Cancelled';
  325.                 }
  326.                 if($request->get('status') == 4){
  327.                     $status 'Closed';
  328.                 }
  329.                 if($request->get('status') == 5){
  330.                     $status 'Archived';
  331.                 }
  332.                 $search_criteria .= $status ' -> ';
  333.             }
  334.             $search_criteria trim($search_criteria' -> ');
  335.         }
  336.         return $this->render('frontend/tender-search.html.twig',
  337.             [
  338.                 'tenders' => $tenders,
  339.                 'search_criteria' => $search_criteria,
  340.                 'tender' => [],
  341.                 'region' => $search_criteria
  342.             ]);
  343.     }
  344.  
  345.     public function getSearchForm()
  346.     {
  347.         $repo_cat $this->getDoctrine()->getRepository(Categories::class)->findAll();
  348.         $repo_region $this->getDoctrine()->getRepository(Regions::class)->findAll();
  349.         return $this->render('frontend/search.html.twig',
  350.         [
  351.             'categories' => $repo_cat,
  352.             'regions' => $repo_region
  353.         ]);
  354.     }
  355.     private function createDocuments($tender_id)
  356.     {
  357.         $repo $this->getDoctrine()->getRepository(Documents::class)->findBy(['tender' => $tender_id]);
  358.         if(count($repo) > 0) {
  359.             $zip = new \ZipArchive();
  360.             $file_path __DIR__ '/../../public/documents/tenders/';
  361.             $file $repo[0]->getDocument() . '-' date('Y-m-d-H-i-s') . '.zip';
  362.             if ($zip->open($file_path $file\ZipArchive::CREATE) === TRUE) {
  363.                 for ($i 0$i count($repo); $i++) {
  364.                     $zip->addFile($file_path $repo[$i]->getDocument(), $repo[$i]->getDocument());
  365.                 }
  366.                 $zip->close();
  367.             } else {
  368.                 die('An error occurred');
  369.             }
  370.             return 'https://sanralsmme.nerdw.com/documents/tenders/'.$file;
  371.         }
  372.     }
  373.     private function downloadDocuments($tender_id)
  374.     {
  375.         $repo $this->getDoctrine()->getRepository(Documents::class)->findBy(['tender' => $tender_id]);
  376.         if(count($repo) > 0) {
  377.             $zip = new \ZipArchive();
  378.             $file_path __DIR__ '/../../public/documents/tenders/';
  379.             $file $repo[0]->getDocument() . '-' date('Y-m-d-H-i-s') . '.zip';
  380.             if ($zip->open($file_path $file\ZipArchive::CREATE) === TRUE) {
  381.                 for ($i 0$i count($repo); $i++) {
  382.                     $zip->addFile($file_path $repo[$i]->getDocument(), $repo[$i]->getDocument());
  383.                 }
  384.                 $zip->close();
  385.             } else {
  386.                 die('An error occurred');
  387.             }
  388.             $response = new BinaryFileResponse($file_path $file);
  389.             $response->setContentDisposition(ResponseHeaderBag::DISPOSITION_ATTACHMENT$file);
  390.             return [$response,'https://sanralsmme.nerdw.com/documents/tenders/'.$file];
  391.         }
  392.     }
  393. }