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 Cdf\BiCoreBundle\Utils\Permessi; |
10
|
|
|
|
11
|
|
|
use Cdf\BiCoreBundle\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
|
11 |
|
public function __construct($em, $modulo, $operatore) |
22
|
|
|
{ |
23
|
11 |
|
$permessi = $em->getRepository(Permessi::class)->findPermessoModuloOperatore($modulo, $operatore); |
24
|
|
|
|
25
|
11 |
|
if ($permessi) { |
26
|
4 |
|
if (stripos(strtoupper($permessi->getCrud()), 'C') !== false) { |
27
|
3 |
|
$this->create = true; |
28
|
|
|
} |
29
|
4 |
|
if (stripos(strtoupper($permessi->getCrud()), 'R') !== false) { |
30
|
4 |
|
$this->read = true; |
31
|
|
|
} |
32
|
4 |
|
if (stripos(strtoupper($permessi->getCrud()), 'U') !== false) { |
33
|
3 |
|
$this->edit = true; |
34
|
|
|
} |
35
|
4 |
|
if (stripos(strtoupper($permessi->getCrud()), 'D') !== false) { |
36
|
4 |
|
$this->delete = true; |
37
|
|
|
} |
38
|
|
|
} else { |
39
|
|
|
/* Per il superadmin si restituisce sempre tutti i permessi a true */ |
40
|
10 |
|
if ($operatore->isSuperadmin()) { |
41
|
8 |
|
$this->create = true; |
42
|
8 |
|
$this->read = true; |
|
|
|
|
43
|
8 |
|
$this->edit = true; |
|
|
|
|
44
|
8 |
|
$this->delete = true; |
45
|
|
|
} |
46
|
|
|
} |
47
|
11 |
|
} |
48
|
11 |
|
public function canRead() |
49
|
|
|
{ |
50
|
11 |
|
return $this->read; |
51
|
|
|
} |
52
|
10 |
|
public function canCreate() |
53
|
|
|
{ |
54
|
10 |
|
return $this->create; |
55
|
|
|
} |
56
|
10 |
|
public function canUpdate() |
57
|
|
|
{ |
58
|
10 |
|
return $this->edit; |
59
|
|
|
} |
60
|
10 |
|
public function canDelete() |
61
|
|
|
{ |
62
|
10 |
|
return $this->delete; |
63
|
|
|
} |
64
|
10 |
|
public function jsonSerialize() |
65
|
|
|
{ |
66
|
10 |
|
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.