|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
/* |
|
4
|
|
|
* To change this license header, choose License Headers in Project Properties. |
|
5
|
|
|
* To change this template file, choose Tools | Templates |
|
6
|
|
|
* and open the template in the editor. |
|
7
|
|
|
*/ |
|
8
|
|
|
|
|
9
|
|
|
namespace Fi\CoreBundle\Utils; |
|
10
|
|
|
|
|
11
|
|
|
use Fi\CoreBundle\Entity\Permessi; |
|
12
|
|
|
|
|
13
|
|
|
class PermessiUtils implements \JsonSerializable |
|
14
|
|
|
{ |
|
15
|
|
|
|
|
16
|
|
|
private $read = false; |
|
|
|
|
|
|
17
|
|
|
private $create = false; |
|
18
|
|
|
private $delete = false; |
|
19
|
|
|
private $edit = false; |
|
|
|
|
|
|
20
|
|
|
|
|
21
|
1 |
|
public function __construct($em, $modulo, $operatore) |
|
22
|
|
|
{ |
|
23
|
1 |
|
$permessi = $em->getRepository(Permessi::class)->findPermessoModuloOperatore($modulo, $operatore); |
|
24
|
|
|
|
|
25
|
1 |
|
if ($permessi) { |
|
26
|
|
|
if (stripos(strtoupper($permessi->getCrud()), 'C') !== false) { |
|
27
|
|
|
$this->create = true; |
|
28
|
|
|
} |
|
29
|
|
|
if (stripos(strtoupper($permessi->getCrud()), 'R') !== false) { |
|
30
|
|
|
$this->read = true; |
|
31
|
|
|
} |
|
32
|
|
|
if (stripos(strtoupper($permessi->getCrud()), 'U') !== false) { |
|
33
|
|
|
$this->edit = true; |
|
34
|
|
|
} |
|
35
|
|
|
if (stripos(strtoupper($permessi->getCrud()), 'D') !== false) { |
|
36
|
|
|
$this->delete = true; |
|
37
|
|
|
} |
|
38
|
|
|
} else { |
|
39
|
|
|
/* Per il superadmin si restituisce sempre tutti i permessi a true */ |
|
40
|
1 |
|
if ($operatore->isSuperadmin()) { |
|
41
|
1 |
|
$this->create = true; |
|
42
|
1 |
|
$this->read = true; |
|
|
|
|
|
|
43
|
1 |
|
$this->edit = true; |
|
|
|
|
|
|
44
|
1 |
|
$this->delete = true; |
|
45
|
|
|
} |
|
46
|
|
|
} |
|
47
|
1 |
|
} |
|
48
|
1 |
|
public function canRead() |
|
49
|
|
|
{ |
|
50
|
1 |
|
return $this->read; |
|
51
|
|
|
} |
|
52
|
1 |
|
public function canCreate() |
|
53
|
|
|
{ |
|
54
|
1 |
|
return $this->create; |
|
55
|
|
|
} |
|
56
|
1 |
|
public function canUpdate() |
|
57
|
|
|
{ |
|
58
|
1 |
|
return $this->edit; |
|
59
|
|
|
} |
|
60
|
1 |
|
public function canDelete() |
|
61
|
|
|
{ |
|
62
|
1 |
|
return $this->delete; |
|
63
|
|
|
} |
|
64
|
1 |
|
public function jsonSerialize() |
|
65
|
|
|
{ |
|
66
|
1 |
|
return array("read" => $this->canRead(), "create" => $this->canCreate(), "delete" => $this->canDelete(), "update" => $this->canUpdate()); |
|
|
|
|
|
|
67
|
|
|
} |
|
68
|
|
|
public function __toString() |
|
69
|
|
|
{ |
|
70
|
|
|
return json_encode($this); |
|
71
|
|
|
} |
|
72
|
|
|
} |
|
73
|
|
|
|
This check looks for multiple assignments in successive lines of code. It will report an issue if the operators are not in a straight line.
To visualize
will produce issues in the first and second line, while this second example
will produce no issues.