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\UserBundle\Entity; |
||
13 | |||
14 | use Doctrine\ORM\Query; |
||
15 | use Mautic\CoreBundle\Entity\CommonRepository; |
||
16 | |||
17 | /** |
||
18 | * PermissionRepository. |
||
19 | */ |
||
20 | class PermissionRepository extends CommonRepository |
||
21 | { |
||
22 | /** |
||
23 | * Delete all permissions for a specific role. |
||
24 | */ |
||
25 | public function purgeRolePermissions(Role $role) |
||
26 | { |
||
27 | $query = $this |
||
28 | ->createQueryBuilder('p') |
||
29 | ->delete('MauticUserBundle:Permission', 'p') |
||
30 | ->where('p.role = :role') |
||
31 | ->setParameter(':role', $role) |
||
32 | ->getQuery(); |
||
33 | $query->execute(); |
||
34 | } |
||
35 | |||
36 | /** |
||
37 | * Retrieves array of permissions for a set role. If $forForm, then the array will contain. |
||
38 | * |
||
39 | * @param bool $forForm |
||
40 | * |
||
41 | * @return array |
||
42 | */ |
||
43 | public function getPermissionsByRole(Role $role, $forForm = false) |
||
44 | { |
||
45 | $results = $this |
||
0 ignored issues
–
show
|
|||
46 | ->createQueryBuilder('p') |
||
47 | ->where('p.role = :role') |
||
48 | ->orderBy('p.bundle') |
||
49 | ->setParameter(':role', $role) |
||
50 | ->getQuery() |
||
51 | ->useResultCache(false) |
||
52 | ->getResult(Query::HYDRATE_ARRAY); |
||
53 | |||
54 | //rearrange the array to meet needs |
||
55 | $permissions = []; |
||
56 | foreach ($results as $r) { |
||
57 | if ($forForm) { |
||
58 | $permissions[$r['bundle']][$r['id']] = [ |
||
59 | 'name' => $r['name'], |
||
60 | 'bitwise' => $r['bitwise'], |
||
61 | ]; |
||
62 | } else { |
||
63 | $permissions[$r['bundle']][$r['name']] = $r['bitwise']; |
||
64 | } |
||
65 | } |
||
66 | |||
67 | return $permissions; |
||
68 | } |
||
69 | } |
||
70 |
This function has been deprecated. The supplier of the function has supplied an explanatory message.
The explanatory message should give you some clue as to whether and when the function will be removed and what other function to use instead.