Spaces:
No application file
No application file
File size: 3,250 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 |
<?php
namespace Mautic\PointBundle\Model;
use Mautic\CoreBundle\Model\FormModel as CommonFormModel;
use Mautic\PointBundle\Entity\TriggerEvent;
use Mautic\PointBundle\Entity\TriggerEventRepository;
use Mautic\PointBundle\Form\Type\TriggerEventType;
use Symfony\Component\Form\FormFactoryInterface;
use Symfony\Component\HttpKernel\Exception\MethodNotAllowedHttpException;
/**
* @extends CommonFormModel<TriggerEvent>
*/
class TriggerEventModel extends CommonFormModel
{
/**
* @return TriggerEventRepository
*/
public function getRepository()
{
return $this->em->getRepository(TriggerEvent::class);
}
public function getPermissionBase(): string
{
return 'point:triggers';
}
public function getEntity($id = null): ?TriggerEvent
{
if (null === $id) {
return new TriggerEvent();
}
return parent::getEntity($id);
}
/**
* @throws MethodNotAllowedHttpException
*/
public function createForm($entity, FormFactoryInterface $formFactory, $action = null, $options = []): \Symfony\Component\Form\FormInterface
{
if (!$entity instanceof TriggerEvent) {
throw new MethodNotAllowedHttpException(['Trigger']);
}
if (!empty($action)) {
$options['action'] = $action;
}
return $formFactory->create(TriggerEventType::class, $entity, $options);
}
/**
* Get segments which are dependent on given segment.
*
* @param int $segmentId
*/
public function getReportIdsWithDependenciesOnSegment($segmentId): array
{
$filter = [
'force' => [
['column' => 'e.type', 'expr' => 'eq', 'value'=>'lead.changelists'],
],
];
$entities = $this->getEntities(
[
'filter' => $filter,
]
);
$dependents = [];
foreach ($entities as $entity) {
$retrFilters = $entity->getProperties();
foreach ($retrFilters as $eachFilter) {
if (in_array($segmentId, $eachFilter)) {
$dependents[] = $entity->getTrigger()->getId();
}
}
}
return $dependents;
}
/**
* @return array<int, int>
*/
public function getPointTriggerIdsWithDependenciesOnEmail(int $emailId): array
{
$filter = [
'force' => [
['column' => 'e.type', 'expr' => 'in', 'value' => ['email.send', 'email.send_to_user']],
],
];
$entities = $this->getEntities(
[
'filter' => $filter,
]
);
$triggerIds = [];
foreach ($entities as $entity) {
$properties = $entity->getProperties();
if (isset($properties['email']) && (int) $properties['email'] === $emailId) {
$triggerIds[] = $entity->getTrigger()->getId();
}
if (isset($properties['useremail']['email']) && (int) $properties['useremail']['email'] === $emailId) {
$triggerIds[] = $entity->getTrigger()->getId();
}
}
return array_unique($triggerIds);
}
}
|