Completed
Push — develop ( a3bac5...6cab8d )
by
unknown
07:34
created

Employee::getRole()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 1
Metric Value
c 1
b 0
f 1
dl 0
loc 3
rs 10
cc 1
eloc 2
nc 1
nop 0
1
<?php
2
/**
3
 * YAWIK
4
 *
5
 * @filesource
6
 * @license MIT
7
 * @copyright  2013 - 2016 Cross Solution <http://cross-solution.de>
8
 */
9
  
10
/** */
11
namespace Organizations\Entity;
12
13
use Auth\Entity\UserInterface;
14
use Doctrine\ODM\MongoDB\Mapping\Annotations as ODM;
15
use Core\Entity\AbstractEntity;
16
17
/**
18
 * Organization employee
19
 *
20
 * Basically a mapping to an user with additional permissions
21
 * specifical to the organization (and its jobs and applications).
22
 *
23
 * @ODM\EmbeddedDocument
24
 * @author Mathias Gelhausen <[email protected]>
25
 * @since 0.18
26
 */
27
class Employee extends AbstractEntity implements EmployeeInterface
28
{
29
    /**
30
     * The user entity
31
     *
32
     * @var \Auth\Entity\UserInterface
33
     * @ODM\ReferenceOne(targetDocument="\Auth\Entity\User", simple=true)
34
     */
35
    protected $user;
36
37
    /**
38
     * The permissions the user has for all organization relevant entities.
39
     *
40
     * @var EmployeePermissionsInterface
41
     * @ODM\EmbedOne(targetDocument="\Organizations\Entity\EmployeePermissions")
42
     */
43
    protected $permissions;
44
45
    /**
46
     * Employee role.
47
     *
48
     * @var EmployeePermissionsInterface
49
     * @ODM\Field(type="string")
50
     */
51
    protected $role;
52
53
    /**
54
     * Status of this employees' association to this organization
55
     *
56
     * @var string
57
     * @ODM\Field(type="string")
58
     */
59
    protected $status = self::STATUS_ASSIGNED;
60
61
    /**
62
     * Creates an instance.
63
     *
64
     * @param UserInterface $user
0 ignored issues
show
Documentation introduced by
Should the type for parameter $user not be null|UserInterface?

This check looks for @param annotations where the type inferred by our type inference engine differs from the declared type.

It makes a suggestion as to what type it considers more descriptive.

Most often this is a case of a parameter that can be null in addition to its declared types.

Loading history...
65
     * @param null|int|EmployeePermissionsInterface $permissions Passing an int means passing the permissions bitmask
66
     *                                                           which is passed along to the constructor of a new
67
     *                                                           instance of EmployeePermissionsInterface
68
     *
69
     * @since 0.19
70
     */
71
    public function __construct(UserInterface $user = null, $permissions = null)
72
    {
73
        if (null !== $user) {
74
            $this->setUser($user);
75
76
            if (is_int($permissions)) {
77
                $permissions = new EmployeePermissions($permissions);
78
            }
79
80
            if ($permissions instanceof EmployeePermissionsInterface) {
81
                $this->setPermissions($permissions);
82
            }
83
        }
84
    }
85
86
    public function setUser(UserInterface $user)
87
    {
88
        $this->user = $user;
89
90
        return $this;
91
    }
92
93
    public function getUser()
94
    {
95
        return $this->user;
96
    }
97
98
    public function setPermissions(EmployeePermissionsInterface $permissions)
99
    {
100
        $this->permissions = $permissions;
101
102
        return $this;
103
    }
104
105
    public function getPermissions()
106
    {
107
        if (!$this->permissions) {
108
            $this->setPermissions(new EmployeePermissions($this->permissions));
109
        }
110
111
        return $this->permissions;
112
    }
113
114
    public function setStatus($status)
115
    {
116
        if (!defined('self::STATUS_' . strtoupper($status))) {
117
            $status = self::STATUS_ASSIGNED;
118
        }
119
120
        $this->status = $status;
121
122
        return $this;
123
    }
124
125
    public function getStatus()
126
    {
127
        return $this->status;
128
    }
129
130
    /**
131
     * Sets the Role of an Employee
132
     *
133
     * @since 0.25
134
     * @param $role
135
     */
136
    public function setRole($role) {
137
        $this->role=$role;
138
    }
139
140
    /**
141
     * Gets the Role of an employee
142
     *
143
     * @since 0.25
144
     * @return EmployeePermissionsInterface
145
     */
146
    public function getRole() {
147
        return $this->role;
148
    }
149
150
    public function isAssigned()
151
    {
152
        return self::STATUS_ASSIGNED == $this->getStatus();
153
    }
154
155
    public function isPending()
156
    {
157
        return self::STATUS_PENDING == $this->getStatus();
158
    }
159
160
    public function isRejected()
161
    {
162
        return self::STATUS_REJECTED == $this->getStatus();
163
    }
164
165
    public function isUnassigned($strict = false)
166
    {
167
        return $strict
168
               ? self::STATUS_UNASSIGNED == $this->getStatus()
169
               : self::STATUS_ASSIGNED != $this->getStatus();
170
    }
171
}
172