1 | <?php |
||
2 | |||
3 | /* |
||
4 | * @copyright 2014 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 Mautic\EmailBundle\Helper; |
||
13 | |||
14 | use Mautic\CoreBundle\Factory\MauticFactory; |
||
15 | use Mautic\LeadBundle\Entity\Lead; |
||
16 | |||
17 | /** |
||
18 | * Class PointEventHelper. |
||
19 | */ |
||
20 | class PointEventHelper |
||
21 | { |
||
22 | /** |
||
23 | * @param $eventDetails |
||
24 | * @param $action |
||
25 | * |
||
26 | * @return int |
||
27 | */ |
||
28 | public static function validateEmail($eventDetails, $action) |
||
29 | { |
||
30 | if (null === $eventDetails) { |
||
31 | return false; |
||
0 ignored issues
–
show
Bug
Best Practice
introduced
by
Loading history...
|
|||
32 | } |
||
33 | |||
34 | $emailId = $eventDetails->getId(); |
||
35 | |||
36 | if (isset($action['properties']['emails'])) { |
||
37 | $limitToEmails = $action['properties']['emails']; |
||
38 | } |
||
39 | |||
40 | if (!empty($limitToEmails) && !in_array($emailId, $limitToEmails)) { |
||
41 | //no points change |
||
42 | return false; |
||
43 | } |
||
44 | |||
45 | return true; |
||
46 | } |
||
47 | |||
48 | /** |
||
49 | * @param $event |
||
50 | * |
||
51 | * @return bool |
||
52 | */ |
||
53 | public static function sendEmail($event, Lead $lead, MauticFactory $factory) |
||
54 | { |
||
55 | $properties = $event['properties']; |
||
56 | $emailId = (int) $properties['email']; |
||
57 | |||
58 | /** @var \Mautic\EmailBundle\Model\EmailModel $model */ |
||
59 | $model = $factory->getModel('email'); |
||
60 | $email = $model->getEntity($emailId); |
||
61 | |||
62 | //make sure the email still exists and is published |
||
63 | if (null != $email && $email->isPublished()) { |
||
64 | $leadFields = $lead->getFields(); |
||
65 | if (isset($leadFields['core']['email']['value']) && $leadFields['core']['email']['value']) { |
||
66 | /** @var \Mautic\LeadBundle\Model\LeadModel $leadModel */ |
||
67 | $leadCredentials = $lead->getProfileFields(); |
||
68 | $leadCredentials['id'] = $lead->getId(); |
||
69 | |||
70 | $options = ['source' => ['trigger', $event['id']]]; |
||
71 | $emailSent = $model->sendEmail($email, $leadCredentials, $options); |
||
72 | |||
73 | return is_array($emailSent) ? false : true; |
||
74 | } |
||
75 | } |
||
76 | |||
77 | return false; |
||
78 | } |
||
79 | } |
||
80 |