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