Spaces:
No application file
No application file
File size: 3,212 Bytes
d2897cd |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 |
<?php
namespace Mautic\FormBundle\Model;
use Mautic\CoreBundle\Model\FormModel as CommonFormModel;
use Mautic\FormBundle\Entity\Action;
use Mautic\FormBundle\Form\Type\ActionType;
use Symfony\Component\Form\FormFactoryInterface;
/**
* @extends CommonFormModel<Action>
*/
class ActionModel extends CommonFormModel
{
/**
* @return \Mautic\FormBundle\Entity\ActionRepository
*/
public function getRepository()
{
return $this->em->getRepository(Action::class);
}
public function getPermissionBase(): string
{
return 'form:forms';
}
public function getEntity($id = null): ?Action
{
if (null === $id) {
return new Action();
}
return parent::getEntity($id);
}
/**
* @param object $entity
* @param array $options
*/
public function createForm($entity, FormFactoryInterface $formFactory, $action = null, $options = []): \Symfony\Component\Form\FormInterface
{
if (!$entity instanceof Action) {
throw new \InvalidArgumentException('Entity must be of class Action');
}
if ($action) {
$options['action'] = $action;
}
if (empty($options['formId']) && null !== $entity->getForm()) {
$options['formId'] = $entity->getForm()->getId();
}
return $formFactory->create(ActionType::class, $entity->convertToArray(), $options);
}
/**
* Get segments which are dependent on given segment.
*
* @param int $segmentId
*/
public function getFormsIdsWithDependenciesOnSegment($segmentId): array
{
$filter = [
'force' => [
['column' => 'e.type', 'expr' => 'LIKE', 'value'=>'lead.changelist'],
],
];
$entities = $this->getEntities(
[
'filter' => $filter,
]
);
$dependents = [];
foreach ($entities as $entity) {
$properties = $entity->getProperties();
foreach ($properties as $property) {
if (in_array($segmentId, $property)) {
$dependents[] = $entity->getForm()->getId();
}
}
}
return $dependents;
}
/**
* @return array<int, int>
*/
public function getFormsIdsWithDependenciesOnEmail(int $emailId): array
{
$filter = [
'force' => [
['column' => 'e.type', 'expr' => 'LIKE', 'value' => 'email.send%'],
],
];
$entities = $this->getEntities(
[
'filter' => $filter,
]
);
$formIds = [];
foreach ($entities as $entity) {
$properties = $entity->getProperties();
if (isset($properties['email']) && (int) $properties['email'] === $emailId) {
$formIds[] = $entity->getForm()->getid();
}
if (isset($properties['useremail']['email']) && (int) $properties['useremail']['email'] === $emailId) {
$formIds[] = $entity->getForm()->getid();
}
}
return array_unique($formIds);
}
}
|