Files
assets
bin
config
migrations
public
src
Controller
Entity
EntityListener
Form
Repository
.gitignore
BlogRepository.php
CommentRepository.php
ProjectsRepository.php
QuotesRepository.php
ResetPasswordRequestRepository.php
SectionRepository.php
UserRepository.php
Security
Kernel.php
templates
translations
.env
.gitignore
README.md
bootstrap.js
composer.json
composer.lock
controllers.json
docker-compose.override.yml
docker-compose.yml
package.json
symfony.lock
webpack.config.js
yarn.lock
Spookie/src/Repository/ProjectsRepository.php
2022-04-11 16:05:12 +02:00

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());
}
}
}