<?php
define('WORKDAY',0);
define('SHORTDAY',1);
define('HOLIDAY',2);
$dayName = [
WORKDAY => 'Рабочий день',
SHORTDAY => 'Сокращенный день',
HOLIDAY => 'Нерабочий день',
];
$dayType = [
'08.05.2019' => SHORTDAY,
'09.05.2019' => HOLIDAY,
'10.05.2019' => HOLIDAY,
'11.05.2019' => HOLIDAY,
];
$inputData = [
[ 'date'=>'06.05.2019', 'fio'=>'', 'hours'=>0 ],
[ 'date'=>'07.05.2019', 'fio'=>'', 'hours'=>8 ],
[ 'date'=>'08.05.2019', 'fio'=>'', 'hours'=>7 ],
[ 'date'=>'09.05.2019', 'fio'=>'', 'hours'=>0 ],
];
$outputData = [];
foreach ($inputData as $day) {
$data = [
'name' => $day['fio'],
'date' => $day['date'],
];
if ( isset($dayType[$day['date']]) ) {
if ($dayType[$day['date']] === HOLIDAY) {
$data['type'] = HOLIDAY;
$data['hours'] = $day['hours']; // calculate for holiday
} else if ($dayType[$day['date']] === SHORTDAY) {
$data['type'] = SHORTDAY;
$data['hours'] = $day['hours']; // calculate for shortday
} else {
// unknown type of day, need exception
}
} else {
$data['type'] = WORKDAY;
$data['hours'] = $day['hours']; // calculate for workday
}
$outputData[] = $data;
}
// Print result
foreach ($outputData as $row) {
echo "<tr><td>${row['name']}</td>";
echo "<td>${row['hours']}</td>";
echo "<td>${row['date']}</td>";
echo "<td>${dayName[$row['type']]}</td></tr>";
}
select
concat(
case when t3.name is null then '' else concat(t3.name,'>') end,
case when t2.name is null then '' else concat(t2.name,'>') end,
case when t1.name is null then '' else t1.name end
) path
from test1 t1
left join test1 t2 on t2.id=t1.pid
left join test1 t3 on t3.id=t2.pid