src/Repository/BlockRepository.php line 88
<?php
namespace App\Repository;
use App\Entity\Block;
use Doctrine\Bundle\DoctrineBundle\Repository\ServiceEntityRepository;
use Doctrine\Persistence\ManagerRegistry;
/**
* @extends ServiceEntityRepository<Block>
*
* @method Block|null find($id, $lockMode = null, $lockVersion = null)
* @method Block|null findOneBy(array $criteria, array $orderBy = null)
* @method Block[] findAll()
* @method Block[] findBy(array $criteria, array $orderBy = null, $limit = null, $offset = null)
*/
class BlockRepository extends ServiceEntityRepository
{
public function __construct(ManagerRegistry $registry)
{
parent::__construct($registry, Block::class);
}
public function save(Block $entity, bool $flush = false): void
{
$this->getEntityManager()->persist($entity);
if ($flush) {
$this->getEntityManager()->flush();
}
}
public function remove(Block $entity, bool $flush = false): void
{
$this->getEntityManager()->remove($entity);
if ($flush) {
$this->getEntityManager()->flush();
}
}
public function getBlockageByFilters( $resourceType, $localisation, $startDate, $endDate,$resource = null, $typeBlockage = null)
{
// $groups = explode(',',$resourceType);
// array_push($groups,...explode(',',$localisation));
$conn = $this->getEntityManager()->getConnection();
if ($resource == null) {
$reqResource = " r.group_id in ($resourceType) and r.group_id in ($localisation)";
}else {
$reqResource = " r.id = $resource";
}
$reqTypeBlocage = "";
if ($typeBlockage != null)
$reqTypeBlocage = " and block_type_id = $typeBlockage ";
$stmt = $conn->prepare("select b.*,r.name as resourceName from block b left join resource r on
b.resource_id = r.id
where $reqResource and
date(start_datetime) >= '$startDate' and date(start_datetime) <= '$endDate' and
date(end_datetime) >= '$startDate' and (date(end_datetime) <= '$endDate' or end_datetime is null) $reqTypeBlocage group by b.id");
$result = $stmt->executeQuery()->fetchAllAssociative();
return $result;
}
public function getBlockageByType($resource = null, $resourceType, $localisation, $startDate, $endDate,$lang)
{
// $groups = explode(',',$resourceType);
// array_push($groups,...explode(',',$localisation));
$conn = $this->getEntityManager()->getConnection();
if ($resource == null) {
$reqResource = " r.group_id in ($resourceType) and r.group_id in ($localisation)";
}else {
$reqResource = " r.id = $resource";
}
$stmt = $conn->prepare("select t.value as item, count(*) as value from block b left join resource r on
b.resource_id = r.id left join block_type bt on b.block_type_id = bt.id left join translator t on bt.id = t.path_id
where t.lang = '$lang' and t.path = 'block_type.label' and $reqResource and
date(start_datetime) >= '$startDate' and date(start_datetime) <= '$endDate' and
date(end_datetime) >= '$startDate' and (date(end_datetime) <= '$endDate' or end_datetime is null) group by bt.id;");
$result = $stmt->executeQuery()->fetchAllAssociative();
return empty($result[0]['item']) ? []:$result;
}
public function getBlockagesGroppedByResource($resource = null, $resourceType, $localisation, $startDate, $endDate, $typeResource, $typeBlockage = 0)
{
// $groups = explode(',',$resourceType);
// array_push($groups,...explode(',',$localisation));
$conn = $this->getEntityManager()->getConnection();
if ($resource == null) {
$reqResource = " and r.group_id in ($resourceType) and r.group_id in ($localisation);";
}else {
$reqResource = " and r.id = $resource";
}
$stmt = $conn->prepare("select ga.group_name as item ,count(*) as value from block b join resource r on
b.resource_id = r.id join group_ancestor_details ga on r.group_parent_id = ga.ancestor_group_id
where ga.group_type_name = '$typeResource' $reqResource and
date(start_datetime) >= '$startDate' and date(start_datetime) <= '$endDate' and
date(end_datetime) >= '$startDate' and (date(end_datetime) <= '$endDate' or end_datetime is null) and block_type_id = $typeBlockage");
$result = $stmt->executeQuery()->fetchAllAssociative();
return empty($result[0]['item']) ? []:$result;
}
public function getBlockByDates($resource = null, $resourceType, $localisation, $startDate, $endDate, $typeBlockage = null)
{
$conn = $this->getEntityManager()->getConnection();
$stmt = $conn->prepare("call getBlockByDates('$startDate','$endDate','$localisation','$resourceType',". ($resource != '' ? $resource : "null") .",". ($typeBlockage ?? "null") .")");
return $stmt->executeQuery()->fetchAllAssociative();
}
// /**
// * @return Block[] Returns an array of Block objects
// */
// public function findByExampleField($value): array
// {
// return $this->createQueryBuilder('b')
// ->andWhere('b.exampleField = :val')
// ->setParameter('val', $value)
// ->orderBy('b.id', 'ASC')
// ->setMaxResults(10)
// ->getQuery()
// ->getResult()
// ;
// }
// public function findOneBySomeField($value): ?Block
// {
// return $this->createQueryBuilder('b')
// ->andWhere('b.exampleField = :val')
// ->setParameter('val', $value)
// ->getQuery()
// ->getOneOrNullResult()
// ;
// }
}