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
<?php
namespace App\Controller ;
use App\Entity\Documents ;
use App\Entity\TenderSubmissions ;
use App\Entity\Tenders ;
use App\Entity\Regions ;
use App\Entity\Categories ;
use App\Entity\TenderRecipient ;
use App\Form\Type\TenderSubmissionFormType ;
use Symfony\Bundle\FrameworkBundle\Controller\AbstractController ;
use Symfony\Component\Form\Extension\Core\Type\EmailType ;
use Symfony\Component\Form\Extension\Core\Type\HiddenType ;
use Symfony\Component\Form\Extension\Core\Type\SubmitType ;
use Symfony\Component\Form\Extension\Core\Type\TextType ;
use Symfony\Component\HttpFoundation\BinaryFileResponse ;
use Symfony\Component\HttpFoundation\Request ;
use Symfony\Component\HttpFoundation\Response ;
use Symfony\Component\HttpFoundation\ResponseHeaderBag ;
use Symfony\Component\Mailer\MailerInterface ;
use Symfony\Component\Mime\Email ;
use Symfony\Component\Routing\Annotation\Route ;
use buildClient ;
class TendersController extends AbstractController {
/**
* @Route("/tender/{id}", name="tenders_page")
*/
public function getTenders ( Request $request ){
$tenders = $this -> getDoctrine ()-> getRepository ( Tenders ::class)-> findBy ([ 'id' => $request -> get ( 'id' )]);
$region = $this -> getDoctrine ()-> getRepository ( Regions ::class)-> findBy ([ 'id' => $tenders [ 0 ]-> getRegion ()]);
$category = $this -> getDoctrine ()-> getRepository ( Categories ::class)-> findBy ([ 'id' => $tenders [ 0 ]-> getCategory ()]);
$documents = count ( $this -> getDoctrine ()-> getRepository ( Documents ::class)-> findBy ([ 'tender' => $request -> get ( 'id' )]));
$tender_recipient = $this -> getDoctrine ()-> getRepository ( TenderRecipient ::class)-> findBy ([ 'id' => $request -> get ( 'id' )]);
return $this -> render ( 'frontend/tenders.html.twig' ,
[
'tender' => $tenders [ 0 ],
'region' => $region [ 0 ],
'category' => $category [ 0 ],
'documents' => $documents
]
);
}
/**
* @Route("/tender-recipient-search/{status}/{status_id}",name="tender_recipient_search")
*/
public function getAwardedTenders ( Request $request )
{
$repo_tenders = $this -> getDoctrine ()-> getRepository ( Tenders ::class);
$tenders_repo = $repo_tenders -> getTendersByStatus ( $request -> get ( 'status_id' ));
$tenders = [];
$search_criteria = '' ;
if( count ( $tenders_repo ) > 0 ){
for ( $i = 0 ; $i < count ( $tenders_repo ); $i ++) {
$region = $this -> getDoctrine ()-> getRepository ( Regions ::class)-> findBy ([ 'id' => $tenders_repo [ $i ]-> getRegion ()]);
$category = $this -> getDoctrine ()-> getRepository ( Categories ::class)-> findBy ([ 'id' => $tenders_repo [ $i ]-> getCategory ()]);
$tenders [] = [
'id' => $tenders_repo [ $i ]-> getId (),
'closingDate' => $tenders_repo [ $i ]-> getClosingDate (),
'closingTime' => $tenders_repo [ $i ]-> getClosingTime (),
'projectNumber' => $tenders_repo [ $i ]-> getProjectNumber (),
'contractDescription' => $tenders_repo [ $i ]-> getContractDescription (),
'region' => $region [ 0 ]-> getRegion (),
'thumbnail' => $region [ 0 ]-> getThumbnail (),
'category' => $category [ 0 ]-> getCategory (),
'created' => $tenders_repo [ $i ]-> getCreated (),
'status' => $request -> get ( 'status' ),
];
}
}
return $this -> render ( 'frontend/tender-recipient-search.html.twig' ,
[
'tenders' => $tenders ,
'search_criteria' => $request -> get ( 'status' ),
'tender' => [],
'region' => $request -> get ( 'status' ),
]);
}
/**
* @Route("/tender-recipient/{id}",name="tender_recipients")
*/
public function getTenderRecipients ( Request $request )
{
$tenders = $this -> getDoctrine ()-> getRepository ( Tenders ::class)-> findBy ([ 'id' => $request -> get ( 'id' )]);
$region = $this -> getDoctrine ()-> getRepository ( Regions ::class)-> findBy ([ 'id' => $tenders [ 0 ]-> getRegion ()]);
$category = $this -> getDoctrine ()-> getRepository ( Categories ::class)-> findBy ([ 'id' => $tenders [ 0 ]-> getCategory ()]);
$documents = count ( $this -> getDoctrine ()-> getRepository ( Documents ::class)-> findBy ([ 'tender' => $request -> get ( 'id' )]));
$tender_recipients = $this -> getDoctrine ()-> getRepository ( TenderRecipient ::class)-> getTenderRecipient ([ $request -> get ( 'id' )]);
return $this -> render ( 'frontend/tender_recipients.html.twig' ,[
'tender' => $tenders [ 0 ],
'region' => $region [ 0 ],
'category' => $category [ 0 ],
'documents' => $documents ,
'tender_recipient' => $tender_recipients
]);
}
/**
* @Route("/tender/thank-you/{id}/{submission_id}", name="tender_thank_you_page")
*/
public function getTenderThankYou ( Request $request ){
$download = $this -> getDoctrine ()-> getRepository ( TenderSubmissions ::class)-> findBy ([ 'id' => $request -> get ( 'submission_id' )]);
$tenders = $this -> getDoctrine ()-> getRepository ( Tenders ::class)-> findBy ([ 'id' => $request -> get ( 'id' )]);
$region = $this -> getDoctrine ()-> getRepository ( Regions ::class)-> findBy ([ 'id' => $tenders [ 0 ]-> getRegion ()]);
$category = $this -> getDoctrine ()-> getRepository ( Categories ::class)-> findBy ([ 'id' => $tenders [ 0 ]-> getCategory ()]);
$documents = count ( $this -> getDoctrine ()-> getRepository ( Documents ::class)-> findBy ([ 'tender' => $request -> get ( 'id' )]));
return $this -> render ( 'tenders_download_thank_you.html.twig' ,
[
'tender' => $tenders [ 0 ],
'region' => $region [ 0 ],
'category' => $category [ 0 ],
'documents' => $download [ 0 ]-> getZip ()
]
);
}
/**
* @Route("/download-form/{id}", name="download_form_page")
*/
public function getDownloadForm ( MailerInterface $mailer , Request $request )
{
$tender = $this -> getDoctrine ()-> getRepository ( Tenders ::class)-> findBy ([ 'id' => $request -> get ( 'id' )]);
$tenders = $this -> getDoctrine ()-> getRepository ( Tenders ::class)-> findBy ([ 'id' => $request -> get ( 'id' )]);
$region = $this -> getDoctrine ()-> getRepository ( Regions ::class)-> findBy ([ 'id' => $tenders [ 0 ]-> getRegion ()]);
$category = $this -> getDoctrine ()-> getRepository ( Categories ::class)-> findBy ([ 'id' => $tenders [ 0 ]-> getCategory ()]);
$documents = count ( $this -> getDoctrine ()-> getRepository ( Documents ::class)-> findBy ([ 'tender' => $request -> get ( 'id' )]));
$form = $this -> createDownloadForm ( $request -> get ( 'id' ));
$form -> handleRequest ( $request );
if ( $form -> isSubmitted () && $form -> isValid ()) {
// data is an array with "name", "email", and "message" keys
$data = $form -> getData ();
// Create zip file with docs
$zip = $this -> createDocuments ( $tender [ 0 ]-> getId ());
$tender_submission = new TenderSubmissions ();
$tender_submission -> setTenderId ( $data -> getTenderId ());
$tender_submission -> setProvince ( $data -> getProvince ());
$tender_submission -> setCompanyName ( $data -> getCompanyName ());
$tender_submission -> setContactName ( $data -> getContactName ());
$tender_submission -> setEmail ( $data -> getEmail ());
$tender_submission -> setTelephone ( $data -> getTelephone ());
$tender_submission -> setZip ( $zip );
$tender_submission -> setCreated ( $data -> getCreated ());
$em = $this -> getDoctrine ()-> getManager ();
$em -> persist ( $tender_submission );
$em -> flush ();
// Send Email
$body = '<table style="padding: 8px; border-collapse: collapse; border: none; font-family: arial">' ;
$body .= '<tr><td colspan="2"><img src="https://huguenottunnel.nerdw.com/images/sanral-preferred-logo_cmyk.png"></td></tr>' ;
$body .= '<tr><td colspan="2"> </td></tr>' ;
$body .= '<tr><td colspan="2">Thank you for submitting your details.</td></tr>' ;
$body .= '<tr><td colspan="2"> </td></tr>' ;
if(!empty( $data -> getProvince ())) {
$body .= '<tr>' ;
$body .= ' <td><b>Province</b></td>' ;
$body .= ' <td>' . $data -> getProvince () . '</td>' ;
$body .= '</tr>' ;
}
$body .= '<tr>' ;
$body .= ' <td><b>Company Name</b></td>' ;
$body .= ' <td>' . $data -> getCompanyName () . '</td>' ;
$body .= '</tr>' ;
$body .= '<tr>' ;
$body .= ' <td><b>Contact Name</b></td>' ;
$body .= ' <td>' . $data -> getContactName () . '</td>' ;
$body .= '</tr>' ;
$body .= '<tr>' ;
$body .= ' <td><b>Email</b></td>' ;
$body .= ' <td>' . $data -> getEmail () . '</td>' ;
$body .= '</tr>' ;
if(!empty( $data -> getTelephone ())) {
$body .= '<tr>' ;
$body .= ' <td><b>Telephone</b></td>' ;
$body .= ' <td>' . $data -> getTelephone () . '</td>' ;
$body .= '</tr>' ;
}
$body .= '<tr>' ;
$body .= ' <td colspan="2"> </td>' ;
$body .= '</tr>' ;
$body .= '<tr>' ;
$body .= ' <td colspan="2">Your files are ready to <a href="' . $zip . '" style="text-decoration: underline">Download</a></td>' ;
$body .= '</tr>' ;
$body .= '</table>' ;
$email = (new Email ())
-> from ( $data -> getEmail ())
-> addTo ( 'SANRAL <karsten@nerdw.com>' )
-> subject ( 'Tender Download' )
-> html ( $body );
$mailer -> send ( $email );
return $this -> render ( 'frontend/tenders_download_thank_you.html.twig' ,
[
'tender' => $tender [ 0 ],
'form' => $form -> createView (),
'tender' => $tenders [ 0 ],
'region' => $region [ 0 ],
'category' => $category [ 0 ],
'documents' => basename ( $zip )
]);
}
return $this -> render ( 'frontend/tender_download_form.html.twig' ,
[
'tender' => $tender [ 0 ],
'form' => $form -> createView (),
'created' => date ( 'Y-m-d H:i:s' ),
'message' => 0
]);
}
protected function createDownloadForm ( $id )
{
$tender_submissions = new TenderSubmissions ();
return $this -> createForm ( TenderSubmissionFormType ::class,
$tender_submissions ,
[
'method' => 'POST' ,
'action' => $this -> generateUrl ( 'download_form_page' ,
[
'id' => $id
]
),
]
);
}
/**
* @Route("/tender-search/{status}/{status_id}", name="tender_search_page")
*/
public function getTenderSearch ( Request $request )
{
$repo_tenders = $this -> getDoctrine ()-> getRepository ( Tenders ::class);
$tenders_repo = $repo_tenders -> getTendersByStatus ( $request -> get ( 'status_id' ));
$tenders = [];
$search_criteria = '' ;
if( count ( $tenders_repo ) > 0 ){
for ( $i = 0 ; $i < count ( $tenders_repo ); $i ++) {
$region = $this -> getDoctrine ()-> getRepository ( Regions ::class)-> findBy ([ 'id' => $tenders_repo [ $i ]-> getRegion ()]);
$category = $this -> getDoctrine ()-> getRepository ( Categories ::class)-> findBy ([ 'id' => $tenders_repo [ $i ]-> getCategory ()]);
$tenders [] = [
'id' => $tenders_repo [ $i ]-> getId (),
'closingDate' => $tenders_repo [ $i ]-> getClosingDate (),
'closingTime' => $tenders_repo [ $i ]-> getClosingTime (),
'projectNumber' => $tenders_repo [ $i ]-> getProjectNumber (),
'contractDescription' => $tenders_repo [ $i ]-> getContractDescription (),
'region' => $region [ 0 ]-> getRegion (),
'thumbnail' => $region [ 0 ]-> getThumbnail (),
'category' => $category [ 0 ]-> getCategory (),
'created' => $tenders_repo [ $i ]-> getCreated (),
'status' => $request -> get ( 'status' ),
];
}
}
return $this -> render ( 'frontend/tender-search.html.twig' ,
[
'tenders' => $tenders ,
'search_criteria' => $request -> get ( 'status' ),
'tender' => [],
'region' => $request -> get ( 'status' ),
]);
}
/**
* @Route("/tender-region/{region}/{region_id}", name="tender_region_page")
*/
public function getTenderRegion ( Request $request )
{
$repo_tenders = $this -> getDoctrine ()-> getRepository ( Tenders ::class);
$tenders_repo = $repo_tenders -> getTendersByRegion ( $request -> get ( 'region_id' ));
$tenders = [];
for( $i = 0 ; $i < count ( $tenders_repo ); $i ++) {
$region = $this -> getDoctrine ()-> getRepository ( Regions ::class)-> findBy ([ 'id' => $request -> get ( 'region_id' )]);
$category = $this -> getDoctrine ()-> getRepository ( Categories ::class)-> findBy ([ 'id' => $tenders_repo [ $i ]-> getCategory ()]);
$tenders [] = [
'id' => $tenders_repo [ $i ]-> getId (),
'closingTime' => $tenders_repo [ $i ]-> getClosingTime (),
'closingDate' => $tenders_repo [ $i ]-> getClosingDate (),
'projectNumber' => $tenders_repo [ $i ]-> getProjectNumber (),
'contractDescription' => $tenders_repo [ $i ]-> getContractDescription (),
'region' => $region [ 0 ]-> getRegion (),
'thumbnail' => $region [ 0 ]-> getThumbnail (),
'category' => $category [ 0 ]-> getCategory (),
'created' => $tenders_repo [ $i ]-> getCreated (),
'status' => $request -> get ( 'status' ),
];
}
$form = $this -> getSearchForm ();
if( count ( $tenders ) == 0 ){
$tenders = [
'status' => $request -> get ( 'status' ),
];
return $this -> render ( 'frontend/tender-search.html.twig' ,
[
'tender' => $tenders ,
'tenders' => [],
'form' => $form ,
]);
}
return $this -> render ( 'frontend/tender-search.html.twig' ,
[
'tenders' => $tenders ,
'tender' => [],
'form' => $form ,
'region' => $request -> get ( 'region' )
]);
}
/**
* @Route("/tender-search-results", name="tender_search_results_page")
* methods={"GET","POST"}
*/
public function getTenderSearchResults ( Request $request )
{
$repo_tenders = $this -> getDoctrine ()-> getRepository ( Tenders ::class);
$tenders = $repo_tenders -> getTenderSearchResults ( $request -> get ( 'region' ), $request -> get ( 'category' ), $request -> get ( 'status' ));
$search_criteria = '' ;
if( count ( $tenders ) == 0 ) {
if (!empty( $request -> get ( 'region' ))) {
$repo_region = $this -> getDoctrine ()-> getRepository ( Regions ::class)-> find ( $request -> get ( 'region' ));
$search_criteria .= $repo_region -> getRegion () . ' -> ' ;
}
if (!empty( $request -> get ( 'category' ))) {
$repo_category = $this -> getDoctrine ()-> getRepository ( Categories ::class)-> find ( $request -> get ( 'category' ));
$search_criteria .= $repo_category -> getCategory () . ' -> ' ;
}
if (!empty( $request -> get ( 'status' ))) {
if( $request -> get ( 'status' ) == 1 ){
$status = 'Advertised' ;
}
if( $request -> get ( 'status' ) == 2 ){
$status = 'Awarded' ;
}
if( $request -> get ( 'status' ) == 3 ){
$status = 'Cancelled' ;
}
if( $request -> get ( 'status' ) == 4 ){
$status = 'Closed' ;
}
if( $request -> get ( 'status' ) == 5 ){
$status = 'Archived' ;
}
$search_criteria .= $status . ' -> ' ;
}
$search_criteria = trim ( $search_criteria , ' -> ' );
}
return $this -> render ( 'frontend/tender-search.html.twig' ,
[
'tenders' => $tenders ,
'search_criteria' => $search_criteria ,
'tender' => [],
'region' => $search_criteria
]);
}
public function getSearchForm ()
{
$repo_cat = $this -> getDoctrine ()-> getRepository ( Categories ::class)-> findAll ();
$repo_region = $this -> getDoctrine ()-> getRepository ( Regions ::class)-> findAll ();
return $this -> render ( 'frontend/search.html.twig' ,
[
'categories' => $repo_cat ,
'regions' => $repo_region
]);
}
private function createDocuments ( $tender_id )
{
$repo = $this -> getDoctrine ()-> getRepository ( Documents ::class)-> findBy ([ 'tender' => $tender_id ]);
if( count ( $repo ) > 0 ) {
$zip = new \ZipArchive ();
$file_path = __DIR__ . '/../../public/documents/tenders/' ;
$file = $repo [ 0 ]-> getDocument () . '-' . date ( 'Y-m-d-H-i-s' ) . '.zip' ;
if ( $zip -> open ( $file_path . $file , \ZipArchive :: CREATE ) === TRUE ) {
for ( $i = 0 ; $i < count ( $repo ); $i ++) {
$zip -> addFile ( $file_path . $repo [ $i ]-> getDocument (), $repo [ $i ]-> getDocument ());
}
$zip -> close ();
} else {
die( 'An error occurred' );
}
return 'https://sanralsmme.nerdw.com/documents/tenders/' . $file ;
}
}
private function downloadDocuments ( $tender_id )
{
$repo = $this -> getDoctrine ()-> getRepository ( Documents ::class)-> findBy ([ 'tender' => $tender_id ]);
if( count ( $repo ) > 0 ) {
$zip = new \ZipArchive ();
$file_path = __DIR__ . '/../../public/documents/tenders/' ;
$file = $repo [ 0 ]-> getDocument () . '-' . date ( 'Y-m-d-H-i-s' ) . '.zip' ;
if ( $zip -> open ( $file_path . $file , \ZipArchive :: CREATE ) === TRUE ) {
for ( $i = 0 ; $i < count ( $repo ); $i ++) {
$zip -> addFile ( $file_path . $repo [ $i ]-> getDocument (), $repo [ $i ]-> getDocument ());
}
$zip -> close ();
} else {
die( 'An error occurred' );
}
$response = new BinaryFileResponse ( $file_path . $file );
$response -> setContentDisposition ( ResponseHeaderBag :: DISPOSITION_ATTACHMENT , $file );
return [ $response , 'https://sanralsmme.nerdw.com/documents/tenders/' . $file ];
}
}
}