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.
198 lines
5.6 KiB
PHP
198 lines
5.6 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 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 initiatives ("Agency XYZ",
|
|
* "Exec committee"). Stakeholders are a global directory (Programs > Stakeholders), independent of
|
|
* initiatives; an initiative links to them through InitiativeStakeholder, which carries the stakeholder's role in that
|
|
* initiative.
|
|
*
|
|
* The type is the key of a stakeholder type set up in Settings > Configuration > Initiative Settings
|
|
* (parameter program_stakeholder_types); see ItemTypeProvider (kind "stakeholder").
|
|
*
|
|
* isPublished (from FormEntity) means "active": an unpublished stakeholder is hidden from the initiative
|
|
* form's stakeholder picker, but keeps its history on the initiatives it is already linked to.
|
|
*/
|
|
class Stakeholder extends FormEntity
|
|
{
|
|
public const TABLE_NAME = 'initiative_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 initiatives this stakeholder is assigned to. Inverse side, read-only from here: the
|
|
* links are managed from the plans (Initiative::addStakeholder/removeStakeholder).
|
|
*
|
|
* @var Collection<int, InitiativeStakeholder>
|
|
*/
|
|
private Collection $initiativeLinks;
|
|
|
|
public function __construct()
|
|
{
|
|
$this->initiativeLinks = 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('initiativeLinks', InitiativeStakeholder::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: 'mautic.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 initiatives this stakeholder is assigned to, each with its role in that initiative.
|
|
*
|
|
* @return Collection<int, InitiativeStakeholder>
|
|
*/
|
|
public function getInitiativeLinks(): Collection
|
|
{
|
|
return $this->initiativeLinks;
|
|
}
|
|
|
|
public function setType(?string $type): static
|
|
{
|
|
$this->isChanged('type', $type);
|
|
$this->type = $type;
|
|
|
|
return $this;
|
|
}
|
|
}
|