Add EntityWorkflowStepHold entity to allow workflow to be put on hold by user

Entity created, migration, and repository.
This commit is contained in:
2024-08-07 16:47:29 +02:00
committed by Julien Fastré
parent bf1af1aaad
commit 9475a708c3
3 changed files with 175 additions and 0 deletions

View File

@@ -0,0 +1,74 @@
<?php
namespace Chill\MainBundle\Repository\Workflow;
use Chill\MainBundle\Entity\User;
use Chill\MainBundle\Entity\Workflow\EntityWorkflowStep;
use Chill\MainBundle\Entity\Workflow\EntityWorkflowStepHold;
use Doctrine\Bundle\DoctrineBundle\Repository\ServiceEntityRepository;
use Doctrine\ORM\NonUniqueResultException;
use Doctrine\ORM\NoResultException;
use Doctrine\Persistence\ManagerRegistry;
class EntityWorkflowStepHoldRepository extends ServiceEntityRepository
{
public function __construct(ManagerRegistry $registry)
{
parent::__construct($registry, EntityWorkflowStepHold::class);
}
/**
* Find an EntityWorkflowStepHold by its ID.
*
* @param int $id
* @return EntityWorkflowStepHold|null
*/
public function findById(int $id): ?EntityWorkflowStepHold
{
return $this->find($id);
}
/**
* Find all EntityWorkflowStepHold records.
*
* @return EntityWorkflowStepHold[]
*/
public function findAllHolds(): array
{
return $this->findAll();
}
/**
* Find EntityWorkflowStepHold by a specific step.
*
* @param EntityWorkflowStep $step
* @return EntityWorkflowStepHold[]
*/
public function findByStep(EntityWorkflowStep $step): array
{
return $this->findBy(['step' => $step]);
}
/**
* Find a single EntityWorkflowStepHold by step and user.
*
* @param EntityWorkflowStep $step
* @param User $user
* @return EntityWorkflowStepHold|null
* @throws NonUniqueResultException
*/
public function findOneByStepAndUser(EntityWorkflowStep $step, User $user): ?EntityWorkflowStepHold
{
try {
return $this->createQueryBuilder('e')
->andWhere('e.step = :step')
->andWhere('e.byUser = :user')
->setParameter('step', $step)
->setParameter('user', $user)
->getQuery()
->getSingleResult();
} catch (NoResultException $e) {
return null;
}
}
}