<?php
/* Вектор */
class Employee {
private $name = null;
private $rank = 1;
private $occupation = null;
private $boss = 0;
public function getName() {
return $this->name;
}
public function getRank() {
return $this->rank;
}
public function getOccupation() {
return $this->occupation;
}
public function isBoss() {
return $this->boss;
}
public function __construct($name, $rank, $occupation, $boss) {
$this->name = $name;
$this->rank = $rank;
$this->occupation = $occupation;
$this->boss = $boss;
}
}
class Department {
private $name = null;
private $employees = array();
public function getName() {
return $this->name;
}
public function getEmployees() {
return $this->employees;
}
private function addEmployee(Employee $employee) {
}
public function hireEmployee($occupation, $rank, $boss) {
$name = $occupation . " " .(string) $rank;
if ($boss) {
$name = $name . "(босс)";
}
$this->addEmployee(new Employee($name, $rank, $occupation, $boss));
}
public function getStatistics() {
$totalExpenses = 0;
$totalCofeConsumption = 0;
$totalPaperProduction = 0;
foreach ($this->employees as $name => $employee) {
$salary = 0;
$cofeConsumption = 0;
$paperProduction = 0;
switch($employee->getOccupation()) {
case "аналтик":
$salary = 800;
$cofeConsumption = 50;
$paperProduction = 5;
break;
case "инженер":
$salary = 200;
$cofeConsumption = 5;
$paperProduction = 50;
break;
case "маркетолог":
$salary = 400;
$cofeConsumption = 15;
$paperProduction = 150;
break;
case "менеджер":
$salary = 500;
$cofeConsumption = 20;
$paperProduction = 200;
break;
}
switch($employee->getRank()){
case 2:
$salary *= 1.25;
break;
case 3:
$salary *= 1.5;
break;
}
if ($employee->isBoss()) {
$salary *= 1.5;
$cofeConsumption *= 2;
$paperProduction = 0;
}
$totalExpenses += $salary;
$totalCofeConsumption += $cofeConsumption;
$totalPaperProduction += $paperProduction;
}
"totalExpenses" => $totalExpenses,
"totalCofeConsumption" => $totalCofeConsumption,
"totalPaperProduction" => $totalPaperProduction,
"numberOfEmployees" => count($this->employees) );
if (($expensesPerPage = ($totalExpenses / $totalPaperProduction)) != 0) {
$statistics["expensesPerPage"] = $expensesPerPage;
} else {
$statistics["expensesPerPage"] = 0;
}
return $statistics;
}
public function __construct($name) {
$this->name = $name;
}
}
class Company {
private $name = null;
private $departments = array();
public function getName() {
return $this->name;
}
public function getDepartments(){
return $this->departments;
}
public function createDepartment($name) {
$this->departments[$name] = new Department($name);
}
public function hireEmployee($occupation, $rank, $boss, $department) {
$this->departments[$department]->hireEmployee($occupation, $rank, $boss);
}
public function getStatistics() {
$numberOfEmployees = 0;
$totalCofeConsumption = 0;
$totalPaperProduction = 0;
$expensesPerPage = 0;
$totalExpenses = 0;
foreach ($this->departments as $name => $department) {
$statistics = $department->getStatistics();
$totalExpenses += $statistics["totalExpenses"];
$totalCofeConsumption += $statistics["totalCofeConsumption"];
$totalPaperProduction += $statistics["totalPaperProduction"];
$numberOfEmployees += $statistics["numberOfEmployees"];
$expensesPerPage += $statistics["expensesPerPage"];
}
"totalExpenses" => $totalExpenses,
"totalCofeConsumption" => $totalCofeConsumption,
"totalPaperProduction" => $totalPaperProduction,
"numberOfEmployees" => $numberOfEmployees,
"numberOfDepartments" => count($this->departments) );
if (($expensesPerPage = ($totalExpenses / $totalPaperProduction)) != 0) {
$statistics["expensesPerPage"] = $expensesPerPage;
} else {
$statistics["expensesPerPage"] = 0;
}
return $statistics;
}
public function __construct($name) {
$this->name = $name;
}
}
$vector = new Company("Вектор");
$vector->createDepartment("Департамент рекламы");
$vector->hireEmployee("менеджер", 3, 0, "Департамент рекламы");
$vector->hireEmployee("аналитик", 2, 0, "Департамент рекламы");
$vector->hireEmployee("инженер", 3, 0, "Департамент рекламы");
$vector->hireEmployee("маркетолог", 3, 1, "Департамент рекламы");
$vector->createDepartment("Департамент управления");
$vector->hireEmployee("менеджер", 3, 1, "Департамент управления");
$vector->hireEmployee("аналитик", 1, 0, "Департамент управления");
$vector->hireEmployee("аналитик", 2, 0, "Департамент управления");
$vector->hireEmployee("менеджер", 3, 0, "Департамент управления");
$vector->getStatistics();
?>