V-Beta-1.0.0
Vision is out of alpha !
This commit is contained in:
0
src/Repository/.gitignore
vendored
Normal file
0
src/Repository/.gitignore
vendored
Normal file
22
src/Repository/AnnounceRepository.php
Normal file
22
src/Repository/AnnounceRepository.php
Normal file
@@ -0,0 +1,22 @@
|
||||
<?php
|
||||
|
||||
namespace App\Repository;
|
||||
|
||||
use App\Entity\Announce;
|
||||
use Doctrine\Persistence\ManagerRegistry;
|
||||
use App\Repository\Tools\DocumentRepositoriesExtension;
|
||||
|
||||
/**
|
||||
* @method Announce|null find($id, $lockMode = null, $lockVersion = null)
|
||||
* @method Announce|null findOneBy(array $criteria, array $orderBy = null)
|
||||
* @method Announce[] findAll()
|
||||
* @method Announce[] findBy(array $criteria, array $orderBy = null, $limit = null, $offset = null)
|
||||
*/
|
||||
class AnnounceRepository extends DocumentRepositoriesExtension
|
||||
{
|
||||
public function __construct(ManagerRegistry $registry)
|
||||
{
|
||||
parent::__construct($registry, Announce::class);
|
||||
$this->fields = ['content']; //with title, list fields we can search in
|
||||
}
|
||||
}
|
||||
22
src/Repository/BraceletRepository.php
Normal file
22
src/Repository/BraceletRepository.php
Normal file
@@ -0,0 +1,22 @@
|
||||
<?php
|
||||
|
||||
namespace App\Repository;
|
||||
|
||||
use App\Entity\Bracelet;
|
||||
use Doctrine\Persistence\ManagerRegistry;
|
||||
use App\Repository\Tools\DocumentRepositoriesExtension;
|
||||
|
||||
/**
|
||||
* @method Bracelet|null find($id, $lockMode = null, $lockVersion = null)
|
||||
* @method Bracelet|null findOneBy(array $criteria, array $orderBy = null)
|
||||
* @method Bracelet[] findAll()
|
||||
* @method Bracelet[] findBy(array $criteria, array $orderBy = null, $limit = null, $offset = null)
|
||||
*/
|
||||
class BraceletRepository extends DocumentRepositoriesExtension
|
||||
{
|
||||
public function __construct(ManagerRegistry $registry)
|
||||
{
|
||||
parent::__construct($registry, Bracelet::class);
|
||||
$this->fields = []; //with title, list fields we can search in
|
||||
}
|
||||
}
|
||||
22
src/Repository/CertificateRepository.php
Normal file
22
src/Repository/CertificateRepository.php
Normal file
@@ -0,0 +1,22 @@
|
||||
<?php
|
||||
|
||||
namespace App\Repository;
|
||||
|
||||
use App\Entity\Certificate;
|
||||
use Doctrine\Persistence\ManagerRegistry;
|
||||
use App\Repository\Tools\DocumentRepositoriesExtension;
|
||||
|
||||
/**
|
||||
* @method Certificate|null find($id, $lockMode = null, $lockVersion = null)
|
||||
* @method Certificate|null findOneBy(array $criteria, array $orderBy = null)
|
||||
* @method Certificate[] findAll()
|
||||
* @method Certificate[] findBy(array $criteria, array $orderBy = null, $limit = null, $offset = null)
|
||||
*/
|
||||
class CertificateRepository extends DocumentRepositoriesExtension
|
||||
{
|
||||
public function __construct(ManagerRegistry $registry)
|
||||
{
|
||||
parent::__construct($registry, Certificate::class);
|
||||
$this->fields = ['content']; //with title, list fields we can search in
|
||||
}
|
||||
}
|
||||
21
src/Repository/CommentRepository.php
Normal file
21
src/Repository/CommentRepository.php
Normal file
@@ -0,0 +1,21 @@
|
||||
<?php
|
||||
|
||||
namespace App\Repository;
|
||||
|
||||
use App\Entity\Comment;
|
||||
use Doctrine\Persistence\ManagerRegistry;
|
||||
use Doctrine\Bundle\DoctrineBundle\Repository\ServiceEntityRepository;
|
||||
|
||||
/**
|
||||
* @method Comment|null find($id, $lockMode = null, $lockVersion = null)
|
||||
* @method Comment|null findOneBy(array $criteria, array $orderBy = null)
|
||||
* @method Comment[] findAll()
|
||||
* @method Comment[] findBy(array $criteria, array $orderBy = null, $limit = null, $offset = null)
|
||||
*/
|
||||
class CommentRepository extends ServiceEntityRepository
|
||||
{
|
||||
public function __construct(ManagerRegistry $registry)
|
||||
{
|
||||
parent::__construct($registry, Comment::class);
|
||||
}
|
||||
}
|
||||
22
src/Repository/ComplaintRepository.php
Normal file
22
src/Repository/ComplaintRepository.php
Normal file
@@ -0,0 +1,22 @@
|
||||
<?php
|
||||
|
||||
namespace App\Repository;
|
||||
|
||||
use App\Entity\Complaint;
|
||||
use Doctrine\Persistence\ManagerRegistry;
|
||||
use App\Repository\Tools\DocumentRepositoriesExtension;
|
||||
|
||||
/**
|
||||
* @method Complaint|null find($id, $lockMode = null, $lockVersion = null)
|
||||
* @method Complaint|null findOneBy(array $criteria, array $orderBy = null)
|
||||
* @method Complaint[] findAll()
|
||||
* @method Complaint[] findBy(array $criteria, array $orderBy = null, $limit = null, $offset = null)
|
||||
*/
|
||||
class ComplaintRepository extends DocumentRepositoriesExtension
|
||||
{
|
||||
public function __construct(ManagerRegistry $registry)
|
||||
{
|
||||
parent::__construct($registry, Complaint::class);
|
||||
$this->fields = ['content', 'versus']; //with title, list fields we can search in
|
||||
}
|
||||
}
|
||||
22
src/Repository/CriminalRepository.php
Normal file
22
src/Repository/CriminalRepository.php
Normal file
@@ -0,0 +1,22 @@
|
||||
<?php
|
||||
|
||||
namespace App\Repository;
|
||||
|
||||
use App\Entity\Criminal;
|
||||
use Doctrine\Persistence\ManagerRegistry;
|
||||
use App\Repository\Tools\DocumentRepositoriesExtension;
|
||||
|
||||
/**
|
||||
* @method Criminal|null find($id, $lockMode = null, $lockVersion = null)
|
||||
* @method Criminal|null findOneBy(array $criteria, array $orderBy = null)
|
||||
* @method Criminal[] findAll()
|
||||
* @method Criminal[] findBy(array $criteria, array $orderBy = null, $limit = null, $offset = null)
|
||||
*/
|
||||
class CriminalRepository extends DocumentRepositoriesExtension
|
||||
{
|
||||
public function __construct(ManagerRegistry $registry)
|
||||
{
|
||||
parent::__construct($registry, Criminal::class);
|
||||
$this->fields = ['article', 'amountMoney', 'amountTime', 'content']; //with title, list fields we can search in
|
||||
}
|
||||
}
|
||||
134
src/Repository/DirectoryRepository.php
Normal file
134
src/Repository/DirectoryRepository.php
Normal file
@@ -0,0 +1,134 @@
|
||||
<?php
|
||||
|
||||
namespace App\Repository;
|
||||
|
||||
use App\Entity\Directory;
|
||||
use Doctrine\ORM\QueryBuilder;
|
||||
use Doctrine\Persistence\ManagerRegistry;
|
||||
use Doctrine\Bundle\DoctrineBundle\Repository\ServiceEntityRepository;
|
||||
|
||||
/**
|
||||
* @method Directory|null find($id, $lockMode = null, $lockVersion = null)
|
||||
* @method Directory|null findOneBy(array $criteria, array $orderBy = null)
|
||||
* @method Directory[] findAll()
|
||||
* @method Directory[] findBy(array $criteria, array $orderBy = null, $limit = null, $offset = null)
|
||||
*/
|
||||
class DirectoryRepository extends ServiceEntityRepository
|
||||
{
|
||||
private array $fields;
|
||||
private QueryBuilder $qb;
|
||||
private ?QueryBuilder $qbsearch = null;
|
||||
|
||||
public function __construct(ManagerRegistry $registry)
|
||||
{
|
||||
parent::__construct($registry, Directory::class);
|
||||
$this->fields = [
|
||||
'gender',
|
||||
'height',
|
||||
'weight',
|
||||
'phone',
|
||||
'address',
|
||||
'firstname',
|
||||
'lastname',
|
||||
'medicalFamilyHistory',
|
||||
'medicalHistory',
|
||||
'medicalAllergies',
|
||||
'medicalBloodGroup',
|
||||
'medicalDrugs',
|
||||
'medicalAlcohol',
|
||||
'medicalTreatment'
|
||||
]; //list fields we can search in
|
||||
}
|
||||
|
||||
/**
|
||||
* Prepare user list (use -> getResult() to get results)
|
||||
*
|
||||
* @return this
|
||||
*/
|
||||
public function list()
|
||||
{
|
||||
$this->qbsearch = null;
|
||||
$this->qb = $this->createQueryBuilder("d");
|
||||
return $this;
|
||||
}
|
||||
|
||||
public function limit(int $limit)
|
||||
{
|
||||
$this->qb->setMaxResults($limit);
|
||||
return $this;
|
||||
}
|
||||
|
||||
public function wanted()
|
||||
{
|
||||
$this->qb->andWhere('d.wanted = 1');
|
||||
return $this;
|
||||
}
|
||||
|
||||
public function dead()
|
||||
{
|
||||
$this->qb->andWhere('d.dead = 1');
|
||||
return $this;
|
||||
}
|
||||
|
||||
public function notDead()
|
||||
{
|
||||
$this->qb->andWhere('d.dead = 0');
|
||||
return $this;
|
||||
}
|
||||
|
||||
public function order(array $order)
|
||||
{
|
||||
foreach ($order as $key => $value) {
|
||||
if ($key === array_key_first($order)) {
|
||||
$this->qb->orderBy('d.' . $key, $value);
|
||||
} else {
|
||||
$this->qb->addorderBy('d.' . $key, $value);
|
||||
}
|
||||
}
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Search a value in directories
|
||||
*
|
||||
* @param string|null $search
|
||||
* @return this
|
||||
*/
|
||||
public function search(?string $search)
|
||||
{
|
||||
if (null === $search) {
|
||||
return $this;
|
||||
}
|
||||
|
||||
if (null === $this->qbsearch) {
|
||||
$this->qbsearch = $this ->createQueryBuilder("s")
|
||||
->where('s.firstname LIKE :searchkey')
|
||||
->orWhere('s.lastname LIKE :searchkey')
|
||||
->orWhere('s.id LIKE :searchkey');
|
||||
|
||||
$searchTime = str_replace('/', '-', $search);
|
||||
if (($timestamp = strtotime($searchTime)) != false) {
|
||||
$this->qbsearch->orWhere('s.birthdate LIKE :searchkeydate')
|
||||
->setParameter('searchkeydate', '%' . date('Y-m-d', $timestamp) . '%');
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
foreach ($this->fields as $key => $value) {
|
||||
$this->qbsearch->orWhere('s.' . $value . ' LIKE :searchkey');
|
||||
}
|
||||
|
||||
$this->qbsearch->setParameter('searchkey', '%' . $search . '%');
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
public function getResult()
|
||||
{
|
||||
if (null !== $this->qbsearch) {
|
||||
$this->qbsearch->andWhere($this->qb->expr()->in('s.id', $this->qb->getDQL()));
|
||||
return $this->qbsearch->getQuery()->getResult();
|
||||
}
|
||||
return $this->qb->getQuery()->getResult();
|
||||
}
|
||||
}
|
||||
21
src/Repository/DocumentRepository.php
Normal file
21
src/Repository/DocumentRepository.php
Normal file
@@ -0,0 +1,21 @@
|
||||
<?php
|
||||
|
||||
namespace App\Repository;
|
||||
|
||||
use App\Entity\Document;
|
||||
use Doctrine\Persistence\ManagerRegistry;
|
||||
use App\Repository\Tools\DocumentRepositoriesExtension;
|
||||
|
||||
/**
|
||||
* @method Document|null find($id, $lockMode = null, $lockVersion = null)
|
||||
* @method Document|null findOneBy(array $criteria, array $orderBy = null)
|
||||
* @method Document[] findAll()
|
||||
* @method Document[] findBy(array $criteria, array $orderBy = null, $limit = null, $offset = null)
|
||||
*/
|
||||
class DocumentRepository extends DocumentRepositoriesExtension
|
||||
{
|
||||
public function __construct(ManagerRegistry $registry)
|
||||
{
|
||||
parent::__construct($registry, Document::class);
|
||||
}
|
||||
}
|
||||
21
src/Repository/FolderRepository.php
Normal file
21
src/Repository/FolderRepository.php
Normal file
@@ -0,0 +1,21 @@
|
||||
<?php
|
||||
|
||||
namespace App\Repository;
|
||||
|
||||
use App\Entity\Folder;
|
||||
use Doctrine\Persistence\ManagerRegistry;
|
||||
use App\Repository\Tools\DocumentRepositoriesExtension;
|
||||
|
||||
/**
|
||||
* @method Folder|null find($id, $lockMode = null, $lockVersion = null)
|
||||
* @method Folder|null findOneBy(array $criteria, array $orderBy = null)
|
||||
* @method Folder[] findAll()
|
||||
* @method Folder[] findBy(array $criteria, array $orderBy = null, $limit = null, $offset = null)
|
||||
*/
|
||||
class FolderRepository extends DocumentRepositoriesExtension
|
||||
{
|
||||
public function __construct(ManagerRegistry $registry)
|
||||
{
|
||||
parent::__construct($registry, Folder::class);
|
||||
}
|
||||
}
|
||||
22
src/Repository/GangRepository.php
Normal file
22
src/Repository/GangRepository.php
Normal file
@@ -0,0 +1,22 @@
|
||||
<?php
|
||||
|
||||
namespace App\Repository;
|
||||
|
||||
use App\Entity\Gang;
|
||||
use Doctrine\Persistence\ManagerRegistry;
|
||||
use App\Repository\Tools\DocumentRepositoriesExtension;
|
||||
|
||||
/**
|
||||
* @method Gang|null find($id, $lockMode = null, $lockVersion = null)
|
||||
* @method Gang|null findOneBy(array $criteria, array $orderBy = null)
|
||||
* @method Gang[] findAll()
|
||||
* @method Gang[] findBy(array $criteria, array $orderBy = null, $limit = null, $offset = null)
|
||||
*/
|
||||
class GangRepository extends DocumentRepositoriesExtension
|
||||
{
|
||||
public function __construct(ManagerRegistry $registry)
|
||||
{
|
||||
parent::__construct($registry, Gang::class);
|
||||
$this->fields = ['content']; //with title, list fields we can search in
|
||||
}
|
||||
}
|
||||
91
src/Repository/GroupRepository.php
Normal file
91
src/Repository/GroupRepository.php
Normal file
@@ -0,0 +1,91 @@
|
||||
<?php
|
||||
|
||||
namespace App\Repository;
|
||||
|
||||
use App\Entity\Group;
|
||||
use Doctrine\ORM\QueryBuilder;
|
||||
use Doctrine\Persistence\ManagerRegistry;
|
||||
use Doctrine\Bundle\DoctrineBundle\Repository\ServiceEntityRepository;
|
||||
|
||||
/**
|
||||
* @method Group|null find($id, $lockMode = null, $lockVersion = null)
|
||||
* @method Group|null findOneBy(array $criteria, array $orderBy = null)
|
||||
* @method Group[] findAll()
|
||||
* @method Group[] findBy(array $criteria, array $orderBy = null, $limit = null, $offset = null)
|
||||
*/
|
||||
class GroupRepository extends ServiceEntityRepository
|
||||
{
|
||||
private QueryBuilder $qb;
|
||||
private array $order = ['name' => 'ASC', 'shortName' => 'ASC', 'createdAt' => 'ASC'];
|
||||
|
||||
public function __construct(ManagerRegistry $registry)
|
||||
{
|
||||
parent::__construct($registry, Group::class);
|
||||
}
|
||||
|
||||
/**
|
||||
* Equivalent of FindAll()
|
||||
* *
|
||||
* @return QueryBuilder
|
||||
*/
|
||||
public function getQueryBuilder()
|
||||
{
|
||||
return $this->createQueryBuilder("g");
|
||||
;
|
||||
}
|
||||
|
||||
public function getAll()
|
||||
{
|
||||
$this->qb = $this->getQueryBuilder();
|
||||
return $this;
|
||||
}
|
||||
|
||||
public function order(array $order)
|
||||
{
|
||||
$this->order = $order;
|
||||
return $this;
|
||||
}
|
||||
|
||||
public function limit(int $limit)
|
||||
{
|
||||
$this->qb->setMaxResults($limit);
|
||||
return $this;
|
||||
}
|
||||
|
||||
public function search(?string $search)
|
||||
{
|
||||
if (null === $search) {
|
||||
return $this;
|
||||
}
|
||||
|
||||
$this->qb ->where('g.name LIKE :searchkey')
|
||||
->orWhere('g.shortName LIKE :searchkey')
|
||||
->setParameter('searchkey', '%' . $search . '%')
|
||||
;
|
||||
|
||||
|
||||
|
||||
$this->qb->setParameter('searchkey', '%' . $search . '%');
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
public function getResult()
|
||||
{
|
||||
if (false === is_null($this->order)) {
|
||||
foreach ($this->order as $key => $value) {
|
||||
if (strtoupper($value) != 'ASC' && strtoupper($value) != 'DESC') {
|
||||
$key = $value;
|
||||
$value = 'ASC';
|
||||
}
|
||||
if ($key === array_key_first($this->order)) {
|
||||
$this->qb->orderBy('g.' . $key, $value);
|
||||
} else {
|
||||
$this->qb->addorderBy('g.' . $key, $value);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return $this->qb->getQuery()->getResult();
|
||||
}
|
||||
}
|
||||
22
src/Repository/InfringementRepository.php
Normal file
22
src/Repository/InfringementRepository.php
Normal file
@@ -0,0 +1,22 @@
|
||||
<?php
|
||||
|
||||
namespace App\Repository;
|
||||
|
||||
use App\Entity\Infringement;
|
||||
use Doctrine\Persistence\ManagerRegistry;
|
||||
use App\Repository\Tools\DocumentRepositoriesExtension;
|
||||
|
||||
/**
|
||||
* @method Infringement|null find($id, $lockMode = null, $lockVersion = null)
|
||||
* @method Infringement|null findOneBy(array $criteria, array $orderBy = null)
|
||||
* @method Infringement[] findAll()
|
||||
* @method Infringement[] findBy(array $criteria, array $orderBy = null, $limit = null, $offset = null)
|
||||
*/
|
||||
class InfringementRepository extends DocumentRepositoriesExtension
|
||||
{
|
||||
public function __construct(ManagerRegistry $registry)
|
||||
{
|
||||
parent::__construct($registry, Infringement::class);
|
||||
$this->fields = ['content']; //with title, list fields we can search in
|
||||
}
|
||||
}
|
||||
22
src/Repository/JailRepository.php
Normal file
22
src/Repository/JailRepository.php
Normal file
@@ -0,0 +1,22 @@
|
||||
<?php
|
||||
|
||||
namespace App\Repository;
|
||||
|
||||
use App\Entity\Jail;
|
||||
use Doctrine\Persistence\ManagerRegistry;
|
||||
use App\Repository\Tools\DocumentRepositoriesExtension;
|
||||
|
||||
/**
|
||||
* @method Jail|null find($id, $lockMode = null, $lockVersion = null)
|
||||
* @method Jail|null findOneBy(array $criteria, array $orderBy = null)
|
||||
* @method Jail[] findAll()
|
||||
* @method Jail[] findBy(array $criteria, array $orderBy = null, $limit = null, $offset = null)
|
||||
*/
|
||||
class JailRepository extends DocumentRepositoriesExtension
|
||||
{
|
||||
public function __construct(ManagerRegistry $registry)
|
||||
{
|
||||
parent::__construct($registry, Jail::class);
|
||||
$this->fields = ['content']; //with title, list fields we can search in
|
||||
}
|
||||
}
|
||||
22
src/Repository/LicenceWithdrawalRepository.php
Normal file
22
src/Repository/LicenceWithdrawalRepository.php
Normal file
@@ -0,0 +1,22 @@
|
||||
<?php
|
||||
|
||||
namespace App\Repository;
|
||||
|
||||
use App\Entity\LicenceWithdrawal;
|
||||
use Doctrine\Persistence\ManagerRegistry;
|
||||
use App\Repository\Tools\DocumentRepositoriesExtension;
|
||||
|
||||
/**
|
||||
* @method LicenceWithdrawal|null find($id, $lockMode = null, $lockVersion = null)
|
||||
* @method LicenceWithdrawal|null findOneBy(array $criteria, array $orderBy = null)
|
||||
* @method LicenceWithdrawal[] findAll()
|
||||
* @method LicenceWithdrawal[] findBy(array $criteria, array $orderBy = null, $limit = null, $offset = null)
|
||||
*/
|
||||
class LicenceWithdrawalRepository extends DocumentRepositoriesExtension
|
||||
{
|
||||
public function __construct(ManagerRegistry $registry)
|
||||
{
|
||||
parent::__construct($registry, LicenceWithdrawal::class);
|
||||
$this->fields = ['type']; //with title, list fields we can search in
|
||||
}
|
||||
}
|
||||
22
src/Repository/MedicalRepository.php
Normal file
22
src/Repository/MedicalRepository.php
Normal file
@@ -0,0 +1,22 @@
|
||||
<?php
|
||||
|
||||
namespace App\Repository;
|
||||
|
||||
use App\Entity\Medical;
|
||||
use Doctrine\Persistence\ManagerRegistry;
|
||||
use App\Repository\Tools\DocumentRepositoriesExtension;
|
||||
|
||||
/**
|
||||
* @method Medical|null find($id, $lockMode = null, $lockVersion = null)
|
||||
* @method Medical|null findOneBy(array $criteria, array $orderBy = null)
|
||||
* @method Medical[] findAll()
|
||||
* @method Medical[] findBy(array $criteria, array $orderBy = null, $limit = null, $offset = null)
|
||||
*/
|
||||
class MedicalRepository extends DocumentRepositoriesExtension
|
||||
{
|
||||
public function __construct(ManagerRegistry $registry)
|
||||
{
|
||||
parent::__construct($registry, Medical::class);
|
||||
$this->fields = ['content']; //with title, list fields we can search in
|
||||
}
|
||||
}
|
||||
86
src/Repository/NotificationRepository.php
Normal file
86
src/Repository/NotificationRepository.php
Normal file
@@ -0,0 +1,86 @@
|
||||
<?php
|
||||
|
||||
namespace App\Repository;
|
||||
|
||||
use App\Entity\User;
|
||||
use App\Entity\Notification;
|
||||
use Doctrine\ORM\QueryBuilder;
|
||||
use Doctrine\Persistence\ManagerRegistry;
|
||||
use Doctrine\Bundle\DoctrineBundle\Repository\ServiceEntityRepository;
|
||||
|
||||
/**
|
||||
* @method Notification|null find($id, $lockMode = null, $lockVersion = null)
|
||||
* @method Notification|null findOneBy(array $criteria, array $orderBy = null)
|
||||
* @method Notification[] findAll()
|
||||
* @method Notification[] findBy(array $criteria, array $orderBy = null, $limit = null, $offset = null)
|
||||
*/
|
||||
class NotificationRepository extends ServiceEntityRepository
|
||||
{
|
||||
private array $fields = [];
|
||||
private QueryBuilder $qb;
|
||||
private ?User $user = null;
|
||||
|
||||
public function __construct(ManagerRegistry $registry)
|
||||
{
|
||||
parent::__construct($registry, Notification::class);
|
||||
}
|
||||
|
||||
/**
|
||||
* Equivalent of FindAll()
|
||||
* *
|
||||
* @return QueryBuilder
|
||||
*/
|
||||
private function getQueryBuilder()
|
||||
{
|
||||
return $this->createQueryBuilder("n");
|
||||
;
|
||||
}
|
||||
|
||||
public function listForUser(User $User)
|
||||
{
|
||||
$this->user = $User;
|
||||
$this->qb = $this ->getQueryBuilder()
|
||||
->where('n.receiver = :userid')
|
||||
->setParameter('userid', $User->getId());
|
||||
return $this;
|
||||
}
|
||||
|
||||
public function limit(int $limit)
|
||||
{
|
||||
$this->qb->setMaxResults($limit);
|
||||
return $this;
|
||||
}
|
||||
|
||||
public function readed(bool $readed = true)
|
||||
{
|
||||
if (true === $readed) {
|
||||
$this->qb->andWhere('n.readed = 1');
|
||||
} else {
|
||||
$this->qb->andWhere('n.readed = 0');
|
||||
}
|
||||
return $this;
|
||||
}
|
||||
|
||||
public function order(array $order)
|
||||
{
|
||||
foreach ($order as $key => $value) {
|
||||
if ($key === array_key_first($order)) {
|
||||
$this->qb->orderBy('n.' . $key, $value);
|
||||
} else {
|
||||
$this->qb->addorderBy('n.' . $key, $value);
|
||||
}
|
||||
}
|
||||
return $this;
|
||||
}
|
||||
|
||||
public function getResult()
|
||||
{
|
||||
return $this->qb->getQuery()->getResult();
|
||||
}
|
||||
|
||||
public function getCount()
|
||||
{
|
||||
$this->qb->select('count(n.id)');
|
||||
return $this->qb->getQuery()->getSingleScalarResult();
|
||||
}
|
||||
}
|
||||
21
src/Repository/RankRepository.php
Normal file
21
src/Repository/RankRepository.php
Normal file
@@ -0,0 +1,21 @@
|
||||
<?php
|
||||
|
||||
namespace App\Repository;
|
||||
|
||||
use App\Entity\Rank;
|
||||
use Doctrine\Bundle\DoctrineBundle\Repository\ServiceEntityRepository;
|
||||
use Doctrine\Persistence\ManagerRegistry;
|
||||
|
||||
/**
|
||||
* @method Rank|null find($id, $lockMode = null, $lockVersion = null)
|
||||
* @method Rank|null findOneBy(array $criteria, array $orderBy = null)
|
||||
* @method Rank[] findAll()
|
||||
* @method Rank[] findBy(array $criteria, array $orderBy = null, $limit = null, $offset = null)
|
||||
*/
|
||||
class RankRepository extends ServiceEntityRepository
|
||||
{
|
||||
public function __construct(ManagerRegistry $registry)
|
||||
{
|
||||
parent::__construct($registry, Rank::class);
|
||||
}
|
||||
}
|
||||
22
src/Repository/ReportRepository.php
Normal file
22
src/Repository/ReportRepository.php
Normal file
@@ -0,0 +1,22 @@
|
||||
<?php
|
||||
|
||||
namespace App\Repository;
|
||||
|
||||
use App\Entity\Report;
|
||||
use Doctrine\Persistence\ManagerRegistry;
|
||||
use App\Repository\Tools\DocumentRepositoriesExtension;
|
||||
|
||||
/**
|
||||
* @method Report|null find($id, $lockMode = null, $lockVersion = null)
|
||||
* @method Report|null findOneBy(array $criteria, array $orderBy = null)
|
||||
* @method Report[] findAll()
|
||||
* @method Report[] findBy(array $criteria, array $orderBy = null, $limit = null, $offset = null)
|
||||
*/
|
||||
class ReportRepository extends DocumentRepositoriesExtension
|
||||
{
|
||||
public function __construct(ManagerRegistry $registry)
|
||||
{
|
||||
parent::__construct($registry, Report::class);
|
||||
$this->fields = ['content']; //with title, list fields we can search in
|
||||
}
|
||||
}
|
||||
35
src/Repository/ResetPasswordRequestRepository.php
Normal file
35
src/Repository/ResetPasswordRequestRepository.php
Normal file
@@ -0,0 +1,35 @@
|
||||
<?php
|
||||
|
||||
namespace App\Repository;
|
||||
|
||||
use App\Entity\ResetPasswordRequest;
|
||||
use Doctrine\Persistence\ManagerRegistry;
|
||||
use Doctrine\Bundle\DoctrineBundle\Repository\ServiceEntityRepository;
|
||||
use SymfonyCasts\Bundle\ResetPassword\Model\ResetPasswordRequestInterface;
|
||||
use SymfonyCasts\Bundle\ResetPassword\Persistence\ResetPasswordRequestRepositoryInterface;
|
||||
use SymfonyCasts\Bundle\ResetPassword\Persistence\Repository\ResetPasswordRequestRepositoryTrait;
|
||||
|
||||
/**
|
||||
* @method ResetPasswordRequest|null find($id, $lockMode = null, $lockVersion = null)
|
||||
* @method ResetPasswordRequest|null findOneBy(array $criteria, array $orderBy = null)
|
||||
* @method ResetPasswordRequest[] findAll()
|
||||
* @method ResetPasswordRequest[] findBy(array $criteria, array $orderBy = null, $limit = null, $offset = null)
|
||||
*/
|
||||
class ResetPasswordRequestRepository extends ServiceEntityRepository implements ResetPasswordRequestRepositoryInterface
|
||||
{
|
||||
use ResetPasswordRequestRepositoryTrait;
|
||||
|
||||
public function __construct(ManagerRegistry $registry)
|
||||
{
|
||||
parent::__construct($registry, ResetPasswordRequest::class);
|
||||
}
|
||||
|
||||
public function createResetPasswordRequest(
|
||||
object $user,
|
||||
\DateTimeInterface $expiresAt,
|
||||
string $selector,
|
||||
string $hashedToken
|
||||
): ResetPasswordRequestInterface {
|
||||
return new ResetPasswordRequest($user, $expiresAt, $selector, $hashedToken);
|
||||
}
|
||||
}
|
||||
22
src/Repository/SanctionRepository.php
Normal file
22
src/Repository/SanctionRepository.php
Normal file
@@ -0,0 +1,22 @@
|
||||
<?php
|
||||
|
||||
namespace App\Repository;
|
||||
|
||||
use App\Entity\Sanction;
|
||||
use Doctrine\Persistence\ManagerRegistry;
|
||||
use App\Repository\Tools\DocumentRepositoriesExtension;
|
||||
|
||||
/**
|
||||
* @method Sanction|null find($id, $lockMode = null, $lockVersion = null)
|
||||
* @method Sanction|null findOneBy(array $criteria, array $orderBy = null)
|
||||
* @method Sanction[] findAll()
|
||||
* @method Sanction[] findBy(array $criteria, array $orderBy = null, $limit = null, $offset = null)
|
||||
*/
|
||||
class SanctionRepository extends DocumentRepositoriesExtension
|
||||
{
|
||||
public function __construct(ManagerRegistry $registry)
|
||||
{
|
||||
parent::__construct($registry, Sanction::class);
|
||||
$this->fields = ['content']; //with title, list fields we can search in
|
||||
}
|
||||
}
|
||||
22
src/Repository/StolenvehicleRepository.php
Normal file
22
src/Repository/StolenvehicleRepository.php
Normal file
@@ -0,0 +1,22 @@
|
||||
<?php
|
||||
|
||||
namespace App\Repository;
|
||||
|
||||
use App\Entity\Stolenvehicle;
|
||||
use Doctrine\Persistence\ManagerRegistry;
|
||||
use App\Repository\Tools\DocumentRepositoriesExtension;
|
||||
|
||||
/**
|
||||
* @method Stolenvehicle|null find($id, $lockMode = null, $lockVersion = null)
|
||||
* @method Stolenvehicle|null findOneBy(array $criteria, array $orderBy = null)
|
||||
* @method Stolenvehicle[] findAll()
|
||||
* @method Stolenvehicle[] findBy(array $criteria, array $orderBy = null, $limit = null, $offset = null)
|
||||
*/
|
||||
class StolenvehicleRepository extends DocumentRepositoriesExtension
|
||||
{
|
||||
public function __construct(ManagerRegistry $registry)
|
||||
{
|
||||
parent::__construct($registry, Stolenvehicle::class);
|
||||
$this->fields = ['type', 'numberplate','model', 'content', 'color']; //with title, list fields we can search in
|
||||
}
|
||||
}
|
||||
50
src/Repository/SubGroupRepository.php
Normal file
50
src/Repository/SubGroupRepository.php
Normal file
@@ -0,0 +1,50 @@
|
||||
<?php
|
||||
|
||||
namespace App\Repository;
|
||||
|
||||
use App\Entity\SubGroup;
|
||||
use Doctrine\Bundle\DoctrineBundle\Repository\ServiceEntityRepository;
|
||||
use Doctrine\Persistence\ManagerRegistry;
|
||||
|
||||
/**
|
||||
* @method SubGroup|null find($id, $lockMode = null, $lockVersion = null)
|
||||
* @method SubGroup|null findOneBy(array $criteria, array $orderBy = null)
|
||||
* @method SubGroup[] findAll()
|
||||
* @method SubGroup[] findBy(array $criteria, array $orderBy = null, $limit = null, $offset = null)
|
||||
*/
|
||||
class SubGroupRepository extends ServiceEntityRepository
|
||||
{
|
||||
public function __construct(ManagerRegistry $registry)
|
||||
{
|
||||
parent::__construct($registry, SubGroup::class);
|
||||
}
|
||||
|
||||
// /**
|
||||
// * @return SubGroup[] Returns an array of SubGroup objects
|
||||
// */
|
||||
/*
|
||||
public function findByExampleField($value)
|
||||
{
|
||||
return $this->createQueryBuilder('s')
|
||||
->andWhere('s.exampleField = :val')
|
||||
->setParameter('val', $value)
|
||||
->orderBy('s.id', 'ASC')
|
||||
->setMaxResults(10)
|
||||
->getQuery()
|
||||
->getResult()
|
||||
;
|
||||
}
|
||||
*/
|
||||
|
||||
/*
|
||||
public function findOneBySomeField($value): ?SubGroup
|
||||
{
|
||||
return $this->createQueryBuilder('s')
|
||||
->andWhere('s.exampleField = :val')
|
||||
->setParameter('val', $value)
|
||||
->getQuery()
|
||||
->getOneOrNullResult()
|
||||
;
|
||||
}
|
||||
*/
|
||||
}
|
||||
22
src/Repository/TemplateRepository.php
Normal file
22
src/Repository/TemplateRepository.php
Normal file
@@ -0,0 +1,22 @@
|
||||
<?php
|
||||
|
||||
namespace App\Repository;
|
||||
|
||||
use App\Entity\Template;
|
||||
use Doctrine\Persistence\ManagerRegistry;
|
||||
use App\Repository\Tools\DocumentRepositoriesExtension;
|
||||
|
||||
/**
|
||||
* @method Template|null find($id, $lockMode = null, $lockVersion = null)
|
||||
* @method Template|null findOneBy(array $criteria, array $orderBy = null)
|
||||
* @method Template[] findAll()
|
||||
* @method Template[] findBy(array $criteria, array $orderBy = null, $limit = null, $offset = null)
|
||||
*/
|
||||
class TemplateRepository extends DocumentRepositoriesExtension
|
||||
{
|
||||
public function __construct(ManagerRegistry $registry)
|
||||
{
|
||||
parent::__construct($registry, Template::class);
|
||||
$this->fields = ['content']; //with title, list fields we can search in
|
||||
}
|
||||
}
|
||||
194
src/Repository/Tools/DocumentRepositoriesExtension.php
Normal file
194
src/Repository/Tools/DocumentRepositoriesExtension.php
Normal file
@@ -0,0 +1,194 @@
|
||||
<?php
|
||||
|
||||
namespace App\Repository\Tools;
|
||||
|
||||
use App\Entity\User;
|
||||
use App\Entity\Group;
|
||||
use App\Entity\Directory;
|
||||
use Doctrine\ORM\QueryBuilder;
|
||||
use Doctrine\Persistence\ManagerRegistry;
|
||||
use Doctrine\Bundle\DoctrineBundle\Repository\ServiceEntityRepository;
|
||||
|
||||
class DocumentRepositoriesExtension extends ServiceEntityRepository
|
||||
{
|
||||
public array $fields = [];
|
||||
private QueryBuilder $qb;
|
||||
private ?QueryBuilder $qbsearch = null;
|
||||
private ?Group $group = null;
|
||||
private ?User $user = null;
|
||||
|
||||
/**
|
||||
* @param string $entityClass The class name of the entity this repository manages
|
||||
* @psalm-param class-string<T> $entityClass
|
||||
*/
|
||||
public function __construct(ManagerRegistry $registry, string $entityClass = null)
|
||||
{
|
||||
parent::__construct($registry, $entityClass);
|
||||
}
|
||||
|
||||
/**
|
||||
* Equivalent of FindAll()
|
||||
* *
|
||||
* @return QueryBuilder
|
||||
*/
|
||||
public function getQueryBuilder()
|
||||
{
|
||||
return $this->createQueryBuilder("d");
|
||||
;
|
||||
}
|
||||
|
||||
/**
|
||||
* Allow listing of documents wich are allowed for a given group
|
||||
*
|
||||
* @param Group $Group
|
||||
* @return QueryBuilder
|
||||
*/
|
||||
public function getGroupQuery(Group $Group)
|
||||
{
|
||||
return $this->getQueryBuilder()
|
||||
->where(':group MEMBER OF d.allowedGroups')
|
||||
->setParameter('group', $Group)
|
||||
;
|
||||
}
|
||||
|
||||
public function listForUser(User $User, bool $ignoreGroup = false)
|
||||
{
|
||||
$this->user = $User;
|
||||
$this->group = $User->getMainGroup();
|
||||
$this->qbsearch = null;
|
||||
$this->qb = ($User->getAdminMode() || $ignoreGroup) ? $this->getQueryBuilder()
|
||||
: $this->getGroupQuery($this->group);
|
||||
|
||||
|
||||
|
||||
if (!$User->hasPermission('group_ignore_subgroups')) {
|
||||
$this->qb->andWhere('d.allowedSubGroups is empty');
|
||||
foreach ($User->getSubGroups() as $key => $subG) {
|
||||
$this->qb->orWhere(':group' . $key . ' MEMBER OF d.allowedSubGroups')
|
||||
->setParameter(':group' . $key, $subG);
|
||||
}
|
||||
}
|
||||
|
||||
if (!$User->getAdminMode()) {
|
||||
if (!$User->hasPermission('general_legal_view')) {
|
||||
$this->qb->andWhere('d.needLegalAccess = 0');
|
||||
}
|
||||
if (!$User->hasPermission('general_medical_view')) {
|
||||
$this->qb->andWhere('d.needMedicalAccess = 0');
|
||||
}
|
||||
if (!$User->hasPermission('group_administrate')) {
|
||||
$this->qb->andWhere('d.needGroupAdministration = 0');
|
||||
}
|
||||
}
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
public function list()
|
||||
{
|
||||
$this->qbsearch = null;
|
||||
$this->qb = $this->getQueryBuilder();
|
||||
return $this;
|
||||
}
|
||||
|
||||
public function getResult()
|
||||
{
|
||||
if (null !== $this->qbsearch) {
|
||||
$this->qbsearch->andWhere($this->qb->expr()->in('s.id', $this->qb->getDQL()));
|
||||
if (null !== $this->user && !$this->user->getAdminMode()) {
|
||||
$this->qbsearch->setParameter('group', $this->group);
|
||||
}
|
||||
return $this->qbsearch->getQuery()->getResult();
|
||||
}
|
||||
|
||||
return $this->qb->getQuery()->getResult();
|
||||
}
|
||||
|
||||
public function limit(int $limit)
|
||||
{
|
||||
$this->qb->setMaxResults($limit);
|
||||
return $this;
|
||||
}
|
||||
|
||||
public function limitType(string $type)
|
||||
{
|
||||
$this->qb->andWhere($this->qb->expr()->isInstanceOf('d', 'App\Entity\\' . ucfirst($type)));
|
||||
return $this;
|
||||
}
|
||||
|
||||
public function archive(bool $archive = true)
|
||||
{
|
||||
if (true === $archive) {
|
||||
$this->qb->andWhere('d.archive = 1');
|
||||
} else {
|
||||
$this->qb->andWhere('d.archive = 0');
|
||||
}
|
||||
return $this;
|
||||
}
|
||||
|
||||
public function limitDirectory(?Directory $directory)
|
||||
{
|
||||
if (null === $directory) {
|
||||
return $this;
|
||||
}
|
||||
|
||||
$this->qb->andWhere('d.directory = ' . $directory->getId());
|
||||
return $this;
|
||||
}
|
||||
|
||||
public function limitGroup(?Group $group)
|
||||
{
|
||||
if (null === $group) {
|
||||
return $this;
|
||||
}
|
||||
|
||||
$this->qb->andWhere('d.mainGroup = ' . $group->getId());
|
||||
return $this;
|
||||
}
|
||||
|
||||
public function order(array $order)
|
||||
{
|
||||
foreach ($order as $key => $value) {
|
||||
if ($key === array_key_first($order)) {
|
||||
$this->qb->orderBy('d.' . $key, $value);
|
||||
} else {
|
||||
$this->qb->addorderBy('d.' . $key, $value);
|
||||
}
|
||||
}
|
||||
return $this;
|
||||
}
|
||||
|
||||
public function search(?string $search)
|
||||
{
|
||||
if (null === $search) {
|
||||
return $this;
|
||||
}
|
||||
|
||||
if (null === $this->qbsearch) {
|
||||
$this->qbsearch = $this ->createQueryBuilder("s")->where('s.title LIKE :searchkey');
|
||||
$this->qbsearch->orWhere('s.id LIKE :searchkey');
|
||||
$searchTime = str_replace('/', '-', $search);
|
||||
if (($timestamp = strtotime($searchTime)) != false) {
|
||||
$this->qbsearch->where('s.createdAt LIKE :searchkeydate')
|
||||
->setParameter('searchkeydate', '%' . date('Y-m-d', $timestamp) . '%');
|
||||
}
|
||||
}
|
||||
|
||||
foreach ($this->fields as $key => $value) {
|
||||
$this->qbsearch->orWhere('s.' . $value . ' LIKE :searchkey');
|
||||
}
|
||||
|
||||
$this->qbsearch ->leftjoin('s.mainGroup', 'mg')
|
||||
->orWhere('mg.shortName LIKE :searchkey')
|
||||
->orWhere('mg.name LIKE :searchkey')
|
||||
;
|
||||
$this->qbsearch ->leftjoin('s.creator', 'cr')
|
||||
->orWhere('cr.firstname LIKE :searchkey')
|
||||
->orWhere('cr.lastname LIKE :searchkey')
|
||||
;
|
||||
|
||||
$this->qbsearch->setParameter('searchkey', '%' . $search . '%');
|
||||
|
||||
return $this;
|
||||
}
|
||||
}
|
||||
126
src/Repository/UserRepository.php
Normal file
126
src/Repository/UserRepository.php
Normal file
@@ -0,0 +1,126 @@
|
||||
<?php
|
||||
|
||||
namespace App\Repository;
|
||||
|
||||
use App\Entity\User;
|
||||
use Doctrine\ORM\QueryBuilder;
|
||||
use Doctrine\Persistence\ManagerRegistry;
|
||||
use Symfony\Component\Security\Core\User\PasswordUpgraderInterface;
|
||||
use Doctrine\Bundle\DoctrineBundle\Repository\ServiceEntityRepository;
|
||||
use Symfony\Component\Security\Core\Exception\UnsupportedUserException;
|
||||
use Symfony\Component\Security\Core\User\PasswordAuthenticatedUserInterface;
|
||||
|
||||
/**
|
||||
* @method User|null find($id, $lockMode = null, $lockVersion = null)
|
||||
* @method User|null findOneBy(array $criteria, array $orderBy = null)
|
||||
* @method User[] findAll()
|
||||
* @method User[] findBy(array $criteria, array $orderBy = null, $limit = null, $offset = null)
|
||||
*/
|
||||
class UserRepository extends ServiceEntityRepository implements PasswordUpgraderInterface
|
||||
{
|
||||
private QueryBuilder $qb;
|
||||
private array $order = ['firstname' => 'ASC', 'lastname' => 'ASC', 'createdAt' => 'ASC'];
|
||||
|
||||
public function __construct(ManagerRegistry $registry)
|
||||
{
|
||||
parent::__construct($registry, User::class);
|
||||
}
|
||||
|
||||
/**
|
||||
* Used to upgrade (rehash) the user's password automatically over time.
|
||||
*/
|
||||
public function upgradePassword(PasswordAuthenticatedUserInterface $user, string $newHashedPassword): void
|
||||
{
|
||||
if (!$user instanceof User) {
|
||||
throw new UnsupportedUserException(sprintf('Instances of "%s" are not supported.', \get_class($user)));
|
||||
}
|
||||
|
||||
$user->setPassword($newHashedPassword);
|
||||
$this->_em->persist($user);
|
||||
$this->_em->flush();
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Equivalent of FindAll()
|
||||
*
|
||||
* @return QueryBuilder
|
||||
*/
|
||||
private function getQueryBuilder()
|
||||
{
|
||||
return $this->createQueryBuilder("u");
|
||||
}
|
||||
|
||||
|
||||
public function getAll()
|
||||
{
|
||||
$this->qb = $this->getQueryBuilder();
|
||||
return $this;
|
||||
}
|
||||
|
||||
public function order(array $order)
|
||||
{
|
||||
$this->order = $order;
|
||||
return $this;
|
||||
}
|
||||
|
||||
public function limit(int $limit)
|
||||
{
|
||||
$this->qb->setMaxResults($limit);
|
||||
return $this;
|
||||
}
|
||||
|
||||
public function onlyValid()
|
||||
{
|
||||
$this->qb->andWhere('u.mainGroup IS NOT NULL');
|
||||
$this->qb->andWhere('u.mainRank IS NOT NULL');
|
||||
$this->qb->andWhere('u.isVerified = 1');
|
||||
$this->qb->andWhere('u.isDesactivated = 0');
|
||||
return $this;
|
||||
}
|
||||
|
||||
public function search(?string $search, bool $adminmode = false)
|
||||
{
|
||||
if (null === $search) {
|
||||
return $this;
|
||||
}
|
||||
|
||||
$this->qb->where('u.firstname LIKE :searchkey')
|
||||
->orWhere('u.lastname LIKE :searchkey')
|
||||
->orWhere('u.phone LIKE :searchkey')
|
||||
->leftjoin('u.mainGroup', 'mg')
|
||||
->orWhere('mg.shortName LIKE :searchkey')
|
||||
->orWhere('mg.name LIKE :searchkey')
|
||||
->leftjoin('u.mainRank', 'mr')
|
||||
->orWhere('mr.shortname LIKE :searchkey')
|
||||
->orWhere('mr.name LIKE :searchkey')
|
||||
;
|
||||
|
||||
if ($adminmode) {
|
||||
$this->qb->orWhere('u.email LIKE :searchkey');
|
||||
}
|
||||
|
||||
$this->qb->setParameter('searchkey', '%' . $search . '%');
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
public function getResult()
|
||||
{
|
||||
if (false === is_null($this->order)) {
|
||||
foreach ($this->order as $key => $value) {
|
||||
if (strtoupper($value) != 'ASC' && strtoupper($value) != 'DESC') {
|
||||
$key = $value;
|
||||
$value = 'ASC';
|
||||
}
|
||||
if ($key === array_key_first($this->order)) {
|
||||
$this->qb->orderBy('u.' . $key, $value);
|
||||
} else {
|
||||
$this->qb->addorderBy('u.' . $key, $value);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return $this->qb->getQuery()->getResult();
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user