These results are based on our legacy PHP analysis, consider migrating to our new PHP analysis engine instead. Learn more
1 | <?php |
||
2 | |||
3 | namespace Kunstmaan\AdminListBundle\AdminList\Configurator; |
||
4 | |||
5 | use Doctrine\ORM\EntityManagerInterface; |
||
6 | use Doctrine\ORM\Query; |
||
7 | use Doctrine\ORM\QueryBuilder; |
||
8 | use Kunstmaan\AdminBundle\Helper\Security\Acl\AclHelper; |
||
9 | use Kunstmaan\AdminBundle\Helper\Security\Acl\Permission\PermissionDefinition; |
||
10 | use Kunstmaan\AdminListBundle\AdminList\Filter; |
||
11 | use Kunstmaan\AdminListBundle\AdminList\FilterType\ORM\AbstractORMFilterType; |
||
12 | use Kunstmaan\AdminListBundle\AdminList\SortableInterface; |
||
13 | use Pagerfanta\Adapter\DoctrineORMAdapter; |
||
14 | use Pagerfanta\Pagerfanta; |
||
15 | use Traversable; |
||
16 | |||
17 | /** |
||
18 | * An abstract admin list configurator that can be used with the orm query builder |
||
19 | */ |
||
20 | abstract class AbstractDoctrineORMAdminListConfigurator extends AbstractAdminListConfigurator |
||
21 | { |
||
22 | /** |
||
23 | * @var EntityManagerInterface |
||
24 | */ |
||
25 | protected $em; |
||
26 | |||
27 | /** |
||
28 | * @var Query |
||
29 | */ |
||
30 | private $query = null; |
||
31 | |||
32 | /** |
||
33 | * @var Pagerfanta |
||
34 | */ |
||
35 | private $pagerfanta = null; |
||
36 | |||
37 | /** |
||
38 | * @var PermissionDefinition |
||
39 | */ |
||
40 | private $permissionDef = null; |
||
41 | |||
42 | /** |
||
43 | * @var AclHelper |
||
44 | */ |
||
45 | protected $aclHelper = null; |
||
46 | |||
47 | /** |
||
48 | * AbstractDoctrineORMAdminListConfigurator constructor. |
||
49 | * |
||
50 | * @param EntityManagerInterface $em |
||
51 | * @param AclHelper|null $aclHelper |
||
52 | */ |
||
53 | public function __construct(EntityManagerInterface $em, AclHelper $aclHelper = null) |
||
54 | { |
||
55 | $this->em = $em; |
||
56 | $this->aclHelper = $aclHelper; |
||
57 | } |
||
58 | |||
59 | /** |
||
60 | * Return the url to edit the given $item |
||
61 | * |
||
62 | * @param object $item |
||
63 | * |
||
64 | * @return array |
||
65 | */ |
||
66 | View Code Duplication | public function getEditUrlFor($item) |
|
67 | { |
||
68 | $params = array('id' => $item->getId()); |
||
69 | $params = array_merge($params, $this->getExtraParameters()); |
||
70 | |||
71 | return array( |
||
72 | 'path' => $this->getPathByConvention($this::SUFFIX_EDIT), |
||
73 | 'params' => $params |
||
74 | ); |
||
75 | } |
||
76 | |||
77 | /** |
||
78 | * Get the delete url for the given $item |
||
79 | * |
||
80 | * @param object $item |
||
81 | * |
||
82 | * @return array |
||
83 | */ |
||
84 | View Code Duplication | public function getDeleteUrlFor($item) |
|
85 | { |
||
86 | $params = array('id' => $item->getId()); |
||
87 | $params = array_merge($params, $this->getExtraParameters()); |
||
88 | |||
89 | return array( |
||
90 | 'path' => $this->getPathByConvention($this::SUFFIX_DELETE), |
||
91 | 'params' => $params |
||
92 | ); |
||
93 | } |
||
94 | |||
95 | /** |
||
96 | * @return Pagerfanta |
||
97 | */ |
||
98 | View Code Duplication | public function getPagerfanta() |
|
99 | { |
||
100 | if (is_null($this->pagerfanta)) { |
||
101 | $adapter = new DoctrineORMAdapter($this->getQuery()); |
||
102 | $this->pagerfanta = new Pagerfanta($adapter); |
||
103 | $this->pagerfanta->setNormalizeOutOfRangePages(true); |
||
104 | $this->pagerfanta->setMaxPerPage($this->getLimit()); |
||
105 | $this->pagerfanta->setCurrentPage($this->getPage()); |
||
106 | } |
||
107 | |||
108 | return $this->pagerfanta; |
||
109 | } |
||
110 | |||
111 | /** |
||
112 | * @param QueryBuilder $queryBuilder |
||
113 | */ |
||
114 | public function adaptQueryBuilder(QueryBuilder $queryBuilder) |
||
115 | { |
||
116 | $queryBuilder->where('1=1'); |
||
117 | } |
||
118 | |||
119 | /** |
||
120 | * @return int |
||
121 | */ |
||
122 | public function getCount() |
||
123 | { |
||
124 | return $this->getPagerfanta()->getNbResults(); |
||
125 | } |
||
126 | |||
127 | /** |
||
128 | * @return array|Traversable |
||
129 | */ |
||
130 | public function getItems() |
||
131 | { |
||
132 | return $this->getPagerfanta()->getCurrentPageResults(); |
||
133 | } |
||
134 | |||
135 | /** |
||
136 | * Return an iterator for all items that matches the current filtering |
||
137 | * |
||
138 | * @return \Iterator |
||
139 | */ |
||
140 | public function getIterator() |
||
141 | { |
||
142 | return $this->getQuery()->iterate(); |
||
143 | } |
||
144 | |||
145 | /** |
||
146 | * @return Query|null |
||
147 | */ |
||
148 | public function getQuery() |
||
149 | { |
||
150 | if (is_null($this->query)) { |
||
151 | $queryBuilder = $this->getQueryBuilder(); |
||
152 | $this->adaptQueryBuilder($queryBuilder); |
||
153 | |||
154 | // Apply filters |
||
155 | $filters = $this->getFilterBuilder()->getCurrentFilters(); |
||
156 | /* @var Filter $filter */ |
||
157 | foreach ($filters as $filter) { |
||
158 | /* @var AbstractORMFilterType $type */ |
||
159 | $type = $filter->getType(); |
||
160 | $type->setQueryBuilder($queryBuilder); |
||
161 | $filter->apply(); |
||
162 | } |
||
163 | |||
164 | // Apply sorting |
||
165 | if (!empty($this->orderBy)) { |
||
166 | $orderBy = $this->orderBy; |
||
167 | if (!strpos($orderBy, '.')) { |
||
168 | $orderBy = 'b.' . $orderBy; |
||
169 | } |
||
170 | $queryBuilder->orderBy($orderBy, ($this->orderDirection == 'DESC' ? 'DESC' : 'ASC')); |
||
171 | } |
||
172 | |||
173 | // Apply other changes |
||
174 | $this->finishQueryBuilder($queryBuilder); |
||
175 | |||
176 | // Apply ACL restrictions (if applicable) |
||
177 | if (!is_null($this->permissionDef) && !is_null($this->aclHelper)) { |
||
178 | $this->query = $this->aclHelper->apply($queryBuilder, $this->permissionDef); |
||
179 | } else { |
||
180 | $this->query = $queryBuilder->getQuery(); |
||
181 | } |
||
182 | } |
||
183 | |||
184 | return $this->query; |
||
185 | } |
||
186 | |||
187 | /** |
||
188 | * @param QueryBuilder $queryBuilder |
||
189 | */ |
||
190 | protected function finishQueryBuilder(QueryBuilder $queryBuilder) |
||
191 | { |
||
192 | if ($this instanceof SortableInterface) { |
||
193 | $queryBuilder->addOrderBy('b.' . $this->getSortableField()); |
||
0 ignored issues
–
show
|
|||
194 | } |
||
195 | } |
||
196 | |||
197 | /** |
||
198 | * @return QueryBuilder |
||
199 | */ |
||
200 | protected function getQueryBuilder() |
||
201 | { |
||
202 | $queryBuilder = $this->em |
||
203 | ->getRepository($this->getRepositoryName()) |
||
204 | ->createQueryBuilder('b'); |
||
205 | |||
206 | return $queryBuilder; |
||
207 | } |
||
208 | |||
209 | /** |
||
210 | * Get current permission definition. |
||
211 | * |
||
212 | * @return PermissionDefinition|null |
||
213 | */ |
||
214 | public function getPermissionDefinition() |
||
215 | { |
||
216 | return $this->permissionDef; |
||
217 | } |
||
218 | |||
219 | /** |
||
220 | * Set permission definition. |
||
221 | * |
||
222 | * @param PermissionDefinition $permissionDef |
||
223 | * |
||
224 | * @return AbstractDoctrineORMAdminListConfigurator |
||
225 | */ |
||
226 | public function setPermissionDefinition(PermissionDefinition $permissionDef) |
||
227 | { |
||
228 | $this->permissionDef = $permissionDef; |
||
229 | |||
230 | return $this; |
||
231 | } |
||
232 | |||
233 | /** |
||
234 | * @param EntityManagerInterface $em |
||
235 | * |
||
236 | * @return AbstractDoctrineORMAdminListConfigurator |
||
237 | */ |
||
238 | public function setEntityManager(EntityManagerInterface $em) |
||
239 | { |
||
240 | $this->em = $em; |
||
241 | |||
242 | return $this; |
||
243 | } |
||
244 | |||
245 | /** |
||
246 | * @return EntityManagerInterface |
||
247 | */ |
||
248 | public function getEntityManager() |
||
249 | { |
||
250 | return $this->em; |
||
251 | } |
||
252 | } |
||
253 |
This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.
This is most likely a typographical error or the method has been renamed.