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\CoreBundle\Event; |
||
13 | |||
14 | use Mautic\CoreBundle\Entity\CommonEntity; |
||
15 | use Mautic\LeadBundle\Entity\Lead; |
||
16 | |||
17 | /** |
||
18 | * Class CommonEvent. |
||
19 | */ |
||
20 | class TokenReplacementEvent extends CommonEvent |
||
21 | { |
||
22 | /** |
||
23 | * @var CommonEntity|string |
||
24 | */ |
||
25 | protected $entity; |
||
26 | |||
27 | /** |
||
28 | * @var string |
||
29 | */ |
||
30 | protected $content; |
||
31 | |||
32 | /** |
||
33 | * @var Lead |
||
34 | */ |
||
35 | protected $lead; |
||
36 | |||
37 | /** |
||
38 | * @var array |
||
39 | */ |
||
40 | protected $clickthrough = []; |
||
41 | |||
42 | /** |
||
43 | * @var array |
||
44 | */ |
||
45 | protected $tokens = []; |
||
46 | |||
47 | /** |
||
48 | * Whatever the calling code wants to make available to the consumers. |
||
49 | * |
||
50 | * @var mixed |
||
51 | */ |
||
52 | protected $passthrough; |
||
53 | |||
54 | /** |
||
55 | * TokenReplacementEvent constructor. |
||
56 | * |
||
57 | * @param $content |
||
58 | * @param null $lead |
||
59 | * @param mixed $passthrough |
||
60 | */ |
||
61 | public function __construct($content, $lead = null, array $clickthrough = [], $passthrough = null) |
||
62 | { |
||
63 | if ($content instanceof CommonEntity) { |
||
64 | $this->entity = $content; |
||
65 | } |
||
66 | |||
67 | $this->content = $content; |
||
68 | $this->lead = $lead; |
||
69 | $this->clickthrough = $clickthrough; |
||
70 | $this->passthrough = $passthrough; |
||
71 | } |
||
72 | |||
73 | /** |
||
74 | * @return string |
||
75 | */ |
||
76 | public function getContent() |
||
77 | { |
||
78 | return $this->content; |
||
79 | } |
||
80 | |||
81 | /** |
||
82 | * @param string $content |
||
83 | */ |
||
84 | public function setContent($content) |
||
85 | { |
||
86 | $this->content = $content; |
||
87 | } |
||
88 | |||
89 | /** |
||
90 | * @return Lead |
||
91 | */ |
||
92 | public function getLead() |
||
93 | { |
||
94 | return $this->lead; |
||
95 | } |
||
96 | |||
97 | /** |
||
98 | * @return array |
||
99 | */ |
||
100 | public function getClickthrough() |
||
101 | { |
||
102 | if (!in_array('lead', $this->clickthrough)) { |
||
103 | if (is_array($this->lead) && !empty($this->lead['id'])) { |
||
0 ignored issues
–
show
introduced
by
Loading history...
|
|||
104 | $this->clickthrough['lead'] = $this->lead['id']; |
||
105 | } elseif ($this->lead instanceof Lead && $this->lead->getId()) { |
||
106 | $this->clickthrough['lead'] = $this->lead->getId(); |
||
107 | } |
||
108 | } |
||
109 | |||
110 | return $this->clickthrough; |
||
111 | } |
||
112 | |||
113 | /** |
||
114 | * @param array $clickthrough |
||
115 | */ |
||
116 | public function setClickthrough($clickthrough) |
||
117 | { |
||
118 | $this->clickthrough = $clickthrough; |
||
119 | } |
||
120 | |||
121 | /** |
||
122 | * @return CommonEntity|string |
||
123 | */ |
||
124 | public function getEntity() |
||
125 | { |
||
126 | return $this->entity; |
||
127 | } |
||
128 | |||
129 | /** |
||
130 | * @param $token |
||
131 | * @param $value |
||
132 | */ |
||
133 | public function addToken($token, $value) |
||
134 | { |
||
135 | $this->tokens[$token] = $value; |
||
136 | } |
||
137 | |||
138 | /** |
||
139 | * @return array |
||
140 | */ |
||
141 | public function getTokens() |
||
142 | { |
||
143 | return $this->tokens; |
||
144 | } |
||
145 | |||
146 | /** |
||
147 | * @return mixed|null |
||
148 | */ |
||
149 | public function getPassthrough() |
||
150 | { |
||
151 | return $this->passthrough; |
||
152 | } |
||
153 | } |
||
154 |