WIP: Implement document handling

This commit is contained in:
Björn Fromme
2023-10-12 10:41:31 +02:00
parent 3e7ca7e166
commit 46915955b0
18 changed files with 529 additions and 49 deletions
+39 -34
View File
@@ -3,7 +3,9 @@
namespace App\Repository;
use App\Entity\Upload;
use App\Repository\Traits\QueryHelperTrait;
use Doctrine\Bundle\DoctrineBundle\Repository\ServiceEntityRepository;
use Doctrine\ORM\Query;
use Doctrine\Persistence\ManagerRegistry;
/**
@@ -16,51 +18,54 @@ use Doctrine\Persistence\ManagerRegistry;
*/
class UploadRepository extends ServiceEntityRepository
{
use QueryHelperTrait;
public function __construct(ManagerRegistry $registry)
{
parent::__construct($registry, Upload::class);
}
public function save(Upload $entity, bool $flush = false): void
public function getDocumentListQuery(): Query
{
$this->getEntityManager()->persist($entity);
$qb = $this->createQueryBuilder('upload');
if ($flush) {
$this->getEntityManager()->flush();
}
return $qb
->where($qb->expr()->eq('upload.type', ':type'))
->setParameter('type', Upload::TYPE_DOCUMENT)
->getQuery()
;
}
public function remove(Upload $entity, bool $flush = false): void
public function getAutocompletionData(string $search): array
{
$this->getEntityManager()->remove($entity);
$qb = $this->createQueryBuilder('upload');
if ($flush) {
$this->getEntityManager()->flush();
$documents = $qb
->where($qb->expr()->orX(
$qb->expr()->like('upload.originalFilename', ':filename'),
$qb->expr()->like('upload.displayName', ':filename')
))
->setParameter('filename', '%'.$this->escapeLikeWildcards($search).'%')
->orderBy('upload.originalFilename', 'ASC')
->getQuery()
->getResult()
;
$data = [
[
'value' => '',
'text' => '...',
],
];
foreach ($documents as $document) {
/** @var Upload $document */
$data[] = [
'value' => $document->getId(),
'text' => $document->getOriginalFilename(),
];
}
return $data;
}
// /**
// * @return Upload[] Returns an array of Upload objects
// */
// public function findByExampleField($value): array
// {
// return $this->createQueryBuilder('u')
// ->andWhere('u.exampleField = :val')
// ->setParameter('val', $value)
// ->orderBy('u.id', 'ASC')
// ->setMaxResults(10)
// ->getQuery()
// ->getResult()
// ;
// }
// public function findOneBySomeField($value): ?Upload
// {
// return $this->createQueryBuilder('u')
// ->andWhere('u.exampleField = :val')
// ->setParameter('val', $value)
// ->getQuery()
// ->getOneOrNullResult()
// ;
// }
}