<?php
namespace Noahtech\Sistemas\InterjamaBundle\Handler;
use Noahtech\Sistemas\InterjamaBundle\Entity\McTurno;
use Noahtech\Sistemas\InterjamaBundle\Utils\Constants;
use Noahtech\Sistemas\InterjamaBundle\Utils\EmailsMessages;
use Noahtech\Sistemas\InterjamaBundle\Utils\Encrypt;
use DateInterval;
use DateTime;
use Doctrine\ORM\EntityManagerInterface;
use Symfony\Component\DependencyInjection\ContainerInterface;
use Symfony\Component\HttpKernel\Exception\HttpException;
use Symfony\Component\HttpFoundation\Request;
class McTurnoHandler extends BaseHandler {
public function __construct(ContainerInterface $container, EntityManagerInterface $entityManager) {
$this->container = $container;
$this->entityManager = $entityManager;
$this->repository = $entityManager->getRepository(McTurno::class);
}
public function search($offset, $limit, $sortField, $sortDirection, $searchParam) {
$today = new DateTime();
$searchParam['fecha'] = $today->format('Y-m-d');
$lp = $this->repository->search($offset, $limit, $sortField, $sortDirection, $searchParam);
$turnos = $this->toarray($lp->getListado(), 'turno');
$lp->setListado($turnos);
return $lp;
}
public function getTurnoFromRequest(Request $request, $id=null):McTurno {
//Datos del noticia
$observacion = $request->request->get('observacion');
if (is_null($id)) {
$turno = new McTurno();
$turno->setFechaCreacion(new DateTime());
}
$turno->setObservacion($observacion);
$turno->setAtendido(0);
return $turno;
}
public function save(McTurno $turno) {
$turno = $this->repository->save($turno);
$turno = $this->toarray($turno, "turno");
return $turno;
}
public function getTurnosByFecha($request) {
$fecha = $request->request->get('fecha');
$turnos = $this->repository->getTurnosByFecha($fecha);
$turnos = $this->toarray($turnos, "turno");
return $turnos;
}
public function getTurnoById($id) {
return $this->repository->findOneById($id);
}
public function getById($id) {
$turno = $this->repository->findOneById($id);
$turno = $this->toarray($turno, "turno");
return $turno;
}
public function update($id) {
$turno = $this->repository->findOneById($id);
$turno->setAtendido(1);
$turno = $this->repository->save($turno);
$turno = $this->toarray($turno, "turno");
return $turno;
}
}