44 lines
1.2 KiB
PHP
44 lines
1.2 KiB
PHP
<?php
|
|
declare(strict_types=1);
|
|
|
|
namespace App\Repository\Blog;
|
|
|
|
use App\Entity\Blog\Tag;
|
|
use Doctrine\Bundle\DoctrineBundle\Repository\ServiceEntityRepository;
|
|
use Doctrine\Persistence\ManagerRegistry;
|
|
|
|
/**
|
|
* @extends ServiceEntityRepository<Tag>
|
|
*
|
|
* @method Tag|null find($id, $lockMode = null, $lockVersion = null)
|
|
* @method Tag|null findOneBy(array $criteria, array $orderBy = null)
|
|
* @method Tag[] findAll()
|
|
* @method Tag[] findBy(array $criteria, array $orderBy = null, $limit = null, $offset = null)
|
|
*/
|
|
class TagRepository extends ServiceEntityRepository
|
|
{
|
|
public function __construct(ManagerRegistry $registry)
|
|
{
|
|
parent::__construct($registry, Tag::class);
|
|
}
|
|
|
|
public function save(Tag $entity, bool $flush = false): void
|
|
{
|
|
$this->getEntityManager()->persist($entity);
|
|
|
|
if ($flush) {
|
|
$this->getEntityManager()->flush();
|
|
}
|
|
}
|
|
|
|
public function findOneByLowerText(string $text): ?Tag
|
|
{
|
|
$qb = $this->createQueryBuilder('t');
|
|
return $qb
|
|
->where('LOWER(t.text) = :text')
|
|
->setParameter('text', \mb_strtolower($text))
|
|
->getQuery()->getOneOrNullResult()
|
|
;
|
|
}
|
|
}
|