fork download
  1. <?php
  2. header("Content-Type: text/plain; charset=utf-8");
  3.  
  4.  
  5. class Antycrisis
  6. {
  7. static function setAnticrisysProgram3($organisation) {
  8. foreach ($organisation->departments as $dep) {
  9. $target = $dep->countManagers12();
  10. $target = ceil($target * 0.5);
  11. //var_dump($target);
  12. foreach ($dep->workers as $worker) {
  13. if ($worker->askManager() == true) {
  14. $worker->riseRank();
  15. $target--;
  16. if ($target == 0) {
  17. break;
  18. }
  19. }
  20. }
  21. }
  22. }
  23. }
  24.  
  25.  
  26. class Organisation //содержит методы для подсчета общих и средних параметров по конторе
  27. {
  28. protected $name;
  29. public $departments = array();
  30.  
  31. public function __construct($name)
  32. {
  33. $this->name = $name;
  34. }
  35.  
  36.  
  37. public function countTotalWorkers()
  38. {
  39. $totalWorkers = 0;
  40. foreach($this->departments as $unit) {
  41. $totalWorkers += $unit->countDepWorkers();
  42. }
  43. return $totalWorkers;
  44. }
  45.  
  46. public function countAveregeWorkers()
  47. {
  48. return $this->countTotalWorkers() / count($this->departments);
  49. }
  50.  
  51. public function countTotalCoffe()
  52. {
  53. $companyCoffe = 0;
  54. foreach ($this->departments as $dep) {
  55. $companyCoffe += $dep->countDepCoffe();
  56. }
  57. return $companyCoffe;
  58. }
  59.  
  60. public function countTotalSalary()
  61. {
  62. $companySalary = 0;
  63. foreach ($this->departments as $dep) {
  64. $companySalary += $dep->countDepSalary();
  65. }
  66. return $companySalary;
  67. }
  68.  
  69. public function countTotalDocs()
  70. {
  71. $companyDocs = 0;
  72. foreach ($this->departments as $dep) {
  73. $companyDocs += $dep->countDepDocs();
  74. }
  75. return $companyDocs;
  76. }
  77.  
  78.  
  79. public function countAveregeCoffe()
  80. {
  81. return $this->countTotalCoffe() / count($this->departments);
  82. }
  83.  
  84. public function countAveregeSalary()
  85. {
  86. return $this->countTotalSalary() / count($this->departments);
  87. }
  88.  
  89. public function countAveregeDocs()
  90. {
  91. return $this->countTotalDocs() / count($this->departments);
  92. }
  93.  
  94. public function countTotalEfficiency()
  95. {
  96. $companyEfficiency = 0;
  97. foreach ($this->departments as $dep) {
  98. $companyEfficiency += $dep->countDepEfficiency();
  99. }
  100. return $companyEfficiency;
  101. }
  102.  
  103. public function countAveregeEfficiency()
  104. {
  105. return $this->countTotalEfficiency() / count($this->departments);
  106. }
  107.  
  108. public function makeReport()
  109. {
  110.  
  111. }
  112.  
  113. }
  114.  
  115. class Department
  116. {
  117. protected $name;
  118. public $workers = array();
  119.  
  120. public function __construct($name)
  121. {
  122. $this->name = $name;
  123. }
  124.  
  125. public function countManagers12() {
  126. $managers12 = 0;
  127. foreach ($this->workers as $name => $worker) {
  128. if ($worker->askManager() == true) {
  129. if (($worker->rank == 1) or ($worker->rank == 2)) {
  130. $managers12++;
  131. }
  132. }
  133. }
  134. return $managers12;
  135. }
  136.  
  137. public function addEmployee($employee)
  138. {
  139. if (is_array($employee)) {
  140. $this->workers = array_merge($this->workers, $employee);
  141. } else {
  142. $this->workers[] = $employee;
  143. }
  144. }
  145.  
  146. public function getName()
  147. {
  148. return $this->name;
  149. }
  150.  
  151. public function countDepWorkers()
  152. {
  153. return count($this->workers);
  154. }
  155.  
  156. public function countDepCoffe()
  157. {
  158. $totalDepCoffe = 0;
  159. foreach ($this->workers as $worker) {
  160. $totalDepCoffe += $worker->getCoffeUsage();
  161. }
  162. return $totalDepCoffe;
  163. }
  164.  
  165. public function countDepSalary()
  166. {
  167. $totalDepSalary = 0;
  168. foreach ($this->workers as $worker) {
  169. $totalDepSalary += $worker->getSalary();
  170. }
  171. return $totalDepSalary;
  172. }
  173.  
  174. public function countDepDocs()
  175. {
  176. $totalDepDocs = 0;
  177. foreach ($this->workers as $worker) {
  178. $totalDepDocs += $worker->getDocs();
  179. }
  180. return $totalDepDocs;
  181. }
  182.  
  183. function countDepEfficiency()
  184. {
  185. return $this->countDepSalary() / $this->countDepDocs();
  186. }
  187.  
  188. }
  189.  
  190. class Employee
  191. {
  192. public $rank;
  193. protected $leader;
  194. protected $defaultSalary;
  195. protected $defaultCoffeUsage;
  196. protected $defaultDocs;
  197.  
  198. public function __construct($rank, $leader) {
  199. $this->rank = $rank;
  200. $this->leader = $leader;
  201. }
  202.  
  203. public function riseRank()
  204. {
  205. if ($this->rank == 1 or $this->rank == 2) {
  206. $this->rank++;
  207. }
  208. }
  209.  
  210. public function askManager()
  211. {
  212. if (get_class($this) == "Manager") {
  213. if (($this->rank == 1) or ($this->rank == 2)) {
  214. return true;
  215. }
  216. }
  217. return false;
  218. }
  219.  
  220. public function getSalary()
  221. {
  222. if ($this->rank == 2) {
  223. $rankBonus = 1.25;
  224. } elseif ($this->rank == 3) {
  225. $rankBonus = 1.5;
  226. } else {
  227. $rankBonus = 1;
  228. }
  229.  
  230. if ($this->leader == true) {
  231. $leaderBonus = 1.5;
  232. } else {
  233. $leaderBonus = 1;
  234. }
  235. return $this->defaultSalary * $rankBonus * $leaderBonus;
  236. }
  237.  
  238. public function getCoffeUsage()
  239. {
  240. if ($this->leader) {
  241. return $this->defaultCoffeUsage * 2;
  242. } else {
  243. return $this->defaultCoffeUsage;
  244. }
  245. }
  246.  
  247. public function getDocs()
  248. {
  249. if ($this->leader) {
  250. return 0;
  251. } else {
  252. return $this->defaultDocs;
  253. }
  254. }
  255. }
  256.  
  257. class Manager extends Employee
  258. {
  259. protected $defaultSalary = 500;
  260. protected $defaultCoffeUsage = 20;
  261. protected $defaultDocs = 200;
  262. }
  263.  
  264. class MarketGuy extends Employee
  265. {
  266. protected $defaultSalary = 400;
  267. protected $defaultCoffeUsage = 15;
  268. protected $defaultDocs = 150;
  269. }
  270.  
  271. class Engineer extends Employee
  272. {
  273. protected $defaultSalary = 200;
  274. protected $defaultCoffeUsage = 5;
  275. protected $defaultDocs = 50;
  276. }
  277.  
  278. class Analyst extends Employee
  279. {
  280. protected $defaultSalary = 800;
  281. protected $defaultCoffeUsage = 50;
  282. protected $defaultDocs = 5;
  283. }
  284.  
  285.  
  286. class Factory
  287. {
  288. static function createEmployee($amount, $class, $rank, $leader)
  289. {
  290. $employees = array();
  291. for($i=1; $i<=$amount; $i++ ) {
  292. $employees[] = new $class($rank, $leader);
  293. }
  294. return $employees;
  295. }
  296.  
  297. }
  298.  
  299. //создаю организацию:
  300. $vector = new Organisation("Вектор");
  301.  
  302. //департаменты
  303. $purchase = new Department("Департамент закупок");
  304. //заполняю планктоном
  305. $purchase->addEmployee(Factory::createEmployee(9, "Manager", 1, false));
  306. $purchase->addEmployee(Factory::createEmployee(3, "Manager", 2, false));
  307. $purchase->addEmployee(Factory::createEmployee(2, "Manager", 3, false));
  308. $purchase->addEmployee(Factory::createEmployee(2, "MarketGuy", 1, false));
  309. $purchase->addEmployee(Factory::createEmployee(1, "Manager", 2, true));
  310. $vector->departments[] = $purchase; //добавляю созданный департамент в организацию
  311.  
  312. $sales = new Department("Департамент продаж");
  313. $sales->addEmployee(Factory::createEmployee(12, "Manager", 1, false));
  314. $sales->addEmployee(Factory::createEmployee(16, "MarketGuy", 1, false));
  315. $sales->addEmployee(Factory::createEmployee(3, "Analyst", 1, false));
  316. $sales->addEmployee(Factory::createEmployee(2, "Analyst", 2, false));
  317. $sales->addEmployee(Factory::createEmployee(1, "MarketGuy", 2, true));
  318. $vector->departments[] = $sales;
  319.  
  320. $advertising = new Department("Департамент рекламы");
  321. $advertising->addEmployee(Factory::createEmployee(15, "MarketGuy", 1, false));
  322. $advertising->addEmployee(Factory::createEmployee(10, "MarketGuy", 2, false));
  323. $advertising->addEmployee(Factory::createEmployee(8, "Manager", 1, false));
  324. $advertising->addEmployee(Factory::createEmployee(2, "Engineer", 1, false));
  325. $advertising->addEmployee(Factory::createEmployee(1, "MarketGuy", 3, true));
  326. $vector->departments[] = $advertising;
  327.  
  328. $logistics = new Department("Департамент логистики");
  329. $logistics->addEmployee(Factory::createEmployee(13, "Manager", 1, false));
  330. $logistics->addEmployee(Factory::createEmployee(5, "Manager", 2, false));
  331. $logistics->addEmployee(Factory::createEmployee(5, "Engineer", 1, false));
  332. $logistics->addEmployee(Factory::createEmployee(1, "Manager", 1, true));
  333. $vector->departments[] = $logistics;
  334.  
  335.  
  336.  
  337.  
  338.  
  339. function padLeft ($string, $length) {
  340. $strLength = mb_strlen($string);
  341. $num = $length - $strLength - 1;
  342. if ($num < 0) {
  343. $num = 0;
  344. }
  345. $spases = str_repeat(" ", $num);
  346. $string = "|" . $spases . $string;
  347. return $string;
  348. }
  349.  
  350. function padRight ($string, $length) {
  351. $strLength = mb_strlen($string);
  352. $num = $length - $strLength;
  353. if ($num < 0) {
  354. $num = 0;
  355. }
  356. $spases = str_repeat(" ", $num);
  357. $string .= $spases;
  358. return $string;
  359. }
  360.  
  361.  
  362. //echo "<pre>";
  363. function makeReport($vector){
  364.  
  365. $col1 = 23;
  366. $col2 = 13;
  367. $col3 = 13;
  368.  
  369. echo padRight("Департамент", $col1) .
  370. padLeft("сотрудников", $col2) .
  371. padLeft("тугрики", $col3) .
  372. padLeft("кофе", $col3) .
  373. padLeft("документы", $col2) .
  374. padLeft("тугр./документы", $col1) .
  375. "\n";
  376.  
  377. echo "--------------------------------------------------------------------------------\n";
  378.  
  379. foreach ($vector->departments as $dep) {
  380. echo padRight($dep->getName(), $col1) .
  381. padLeft($dep->countDepWorkers(), $col2) .
  382. padLeft($dep->countDepSalary(), $col3) .
  383. padLeft($dep->countDepCoffe(), $col3) .
  384. padLeft($dep->countDepDocs(), $col2) .
  385. padLeft($dep->countDepEfficiency(), $col1) .
  386. "\n";
  387. }
  388.  
  389. echo "--------------------------------------------------------------------------------\n";
  390.  
  391. echo padRight("Среднее", $col1) .
  392. padLeft($vector->countAveregeWorkers(), $col2) .
  393. padLeft($vector->countAveregeSalary(), $col3) .
  394. padLeft($vector->countAveregeCoffe(), $col3) .
  395. padLeft($vector->countAveregeDocs(), $col2) .
  396. padLeft($vector->countAveregeEfficiency(), $col1) .
  397. "\n" ;
  398.  
  399. echo padRight("Всего", $col1) .
  400. padLeft($vector->countTotalWorkers(), $col2) .
  401. padLeft($vector->countTotalSalary(), $col3) .
  402. padLeft($vector->countTotalCoffe(), $col3) .
  403. padLeft($vector->countTotalDocs(), $col2) .
  404. "|\n\n\n";
  405.  
  406. }
  407.  
  408. makeReport($vector);
  409.  
  410. Antycrisis::setAnticrisysProgram3($vector);
  411.  
  412. makereport($vector);
  413.  
Success #stdin #stdout 0.02s 24448KB
stdin
Standard input is empty
stdout
Департамент            | сотрудников|     тугрики|        кофе|   документы|       тугр./документы
--------------------------------------------------------------------------------
Департамент закупок    |          17|      9612.5|         350|        3100|       3.1008064516129
Департамент продаж     |          34|       17550|         760|        4825|       3.6373056994819
Департамент рекламы    |          36|       16300|         575|        5450|       2.9908256880734
Департамент логистики  |          24|       11375|         425|        3850|       2.9545454545455
--------------------------------------------------------------------------------
Среднее                |       27.75|   13709.375|       527.5|     4306.25|       3.1708708234284
Всего                  |         111|     54837.5|        2110|       17225|


Департамент            | сотрудников|     тугрики|        кофе|   документы|       тугр./документы
--------------------------------------------------------------------------------
Департамент закупок    |          17|     10487.5|         350|        3100|        3.383064516129
Департамент продаж     |          34|       18300|         760|        4825|       3.7927461139896
Департамент рекламы    |          36|       16800|         575|        5450|       3.0825688073394
Департамент логистики  |          24|       12625|         425|        3850|       3.2792207792208
--------------------------------------------------------------------------------
Среднее                |       27.75|   14553.125|       527.5|     4306.25|       3.3844000541697
Всего                  |         111|     58212.5|        2110|       17225|