<?php
namespace App\Repository;
use App\Entity\SchulungWerbung;
use Doctrine\Bundle\DoctrineBundle\Repository\ServiceEntityRepository;
use Doctrine\Persistence\ManagerRegistry;
use Exception;
/**
* @method SchulungWerbung|null find($id, $lockMode = null, $lockVersion = null)
* @method SchulungWerbung|null findOneBy(array $criteria, array $orderBy = null)
* @method SchulungWerbung[] findAll()
* @method SchulungWerbung[] findBy(array $criteria, array $orderBy = null, $limit = null, $offset = null)
*/
class SchulungWerbungRepository extends ServiceEntityRepository
{
public function __construct(ManagerRegistry $registry)
{
parent::__construct($registry, SchulungWerbung::class);
}
/**
* @throws Exception
*/
public function findWerbungAktiv($limit = -1)
{
$queryBuilder = $this->createQueryBuilder('sw')
->innerJoin('sw.schulung', 's')
->andWhere('s.freigabe = 1')
->andWhere('sw.aktiv = 1')
->andWhere('sw.von <= :now')
->andWhere('sw.bis >= :now')
->setParameter('now',new \DateTime('now', new \DateTimeZone('Europe/Berlin')))
->orderBy('RAND()');
if($limit != -1) {
$queryBuilder->setMaxResults($limit);
}
return $queryBuilder->getQuery()->getResult();
}
}