Completed
Push — master ( ffd269...212b2a )
by Luis Ramón
34:54
created

Role::getElement()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
c 1
b 0
f 0
dl 0
loc 4
rs 10
cc 1
eloc 2
nc 1
nop 0
1
<?php
2
/*
3
  ÁTICA - Aplicación web para la gestión documental de centros educativos
4
5
  Copyright (C) 2015-2017: Luis Ramón López López
6
7
  This program is free software: you can redistribute it and/or modify
8
  it under the terms of the GNU Affero General Public License as published by
9
  the Free Software Foundation, either version 3 of the License, or
10
  (at your option) any later version.
11
12
  This program is distributed in the hope that it will be useful,
13
  but WITHOUT ANY WARRANTY; without even the implied warranty of
14
  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
15
  GNU Affero General Public License for more details.
16
17
  You should have received a copy of the GNU Affero General Public License
18
  along with this program.  If not, see [http://www.gnu.org/licenses/].
19
*/
20
21
namespace AppBundle\Entity;
22
23
use Doctrine\ORM\Mapping as ORM;
24
25
/**
26
 * @ORM\Entity
27
 */
28
class Role
29
{
30
    /**
31
     * @ORM\Id
32
     * @ORM\ManyToOne(targetEntity="Element", inversedBy="roles")
33
     * @ORM\JoinColumn(nullable=false)
34
     * @var Element
35
     */
36
    private $element;
37
38
    /**
39
     * @ORM\Id
40
     * @ORM\ManyToOne(targetEntity="User", inversedBy="assignedRoles")
41
     * @ORM\JoinColumn(nullable=false)
42
     * @var User
43
     */
44
    private $user;
45
46
    /**
47
     * @ORM\Id
48
     * @ORM\ManyToOne(targetEntity="Profile")
49
     * @ORM\JoinColumn(nullable=false)
50
     * @var Profile
51
     */
52
    private $profile;
53
54
    /**
55
     * Convert role to string
56
     *
57
     * @return string
58
     */
59
    public function __toString()
60
    {
61
        return $this->getUser().' ('.$this->getProfile()->getName($this->getUser()).')';
62
    }
63
64
    /**
65
     * Convert role to profile code
66
     *
67
     * @return string
68
     */
69
    public function getProfileCode()
70
    {
71
        return 'profile.'.$this->getProfile()->getCode().'.'.($this->getUser()->getGender());
72
    }
73
74
    /**
75
     * Convert role to profile code
76
     *
77
     * @return string
78
     */
79
    public function getProfileCodeNeutral()
80
    {
81
        return 'profile.'.$this->getProfile()->getCode().'.'.(User::GENDER_NEUTRAL);
82
    }
83
84
    /**
85
     * Set role
86
     *
87
     * @param Profile $profile
88
     *
89
     * @return Role
90
     */
91
    public function setProfile(Profile $profile)
92
    {
93
        $this->profile = $profile;
94
95
        return $this;
96
    }
97
98
    /**
99
     * Get role
100
     *
101
     * @return Profile
102
     */
103
    public function getProfile()
104
    {
105
        return $this->profile;
106
    }
107
108
    /**
109
     * Set element
110
     *
111
     * @param Element $element
112
     *
113
     * @return Role
114
     */
115
    public function setElement(Element $element)
116
    {
117
        $this->element = $element;
118
119
        return $this;
120
    }
121
122
    /**
123
     * Get element
124
     *
125
     * @return Element
126
     */
127
    public function getElement()
128
    {
129
        return $this->element;
130
    }
131
132
    /**
133
     * Set user
134
     *
135
     * @param User $user
136
     *
137
     * @return Role
138
     */
139
    public function setUser(User $user)
140
    {
141
        $this->user = $user;
142
143
        return $this;
144
    }
145
146
    /**
147
     * Get user
148
     *
149
     * @return User
150
     */
151
    public function getUser()
152
    {
153
        return $this->user;
154
    }
155
}
156