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\MauticCitrixBundle\Entity; |
||||
13 | |||||
14 | use Doctrine\ORM\Tools\Pagination\Paginator; |
||||
15 | use Mautic\CoreBundle\Entity\CommonRepository; |
||||
16 | use Mautic\LeadBundle\Entity\TimelineTrait; |
||||
17 | |||||
18 | class CitrixEventRepository extends CommonRepository |
||||
19 | { |
||||
20 | use TimelineTrait; |
||||
21 | |||||
22 | /** |
||||
23 | * Fetch the base event data from the database. |
||||
24 | * |
||||
25 | * @param string $product |
||||
26 | * @param string $eventType |
||||
27 | * @param \DateTime $fromDate |
||||
28 | * |
||||
29 | * @return mixed |
||||
30 | * |
||||
31 | * @throws \InvalidArgumentException |
||||
32 | */ |
||||
33 | public function getEvents($product, $eventType, \DateTime $fromDate = null) |
||||
34 | { |
||||
35 | $q = $this->createQueryBuilder('c'); |
||||
36 | |||||
37 | $expr = $q->expr()->andX( |
||||
38 | $q->expr()->eq('c.product', ':product'), |
||||
39 | $q->expr()->eq('c.event_type', ':eventType') |
||||
40 | ); |
||||
41 | |||||
42 | if ($fromDate) { |
||||
43 | $expr->add( |
||||
44 | $q->expr()->gte('c.event_date', ':fromDate') |
||||
45 | ); |
||||
46 | $q->setParameter('fromDate', $fromDate); |
||||
47 | } |
||||
48 | |||||
49 | $q->where($expr) |
||||
50 | ->setParameter('eventType', $eventType) |
||||
51 | ->setParameter('product', $product); |
||||
52 | |||||
53 | return $q->getQuery()->getArrayResult(); |
||||
54 | } |
||||
55 | |||||
56 | /** |
||||
57 | * @param $product |
||||
58 | * @param null $leadId |
||||
59 | * |
||||
60 | * @return array |
||||
61 | */ |
||||
62 | public function getEventsForTimeline($product, $leadId = null, array $options = []) |
||||
63 | { |
||||
64 | $eventType = null; |
||||
65 | if (is_array($product)) { |
||||
66 | list($product, $eventType) = $product; |
||||
67 | } |
||||
68 | |||||
69 | $query = $this->getEntityManager()->getConnection()->createQueryBuilder() |
||||
70 | ->from(MAUTIC_TABLE_PREFIX.'plugin_citrix_events', 'c') |
||||
71 | ->select('c.*'); |
||||
72 | |||||
73 | $query->where( |
||||
74 | $query->expr()->eq('c.product', ':product') |
||||
75 | ) |
||||
76 | ->setParameter('product', $product); |
||||
77 | |||||
78 | if ($eventType) { |
||||
79 | $query->andWhere( |
||||
80 | $query->expr()->eq('c.event_type', ':type') |
||||
81 | ) |
||||
82 | ->setParameter('type', $eventType); |
||||
83 | } |
||||
84 | |||||
85 | if ($leadId) { |
||||
86 | $query->andWhere('c.lead_id = '.(int) $leadId); |
||||
87 | } |
||||
88 | |||||
89 | if (isset($options['search']) && $options['search']) { |
||||
90 | $query->andWhere($query->expr()->orX( |
||||
91 | $query->expr()->like('c.event_name', $query->expr()->literal('%'.$options['search'].'%')), |
||||
92 | $query->expr()->like('c.product', $query->expr()->literal('%'.$options['search'].'%')) |
||||
93 | )); |
||||
94 | } |
||||
95 | |||||
96 | return $this->getTimelineResults($query, $options, 'c.event_name', 'c.event_date', [], ['event_date']); |
||||
97 | } |
||||
98 | |||||
99 | /** |
||||
100 | * @param string $product |
||||
101 | * @param string $email |
||||
102 | * |
||||
103 | * @return array |
||||
104 | */ |
||||
105 | public function findByEmail($product, $email) |
||||
106 | { |
||||
107 | return $this->findBy( |
||||
108 | [ |
||||
109 | 'product' => $product, |
||||
110 | 'email' => $email, |
||||
111 | ] |
||||
112 | ); |
||||
113 | } |
||||
114 | |||||
115 | /** |
||||
116 | * Get a list of entities. |
||||
117 | * |
||||
118 | * @return Paginator |
||||
119 | */ |
||||
120 | public function getEntities(array $args = []) |
||||
121 | { |
||||
122 | $alias = $this->getTableAlias(); |
||||
123 | |||||
124 | $q = $this->_em |
||||
125 | ->createQueryBuilder() |
||||
126 | ->select($alias) |
||||
127 | ->from('MauticCitrixBundle:CitrixEvent', $alias, $alias.'.id'); |
||||
128 | |||||
129 | $args['qb'] = $q; |
||||
130 | |||||
131 | return parent::getEntities($args); |
||||
0 ignored issues
–
show
Bug
Best Practice
introduced
by
Loading history...
|
|||||
132 | } |
||||
133 | |||||
134 | /** |
||||
135 | * @param \Doctrine\ORM\QueryBuilder|\Doctrine\DBAL\Query\QueryBuilder $q |
||||
136 | * @param $filter |
||||
137 | * |
||||
138 | * @return array |
||||
139 | */ |
||||
140 | protected function addCatchAllWhereClause($q, $filter) |
||||
141 | { |
||||
142 | return $this->addStandardCatchAllWhereClause($q, $filter, ['c.product', 'c.email', 'c.eventType', 'c.eventName']); |
||||
0 ignored issues
–
show
It seems like
$q can also be of type Doctrine\DBAL\Query\QueryBuilder ; however, parameter $q of Mautic\CoreBundle\Entity...rdCatchAllWhereClause() does only seem to accept Doctrine\ORM\QueryBuilder , maybe add an additional type check?
(
Ignorable by Annotation
)
If this is a false-positive, you can also ignore this issue in your code via the
Loading history...
|
|||||
143 | } |
||||
144 | |||||
145 | /** |
||||
146 | * @param \Doctrine\ORM\QueryBuilder|\Doctrine\DBAL\Query\QueryBuilder $q |
||||
147 | * @param $filter |
||||
148 | * |
||||
149 | * @return array |
||||
150 | */ |
||||
151 | protected function addSearchCommandWhereClause($q, $filter) |
||||
152 | { |
||||
153 | return $this->addStandardSearchCommandWhereClause($q, $filter); |
||||
154 | } |
||||
155 | |||||
156 | /** |
||||
157 | * @return array |
||||
158 | */ |
||||
159 | public function getSearchCommands() |
||||
160 | { |
||||
161 | return $this->getStandardSearchCommands(); |
||||
162 | } |
||||
163 | |||||
164 | /** |
||||
165 | * @return string |
||||
166 | */ |
||||
167 | protected function getDefaultOrder() |
||||
168 | { |
||||
169 | return [ |
||||
0 ignored issues
–
show
|
|||||
170 | [$this->getTableAlias().'.eventDate', 'ASC'], |
||||
171 | ]; |
||||
172 | } |
||||
173 | |||||
174 | /** |
||||
175 | * {@inheritdoc} |
||||
176 | * |
||||
177 | * @return string |
||||
178 | */ |
||||
179 | public function getTableAlias() |
||||
180 | { |
||||
181 | return 'c'; |
||||
182 | } |
||||
183 | } |
||||
184 |