73 lines
1.9 KiB
PHP
73 lines
1.9 KiB
PHP
<?php
|
|
|
|
namespace App\Controller;
|
|
|
|
use App\Entity\Warranty;
|
|
|
|
use Doctrine\ORM\Query;
|
|
use Symfony\Component\HttpFoundation\Request;
|
|
use Symfony\Component\HttpFoundation\Response;
|
|
use Symfony\Component\Validator\Validator\ValidatorInterface;
|
|
use Symfony\Bundle\FrameworkBundle\Controller\Controller;
|
|
|
|
use Catalyst\MenuBundle\Annotation\Menu;
|
|
|
|
class WarrantySearchController extends Controller
|
|
{
|
|
/**
|
|
* @Menu(selected="warranty_search")
|
|
*/
|
|
public function index()
|
|
{
|
|
$this->denyaccessUnlessGranted('warranty.search', null, 'No access.');
|
|
$params["mode"] = "form";
|
|
|
|
// response
|
|
return $this->render('warranty-search/form.html.twig', $params);
|
|
}
|
|
|
|
/**
|
|
* @Menu(selected="warranty_search")
|
|
*/
|
|
public function search(Request $req)
|
|
{
|
|
$this->denyAccessUnlessGranted('warranty.search', null, 'No access.');
|
|
|
|
$serial = $req->query->get('battery_serial');
|
|
$name = $req->query->get('owner_name');
|
|
$plate_num = $req->query->get('plate_num');
|
|
|
|
// find the warranty
|
|
$qb = $this->getDoctrine()
|
|
->getRepository(Warranty::class)
|
|
->createQueryBuilder('w');
|
|
|
|
$query = $qb;
|
|
if (!empty($serial))
|
|
{
|
|
$qb->where('w.serial = :serial')
|
|
->setParameter('serial', $serial);
|
|
}
|
|
|
|
if (!empty($plate_num))
|
|
{
|
|
$qb->andWhere('w.plate_number = :plate_num')
|
|
->setParameter('plate_num', $plate_num);
|
|
}
|
|
|
|
$results = $query->getQuery()->getResult();
|
|
|
|
$res = [];
|
|
foreach ($results as $result) {
|
|
$res[] = $result;
|
|
}
|
|
$params['data'] = $res;
|
|
$params['battery_serial'] = $serial;
|
|
$params['owner_name'] = $name;
|
|
$params['plate_num'] = $plate_num;
|
|
$params['mode'] = "results";
|
|
|
|
// response
|
|
return $this->render('warranty-search/form.html.twig', $params);
|
|
}
|
|
}
|