summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authormsquare <msquare@notrademark.de>2016-12-29 14:51:43 +0100
committermsquare <msquare@notrademark.de>2016-12-29 14:51:43 +0100
commitfe5dec73ba4048e65f3edb0f0f637600936429bf (patch)
tree79dfb4d73074e5e035c449ae7354484386bc6a4c
parent68aeb14edbcefc66e49865df2665cbca0a135e3b (diff)
bring back filtering by occupancy
-rw-r--r--includes/controller/users_controller.php38
-rw-r--r--includes/model/Shifts_model.php47
-rw-r--r--includes/pages/user_shifts.php1
-rw-r--r--includes/view/ShiftCalendarShiftRenderer.php1
4 files changed, 35 insertions, 52 deletions
diff --git a/includes/controller/users_controller.php b/includes/controller/users_controller.php
index ce7e95b2..e891f85d 100644
--- a/includes/controller/users_controller.php
+++ b/includes/controller/users_controller.php
@@ -326,16 +326,44 @@ function shiftCalendarRendererByShiftFilter(ShiftsFilter $shiftsFilter) {
$needed_angeltypes[$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) {
- $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($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);
}
?>
diff --git a/includes/model/Shifts_model.php b/includes/model/Shifts_model.php
index 07467103..9d91b00c 100644
--- a/includes/model/Shifts_model.php
+++ b/includes/model/Shifts_model.php
@@ -36,52 +36,7 @@ function Shifts_by_ShiftsFilter(ShiftsFilter $shiftsFilter) {
AND `NeededAngelTypes`.`count` > 0
AND NOT `Shifts`.`PSID` IS NULL) as tmp_shifts
- 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`";
- */
+ ORDER BY `start`";
$result = sql_select($SQL);
if ($result === false) {
engelsystem_error("Unable to load shifts by filter.");
diff --git a/includes/pages/user_shifts.php b/includes/pages/user_shifts.php
index 3ea7309c..60ac79bf 100644
--- a/includes/pages/user_shifts.php
+++ b/includes/pages/user_shifts.php
@@ -1,6 +1,5 @@
<?php
use Engelsystem\ShiftsFilter;
-use Engelsystem\ShiftCalendarRenderer;
function shifts_title() {
return _("Shifts");
diff --git a/includes/view/ShiftCalendarShiftRenderer.php b/includes/view/ShiftCalendarShiftRenderer.php
index 2a345692..c00d620b 100644
--- a/includes/view/ShiftCalendarShiftRenderer.php
+++ b/includes/view/ShiftCalendarShiftRenderer.php
@@ -21,6 +21,7 @@ class ShiftCalendarShiftRenderer {
$info_text = glyph('info-sign') . $shift['title'] . '<br>';
}
list($shift_signup_state, $shifts_row) = $this->renderShiftNeededAngeltypes($shift, $needed_angeltypes, $shift_entries, $user);
+
$class = $this->classForSignupState($shift_signup_state);
$blocks = ceil(($shift["end"] - $shift["start"]) / ShiftCalendarRenderer::SECONDS_PER_ROW);