mirror of
https://gitlab.com/Chill-Projet/chill-bundles.git
synced 2025-06-07 18:44:08 +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:
parent
bf1af1aaad
commit
9475a708c3
@ -0,0 +1,60 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
namespace Chill\MainBundle\Entity\Workflow;
|
||||||
|
|
||||||
|
use Chill\MainBundle\Doctrine\Model\TrackCreationInterface;
|
||||||
|
use Chill\MainBundle\Doctrine\Model\TrackCreationTrait;
|
||||||
|
use Chill\MainBundle\Entity\User;
|
||||||
|
use Doctrine\ORM\Mapping as ORM;
|
||||||
|
|
||||||
|
|
||||||
|
#[ORM\Entity]
|
||||||
|
#[ORM\Table('chill_main_workflow_entity_step_hold')]
|
||||||
|
class EntityWorkflowStepHold implements TrackCreationInterface
|
||||||
|
{
|
||||||
|
use TrackCreationTrait;
|
||||||
|
|
||||||
|
#[ORM\Id]
|
||||||
|
#[ORM\GeneratedValue]
|
||||||
|
#[ORM\Column(type: \Doctrine\DBAL\Types\Types::INTEGER)]
|
||||||
|
private ?int $id;
|
||||||
|
|
||||||
|
#[ORM\ManyToOne(targetEntity: EntityWorkflowStep::class)]
|
||||||
|
#[ORM\JoinColumn(nullable: false)]
|
||||||
|
private EntityWorkflowStep $step;
|
||||||
|
|
||||||
|
#[ORM\ManyToOne(targetEntity: User::class)]
|
||||||
|
#[ORM\JoinColumn(nullable: false)]
|
||||||
|
private User $byUser;
|
||||||
|
|
||||||
|
public function getId(): ?int
|
||||||
|
{
|
||||||
|
return $this->id;
|
||||||
|
}
|
||||||
|
|
||||||
|
public function setId(?int $id): void
|
||||||
|
{
|
||||||
|
$this->id = $id;
|
||||||
|
}
|
||||||
|
|
||||||
|
public function getStep(): EntityWorkflowStep
|
||||||
|
{
|
||||||
|
return $this->step;
|
||||||
|
}
|
||||||
|
|
||||||
|
public function setStep(EntityWorkflowStep $step): void
|
||||||
|
{
|
||||||
|
$this->step = $step;
|
||||||
|
}
|
||||||
|
|
||||||
|
public function getByUser(): User
|
||||||
|
{
|
||||||
|
return $this->byUser;
|
||||||
|
}
|
||||||
|
|
||||||
|
public function setByUser(User $byUser): void
|
||||||
|
{
|
||||||
|
$this->byUser = $byUser;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
@ -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;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,41 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
declare(strict_types=1);
|
||||||
|
|
||||||
|
namespace Chill\Migrations\Main;
|
||||||
|
|
||||||
|
use Doctrine\DBAL\Schema\Schema;
|
||||||
|
use Doctrine\Migrations\AbstractMigration;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Auto-generated Migration: Please modify to your needs!
|
||||||
|
*/
|
||||||
|
final class Version20240807123801 extends AbstractMigration
|
||||||
|
{
|
||||||
|
public function getDescription(): string
|
||||||
|
{
|
||||||
|
return 'Create workflow step waiting entity';
|
||||||
|
}
|
||||||
|
|
||||||
|
public function up(Schema $schema): void
|
||||||
|
{
|
||||||
|
$this->addSql('CREATE SEQUENCE chill_main_workflow_entity_step_hold_id_seq INCREMENT BY 1 MINVALUE 1 START 1');
|
||||||
|
$this->addSql('CREATE TABLE chill_main_workflow_entity_step_hold (id INT NOT NULL, step_id INT NOT NULL, createdAt TIMESTAMP(0) WITHOUT TIME ZONE DEFAULT NULL, byUser_id INT NOT NULL, createdBy_id INT DEFAULT NULL, PRIMARY KEY(id))');
|
||||||
|
$this->addSql('CREATE INDEX IDX_1BE2E7C73B21E9C ON chill_main_workflow_entity_step_hold (step_id)');
|
||||||
|
$this->addSql('CREATE INDEX IDX_1BE2E7CD23C0240 ON chill_main_workflow_entity_step_hold (byUser_id)');
|
||||||
|
$this->addSql('CREATE INDEX IDX_1BE2E7C3174800F ON chill_main_workflow_entity_step_hold (createdBy_id)');
|
||||||
|
$this->addSql('COMMENT ON COLUMN chill_main_workflow_entity_step_hold.createdAt IS \'(DC2Type:datetime_immutable)\'');
|
||||||
|
$this->addSql('ALTER TABLE chill_main_workflow_entity_step_hold ADD CONSTRAINT FK_1BE2E7C73B21E9C FOREIGN KEY (step_id) REFERENCES chill_main_workflow_entity_step (id) NOT DEFERRABLE INITIALLY IMMEDIATE');
|
||||||
|
$this->addSql('ALTER TABLE chill_main_workflow_entity_step_hold ADD CONSTRAINT FK_1BE2E7CD23C0240 FOREIGN KEY (byUser_id) REFERENCES users (id) NOT DEFERRABLE INITIALLY IMMEDIATE');
|
||||||
|
$this->addSql('ALTER TABLE chill_main_workflow_entity_step_hold ADD CONSTRAINT FK_1BE2E7C3174800F FOREIGN KEY (createdBy_id) REFERENCES users (id) NOT DEFERRABLE INITIALLY IMMEDIATE');
|
||||||
|
}
|
||||||
|
|
||||||
|
public function down(Schema $schema): void
|
||||||
|
{
|
||||||
|
$this->addSql('DROP SEQUENCE chill_main_workflow_entity_step_hold_id_seq CASCADE');
|
||||||
|
$this->addSql('ALTER TABLE chill_main_workflow_entity_step_hold DROP CONSTRAINT FK_1BE2E7C73B21E9C');
|
||||||
|
$this->addSql('ALTER TABLE chill_main_workflow_entity_step_hold DROP CONSTRAINT FK_1BE2E7CD23C0240');
|
||||||
|
$this->addSql('ALTER TABLE chill_main_workflow_entity_step_hold DROP CONSTRAINT FK_1BE2E7C3174800F');
|
||||||
|
$this->addSql('DROP TABLE chill_main_workflow_entity_step_hold');
|
||||||
|
}
|
||||||
|
}
|
Loading…
x
Reference in New Issue
Block a user