Files
Alexandre Gain ea88b7a772 refactor(plugin): rebrand as MT3SMarketingProgram, release 0.17.0
Rename the plugin's vendor/namespace from experiential/Program to mt3s/MT3SMarketingProgram (composer: mt3s/mautic-marketing-program-bundle):

- ProgramBundle -> MT3SMarketingProgramBundle; extension, integration,
  config support, permissions, events and twig extension renamed likewise
- Initiative* -> Program*: controller (InitiativeController ->
  ProgramController), model, entities, repositories, form types and views
  (new _tabs/_task_table/_tab_table_filter partials, details page)
- Settings config form theme -> _config_mt3smarketingprogramconfig_widget;
  routes and translations re-prefixed (mt3s_marketing_program_*)
- Assets: icon.svg -> mt3s-mp-icon.svg; program.js -> mt3s-mp-program.js
  (OnLoad hooks renamed mt3sMpProgram*)
- Add Command/RefreshStatsCommand; Migrations/Version_0_17_0.php renames
  the tables to mt3s_mp_program_*
2026-11-15 17:48:01 +01:00

198 lines
5.6 KiB
PHP

<?php
declare(strict_types=1);
namespace MauticPlugin\MT3SMarketingProgramBundle\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 Symfony\Component\Validator\Constraints\Email;
use Symfony\Component\Validator\Constraints\Length;
use Symfony\Component\Validator\Constraints\NotBlank;
use Symfony\Component\Validator\Mapping\ClassMetadata;
/**
* A stakeholder of the program: a person, a company or a team involved in the mt3s_mp_programs ("Agency XYZ",
* "Exec committee"). Stakeholders are a global directory (Programs > Stakeholders), independent of
* mt3s_mp_programs; an program links to them through ProgramStakeholder, which carries the stakeholder's role in that
* program.
*
* The type is the key of a stakeholder type set up in Settings > Configuration > Program Settings
* (parameter program_stakeholder_types); see ItemTypeProvider (kind "stakeholder").
*
* isPublished (from FormEntity) means "active": an unpublished stakeholder is hidden from the program
* form's stakeholder picker, but keeps its history on the mt3s_mp_programs it is already linked to.
*/
class Stakeholder extends FormEntity
{
public const TABLE_NAME = 'mt3s_mp_program_stakeholders';
public const TYPE_MAX_LENGTH = 64;
private ?int $id = null;
private ?string $name = null;
private ?string $email = null;
/**
* Free input, normalized to E.164 on save when it parses (StakeholderModel); the raw input is
* kept when it doesn't.
*/
private ?string $phone = null;
private ?string $role = null;
private ?string $type = null;
/**
* The links to the mt3s_mp_programs this stakeholder is assigned to. Inverse side, read-only from here: the
* links are managed from the plans (Program::addStakeholder/removeStakeholder).
*
* @var Collection<int, ProgramStakeholder>
*/
private Collection $programLinks;
public function __construct()
{
$this->programLinks = new ArrayCollection();
}
public static function loadMetadata(OrmClassMetadata $metadata): void
{
$builder = new ClassMetadataBuilder($metadata);
$builder->setTable(self::TABLE_NAME)
->setCustomRepositoryClass(StakeholderRepository::class);
$builder->addId();
$builder->createField('name', Types::STRING)
->length(191)
->build();
$builder->createField('email', Types::STRING)
->length(191)
->nullable()
->build();
// Indexed for duplicate detection.
$builder->createField('phone', Types::STRING)
->length(50)
->nullable()
->build();
$builder->createField('role', Types::STRING)
->length(191)
->nullable()
->build();
$builder->createField('type', Types::STRING)
->length(self::TYPE_MAX_LENGTH)
->nullable()
->build();
$builder->createOneToMany('programLinks', ProgramStakeholder::class)
->mappedBy('stakeholder')
->fetchExtraLazy()
->build();
$builder->addIndex(['email'], 'program_stakeholder_email');
}
public static function loadValidatorMetadata(ClassMetadata $metadata): void
{
$metadata->addPropertyConstraint('name', new NotBlank(message: 'mautic.core.name.required'));
$metadata->addPropertyConstraint('name', new Length(max: 191));
$metadata->addPropertyConstraint('email', new Email(mode: Email::VALIDATION_MODE_HTML5, message: 'mt3s.marketing_program.stakeholder.email.invalid'));
$metadata->addPropertyConstraint('email', new Length(max: 191));
$metadata->addPropertyConstraint('phone', new Length(max: 50));
$metadata->addPropertyConstraint('role', new Length(max: 191));
$metadata->addPropertyConstraint('type', new Length(max: self::TYPE_MAX_LENGTH));
}
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 getEmail(): ?string
{
return $this->email;
}
public function setEmail(?string $email): static
{
$this->isChanged('email', $email);
$this->email = $email;
return $this;
}
public function getPhone(): ?string
{
return $this->phone;
}
public function setPhone(?string $phone): static
{
$this->isChanged('phone', $phone);
$this->phone = $phone;
return $this;
}
public function getRole(): ?string
{
return $this->role;
}
public function setRole(?string $role): static
{
$this->isChanged('role', $role);
$this->role = $role;
return $this;
}
public function getType(): ?string
{
return $this->type;
}
/**
* The links to the mt3s_mp_programs this stakeholder is assigned to, each with its role in that program.
*
* @return Collection<int, ProgramStakeholder>
*/
public function getProgramLinks(): Collection
{
return $this->programLinks;
}
public function setType(?string $type): static
{
$this->isChanged('type', $type);
$this->type = $type;
return $this;
}
}