Skip to content

Commit bfaef14

Browse files
committed
Added new files
1 parent 2c22e45 commit bfaef14

9 files changed

Lines changed: 331 additions & 1 deletion

File tree

Config/config.php

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,6 @@
5757
'mautic.sqlConditions' => [
5858
'route' => 'mautic_sqlConditions_index',
5959
'parent' => 'mautic.campaign.menu.index',
60-
'iconClass' => 'fa fa-database',
6160
'priority' => 70,
6261
'checks' => [
6362
'integration' => [
Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,56 @@
1+
<?php
2+
3+
/*
4+
* @copyright 2016 Mautic Contributors. All rights reserved
5+
* @author Mautic, Inc.
6+
*
7+
* @link https://mautic.org
8+
*
9+
* @license GNU/GPLv3 http://www.gnu.org/licenses/gpl-3.0.html
10+
*/
11+
12+
namespace MauticPlugin\MauticSqlConditionsBundle\EventListener;
13+
14+
use Mautic\CampaignBundle\CampaignEvents;
15+
use Mautic\CampaignBundle\Event\CampaignBuilderEvent;
16+
use Mautic\CampaignBundle\Event\ConditionEvent;
17+
use MauticPlugin\MauticSqlConditionsBundle\SqlConditionsEvents;
18+
use Symfony\Component\EventDispatcher\EventSubscriberInterface;
19+
20+
/**
21+
* Class CampaignConditionSubscriber.
22+
*/
23+
class CampaignConditionSubscriber implements EventSubscriberInterface
24+
{
25+
/**
26+
* @return array
27+
*/
28+
public static function getSubscribedEvents()
29+
{
30+
return [
31+
CampaignEvents::CAMPAIGN_ON_BUILD => ['onCampaignBuild', 0],
32+
SqlConditionsEvents::ON_CAMPAIGN_CONDITION_TRIGGER => ['onCampaignTriggerCondition', 0],
33+
];
34+
}
35+
36+
/**
37+
* @param CampaignBuilderEvent $event
38+
*/
39+
public function onCampaignBuild(CampaignBuilderEvent $event)
40+
{
41+
$event->addCondition(
42+
'sql.condition',
43+
[
44+
'label' => 'mautic.sqlConditions',
45+
'eventName' => SqlConditionsEvents::ON_CAMPAIGN_CONDITION_TRIGGER,
46+
]
47+
);
48+
}
49+
50+
/**
51+
* @param ConditionEvent $event
52+
*/
53+
public function onCampaignTriggerCondition(ConditionEvent $event)
54+
{
55+
}
56+
}

Executioner/Parser/Parser.php

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
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+
class Parser
15+
{
16+
public function parse()
17+
{
18+
}
19+
}

Executioner/QueryBuilder.php

Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
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 Doctrine\DBAL\Connections\MasterSlaveConnection;
15+
use Doctrine\ORM\EntityManager;
16+
17+
class QueryBuilder
18+
{
19+
/**
20+
* @var EntityManager
21+
*/
22+
private $entityManager;
23+
24+
/**
25+
* @var \Doctrine\DBAL\Connection
26+
*/
27+
private $connection;
28+
29+
/**
30+
* SqlExecutioner constructor.
31+
*
32+
* @param SqlConditionDetails $sqlConditionDetails
33+
*/
34+
public function __construct(EntityManager $entityManager)
35+
{
36+
$this->entityManager = $entityManager;
37+
38+
/** @var Connection $connection */
39+
$this->connection = $this->entityManager->getConnection();
40+
if ($this->connection instanceof MasterSlaveConnection) {
41+
$this->connection->connect('slave');
42+
}
43+
}
44+
45+
public function getQuery()
46+
{
47+
//getdetail
48+
// getParams
49+
$this->connection->executeQuery($query, $params);
50+
$queryBuilder = new QueryBuilder($this->connection);
51+
}
52+
53+
54+
}
Lines changed: 120 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,120 @@
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+
}

Executioner/SqlExecutioner.php

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
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+
class SqlExecutioner
15+
{
16+
/**
17+
* @var SqlConditionDetails
18+
*/
19+
private $sqlConditionDetails;
20+
21+
/**
22+
* SqlExecutioner constructor.
23+
*
24+
* @param SqlConditionDetails $sqlConditionDetails
25+
*/
26+
public function __construct(SqlConditionDetails $sqlConditionDetails)
27+
{
28+
$this->sqlConditionDetails = $sqlConditionDetails;
29+
}
30+
31+
public function runQuery()
32+
{
33+
34+
}
35+
36+
}
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
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\Token;
13+
14+
abstract class AbstractToken
15+
{
16+
protected $token;
17+
18+
19+
}

Executioner/Token/Prefix.php

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
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\Token;
13+
14+
class Prefix extends AbstractToken
15+
{
16+
protected $token = 'PREFIX';
17+
protected $value = 'PREFIX';
18+
}

SqlConditionsEvents.php

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -54,4 +54,13 @@ final class SqlConditionsEvents
5454
*/
5555
const POST_DELETE = 'mautic.sqlConditions_post_delete';
5656

57+
/**
58+
* The mautic.sqlConditions.on_campaign_condition_trigger event is dispatched when the campaign sql condition is executed.
59+
*
60+
* The event listener receives a * Mautic\CampaignBundle\Event\CampaignExecutionEvent
61+
*
62+
* @var string
63+
*/
64+
const ON_CAMPAIGN_CONDITION_TRIGGER = 'mautic.sqlConditions.on_campaign_condition_trigger';
65+
5766
}

0 commit comments

Comments
 (0)