mirror of
https://gitlab.com/Chill-Projet/chill-bundles.git
synced 2025-09-26 16:45:01 +00:00
Add EntityWorkflowStepHold entity to allow workflow to be put on hold by user
Entity created, migration, and repository.
This commit is contained in:
@@ -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;
|
||||
}
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user