|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
/** |
|
4
|
|
|
* Class Departament. |
|
5
|
|
|
* |
|
6
|
|
|
* Stores employees. |
|
7
|
|
|
*/ |
|
8
|
|
|
class Departament implements Unit |
|
9
|
|
|
{ |
|
10
|
|
|
/** @var string departament name */ |
|
11
|
|
|
private $name; |
|
12
|
|
|
/** @var Employee[] departament employees */ |
|
13
|
|
|
private $employees = []; |
|
14
|
|
|
|
|
15
|
|
|
/** |
|
16
|
|
|
* Departament constructor. |
|
17
|
|
|
* |
|
18
|
|
|
* @param string $name departament name |
|
19
|
|
|
*/ |
|
20
|
|
|
public function __construct(string $name) |
|
21
|
|
|
{ |
|
22
|
|
|
$this->name = $name; |
|
23
|
|
|
} |
|
24
|
|
|
|
|
25
|
|
|
/** |
|
26
|
|
|
* Adds an employee to the departament. |
|
27
|
|
|
* |
|
28
|
|
|
* @param Employee $employee new employee |
|
29
|
|
|
*/ |
|
30
|
|
|
public function addEmployee(Employee $employee): void |
|
31
|
|
|
{ |
|
32
|
|
|
$this->employees[$employee->getIdCard()->getNumber()] = $employee; |
|
33
|
|
|
$employee->setDepartament($this); |
|
34
|
|
|
} |
|
35
|
|
|
|
|
36
|
|
|
/** |
|
37
|
|
|
* Removes an employee from the departament. |
|
38
|
|
|
* |
|
39
|
|
|
* @param Employee $employee employee to remove |
|
40
|
|
|
*/ |
|
41
|
|
|
public function removeEmployee(Employee $employee): void |
|
42
|
|
|
{ |
|
43
|
|
|
unset($this->employees[$employee->getIdCard()->getNumber()]); |
|
44
|
|
|
} |
|
45
|
|
|
|
|
46
|
|
|
/** |
|
47
|
|
|
* Counts departament employees. |
|
48
|
|
|
* |
|
49
|
|
|
* @return int number of employees |
|
50
|
|
|
*/ |
|
51
|
|
|
public function getPersonCount(): int |
|
52
|
|
|
{ |
|
53
|
|
|
return count($this->employees); |
|
54
|
|
|
} |
|
55
|
|
|
|
|
56
|
|
|
/** |
|
57
|
|
|
* Getter for departament name. |
|
58
|
|
|
* |
|
59
|
|
|
* @see Departament::$name |
|
60
|
|
|
* |
|
61
|
|
|
* @return string departament name |
|
62
|
|
|
*/ |
|
63
|
|
|
public function getName(): string |
|
64
|
|
|
{ |
|
65
|
|
|
return $this->name; |
|
66
|
|
|
} |
|
67
|
|
|
|
|
68
|
|
|
/** |
|
69
|
|
|
* Getter for employees. |
|
70
|
|
|
* |
|
71
|
|
|
* @see Departament::$employees |
|
72
|
|
|
* |
|
73
|
|
|
* @return Employee[] departament employees |
|
74
|
|
|
*/ |
|
75
|
|
|
public function getEmployees(): array |
|
76
|
|
|
{ |
|
77
|
|
|
return $this->employees; |
|
78
|
|
|
} |
|
79
|
|
|
|
|
80
|
|
|
/** |
|
81
|
|
|
* Setter for departament name. |
|
82
|
|
|
* |
|
83
|
|
|
* @see Departament::$name |
|
84
|
|
|
* |
|
85
|
|
|
* @param string $name new departament name |
|
86
|
|
|
*/ |
|
87
|
|
|
public function setName(string $name): void |
|
88
|
|
|
{ |
|
89
|
|
|
$this->name = $name; |
|
90
|
|
|
} |
|
91
|
|
|
} |