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.
480 lines
14 KiB
PHP
480 lines
14 KiB
PHP
<?php
|
|
|
|
declare(strict_types=1);
|
|
|
|
namespace MauticPlugin\ProgramBundle\Entity;
|
|
|
|
use Doctrine\Common\Collections\ArrayCollection;
|
|
use Doctrine\Common\Collections\Collection;
|
|
use Doctrine\DBAL\Types\Types;
|
|
use Doctrine\ORM\Mapping\ClassMetadata as OrmClassMetadata;
|
|
use Mautic\CoreBundle\Doctrine\Mapping\ClassMetadataBuilder;
|
|
use Mautic\CoreBundle\Entity\FormEntity;
|
|
use Mautic\LeadBundle\Entity\LeadList;
|
|
use Mautic\StageBundle\Entity\Stage;
|
|
use Symfony\Component\Validator\Constraints\Length;
|
|
use Symfony\Component\Validator\Constraints\NotBlank;
|
|
use Symfony\Component\Validator\Constraints\PositiveOrZero;
|
|
use Symfony\Component\Validator\Mapping\ClassMetadata;
|
|
|
|
/**
|
|
* One audience of the global directory (Programs > Audiences): who the plan is aimed at, and how.
|
|
* Audiences are independent of plans; a plan links to them from its Audiences tab through InitiativeAudience,
|
|
* which carries the audience's priority in that plan, and possibly a initiative-specific message.
|
|
*
|
|
* Which attributes are offered on the forms is set up by the admin in Settings > Configuration >
|
|
* Initiative Settings (per-attribute toggles, so a b2b install and a b2c install define their personas
|
|
* differently); the decision roles and the tones are lists edited there too. See AudienceAttributes.
|
|
*
|
|
* The stages are the Mautic stages (Settings > Stages) this audience maps to; an audience can have
|
|
* any number of them, or none. Deleting a stage removes the link (join table row), not the audience.
|
|
*
|
|
* The segments are the Mautic segments (LeadBundle lists) this audience maps to. They are purely
|
|
* informational: the user may assign none, one or several; the list view shows their names and
|
|
* their contact counts. Deleting a segment removes the link, not the audience.
|
|
*
|
|
* isPublished (from FormEntity) means "active": an unpublished audience is hidden from the initiative
|
|
* form's audience picker, but keeps its history on the initiatives it is already linked to.
|
|
*/
|
|
class Audience extends FormEntity
|
|
{
|
|
public const TABLE_NAME = 'initiative_audiences';
|
|
|
|
/**
|
|
* Keys offered for preferredChannels, in display order.
|
|
*/
|
|
public const CHANNELS = [
|
|
'email' => 'mautic.program.audience.channel.email',
|
|
'sms' => 'mautic.program.audience.channel.sms',
|
|
'web' => 'mautic.program.audience.channel.web',
|
|
'social_organic' => 'mautic.program.audience.channel.social_organic',
|
|
'paid_social' => 'mautic.program.audience.channel.paid_social',
|
|
'paid_search' => 'mautic.program.audience.channel.paid_search',
|
|
'events_webinar' => 'mautic.program.audience.channel.events_webinar',
|
|
'outbound_sales' => 'mautic.program.audience.channel.outbound_sales',
|
|
'partners' => 'mautic.program.audience.channel.partners',
|
|
];
|
|
|
|
private ?int $id = null;
|
|
|
|
private ?string $name = null;
|
|
|
|
private AudienceType $audienceType = AudienceType::Persona;
|
|
|
|
/**
|
|
* One-line positioning statement ("The busy CFO who…").
|
|
*/
|
|
private ?string $tagline = null;
|
|
|
|
/**
|
|
* Demographics, firmographics, job titles, geography.
|
|
*/
|
|
private ?string $profileCriteria = null;
|
|
|
|
/**
|
|
* What drives the audience.
|
|
*/
|
|
private ?string $motivations = null;
|
|
|
|
/**
|
|
* What holds the audience back from buying.
|
|
*/
|
|
private ?string $barriers = null;
|
|
|
|
/**
|
|
* What annoys or blocks the audience day to day (formerly Pain points).
|
|
*/
|
|
private ?string $frustrations = null;
|
|
|
|
/**
|
|
* What makes the audience act (content, season, event…).
|
|
*/
|
|
private ?string $triggers = null;
|
|
|
|
/**
|
|
* Key of a decision role set up in Settings > Configuration > Initiative Settings
|
|
* (parameter program_audience_decision_roles), or null when the attribute is unused.
|
|
*/
|
|
private ?string $decisionRole = null;
|
|
|
|
/**
|
|
* Keys of tones set up in Settings > Configuration > Initiative Settings
|
|
* (parameter program_audience_tones), or null/[] when the attribute is unused.
|
|
*
|
|
* @var list<string>|null
|
|
*/
|
|
private ?array $preferredTones = null;
|
|
|
|
/**
|
|
* Keys of self::CHANNELS the initiative means to use for this audience.
|
|
*
|
|
* @var list<string>|null
|
|
*/
|
|
private ?array $preferredChannels = null;
|
|
|
|
/**
|
|
* The Mautic stages this audience maps to; any number, or none.
|
|
*
|
|
* @var Collection<int, Stage>
|
|
*/
|
|
private Collection $stages;
|
|
|
|
/**
|
|
* The Mautic segments this audience maps to; any number, or none. Purely informational.
|
|
*
|
|
* @var Collection<int, LeadList>
|
|
*/
|
|
private Collection $segments;
|
|
|
|
/**
|
|
* Estimated number of people or accounts, or null when unknown.
|
|
*/
|
|
private ?int $estimatedSize = null;
|
|
|
|
/**
|
|
* The links to the initiatives this audience is assigned to. Inverse side, read-only from here: the
|
|
* links are managed from the plans (Initiative::addAudience/removeAudience).
|
|
*
|
|
* @var Collection<int, InitiativeAudience>
|
|
*/
|
|
private Collection $initiativeLinks;
|
|
|
|
public function __construct()
|
|
{
|
|
$this->stages = new ArrayCollection();
|
|
$this->segments = new ArrayCollection();
|
|
$this->initiativeLinks = new ArrayCollection();
|
|
}
|
|
|
|
public function __clone()
|
|
{
|
|
$this->id = null;
|
|
$this->stages = new ArrayCollection();
|
|
$this->segments = new ArrayCollection();
|
|
$this->initiativeLinks = new ArrayCollection();
|
|
|
|
parent::__clone();
|
|
}
|
|
|
|
public static function loadMetadata(OrmClassMetadata $metadata): void
|
|
{
|
|
$builder = new ClassMetadataBuilder($metadata);
|
|
|
|
$builder->setTable(self::TABLE_NAME)
|
|
->setCustomRepositoryClass(AudienceRepository::class);
|
|
|
|
$builder->addId();
|
|
|
|
$builder->createField('name', Types::STRING)
|
|
->length(191)
|
|
->build();
|
|
|
|
// Mapped on the raw metadata: ClassMetadataBuilder::addField() forces every string to VARCHAR(191).
|
|
$metadata->mapField([
|
|
'fieldName' => 'audienceType',
|
|
'columnName' => 'audience_type',
|
|
'type' => Types::STRING,
|
|
'length' => 30,
|
|
'enumType' => AudienceType::class,
|
|
'options' => ['default' => AudienceType::Persona->value],
|
|
]);
|
|
|
|
foreach ([
|
|
'tagline' => 'tagline',
|
|
'profileCriteria' => 'profile_criteria',
|
|
'motivations' => 'motivations',
|
|
'barriers' => 'barriers',
|
|
'frustrations' => 'frustrations',
|
|
'triggers' => 'triggers',
|
|
] as $field => $column) {
|
|
$metadata->mapField([
|
|
'fieldName' => $field,
|
|
'columnName' => $column,
|
|
'type' => Types::TEXT,
|
|
'nullable' => true,
|
|
]);
|
|
}
|
|
|
|
// Key of a configured decision role; the attribute may be unused (null).
|
|
$builder->createField('decisionRole', Types::STRING)
|
|
->columnName('decision_role')
|
|
->length(64)
|
|
->nullable()
|
|
->build();
|
|
|
|
$builder->createField('preferredTones', Types::JSON)
|
|
->columnName('preferred_tones')
|
|
->nullable()
|
|
->build();
|
|
|
|
$builder->createField('preferredChannels', Types::JSON)
|
|
->columnName('preferred_channels')
|
|
->nullable()
|
|
->build();
|
|
|
|
$builder->createManyToMany('stages', Stage::class)
|
|
->setJoinTable('initiative_audiences_stages')
|
|
->addJoinColumn('audience_id', 'id', false, false, 'CASCADE')
|
|
->addInverseJoinColumn('stage_id', 'id', false, false, 'CASCADE')
|
|
->build();
|
|
|
|
$builder->createManyToMany('segments', LeadList::class)
|
|
->setJoinTable('initiative_audiences_segments')
|
|
->addJoinColumn('audience_id', 'id', false, false, 'CASCADE')
|
|
->addInverseJoinColumn('leadlist_id', 'id', false, false, 'CASCADE')
|
|
->build();
|
|
|
|
$builder->createField('estimatedSize', Types::INTEGER)
|
|
->columnName('estimated_size')
|
|
->nullable()
|
|
->option('unsigned', true)
|
|
->build();
|
|
|
|
// The links to the initiatives, managed from the initiatives.
|
|
$builder->createOneToMany('initiativeLinks', InitiativeAudience::class)
|
|
->mappedBy('audience')
|
|
->fetchExtraLazy()
|
|
->build();
|
|
}
|
|
|
|
public static function loadValidatorMetadata(ClassMetadata $metadata): void
|
|
{
|
|
$metadata->addPropertyConstraint('name', new NotBlank(message: 'mautic.program.audience.name.required'));
|
|
$metadata->addPropertyConstraint('name', new Length(max: 191));
|
|
$metadata->addPropertyConstraint('estimatedSize', new PositiveOrZero(message: 'mautic.program.audience.estimated_size.invalid'));
|
|
$metadata->addPropertyConstraint('decisionRole', new Length(max: 64));
|
|
}
|
|
|
|
public function getId(): ?int
|
|
{
|
|
return $this->id;
|
|
}
|
|
|
|
public function getName(): ?string
|
|
{
|
|
return $this->name;
|
|
}
|
|
|
|
public function setName(?string $name): static
|
|
{
|
|
$this->isChanged('name', $name);
|
|
$this->name = $name;
|
|
|
|
return $this;
|
|
}
|
|
|
|
public function getAudienceType(): AudienceType
|
|
{
|
|
return $this->audienceType;
|
|
}
|
|
|
|
public function setAudienceType(AudienceType $audienceType): static
|
|
{
|
|
if ($audienceType !== $this->audienceType) {
|
|
// isChanged() can't log enums (they aren't stringable), so log the backing values.
|
|
$this->addChange('audienceType', [$this->audienceType->value, $audienceType->value]);
|
|
}
|
|
$this->audienceType = $audienceType;
|
|
|
|
return $this;
|
|
}
|
|
|
|
public function getTagline(): ?string
|
|
{
|
|
return $this->tagline;
|
|
}
|
|
|
|
public function setTagline(?string $tagline): static
|
|
{
|
|
$this->isChanged('tagline', $tagline);
|
|
$this->tagline = $tagline;
|
|
|
|
return $this;
|
|
}
|
|
|
|
/**
|
|
* @return Collection<int, Stage>
|
|
*/
|
|
public function getStages(): Collection
|
|
{
|
|
return $this->stages;
|
|
}
|
|
|
|
public function addStage(Stage $stage): static
|
|
{
|
|
if (!$this->stages->contains($stage)) {
|
|
$this->stages->add($stage);
|
|
}
|
|
|
|
return $this;
|
|
}
|
|
|
|
public function removeStage(Stage $stage): static
|
|
{
|
|
$this->stages->removeElement($stage);
|
|
|
|
return $this;
|
|
}
|
|
|
|
/**
|
|
* @return Collection<int, LeadList>
|
|
*/
|
|
public function getSegments(): Collection
|
|
{
|
|
return $this->segments;
|
|
}
|
|
|
|
public function addSegment(LeadList $segment): static
|
|
{
|
|
if (!$this->segments->contains($segment)) {
|
|
$this->segments->add($segment);
|
|
}
|
|
|
|
return $this;
|
|
}
|
|
|
|
public function removeSegment(LeadList $segment): static
|
|
{
|
|
$this->segments->removeElement($segment);
|
|
|
|
return $this;
|
|
}
|
|
|
|
public function getEstimatedSize(): ?int
|
|
{
|
|
return $this->estimatedSize;
|
|
}
|
|
|
|
public function setEstimatedSize(?int $estimatedSize): static
|
|
{
|
|
$this->isChanged('estimatedSize', $estimatedSize);
|
|
$this->estimatedSize = $estimatedSize;
|
|
|
|
return $this;
|
|
}
|
|
|
|
public function getProfileCriteria(): ?string
|
|
{
|
|
return $this->profileCriteria;
|
|
}
|
|
|
|
public function setProfileCriteria(?string $profileCriteria): static
|
|
{
|
|
$this->isChanged('profileCriteria', $profileCriteria);
|
|
$this->profileCriteria = $profileCriteria;
|
|
|
|
return $this;
|
|
}
|
|
|
|
public function getMotivations(): ?string
|
|
{
|
|
return $this->motivations;
|
|
}
|
|
|
|
public function setMotivations(?string $motivations): static
|
|
{
|
|
$this->isChanged('motivations', $motivations);
|
|
$this->motivations = $motivations;
|
|
|
|
return $this;
|
|
}
|
|
|
|
public function getBarriers(): ?string
|
|
{
|
|
return $this->barriers;
|
|
}
|
|
|
|
public function setBarriers(?string $barriers): static
|
|
{
|
|
$this->isChanged('barriers', $barriers);
|
|
$this->barriers = $barriers;
|
|
|
|
return $this;
|
|
}
|
|
|
|
public function getFrustrations(): ?string
|
|
{
|
|
return $this->frustrations;
|
|
}
|
|
|
|
public function setFrustrations(?string $frustrations): static
|
|
{
|
|
$this->isChanged('frustrations', $frustrations);
|
|
$this->frustrations = $frustrations;
|
|
|
|
return $this;
|
|
}
|
|
|
|
public function getTriggers(): ?string
|
|
{
|
|
return $this->triggers;
|
|
}
|
|
|
|
public function setTriggers(?string $triggers): static
|
|
{
|
|
$this->isChanged('triggers', $triggers);
|
|
$this->triggers = $triggers;
|
|
|
|
return $this;
|
|
}
|
|
|
|
public function getDecisionRole(): ?string
|
|
{
|
|
return $this->decisionRole;
|
|
}
|
|
|
|
public function setDecisionRole(?string $decisionRole): static
|
|
{
|
|
$this->isChanged('decisionRole', $decisionRole);
|
|
$this->decisionRole = $decisionRole;
|
|
|
|
return $this;
|
|
}
|
|
|
|
/**
|
|
* @return list<string>|null
|
|
*/
|
|
public function getPreferredTones(): ?array
|
|
{
|
|
return $this->preferredTones;
|
|
}
|
|
|
|
/**
|
|
* @param list<string>|null $preferredTones
|
|
*/
|
|
public function setPreferredTones(?array $preferredTones): static
|
|
{
|
|
$this->isChanged('preferredTones', $preferredTones);
|
|
$this->preferredTones = $preferredTones;
|
|
|
|
return $this;
|
|
}
|
|
|
|
/**
|
|
* @return list<string>|null
|
|
*/
|
|
public function getPreferredChannels(): ?array
|
|
{
|
|
return $this->preferredChannels;
|
|
}
|
|
|
|
/**
|
|
* @param list<string>|null $preferredChannels
|
|
*/
|
|
public function setPreferredChannels(?array $preferredChannels): static
|
|
{
|
|
$this->isChanged('preferredChannels', $preferredChannels);
|
|
$this->preferredChannels = $preferredChannels;
|
|
|
|
return $this;
|
|
}
|
|
|
|
/**
|
|
* @return Collection<int, InitiativeAudience>
|
|
*/
|
|
public function getInitiativeLinks(): Collection
|
|
{
|
|
return $this->initiativeLinks;
|
|
}
|
|
}
|