Entities & Repos

This commit is contained in:
2024-05-13 21:08:21 -04:00
parent 21f014d08d
commit 658b021962
15 changed files with 1552 additions and 0 deletions
+56
View File
@@ -0,0 +1,56 @@
<?php
namespace App\Repository;
use App\Entity\Note;
use App\Entity\User;
use Doctrine\Bundle\DoctrineBundle\Repository\ServiceEntityRepository;
use Doctrine\Persistence\ManagerRegistry;
/**
* @extends ServiceEntityRepository<Note>
*/
class NoteRepository extends ServiceEntityRepository
{
public function __construct(ManagerRegistry $registry)
{
parent::__construct($registry, Note::class);
}
public function getLast4Notes(?User $user): array
{
$ret = $this->createQueryBuilder('n')
->where('n.user = :user')
->setParameter('user', (string) $user->getId())
->orderBy('n.date', 'DESC')
->setMaxResults(4)
->getQuery()
->getResult();
return $ret;
}
// /**
// * @return Note[] Returns an array of Note objects
// */
// public function findByExampleField($value): array
// {
// return $this->createQueryBuilder('n')
// ->andWhere('n.exampleField = :val')
// ->setParameter('val', $value)
// ->orderBy('n.id', 'ASC')
// ->setMaxResults(10)
// ->getQuery()
// ->getResult()
// ;
// }
// public function findOneBySomeField($value): ?Note
// {
// return $this->createQueryBuilder('n')
// ->andWhere('n.exampleField = :val')
// ->setParameter('val', $value)
// ->getQuery()
// ->getOneOrNullResult()
// ;
// }
}