/
vladislavts
/
gcppmsp
Обзор
Документация
Войти
/
vladislavts
/
gcppmsp
Код
Запросы
0
Задачи
Вики
Пакеты
0
Релизы
0
Аналитика
Безопасность
prod
src/Repository/ArticleRepository.php
90 строк
2 KB
Vladislav
kajdk
14 ноя 2022, 22:42
14 ноя 2022, 22:42
6ff8f12
Код
Авторство
О чём код?
<?php namespace App\Repository; use App\Entity\Article; use Doctrine\Bundle\DoctrineBundle\Repository\ServiceEntityRepository; use Doctrine\Persistence\ManagerRegistry; /** * @extends ServiceEntityRepository<Article> * * @method Article|null find($id, $lockMode = null, $lockVersion = null) * @method Article|null findOneBy(array $criteria, array $orderBy = null) * @method Article[] findAll() * @method Article[] findBy(array $criteria, array $orderBy = null, $limit = null, $offset = null) */ class ArticleRepository extends ServiceEntityRepository { public function __construct(ManagerRegistry $registry) { parent::__construct($registry, Article::class); } public function add(Article $entity, bool $flush = false): void { $this->getEntityManager()->persist($entity); if ($flush) { $this->getEntityManager()->flush(); } } public function remove(Article $entity, bool $flush = false): void { $this->getEntityManager()->remove($entity); if ($flush) { $this->getEntityManager()->flush(); } } public function findAllWithSearch(?string $search, ?string $type = null, bool $withShowDeleted = false) { $qb = $this->createQueryBuilder('article'); if ($search){ $qb ->andWhere('article.title LIKE :search') ->setParameter('search', "%$search%") ; } if ($type){ $qb ->andWhere('article.aplication LIKE :type') ->setParameter('type', "%$type%") ; } if ($withShowDeleted){ $this->getEntityManager()->getFilters()->disable('softdeleteable'); } return $qb->getQuery()->getResult();; } // /** // * @return Article[] Returns an array of Article objects // */ // public function findByExampleField($value): array // { // return $this->createQueryBuilder('a') // ->andWhere('a.exampleField = :val') // ->setParameter('val', $value) // ->orderBy('a.id', 'ASC') // ->setMaxResults(10) // ->getQuery() // ->getResult() // ; // } // public function findOneBySomeField($value): ?Article // { // return $this->createQueryBuilder('a') // ->andWhere('a.exampleField = :val') // ->setParameter('val', $value) // ->getQuery() // ->getOneOrNullResult() // ; // } }