bring back filtering by occupancy
This commit is contained in:
parent
68aeb14edb
commit
fe5dec73ba
|
@ -326,16 +326,44 @@ function shiftCalendarRendererByShiftFilter(ShiftsFilter $shiftsFilter) {
|
||||||
$needed_angeltypes[$shift['SID']] = [];
|
$needed_angeltypes[$shift['SID']] = [];
|
||||||
$shift_entries[$shift['SID']] = [];
|
$shift_entries[$shift['SID']] = [];
|
||||||
}
|
}
|
||||||
foreach ($needed_angeltypes_source as $needed_angeltype) {
|
|
||||||
$needed_angeltypes[$needed_angeltype['SID']][] = $needed_angeltype;
|
|
||||||
}
|
|
||||||
foreach ($shift_entries_source as $shift_entry) {
|
foreach ($shift_entries_source as $shift_entry) {
|
||||||
$shift_entries[$shift_entry['SID']][] = $shift_entry;
|
if (isset($shift_entries[$shift_entry['SID']])) {
|
||||||
|
$shift_entries[$shift_entry['SID']][] = $shift_entry;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
foreach ($needed_angeltypes_source as $needed_angeltype) {
|
||||||
|
if (isset($needed_angeltypes[$needed_angeltype['SID']])) {
|
||||||
|
$needed_angeltypes[$needed_angeltype['SID']][] = $needed_angeltype;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
unset($needed_angeltypes_source);
|
unset($needed_angeltypes_source);
|
||||||
unset($shift_entries_source);
|
unset($shift_entries_source);
|
||||||
|
|
||||||
return new ShiftCalendarRenderer($shifts, $needed_angeltypes, $shift_entries, $shiftsFilter);
|
if (in_array(ShiftsFilter::FILLED_FREE, $shiftsFilter->getFilled()) && in_array(ShiftsFilter::FILLED_FILLED, $shiftsFilter->getFilled())) {
|
||||||
|
return new ShiftCalendarRenderer($shifts, $needed_angeltypes, $shift_entries, $shiftsFilter);
|
||||||
|
}
|
||||||
|
|
||||||
|
$filtered_shifts = [];
|
||||||
|
foreach ($shifts as $shift) {
|
||||||
|
$needed_angels_count = 0;
|
||||||
|
foreach ($needed_angeltypes[$shift['SID']] as $needed_angeltype) {
|
||||||
|
$needed_angels_count += $needed_angeltype['count'];
|
||||||
|
}
|
||||||
|
$taken = 0;
|
||||||
|
foreach ($shift_entries[$shift['SID']] as $shift_entry) {
|
||||||
|
if ($shift_entry['freeloaded'] == 0) {
|
||||||
|
$taken ++;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if (in_array(ShiftsFilter::FILLED_FREE, $shiftsFilter->getFilled()) && $taken < $needed_angels_count) {
|
||||||
|
$filtered_shifts[] = $shift;
|
||||||
|
}
|
||||||
|
if (in_array(ShiftsFilter::FILLED_FILLED, $shiftsFilter->getFilled()) && $taken >= $needed_angels_count) {
|
||||||
|
$filtered_shifts[] = $shift;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return new ShiftCalendarRenderer($filtered_shifts, $needed_angeltypes, $shift_entries, $shiftsFilter);
|
||||||
}
|
}
|
||||||
|
|
||||||
?>
|
?>
|
||||||
|
|
|
@ -36,52 +36,7 @@ function Shifts_by_ShiftsFilter(ShiftsFilter $shiftsFilter) {
|
||||||
AND `NeededAngelTypes`.`count` > 0
|
AND `NeededAngelTypes`.`count` > 0
|
||||||
AND NOT `Shifts`.`PSID` IS NULL) as tmp_shifts
|
AND NOT `Shifts`.`PSID` IS NULL) as tmp_shifts
|
||||||
|
|
||||||
ORDER BY `start`
|
ORDER BY `start`";
|
||||||
";
|
|
||||||
/**
|
|
||||||
* $SQL = "SELECT DISTINCT `Shifts`.*, `ShiftTypes`.`name`, `Room`.`Name` as `room_name`
|
|
||||||
* FROM `Shifts`
|
|
||||||
* INNER JOIN `Room` USING (`RID`)
|
|
||||||
* INNER JOIN `ShiftTypes` ON (`ShiftTypes`.`id` = `Shifts`.`shifttype_id`)
|
|
||||||
* LEFT JOIN (
|
|
||||||
* SELECT COUNT(*) AS special_needs , nat3.`shift_id`
|
|
||||||
* FROM `NeededAngelTypes` AS nat3
|
|
||||||
* WHERE `shift_id` IS NOT NULL
|
|
||||||
* GROUP BY nat3.`shift_id`
|
|
||||||
* ) AS nat2 ON nat2.`shift_id` = `Shifts`.`SID`
|
|
||||||
* INNER JOIN `NeededAngelTypes` AS nat
|
|
||||||
* ON nat.`count` != 0
|
|
||||||
* AND nat.`angel_type_id` IN (" . implode(',', $shiftsFilter->getTypes()) . ")
|
|
||||||
* AND (
|
|
||||||
* (nat2.`special_needs` > 0 AND nat.`shift_id` = `Shifts`.`SID`)
|
|
||||||
* OR
|
|
||||||
* (
|
|
||||||
* (nat2.`special_needs` = 0 OR nat2.`special_needs` IS NULL)
|
|
||||||
* AND nat.`room_id` = `RID`)
|
|
||||||
* )
|
|
||||||
* LEFT JOIN (
|
|
||||||
* SELECT se.`SID`, se.`TID`, COUNT(*) as count
|
|
||||||
* FROM `ShiftEntry` AS se GROUP BY se.`SID`, se.`TID`
|
|
||||||
* ) AS entries ON entries.`SID` = `Shifts`.`SID` AND entries.`TID` = nat.`angel_type_id`
|
|
||||||
* WHERE `Shifts`.`RID` IN (" . implode(',', $shiftsFilter->getRooms()) . ")
|
|
||||||
* AND `start` BETWEEN " . $shiftsFilter->getStartTime() . " AND " . $shiftsFilter->getEndTime();
|
|
||||||
*
|
|
||||||
* if (count($shiftsFilter->getFilled()) == 1) {
|
|
||||||
* if ($shiftsFilter->getFilled()[0] == ShiftsFilter::FILLED_FREE) {
|
|
||||||
* $SQL .= "
|
|
||||||
* AND (
|
|
||||||
* nat.`count` > entries.`count` OR entries.`count` IS NULL
|
|
||||||
* )";
|
|
||||||
* } elseif ($_SESSION['user_shifts']['filled'][0] == ShiftsFilter::FILLED_FILLED) {
|
|
||||||
* $SQL .= "
|
|
||||||
* AND (
|
|
||||||
* nat.`count` <= entries.`count`
|
|
||||||
* )";
|
|
||||||
* }
|
|
||||||
* }
|
|
||||||
* $SQL .= "
|
|
||||||
* ORDER BY `start`";
|
|
||||||
*/
|
|
||||||
$result = sql_select($SQL);
|
$result = sql_select($SQL);
|
||||||
if ($result === false) {
|
if ($result === false) {
|
||||||
engelsystem_error("Unable to load shifts by filter.");
|
engelsystem_error("Unable to load shifts by filter.");
|
||||||
|
|
|
@ -1,6 +1,5 @@
|
||||||
<?php
|
<?php
|
||||||
use Engelsystem\ShiftsFilter;
|
use Engelsystem\ShiftsFilter;
|
||||||
use Engelsystem\ShiftCalendarRenderer;
|
|
||||||
|
|
||||||
function shifts_title() {
|
function shifts_title() {
|
||||||
return _("Shifts");
|
return _("Shifts");
|
||||||
|
|
|
@ -21,6 +21,7 @@ class ShiftCalendarShiftRenderer {
|
||||||
$info_text = glyph('info-sign') . $shift['title'] . '<br>';
|
$info_text = glyph('info-sign') . $shift['title'] . '<br>';
|
||||||
}
|
}
|
||||||
list($shift_signup_state, $shifts_row) = $this->renderShiftNeededAngeltypes($shift, $needed_angeltypes, $shift_entries, $user);
|
list($shift_signup_state, $shifts_row) = $this->renderShiftNeededAngeltypes($shift, $needed_angeltypes, $shift_entries, $user);
|
||||||
|
|
||||||
$class = $this->classForSignupState($shift_signup_state);
|
$class = $this->classForSignupState($shift_signup_state);
|
||||||
|
|
||||||
$blocks = ceil(($shift["end"] - $shift["start"]) / ShiftCalendarRenderer::SECONDS_PER_ROW);
|
$blocks = ceil(($shift["end"] - $shift["start"]) / ShiftCalendarRenderer::SECONDS_PER_ROW);
|
||||||
|
|
Loading…
Reference in New Issue