<?php
//Вот что надо сделать:
//
//- заменить один класс на несколько, чтобы каждый соответствовал одной сущности
//- убрать из классов все что к ним не относится. Например разбор строки с должностью и уровнем надо убрать. Также, посмотреть и избавиться от лишних массивов.
//- проставить правильно private/public
//- сделать еще и вторую часть задания
class Department {
private function chooseProfession( $post ) {
switch ( $post ) {
case 'ме' :
return new Manager;
case 'ма' :
return new Marketer;
case 'ин' :
return new Ingeneer;
case 'ан' :
return new Analyst;
}
}
public function countTotalSalary( $qty , $rank , $post , $boss ) {
$employee = $this -> chooseProfession ( $post ) ;
$employee -> rank = $rank ;
$employee -> post = $post ;
$employee -> boss = $boss ;
$totalSalary = $qty * $employee -> countSalary ( ) ;
return $totalSalary ;
}
public function countTotalCoffee( $qty , $post , $boss ) {
$employee = $this -> chooseProfession ( $post ) ;
$employee -> boss = $boss ;
$coffee = $qty * $employee -> countCoffee ( ) ;
return $coffee ;
}
public function countTotalPages( $qty , $post , $boss ) {
$employee = $this -> chooseProfession ( $post ) ;
$employee -> boss = $boss ;
$pages = $qty * $employee -> countPages ( ) ;
return $pages ;
}
}
abstract class Employee extends Department {
protected $rate ;
protected $rank ;
protected $boss ;
protected $post ;
//На основе ранга определяет ставку
protected function rateScaleBasedOnRank( $rate ) {
switch ( $this -> rank ) {
case 2 :
$rate += $rate * 0.25 ;
break ;
case 3 :
$rate += $rate * 0.5 ;
}
return $rate ;
}
abstract protected function countSalary( ) ;
abstract protected function countCoffee( ) ;
abstract protected function countPages( ) ;
}
class Manager extends Employee {
protected function countSalary( ) {
$this -> rate = 500 ;
$salary = $this -> rateScaleBasedOnRank ( $this -> rate ) ;
if ( $this -> boss ) { $salary += $salary * 0.5 ; }
return $salary ;
}
protected function countCoffee( ) {
$coffee = 20 ;
if ( $this -> boss ) { $coffee *= 2 ; }
return $coffee ;
}
protected function countPages( ) {
if ( $this -> boss ) { return 0 ; }
return $pages = 200 ;
}
}
class Marketer extends Employee {
protected function countSalary( ) {
$this -> rate = 400 ;
$salary = $this -> rateScaleBasedOnRank ( $this -> rate ) ;
if ( $this -> boss ) { $salary += $salary * 0.5 ; }
return $salary ;
}
protected function countCoffee( ) {
$coffee = 15 ;
if ( $this -> boss ) { $coffee *= 2 ; }
return $coffee ;
}
protected function countPages( ) {
if ( $this -> boss ) { return 0 ; }
return $pages = 150 ;
}
}
class Ingeneer extends Employee {
protected function countSalary( ) {
$this -> rate = 200 ;
$salary = $this -> rateScaleBasedOnRank ( $this -> rate ) ;
if ( $this -> boss ) { $salary += $salary * 0.5 ; }
return $salary ;
}
protected function countCoffee( ) {
$coffee = 5 ;
if ( $this -> boss ) { $coffee *= 2 ; }
return $coffee ;
}
protected function countPages( ) {
if ( $this -> boss ) { return 0 ; }
return $pages = 50 ;
}
}
class Analyst extends Employee {
protected function countSalary( ) {
$this -> rate = 800 ;
$salary = $this -> rateScaleBasedOnRank ( $this -> rate ) ;
if ( $this -> boss ) { $salary += $salary * 0.5 ; }
return $salary ;
}
protected function countCoffee( ) {
$coffee = 50 ;
if ( $this -> boss ) { $coffee *= 2 ; }
return $coffee ;
}
protected function countPages( ) {
if ( $this -> boss ) { return 0 ; }
return $pages = 5 ;
}
}
function splitQtyPostRank( $qtyPostRank ) {
$qty = preg_split ( '/х?ме|ма|ин|ан/u' , $qtyPostRank ) ; if ( $qty [ 0 ] == "" ) {
$qty [ 0 ] = 1 ;
}
$rank = $qty [ 1 ] ; //Ранг
$qty = $qty [ 0 ] ; //Кол-во
$pattern = [ "/[0-9]/u" , "/х/u" ] ;
$post = preg_filter( $pattern , "" , $qtyPostRank ) ; //Должность
$qtyPostRank = [ "qty" => $qty , "post" => $post , "rank" => $rank ] ;
return $qtyPostRank ;
}
$purchaseDepartment = [ '9хме1' , '3хме2' , '2хме3' , 'ме2' ] ;
$sellingDepartment = [ '12хме1' , '6хма1' , '3хан1' , '2хан2' , 'ма2' ] ;
$advertisementDepartment = [ '15хма1' , '10хма2' , '8хме1' , '2хин1' , 'ма3' ] ;
$logisticsDepartment = [ '13хме1' , '5хме2' , '5хин1' , 'ме1' ] ;
$departments = [
'Закупок' => $purchaseDepartment ,
'Продаж' => $sellingDepartment ,
'Рекламы' => $advertisementDepartment ,
'Логистики' => $logisticsDepartment
] ;
$total = [
'employees' => 0 ,
'salary' => 0 ,
'coffee' => 0 ,
'pages' => 0 ,
'tugrPerPage' => 0
] ;
$avrg = [
'employees' => 0 ,
'salary' => 0 ,
'coffee' => 0 ,
'pages' => 0 ,
'tugrPerPage' => 0
] ;
// Ширина колонок
$col1 = 30 ;
$col2 = 6 ;
$col3 = 10 ;
$col4 = 10 ;
$col5 = 9 ;
$col6 = 15 ;
function padRight( $string , $length ) {
return $string ;
} else {
die ( 'Ширина столбца меньше длины строки' ) ; }
}
function padLeft( $string , $length ) {
return $string ;
} else {
return $string ;
}
}
// Шапка таблицы
echo padRight( 'Департамент' , $col1 ) ;
echo padLeft( 'сотр.' , $col2 ) ;
echo padLeft( 'тугр.' , $col3 ) ;
echo padLeft( 'кофе.' , $col4 ) ;
echo padLeft( 'стр.' , $col5 ) ;
echo padLeft( 'тугр./стр..' , $col6 ) . "\n " ;
foreach ( $departments as $name => $department ) {
$departmentTotals = [ // Результаты для опеределенного департамента
'employees' => 0 ,
'salary' => 0 ,
'coffee' => 0 ,
'pages' => 0 ,
'tugrPerPage' => 0
] ;
echo padRight( $name , $col1 ) ;
foreach ( $department as $number => $consist ) {
$qtyPostRank = splitQtyPostRank( $consist ) ;
if ( $number == count ( $purchaseDepartment ) - 1 ) { $boss = true ;
} else {
$boss = false ;
}
$qty = $qtyPostRank [ 'qty' ] ;
$post = $qtyPostRank [ 'post' ] ;
$rank = $qtyPostRank [ 'rank' ] ;
$partOfDepartment = new Department( ) ;
if ( $partOfDepartment -> countTotalPages ( $qty , $post , $boss ) != 0 ) {
$total [ 'tugrPerPage' ] += round ( $partOfDepartment -> countTotalSalary ( $qty , $rank , $post , $boss ) /
$partOfDepartment -> countTotalPages ( $qty , $post , $boss )
, 2 ) ;
$departmentTotals [ 'tugrPerPage' ] += round ( $partOfDepartment -> countTotalSalary ( $qty , $rank , $post , $boss ) /
$partOfDepartment -> countTotalPages ( $qty , $post , $boss )
, 2 ) ;
} else {
$total [ 'tugrPerPage' ] += 0 ;
$departmentTotals [ 'tugrPerPage' ] += 0 ;
}
$total [ 'employees' ] += $qty ;
$total [ 'salary' ] += $partOfDepartment -> countTotalSalary ( $qty , $rank , $post , $boss ) ;
$total [ 'coffee' ] += $partOfDepartment -> countTotalCoffee ( $qty , $post , $boss ) ;
$total [ 'pages' ] += $partOfDepartment -> countTotalPages ( $qty , $post , $boss ) ;
$departmentTotals [ 'employees' ] += $qty ;
$departmentTotals [ 'salary' ] += $partOfDepartment -> countTotalSalary ( $qty , $rank , $post , $boss ) ;
$departmentTotals [ 'coffee' ] += $partOfDepartment -> countTotalCoffee ( $qty , $post , $boss ) ;
$departmentTotals [ 'pages' ] += $partOfDepartment -> countTotalPages ( $qty , $post , $boss ) ;
}
echo padLeft( $departmentTotals [ 'employees' ] , $col2 ) ;
echo padLeft( $departmentTotals [ 'salary' ] , $col3 ) ;
echo padLeft( $departmentTotals [ 'coffee' ] , $col4 ) ;
echo padLeft( $departmentTotals [ 'pages' ] , $col5 ) ;
echo padLeft( $departmentTotals [ 'tugrPerPage' ] , $col6 ) . "\n " ;
}
$avrg [ 'employees' ] = round ( $total [ 'employees' ] / count ( $departments ) , 2 ) ; $avrg [ 'salary' ] = round ( $total [ 'salary' ] / count ( $departments ) , 2 ) ; $avrg [ 'coffee' ] = round ( $total [ 'coffee' ] / count ( $departments ) , 2 ) ; $avrg [ 'pages' ] = round ( $total [ 'pages' ] / count ( $departments ) , 2 ) ; $avrg [ 'tugrPerPage' ] = round ( $total [ 'tugrPerPage' ] / count ( $departments ) , 2 ) ; /* TEST
$post = 'ме';
$rank = 2;
$boss = false;
$test = new Department();
$test->countTotalSalary(3, $rank, $post, $boss);
$test->countTotalCoffee(3, $post, $boss);
$test->countTotalPages(14, $post, $boss);
*/
PD9waHAKCi8v0JLQvt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ICBmb3JlYWNoKCRkZXBhcnRtZW50IGFzICRudW1iZXIgPT4gJGNvbnNpc3QpIHsKICAgICAgICAkcXR5UG9zdFJhbmsgPSBzcGxpdFF0eVBvc3RSYW5rKCRjb25zaXN0KTsKICAgICAgICBpZigkbnVtYmVyID09IGNvdW50KCRwdXJjaGFzZURlcGFydG1lbnQpLTEpIHsKICAgICAgICAgICAgJGJvc3MgPSB0cnVlOwogICAgICAgIH1lbHNlewogICAgICAgICAgICAkYm9zcyA9IGZhbHNlOwogICAgICAgIH0KICAgICAgICAkcXR5ID0gJHF0eVBvc3RSYW5rWydxdHknXTsKICAgICAgICAkcG9zdCA9ICRxdHlQb3N0UmFua1sncG9zdCddOwogICAgICAgICRyYW5rID0gJHF0eVBvc3RSYW5rWydyYW5rJ107CiAgICAgICAgJHBhcnRPZkRlcGFydG1lbnQgPSBuZXcgRGVwYXJ0bWVudCgpOwogICAgICAgIGlmKCRwYXJ0T2ZEZXBhcnRtZW50LT5jb3VudFRvdGFsUGFnZXMoJHF0eSwgJHBvc3QsICRib3NzKSAhPSAwKSB7CiAgICAgICAgICAgICR0b3RhbFsndHVnclBlclBhZ2UnXSArPSByb3VuZCgKICAgICAgICAgICAgICAgICRwYXJ0T2ZEZXBhcnRtZW50LT5jb3VudFRvdGFsU2FsYXJ5KCRxdHksICRyYW5rLCAkcG9zdCwgJGJvc3MpIC8KICAgICAgICAgICAgICAgICRwYXJ0T2ZEZXBhcnRtZW50LT5jb3VudFRvdGFsUGFnZXMoJHF0eSwgJHBvc3QsICRib3NzKQogICAgICAgICAgICAgICAgLCAyKTsKICAgICAgICAgICAgJGRlcGFydG1lbnRUb3RhbHNbJ3R1Z3JQZXJQYWdlJ10gKz0gcm91bmQoCiAgICAgICAgICAgICAgICAkcGFydE9mRGVwYXJ0bWVudC0+Y291bnRUb3RhbFNhbGFyeSgkcXR5LCAkcmFuaywgJHBvc3QsICRib3NzKSAvCiAgICAgICAgICAgICAgICAkcGFydE9mRGVwYXJ0bWV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