<?php
namespace App\Repository;
use App\Entity\Societe;
use App\Entity\TextLoi;
use Doctrine\Persistence\ManagerRegistry;
use Doctrine\Bundle\DoctrineBundle\Repository\ServiceEntityRepository;
/**
* @method TextLoi|null find($id, $lockMode = null, $lockVersion = null)
* @method TextLoi|null findOneBy(array $criteria, array $orderBy = null)
* @method TextLoi[] findAll()
* @method TextLoi[] findBy(array $criteria, array $orderBy = null, $limit = null, $offset = null)
*/
class TextLoiRepository extends ServiceEntityRepository
{
public function __construct(ManagerRegistry $registry)
{
parent::__construct($registry, TextLoi::class);
}
/**
* @method integer countTextLoi
*/
public function countTextLoi()
{
$entityManager = $this->getEntityManager();
$query = $entityManager->createQuery(
'SELECT count(t)
FROM App\Entity\TextLoi t'
);
// returns an array of Product objects
return $query->getSingleScalarResult();
}
/*************************************************************************/
// /**
// * @return TextLoi[] Returns an array of TextLoi objects
// */
//
/*
public function test($soc)
{
return $this->createQueryBuilder('t')
->andWhere('t.exampleField = :val')
->setParameter('val', $value)
->orderBy('t.id', 'ASC')
->setMaxResults(10)
->getQuery()
->getResult()
;
}*/
/**
* @method array countText
*/
public function listeTextLois(Societe $societe): array
{
//$entityManager = $this->getEntityManager();
$conn = $this->getEntityManager()->getConnection();
$sql = "SELECT text_loi.id as id1,sl.id as id2
FROM text_loi
LEFT OUTER JOIN (SELECT *
FROM text_societe
WHERE text_societe.societe_id=:s) sl
ON text_loi.id = sl.text_loi_id
";
$stmt = $conn->prepare($sql);
$stmt->execute(['s' => $societe->getId()]);
//dd($stmt->fetchAllAssociative());
// returns an array of arrays (i.e. a raw data set)
return $stmt->fetchAllAssociative();
}
/*
public function findOneBySomeField($value): ?TextLoi
{
return $this->createQueryBuilder('t')
->andWhere('t.exampleField = :val')
->setParameter('val', $value)
->getQuery()
->getOneOrNullResult()
;
}
*/
}