Passed
Push — master ( 492dcf...32ce96 )
by Julito
09:05
created

ToolResourceRight   A

Complexity

Total Complexity 10

Size/Duplication

Total Lines 131
Duplicated Lines 0 %

Importance

Changes 0
Metric Value
eloc 24
dl 0
loc 131
rs 10
c 0
b 0
f 0
wmc 10

10 Methods

Rating   Name   Duplication   Size   Complexity  
A setTool() 0 5 1
A getRole() 0 3 1
A getId() 0 3 1
A getDefaultRoles() 0 5 1
A getTool() 0 3 1
A setMask() 0 5 1
A setRole() 0 5 1
A getMask() 0 3 1
A __toString() 0 3 1
A getMaskList() 0 8 1
1
<?php
2
/* For licensing terms, see /license.txt */
3
4
namespace Chamilo\CoreBundle\Entity;
5
6
use Chamilo\CoreBundle\Security\Authorization\Voter\ResourceNodeVoter;
7
use Doctrine\ORM\Mapping as ORM;
8
9
/**
10
 * ToolResourceRight.
11
 *
12
 * @ORM\Table(name="tool_resource_right")
13
 * @ORM\Entity
14
 */
15
class ToolResourceRight
16
{
17
    /**
18
     * @var int
19
     *
20
     * @ORM\Column(name="id", type="integer", nullable=false, unique=false)
21
     * @ORM\Id
22
     * @ORM\GeneratedValue
23
     */
24
    protected $id;
25
26
    /**
27
     * @var string
28
     *
29
     * @ORM\Column(name="role", type="string", length=255, nullable=false)
30
     */
31
    protected $role;
32
33
    /**
34
     * @var string
35
     *
36
     * @ORM\Column(name="mask", type="integer", nullable=false)
37
     */
38
    protected $mask;
39
40
    /**
41
     * @ORM\ManyToOne(targetEntity="Chamilo\CoreBundle\Entity\Tool", inversedBy="toolResourceRight", cascade={"persist"})
42
     * @ORM\JoinColumn(name="tool_id", referencedColumnName="id")
43
     */
44
    protected $tool;
45
46
    /**
47
     * @return string
48
     */
49
    public function __toString()
50
    {
51
        return (string) $this->getMask();
52
    }
53
54
    /**
55
     * @return Tool
56
     */
57
    public function getTool()
58
    {
59
        return $this->tool;
60
    }
61
62
    /**
63
     * @param Tool $tool
64
     *
65
     * @return $this
66
     */
67
    public function setTool($tool)
68
    {
69
        $this->tool = $tool;
70
71
        return $this;
72
    }
73
74
    /**
75
     * @return string
76
     */
77
    public function getRole()
78
    {
79
        return $this->role;
80
    }
81
82
    /**
83
     * @param string $role
84
     *
85
     * @return $this
86
     */
87
    public function setRole($role)
88
    {
89
        $this->role = $role;
90
91
        return $this;
92
    }
93
94
    /**
95
     * @return int
96
     */
97
    public function getMask()
98
    {
99
        return $this->mask;
0 ignored issues
show
Bug Best Practice introduced by
The expression return $this->mask returns the type string which is incompatible with the documented return type integer.
Loading history...
100
    }
101
102
    /**
103
     * @param mixed $mask
104
     *
105
     * @return $this
106
     */
107
    public function setMask($mask)
108
    {
109
        $this->mask = $mask;
110
111
        return $this;
112
    }
113
114
    /**
115
     * Get id.
116
     *
117
     * @return int
118
     */
119
    public function getId(): int
120
    {
121
        return $this->id;
122
    }
123
124
    /**
125
     * @return array
126
     */
127
    public static function getDefaultRoles(): array
128
    {
129
        return [
130
            'Students' => 'ROLE_STUDENT',
131
            'Teachers' => 'ROLE_TEACHER',
132
        ];
133
    }
134
135
    /**
136
     * @return array
137
     */
138
    public static function getMaskList(): array
139
    {
140
        $readerMask = ResourceNodeVoter::getReaderMask();
141
        $editorMask = ResourceNodeVoter::getEditorMask();
142
143
        return [
144
            'Can read' => $readerMask,
145
            'Can edit' => $editorMask,
146
        ];
147
    }
148
}
149