summaryrefslogtreecommitdiff
path: root/includes/model/Shifts_model.php
diff options
context:
space:
mode:
authormsquare <msquare@notrademark.de>2016-12-27 16:02:13 +0100
committermsquare <msquare@notrademark.de>2016-12-27 16:02:13 +0100
commitb05b235cf821ec2d9fc84779d09db71dc1bf7797 (patch)
tree795dc5c5511f1d412575036188340c50c0af2edc /includes/model/Shifts_model.php
parent9975e42d3ceabfba7c43b1e59929b017749d8300 (diff)
fix slow query
Diffstat (limited to 'includes/model/Shifts_model.php')
-rw-r--r--includes/model/Shifts_model.php28
1 files changed, 12 insertions, 16 deletions
diff --git a/includes/model/Shifts_model.php b/includes/model/Shifts_model.php
index ed484e1b..74cfa356 100644
--- a/includes/model/Shifts_model.php
+++ b/includes/model/Shifts_model.php
@@ -11,7 +11,15 @@ function Shifts_by_room($room) {
}
function Shifts_by_ShiftsFilter(ShiftsFilter $shiftsFilter, $user) {
- $SQL = "SELECT DISTINCT `Shifts`.*, `ShiftTypes`.`name`, `Room`.`Name` as `room_name`, nat2.`special_needs` > 0 AS 'has_special_needs'
+ $SQL="SELECT `Shifts`.*, `ShiftTypes`.`name`, `Room`.`Name` as `room_name`
+ FROM `Shifts`
+ JOIN `Room` USING (`RID`)
+ JOIN `ShiftTypes` ON `ShiftTypes`.`id` = `Shifts`.`shifttype_id`
+ WHERE `Shifts`.`RID` IN (" . implode(',', $shiftsFilter->getRooms()) . ")
+ AND `start` BETWEEN " . $shiftsFilter->getStartTime() . " AND " . $shiftsFilter->getEndTime() . "
+ ORDER BY `Shifts`.`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`)
@@ -42,30 +50,18 @@ function Shifts_by_ShiftsFilter(ShiftsFilter $shiftsFilter, $user) {
if ($shiftsFilter->getFilled()[0] == ShiftsFilter::FILLED_FREE) {
$SQL .= "
AND (
- nat.`count` > entries.`count` OR entries.`count` IS NULL
- OR EXISTS (
- SELECT `SID`
- FROM `ShiftEntry`
- WHERE `UID` = '" . sql_escape($user['UID']) . "'
- AND `ShiftEntry`.`SID` = `Shifts`.`SID`
- )
+ nat.`count` > entries.`count` OR entries.`count` IS NULL
)";
} elseif ($_SESSION['user_shifts']['filled'][0] == ShiftsFilter::FILLED_FILLED) {
$SQL .= "
AND (
- nat.`count` <= entries.`count`
- OR EXISTS (
- SELECT `SID`
- FROM `ShiftEntry`
- WHERE `UID` = '" . sql_escape($user['UID']) . "'
- AND `ShiftEntry`.`SID` = `Shifts`.`SID`
- )
+ nat.`count` <= entries.`count`
)";
}
}
$SQL .= "
ORDER BY `start`";
-
+ */
$result = sql_select($SQL);
if ($result === false) {
engelsystem_error("Unable to load shifts by filter.");