forked from Golenzovskiy/oop
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathclasses.php
More file actions
161 lines (139 loc) · 3.67 KB
/
classes.php
File metadata and controls
161 lines (139 loc) · 3.67 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
<?php
abstract class Employee
{
protected $id; // Id сотрудника
protected $name; // Имя сотрудника
protected $payment; // Среднемесячная выплата
abstract protected function payment();
/**
* Employee constructor.
* @param $id
* @param $name
*/
public function __construct($id, $name)
{
$this->id = $id;
$this->name = $name;
$this->payment = (int) $this->payment();
}
public function getId()
{
return $this->id;
}
/**
* @return int
*/
public function getPayment(): int
{
return $this->payment;
}
/**
* @return mixed
*/
public function getName()
{
return htmlspecialchars($this->name);
}
}
class Designer extends Employee
{
protected $salary; // Оклад сотрдуника
/**
* Designer constructor.
* @param $id
* @param $name
* @param $salary
*/
public function __construct($id, $name, $salary)
{
$this->salary = $salary;
parent::__construct($id, $name);
}
protected function payment()
{
return $this->salary;
}
}
class Seller extends Designer
{
protected $plan; // Сотрудник продал на сумму
/**
* Seller constructor.
* @param $id
* @param $name
* @param $salary
* @param $plan
*/
public function __construct($id, $name, $salary, $plan)
{
$this->plan = $plan;
parent::__construct($id, $name, $salary);
}
protected function payment()
{
$percent = $this->plan * 1.2;
return $this->salary + $percent;
}
}
class Supernumerary extends Employee
{
protected $hourlyRate; // часовая ставка
/**
* Supernumerary constructor.
* @param $id
* @param $name
* @param $hourlyRate
*/
public function __construct($id, $name, $hourlyRate)
{
$this->hourlyRate = $hourlyRate;
parent::__construct($id, $name);
}
protected function payment()
{
return 20.8 * 8 * $this->hourlyRate;
}
}
class EmployeeCollection {
protected $employees;
/**
* EmployeeCollection constructor.
* @param array $employees
*/
public function __construct(array $employees)
{
$this->employees = $employees;
}
/**
* @return array
*/
public function getEmployees(): array
{
return $this->employees;
}
public function sortByTwoFields($propertyOne, $propertyTwo)
{
usort($this->employees, function($userOne, $userTwo) use ($propertyOne, $propertyTwo) {
return $userTwo->$propertyOne() <=> $userOne->$propertyOne() ?:
$userOne->$propertyTwo() <=> $userTwo->$propertyTwo();
});
}
}
$id = 1;
foreach ($employeeData as $position => $arrEmployees) {
if ($position == 'Designer') {
foreach ($arrEmployees as $name => $value) {
$employees[] = new $position($id++, $name, $value[0]);
}
} elseif ($position == 'Seller') {
foreach ($arrEmployees as $name => $value) {
$employees[] = new $position($id++, $name, $value[0], $value[1]);
}
} elseif ($position == 'Supernumerary') {
foreach ($arrEmployees as $name => $value) {
$employees[] = new $position($id++, $name, $value[0]);
}
}
}
$collection = new EmployeeCollection($employees);
$collection->sortByTwoFields('getPayment', 'getName');