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 */ 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 */ public function getProgramLinks(): Collection { return $this->programLinks; } public function setType(?string $type): static { $this->isChanged('type', $type); $this->type = $type; return $this; } }