Rename the Plan bundle to Program across config, routes, menus, and controllers (Plan -> Initiative), bump version to 0.16.0, and introduce new audience and UTM taxonomy routes and permissions to support the expanded Programs feature set.
158 lines
4.3 KiB
PHP
158 lines
4.3 KiB
PHP
<?php
|
|
|
|
declare(strict_types=1);
|
|
|
|
namespace MauticPlugin\ProgramBundle\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 initiative-specific message ("Key message for this plan"): the same
|
|
* audience can be primary in one plan and secondary in another.
|
|
*
|
|
* Initiative::$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 InitiativeAudience
|
|
{
|
|
public const TABLE_NAME = 'initiative_audiences_initiative';
|
|
|
|
private ?int $id = null;
|
|
|
|
private ?Initiative $initiative = 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->initiative = null;
|
|
}
|
|
|
|
public static function loadMetadata(OrmClassMetadata $metadata): void
|
|
{
|
|
$builder = new ClassMetadataBuilder($metadata);
|
|
|
|
$builder->setTable(self::TABLE_NAME)
|
|
->setCustomRepositoryClass(InitiativeAudienceRepository::class);
|
|
|
|
$builder->addId();
|
|
|
|
$builder->createManyToOne('initiative', Initiative::class)
|
|
->inversedBy('audiences')
|
|
->addJoinColumn('initiative_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: 'mautic.program.audience_link.audience.required'));
|
|
$metadata->addPropertyConstraint('valueProposition', new Length(max: 1000));
|
|
}
|
|
|
|
public function getId(): ?int
|
|
{
|
|
return $this->id;
|
|
}
|
|
|
|
public function getInitiative(): ?Initiative
|
|
{
|
|
return $this->initiative;
|
|
}
|
|
|
|
public function setInitiative(?Initiative $initiative): static
|
|
{
|
|
$this->initiative = $initiative;
|
|
|
|
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;
|
|
}
|
|
}
|