84 lines
2.4 KiB
PHP
84 lines
2.4 KiB
PHP
<?php
|
|
|
|
namespace App\Repository;
|
|
|
|
use App\Entity\Ticket;
|
|
use Doctrine\Bundle\DoctrineBundle\Repository\ServiceEntityRepository;
|
|
use Doctrine\ORM\Query;
|
|
use Doctrine\Persistence\ManagerRegistry;
|
|
use Doctrine\ORM\EntityRepository;
|
|
|
|
/**
|
|
* @extends ServiceEntityRepository<Ticket>
|
|
*
|
|
* @method Ticket|null find($id, $lockMode = null, $lockVersion = null)
|
|
* @method Ticket|null findOneBy(array $criteria, array $orderBy = null)
|
|
* @method Ticket[] findAll()
|
|
* @method Ticket[] findBy(array $criteria, array $orderBy = null, $limit = null, $offset = null)
|
|
*/
|
|
class TicketRepository extends EntityRepository
|
|
{
|
|
|
|
public function save(Ticket $entity, bool $flush = false): void
|
|
{
|
|
$this->getEntityManager()->persist($entity);
|
|
|
|
if ($flush) {
|
|
$this->getEntityManager()->flush();
|
|
}
|
|
}
|
|
|
|
public function remove(Ticket $entity, bool $flush = false): void
|
|
{
|
|
$this->getEntityManager()->remove($entity);
|
|
|
|
if ($flush) {
|
|
$this->getEntityManager()->flush();
|
|
}
|
|
}
|
|
/**
|
|
* Returns Query of tickets matching the provided string.
|
|
*/
|
|
public function getByKeyword(string $keywordString) : Query
|
|
{
|
|
$keywords = explode(" ", $keywordString);
|
|
$qb = $this->getEntityManager()->createQueryBuilder('t')
|
|
->select('t')
|
|
->from('App\\Entity\\Ticket', 't');
|
|
foreach ($keywords as $i => $keyword)
|
|
{
|
|
$qb->andwhere('t.description LIKE :keyword'.$i)
|
|
->orwhere('t.summary LIKE :keyword'.$i)
|
|
->orwhere('t.id LIKE :keyword'.$i)
|
|
->setParameter('keyword'.$i, '%'.$keyword.'%');
|
|
}
|
|
return $qb
|
|
->orderBy('t.id','DESC')
|
|
->getQuery();
|
|
}
|
|
// /**
|
|
// * @return Ticket[] Returns an array of Ticket objects
|
|
// */
|
|
// public function findByExampleField($value): array
|
|
// {
|
|
// return $this->createQueryBuilder('t')
|
|
// ->andWhere('t.exampleField = :val')
|
|
// ->setParameter('val', $value)
|
|
// ->orderBy('t.id', 'ASC')
|
|
// ->setMaxResults(10)
|
|
// ->getQuery()
|
|
// ->getResult()
|
|
// ;
|
|
// }
|
|
|
|
// public function findOneBySomeField($value): ?Ticket
|
|
// {
|
|
// return $this->createQueryBuilder('t')
|
|
// ->andWhere('t.exampleField = :val')
|
|
// ->setParameter('val', $value)
|
|
// ->getQuery()
|
|
// ->getOneOrNullResult()
|
|
// ;
|
|
// }
|
|
}
|