- Correct getChoices() docblock to reflect translated label => enum backing value order instead of value => label - Re-indent Smart Links menu config to match actual array nesting - Align assignment operators in RefreshStatsCommand - Add missing newline at end of RefreshStatsCommand.php
158 lines
4.3 KiB
PHP
158 lines
4.3 KiB
PHP
<?php
|
|
|
|
declare(strict_types=1);
|
|
|
|
namespace MauticPlugin\MT3SMarketingProgramBundle\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;
|
|
|
|
/**
|
|
* The link between a plan and an audience of the global directory, with the audience's priority
|
|
* in that plan and possibly a program-specific message ("Key message for this plan"): the same
|
|
* audience can be primary in one plan and secondary in another.
|
|
*
|
|
* Program::$audiences owns the lifecycle: links are saved and deleted with their plan. Deleting an
|
|
* audience deletes its links (ON DELETE CASCADE on both sides).
|
|
*/
|
|
class ProgramAudience
|
|
{
|
|
public const TABLE_NAME = 'mt3s_mp_program_audiences_program';
|
|
|
|
private ?int $id = null;
|
|
|
|
private ?Program $program = null;
|
|
|
|
private ?Audience $audience = null;
|
|
|
|
private AudiencePriority $priority = AudiencePriority::Primary;
|
|
|
|
/**
|
|
* Key message / hook for this audience in this plan, overriding the audience's own positioning.
|
|
*/
|
|
private ?string $valueProposition = 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->program = null;
|
|
}
|
|
|
|
public static function loadMetadata(OrmClassMetadata $metadata): void
|
|
{
|
|
$builder = new ClassMetadataBuilder($metadata);
|
|
|
|
$builder->setTable(self::TABLE_NAME)
|
|
->setCustomRepositoryClass(ProgramAudienceRepository::class);
|
|
|
|
$builder->addId();
|
|
|
|
$builder->createManyToOne('program', Program::class)
|
|
->inversedBy('audiences')
|
|
->addJoinColumn('program_id', 'id', false, false, 'CASCADE')
|
|
->build();
|
|
|
|
$builder->createManyToOne('audience', Audience::class)
|
|
->addJoinColumn('audience_id', 'id', false, false, 'CASCADE')
|
|
->build();
|
|
|
|
// Mapped on the raw metadata: ClassMetadataBuilder::addField() forces every string to VARCHAR(191).
|
|
$metadata->mapField([
|
|
'fieldName' => 'priority',
|
|
'type' => Types::STRING,
|
|
'length' => 20,
|
|
'enumType' => AudiencePriority::class,
|
|
'options' => ['default' => AudiencePriority::Primary->value],
|
|
]);
|
|
|
|
$builder->createField('valueProposition', Types::TEXT)
|
|
->columnName('value_proposition')
|
|
->nullable()
|
|
->build();
|
|
|
|
$builder->createField('position', Types::INTEGER)
|
|
->option('default', 0)
|
|
->build();
|
|
}
|
|
|
|
public static function loadValidatorMetadata(ClassMetadata $metadata): void
|
|
{
|
|
$metadata->addPropertyConstraint('audience', new NotBlank(message: 'mt3s.marketing_program.audience_link.audience.required'));
|
|
$metadata->addPropertyConstraint('valueProposition', new Length(max: 1000));
|
|
}
|
|
|
|
public function getId(): ?int
|
|
{
|
|
return $this->id;
|
|
}
|
|
|
|
public function getProgram(): ?Program
|
|
{
|
|
return $this->program;
|
|
}
|
|
|
|
public function setProgram(?Program $program): static
|
|
{
|
|
$this->program = $program;
|
|
|
|
return $this;
|
|
}
|
|
|
|
public function getAudience(): ?Audience
|
|
{
|
|
return $this->audience;
|
|
}
|
|
|
|
public function setAudience(?Audience $audience): static
|
|
{
|
|
$this->audience = $audience;
|
|
|
|
return $this;
|
|
}
|
|
|
|
public function getPriority(): AudiencePriority
|
|
{
|
|
return $this->priority;
|
|
}
|
|
|
|
public function setPriority(AudiencePriority $priority): static
|
|
{
|
|
$this->priority = $priority;
|
|
|
|
return $this;
|
|
}
|
|
|
|
public function getValueProposition(): ?string
|
|
{
|
|
return $this->valueProposition;
|
|
}
|
|
|
|
public function setValueProposition(?string $valueProposition): static
|
|
{
|
|
$this->valueProposition = $valueProposition;
|
|
|
|
return $this;
|
|
}
|
|
|
|
public function getPosition(): int
|
|
{
|
|
return $this->position;
|
|
}
|
|
|
|
public function setPosition(?int $position): static
|
|
{
|
|
$this->position = $position ?? 0;
|
|
|
|
return $this;
|
|
}
|
|
}
|