first delivery

This commit is contained in:
Alexandre Gain committed 2026-11-07 19:31:49 +01:00
1 parent 793fbc0c91
commit f6684f3b2e
65 files changed
+5828

No files matched your search

+131
View File
@@ -0,0 +1,131 @@
<?php
declare(strict_types=1);
namespace MauticPlugin\PlanBundle\Entity;
use Doctrine\DBAL\Types\Types;
use Doctrine\ORM\Mapping\ClassMetadata as OrmClassMetadata;
use Mautic\CoreBundle\Doctrine\Mapping\ClassMetadataBuilder;
use Symfony\Component\Validator\Constraints\Length;
use Symfony\Component\Validator\Constraints\NotBlank;
use Symfony\Component\Validator\Mapping\ClassMetadata;
/**
* One item of a plan's Description tab. Plan::$descriptionItems owns the lifecycle: items are saved and
* deleted with their plan, and are ordered by position.
*
* The type is the key of a type set up in Settings > Configuration > Plan (parameter
* plan_description_item_types); see ItemTypeProvider (kind "description") for its name and description.
*/
class PlanDescriptionItem
{
public const TABLE_NAME = 'plan_description_items';
public const TYPE_MAX_LENGTH = 64;
private ?int $id = null;
private ?Plan $plan = null;
private ?string $type = null;
private ?string $description = null;
/**
* Display order within the plan, from 0. Set by drag and drop in the form.
*/
private int $position = 0;
public function __clone()
{
$this->id = null;
$this->plan = null;
}
public static function loadMetadata(OrmClassMetadata $metadata): void
{
$builder = new ClassMetadataBuilder($metadata);
$builder->setTable(self::TABLE_NAME)
->setCustomRepositoryClass(PlanDescriptionItemRepository::class);
$builder->addId();
$builder->createManyToOne('plan', Plan::class)
->inversedBy('descriptionItems')
->addJoinColumn('plan_id', 'id', false, false, 'CASCADE')
->build();
$builder->createField('type', Types::STRING)
->length(self::TYPE_MAX_LENGTH)
->build();
$builder->createField('description', Types::TEXT)
->nullable()
->build();
$builder->createField('position', Types::INTEGER)
->option('default', 0)
->build();
}
public static function loadValidatorMetadata(ClassMetadata $metadata): void
{
$metadata->addPropertyConstraint('type', new NotBlank(message: 'mautic.plan.description_item.type.required'));
$metadata->addPropertyConstraint('type', new Length(max: self::TYPE_MAX_LENGTH));
}
public function getId(): ?int
{
return $this->id;
}
public function getPlan(): ?Plan
{
return $this->plan;
}
public function setPlan(?Plan $plan): static
{
$this->plan = $plan;
return $this;
}
public function getType(): ?string
{
return $this->type;
}
public function setType(?string $type): static
{
$this->type = $type;
return $this;
}
public function getDescription(): ?string
{
return $this->description;
}
public function setDescription(?string $description): static
{
$this->description = $description;
return $this;
}
public function getPosition(): int
{
return $this->position;
}
public function setPosition(?int $position): static
{
$this->position = $position ?? 0;
return $this;
}
}