<?php
class Organisation //содержит методы для подсчета общих и средних параметров по конторе
{
public $name;
public $departments = [];
public function __construct($name)
{
$this->name = $name;
}
public function countTotalWorkers()
{
$totalWorkers = 0;
foreach($this->departments as $unit) {
$totalWorkers += $unit->countDepWorkers();
}
return $totalWorkers;
}
public function countAveregeWorkers()
{
return $this->countTotalWorkers() / count($this->departments); }
public function countTotalStuff($stuff)
{
$companyStuff = 0;
foreach ($this->departments as $dep) {
$companyStuff += $dep->countDepStuff($stuff);
}
return $companyStuff;
}
public function countAveregeStuff($stuff)
{
return $this->countTotalStuff($stuff) / count($this->departments); }
public function countTotalEfficiency()
{
$companyEfficiency = 0;
foreach ($this->departments as $dep) {
$companyEfficiency += $dep->countDepEfficiency();
}
return $companyEfficiency;
}
public function countAveregeEfficiency()
{
return $this->countTotalEfficiency() / count($this->departments); }
}
class Department
{
public $name;
public $workers = [];
public function __construct($name)
{
$this->name = $name;
}
public function addWorkers($amount, $class, $rank, $leader) {
for($i=1; $i<=$amount; $i++ ) {
$this->workers[] = new $class($rank, $leader);
}
}
public function getName()
{
return $this->name;
}
public function countDepWorkers()
{
return count($this->workers); }
public function countDepStuff($stuff)
{
$totalDepStuff = 0;
foreach ($this->workers as $worker) {
$totalDepStuff += $worker->$stuff;
}
return $totalDepStuff;
}
function countDepEfficiency()
{
return $this->countDepStuff("salary") / $this->countDepStuff("docs");
}
}
class Employee
{
public $salary;
public $coffeUsage;
public $docs;
public $rank;
public $leader;
public $defaultSalary;
public function __construct($rank, $leader) {
$this->rank = $rank;
$this->leader = $leader;
$this->setSalary();
$this->setCoffeUsage();
$this->setDocs();
}
public function setSalary ()
{
if ($this->rank == 2) {
$rankBonus = 1.25;
} elseif ($this->rank == 3) {
$rankBonus = 1.5;
} else {
$rankBonus = 1;
}
if ($this->leader == true) {
$leaderBonus = 1.5;
} else {
$leaderBonus = 1;
}
$this->salary = $this->defaultSalary * $rankBonus * $leaderBonus;
}
public function setCoffeUsage()
{
if ($this->leader) {
$this->coffeUsage = $this->defaultCoffeUsage * 2;
} else {
$this->coffeUsage = $this->defaultCoffeUsage;
}
}
public function setDocs ()
{
if ($this->leader) {
$this->docs = 0;
} else {
$this->docs = $this->defaultDocs;
}
}
}
class Manager extends Employee
{
public $defaultSalary = 500;
public $defaultCoffeUsage = 20;
public $defaultDocs = 200;
}
class MarketGuy extends Employee
{
public $defaultSalary = 400;
public $defaultCoffeUsage = 15;
public $defaultDocs = 150;
}
class Engineer extends Employee
{
public $defaultSalary = 200;
public $defaultCoffeUsage = 5;
public $defaultDocs = 50;
}
class Analyst extends Employee
{
public $defaultSalary = 800;
public $defaultCoffeUsage = 50;
public $defaultDocs = 5;
}
function padLeft ($string, $length) {
$spases = str_repeat(" ", ($length - $strLength - 1)); $string = "|" . $spases . $string;
return $string;
}
function padRight ($string, $length) {
$spases = str_repeat(" ", ($length - $strLength)); $string .= $spases;
return $string;
}
$engineer = new Engineer(1, false);
echo "зряплата: $engineer->salary\n";
// повысим человека за хорошую работу
$engineer->rank = 2;
echo "зряплата 2-го ранга: $engineer->salary\n";