|
| 1 | +<?php |
| 2 | + |
| 3 | +/* |
| 4 | + * @copyright 2019 Mautic Contributors. All rights reserved |
| 5 | + * @author Mautic |
| 6 | + * |
| 7 | + * @link http://mautic.org |
| 8 | + * |
| 9 | + * @license GNU/GPLv3 http://www.gnu.org/licenses/gpl-3.0.html |
| 10 | + */ |
| 11 | + |
| 12 | +namespace MauticPlugin\MauticSqlConditionsBundle\SqlExecutioner; |
| 13 | + |
| 14 | +use Mautic\CampaignBundle\Event\ConditionEvent; |
| 15 | +use MauticPlugin\MauticSqlConditionsBundle\Model\SqlConditionsModel; |
| 16 | + |
| 17 | +class SqlConditionDetails |
| 18 | +{ |
| 19 | + /** |
| 20 | + * @var SqlConditionsModel |
| 21 | + */ |
| 22 | + private $sqlConditionsModel; |
| 23 | + |
| 24 | + /** |
| 25 | + * @var ConditionEvent |
| 26 | + */ |
| 27 | + private $conditionEvent; |
| 28 | + |
| 29 | + /** |
| 30 | + * SqlCondition constructor. |
| 31 | + * |
| 32 | + * @param SqlConditionsModel $sqlConditionsModel |
| 33 | + */ |
| 34 | + public function __construct(SqlConditionsModel $sqlConditionsModel) |
| 35 | + { |
| 36 | + $this->sqlConditionsModel = $sqlConditionsModel; |
| 37 | + } |
| 38 | + |
| 39 | + /** |
| 40 | + * @param ConditionEvent $conditionEvent |
| 41 | + */ |
| 42 | + public function setConditionEvent(ConditionEvent $conditionEvent) |
| 43 | + { |
| 44 | + $this->conditionEvent = $conditionEvent; |
| 45 | + } |
| 46 | + |
| 47 | + |
| 48 | + /** |
| 49 | + * @return ConditionEvent |
| 50 | + * @throws \Exception |
| 51 | + */ |
| 52 | + public function getConditionEvent() |
| 53 | + { |
| 54 | + if (!$this->conditionEvent) { |
| 55 | + throw new \Exception('Condition event not exist'); |
| 56 | + } |
| 57 | + |
| 58 | + return $this->conditionEvent; |
| 59 | + } |
| 60 | + |
| 61 | + /** |
| 62 | + * @return mixed |
| 63 | + * @throws \Exception |
| 64 | + */ |
| 65 | + public function getSqlQuery() |
| 66 | + { |
| 67 | + $sqlConditionId = $this->getConditionEvent()->getEventConfig()['sql']; |
| 68 | + $entity = $this->sqlConditionsModel->getEntity($sqlConditionId); |
| 69 | + |
| 70 | + if ($entity) { |
| 71 | + return $entity->getSqlQuery(); |
| 72 | + } |
| 73 | + |
| 74 | + } |
| 75 | + |
| 76 | + /** |
| 77 | + * @return int |
| 78 | + * @throws \Exception |
| 79 | + */ |
| 80 | + public function getContactId() |
| 81 | + { |
| 82 | + return $this->getConditionEvent()->getLead()->getId(); |
| 83 | + } |
| 84 | + |
| 85 | + /** |
| 86 | + * @return int |
| 87 | + * @throws \Exception |
| 88 | + */ |
| 89 | + public function getCampaignId() |
| 90 | + { |
| 91 | + return $this->getConditionEvent()->getLogEntry()->getCampaign()->getId(); |
| 92 | + } |
| 93 | + |
| 94 | + /** |
| 95 | + * @return int |
| 96 | + * @throws \Exception |
| 97 | + */ |
| 98 | + public function getEventId() |
| 99 | + { |
| 100 | + return $this->getConditionEvent()->getEvent()['id']; |
| 101 | + } |
| 102 | + |
| 103 | + /** |
| 104 | + * @return int |
| 105 | + * @throws \Exception |
| 106 | + */ |
| 107 | + public function getRotation() |
| 108 | + { |
| 109 | + return $this->getConditionEvent()->getLogEntry()->getRotation(); |
| 110 | + } |
| 111 | + |
| 112 | + /** |
| 113 | + * @return string |
| 114 | + */ |
| 115 | + public function getPrefix() |
| 116 | + { |
| 117 | + return MAUTIC_TABLE_PREFIX; |
| 118 | + } |
| 119 | + |
| 120 | +} |
0 commit comments