A new Mautic component, listed under Components > Call Scripts (/s/call-scripts),
built like the other domains on AbstractStandardFormController/FormModel.
- CallScript (mt3s_call_scripts): name, description, category, owner, status,
the publish window shown as start/end date and time, the HTML script with
dynamic tokens kept as typed (html cleaning mask), the calling window
(weekdays, hours, sentinel in the contact's or a fixed timezone) and the retry
policy (max attempts, delay, backoff: none/linear/exponential)
- CallScriptOutcome (mt3s_call_script_outcomes, ON DELETE CASCADE): label,
data type (checkbox/radio/free text/dropdown), options JSON ({value,label})
and position; nested collections reuse the program-collection JS
- validators: ValidCallingWindow, ValidCallScriptOutcomeOptions, and an atPath
option on EndDateAfterStartDate so its violation lands on publishDown
- config: routes, the Components menu item (parent mautic.core.components),
call_script category type, model alias, call_scripts permissions, version 0.19.0
- migration Version_0_19_0 creates both tables and their FKs immediately
(users/categories SET NULL, outcomes CASCADE), idempotent
- translations en_US/fr_FR, unit tests, readme/AGENTS documentation
81 lines
2.2 KiB
PHP
81 lines
2.2 KiB
PHP
<?php
|
|
|
|
declare(strict_types=1);
|
|
|
|
namespace MauticPlugin\MT3SMarketingProgramBundle\Model;
|
|
|
|
use Mautic\CoreBundle\Model\FormModel;
|
|
use MauticPlugin\MT3SMarketingProgramBundle\Entity\CallScript;
|
|
use MauticPlugin\MT3SMarketingProgramBundle\Entity\CallScriptRepository;
|
|
use MauticPlugin\MT3SMarketingProgramBundle\Form\Type\CallScriptType;
|
|
use Symfony\Component\Form\FormFactoryInterface;
|
|
use Symfony\Component\Form\FormInterface;
|
|
use Symfony\Component\HttpKernel\Exception\MethodNotAllowedHttpException;
|
|
|
|
/**
|
|
* Available as mautic.mt3smarketingprogram.model.call_script, or
|
|
* getModel('mt3smarketingprogram.call_script').
|
|
*
|
|
* @extends FormModel<CallScript>
|
|
*/
|
|
class CallScriptModel extends FormModel
|
|
{
|
|
public function getRepository(): CallScriptRepository
|
|
{
|
|
$repository = $this->em->getRepository(CallScript::class);
|
|
\assert($repository instanceof CallScriptRepository);
|
|
|
|
return $repository;
|
|
}
|
|
|
|
public function getPermissionBase(): string
|
|
{
|
|
return 'mt3smarketingprogram:call_scripts';
|
|
}
|
|
|
|
/**
|
|
* With no ID, returns a new script with the current user as owner.
|
|
*/
|
|
public function getEntity($id = null): ?CallScript
|
|
{
|
|
if (null === $id) {
|
|
$callScript = new CallScript();
|
|
$callScript->setOwner($this->userHelper->getUser(true));
|
|
|
|
return $callScript;
|
|
}
|
|
|
|
$callScript = parent::getEntity($id);
|
|
|
|
return $callScript instanceof CallScript ? $callScript : null;
|
|
}
|
|
|
|
/**
|
|
* Keeps the outcome positions contiguous (0..n-1) before saving.
|
|
*/
|
|
public function saveEntity($entity, $unlock = true): void
|
|
{
|
|
if ($entity instanceof CallScript) {
|
|
$entity->normalizePositions();
|
|
}
|
|
|
|
parent::saveEntity($entity, $unlock);
|
|
}
|
|
|
|
/**
|
|
* @param array<string, mixed> $options
|
|
*/
|
|
public function createForm($entity, FormFactoryInterface $formFactory, $action = null, $options = []): FormInterface
|
|
{
|
|
if (!$entity instanceof CallScript) {
|
|
throw new MethodNotAllowedHttpException(['CallScript']);
|
|
}
|
|
|
|
if (!empty($action)) {
|
|
$options['action'] = $action;
|
|
}
|
|
|
|
return $formFactory->create(CallScriptType::class, $entity, $options);
|
|
}
|
|
}
|