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.
107 lines
3.9 KiB
PHP
107 lines
3.9 KiB
PHP
<?php
|
|
|
|
declare(strict_types=1);
|
|
|
|
namespace MauticPlugin\ProgramBundle\Service;
|
|
|
|
use Mautic\CoreBundle\Helper\CoreParametersHelper;
|
|
|
|
/**
|
|
* Reads the Audience attributes set up in Settings > Configuration > Program Settings.
|
|
*
|
|
* Which attributes of an audience persona are offered on the forms is chosen there, one toggle per
|
|
* attribute, so a b2b install and a b2c install define their personas differently. Each toggle is
|
|
* a local.php parameter (default enabled; an admin turns off what they don't use):
|
|
* - program_audience_attribute_tagline (Tagline)
|
|
* - program_audience_attribute_profile (Profile criteria)
|
|
* - program_audience_attribute_motivations (Motivations)
|
|
* - program_audience_attribute_barriers (Barriers)
|
|
* - program_audience_attribute_frustrations (Frustrations)
|
|
* - program_audience_attribute_triggers (Triggers)
|
|
* - program_audience_attribute_decision_role (Decision-making role; values program_audience_decision_roles)
|
|
* - program_audience_attribute_tones (Preferred tones; values program_audience_tones)
|
|
* - program_audience_attribute_channels (Preferred channels)
|
|
* - program_audience_attribute_stages (Stages)
|
|
* - program_audience_attribute_size (Estimated size)
|
|
*
|
|
* The values of the decision roles and the tones are lists edited in the same place, with a name
|
|
* per language — read through ItemTypeProvider (kinds "audience_decision_role" and "audience_tone").
|
|
*
|
|
* The segments are NOT part of this: every audience offers them (always, purely informational).
|
|
*/
|
|
class AudienceAttributes
|
|
{
|
|
/**
|
|
* Attribute key => form field name. The keys name the local.php toggle parameters; the values
|
|
* are the Audience entity's fields. The order is the order of the forms and of the tables.
|
|
*/
|
|
public const ATTRIBUTES = [
|
|
'tagline' => 'tagline',
|
|
'profile' => 'profileCriteria',
|
|
'motivations' => 'motivations',
|
|
'barriers' => 'barriers',
|
|
'frustrations' => 'frustrations',
|
|
'triggers' => 'triggers',
|
|
'decision_role' => 'decisionRole',
|
|
'tones' => 'preferredTones',
|
|
'channels' => 'preferredChannels',
|
|
'stages' => 'stages',
|
|
'size' => 'estimatedSize',
|
|
];
|
|
|
|
public function __construct(
|
|
private CoreParametersHelper $coreParametersHelper,
|
|
) {
|
|
}
|
|
|
|
/**
|
|
* True when an attribute is offered on the audience forms. The toggle defaults to enabled, so
|
|
* an install that never touches the settings gets every attribute; turning it off stores false.
|
|
*/
|
|
public function isEnabled(string $attribute): bool
|
|
{
|
|
if (!isset(self::ATTRIBUTES[$attribute])) {
|
|
return false;
|
|
}
|
|
|
|
// Null (parameter never set) and true both mean enabled; only an explicit false turns it off.
|
|
return false !== $this->coreParametersHelper->get(self::toggleParameter($attribute));
|
|
}
|
|
|
|
/**
|
|
* The enabled attribute keys, in canonical order.
|
|
*
|
|
* @return list<string>
|
|
*/
|
|
public function getEnabled(): array
|
|
{
|
|
$enabled = [];
|
|
foreach (array_keys(self::ATTRIBUTES) as $attribute) {
|
|
if ($this->isEnabled($attribute)) {
|
|
$enabled[] = $attribute;
|
|
}
|
|
}
|
|
|
|
return $enabled;
|
|
}
|
|
|
|
/**
|
|
* The form field name of an attribute ('tagline', 'profileCriteria', …).
|
|
*/
|
|
public function getField(string $attribute): string
|
|
{
|
|
if (!isset(self::ATTRIBUTES[$attribute])) {
|
|
throw new \InvalidArgumentException('Unknown audience attribute: '.$attribute);
|
|
}
|
|
|
|
return self::ATTRIBUTES[$attribute];
|
|
}
|
|
|
|
/**
|
|
* The local.php parameter holding an attribute's toggle.
|
|
*/
|
|
public static function toggleParameter(string $attribute): string
|
|
{
|
|
return 'program_audience_attribute_'.$attribute;
|
|
}
|
|
} |