74 lines
1.8 KiB
PHP
74 lines
1.8 KiB
PHP
<?php
|
|
|
|
namespace App\Repository;
|
|
|
|
use App\Entity\Projects;
|
|
use Doctrine\Bundle\DoctrineBundle\Repository\ServiceEntityRepository;
|
|
use Doctrine\ORM\NonUniqueResultException;
|
|
use Doctrine\Persistence\ManagerRegistry;
|
|
|
|
/**
|
|
* @method Projects|null find($id, $lockMode = null, $lockVersion = null)
|
|
* @method Projects|null findOneBy(array $criteria, array $orderBy = null)
|
|
* @method Projects[] findAll()
|
|
* @method Projects[] findBy(array $criteria, array $orderBy = null, $limit = null, $offset = null)
|
|
*/
|
|
class ProjectsRepository extends ServiceEntityRepository
|
|
{
|
|
public function __construct(ManagerRegistry $registry)
|
|
{
|
|
parent::__construct(registry: $registry, entityClass: Projects::class);
|
|
}
|
|
|
|
/**
|
|
*/
|
|
public function add(Projects $entity, bool $flush = true): void
|
|
{
|
|
$this->_em->persist($entity);
|
|
if ($flush) {
|
|
$this->_em->flush();
|
|
}
|
|
}
|
|
|
|
/**
|
|
*/
|
|
public function remove(Projects $entity, bool $flush = true): void
|
|
{
|
|
$this->_em->remove($entity);
|
|
if ($flush) {
|
|
$this->_em->flush();
|
|
}
|
|
}
|
|
|
|
// /**
|
|
// * @return Projects[] Returns an array of Projects objects
|
|
// */
|
|
/*
|
|
public function findByExampleField($value)
|
|
{
|
|
return $this->createQueryBuilder('p')
|
|
->andWhere('p.exampleField = :val')
|
|
->setParameter('val', $value)
|
|
->orderBy('p.id', 'ASC')
|
|
->setMaxResults(10)
|
|
->getQuery()
|
|
->getResult()
|
|
;
|
|
}
|
|
*/
|
|
|
|
public function findOneByName($value): ?Projects
|
|
{
|
|
|
|
try {
|
|
return $this->createQueryBuilder(alias: 'q')
|
|
->andWhere('q.name = :val')
|
|
->setParameter(key: 'val', value: $value)
|
|
->getQuery()
|
|
->getOneOrNullResult();
|
|
} catch(NonUniqueResultException $e) {
|
|
dd($e->getMessage());
|
|
}
|
|
}
|
|
}
|