From 6ff5e7997a2e70178513824d8a1d1eca14622e46 Mon Sep 17 00:00:00 2001 From: msquare Date: Sun, 2 Oct 2016 21:19:03 +0200 Subject: split user_shifts into different functions --- includes/engelsystem_provider.php | 2 ++ 1 file changed, 2 insertions(+) (limited to 'includes/engelsystem_provider.php') diff --git a/includes/engelsystem_provider.php b/includes/engelsystem_provider.php index 84a73275..979102e0 100644 --- a/includes/engelsystem_provider.php +++ b/includes/engelsystem_provider.php @@ -28,6 +28,7 @@ require_once realpath(__DIR__ . '/../includes/view/AngelTypes_view.php'); require_once realpath(__DIR__ . '/../includes/view/EventConfig_view.php'); require_once realpath(__DIR__ . '/../includes/view/Questions_view.php'); require_once realpath(__DIR__ . '/../includes/view/Rooms_view.php'); +require_once realpath(__DIR__ . '/../includes/view/ShiftCalendarRenderer.php'); require_once realpath(__DIR__ . '/../includes/view/Shifts_view.php'); require_once realpath(__DIR__ . '/../includes/view/ShiftEntry_view.php'); require_once realpath(__DIR__ . '/../includes/view/ShiftTypes_view.php'); @@ -38,6 +39,7 @@ require_once realpath(__DIR__ . '/../includes/view/User_view.php'); require_once realpath(__DIR__ . '/../includes/controller/angeltypes_controller.php'); require_once realpath(__DIR__ . '/../includes/controller/event_config_controller.php'); require_once realpath(__DIR__ . '/../includes/controller/rooms_controller.php'); +require_once realpath(__DIR__ . '/../includes/controller/shift_entries_controller.php'); require_once realpath(__DIR__ . '/../includes/controller/shifts_controller.php'); require_once realpath(__DIR__ . '/../includes/controller/shifttypes_controller.php'); require_once realpath(__DIR__ . '/../includes/controller/users_controller.php'); -- cgit v1.3.1 From 5e66007f0629ab5a9b4449ca6ea4070f372bd656 Mon Sep 17 00:00:00 2001 From: msquare Date: Sun, 2 Oct 2016 23:00:01 +0200 Subject: introduce ShiftsFilter --- includes/engelsystem_provider.php | 1 + includes/model/Shifts_model.php | 65 +++- includes/pages/user_shifts.php | 732 ++++++++++++++------------------------ includes/sys_page.php | 13 + templates/user_shifts.html | 1 - 5 files changed, 351 insertions(+), 461 deletions(-) (limited to 'includes/engelsystem_provider.php') diff --git a/includes/engelsystem_provider.php b/includes/engelsystem_provider.php index 979102e0..c6d34d1a 100644 --- a/includes/engelsystem_provider.php +++ b/includes/engelsystem_provider.php @@ -18,6 +18,7 @@ require_once realpath(__DIR__ . '/../includes/model/NeededAngelTypes_model.php') require_once realpath(__DIR__ . '/../includes/model/Room_model.php'); require_once realpath(__DIR__ . '/../includes/model/ShiftEntry_model.php'); require_once realpath(__DIR__ . '/../includes/model/Shifts_model.php'); +require_once realpath(__DIR__ . '/../includes/model/ShiftsFilter.php'); require_once realpath(__DIR__ . '/../includes/model/ShiftTypes_model.php'); require_once realpath(__DIR__ . '/../includes/model/UserAngelTypes_model.php'); require_once realpath(__DIR__ . '/../includes/model/UserDriverLicenses_model.php'); diff --git a/includes/model/Shifts_model.php b/includes/model/Shifts_model.php index a827c6b5..b83d1a00 100644 --- a/includes/model/Shifts_model.php +++ b/includes/model/Shifts_model.php @@ -1,9 +1,70 @@ 0 AS 'has_special_needs' + 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 + OR EXISTS ( + SELECT `SID` + FROM `ShiftEntry` + WHERE `UID` = '" . sql_escape($user['UID']) . "' + AND `ShiftEntry`.`SID` = `Shifts`.`SID` + ) + )"; + } elseif ($_SESSION['user_shifts']['filled'][0] == 1) { + $SQL .= " + AND ( + nat.`count` <= entries.`count` + OR EXISTS ( + SELECT `SID` + FROM `ShiftEntry` + WHERE `UID` = '" . sql_escape($user['UID']) . "' + AND `ShiftEntry`.`SID` = `Shifts`.`SID` + ) + )"; + } + } + $SQL .= " + ORDER BY `start`"; + + return sql_select($SQL); +} /** * Check if a shift collides with other shifts (in time). - * @param Shift $shift - * @param array $shifts + * + * @param Shift $shift + * @param array $shifts */ function Shift_collides($shift, $shifts) { foreach ($shifts as $other_shift) { diff --git a/includes/pages/user_shifts.php b/includes/pages/user_shifts.php index 77ae8582..d3ad0aa2 100644 --- a/includes/pages/user_shifts.php +++ b/includes/pages/user_shifts.php @@ -1,4 +1,5 @@ setUserShiftsAdmin($user_shifts_admin); + $shiftsFilter->setFilled(check_request_int_array('filled')); + $shiftsFilter->setRooms(check_request_int_array('rooms')); + $shiftsFilter->setTypes(check_request_int_array('types')); + + $day = date('Y-m-d', time()); + $start_day = in_array($day, $days) ? $day : min($days); + if (isset($_REQUEST['start_day']) && in_array($_REQUEST['start_day'], $days)) { + $start_day = $_REQUEST['start_day']; + } + + $start_time = date("H:i"); + if (isset($_REQUEST['start_time']) && preg_match('#^\d{1,2}:\d\d$#', $_REQUEST['start_time'])) { + $start_time = $_REQUEST['start_time']; + } + + $day = date('Y-m-d', time() + 24 * 60 * 60); + $end_day = in_array($day, $days) ? $day : max($days); + if (isset($_REQUEST['end_day']) && in_array($_REQUEST['end_day'], $days)) { + $end_day = $_REQUEST['end_day']; + } + + $end_time = date("H:i"); + if (isset($_REQUEST['end_time']) && preg_match('#^\d{1,2}:\d\d$#', $_REQUEST['end_time'])) { + $end_time = $_REQUEST['end_time']; + } + + if ($start_day > $end_day) { + $end_day = $start_day; + } + if ($start_day == $end_day && $start_time >= $end_time) { + $end_time = "23:59"; + } + + $startdatetime = DateTime::createFromFormat("Y-m-d H:i", $start_day . " " . $start_time); + $shiftsFilter->setStartTime($startdatetime->getTimestamp()); + + $enddatetime = DateTime::createFromFormat("Y-m-d H:i", $end_day . " " . $end_time); + $shiftsFilter->setEndTime($enddatetime->getTimestamp()); + + return $shiftsFilter; +} + function view_user_shifts() { global $user, $privileges; global $ical_shifts; @@ -43,7 +95,6 @@ function view_user_shifts() { } $rooms = sql_select("SELECT `RID` AS `id`, `Name` AS `name` FROM `Room` WHERE `show`='Y' ORDER BY `Name`"); - if (count($rooms) == 0) { error(_("The administration has not configured any rooms yet.")); redirect('?'); @@ -57,137 +108,32 @@ function view_user_shifts() { if (empty($types)) { $types = sql_select("SELECT `id`, `name` FROM `AngelTypes` WHERE `restricted` = 0"); } - $filled = [ - [ - 'id' => '1', - 'name' => _("occupied") - ], - [ - 'id' => '0', - 'name' => _("free") - ] - ]; if (count($types) == 0) { error(_("The administration has not configured any angeltypes yet - or you are not subscribed to any angeltype.")); redirect('?'); } - if (! isset($_SESSION['user_shifts'])) { - $_SESSION['user_shifts'] = []; + if (! isset($_SESSION['ShiftsFilter'])) { + $room_ids = array_map('get_ids_from_array', $rooms); + $type_ids = array_map('get_ids_from_array', $types); + $_SESSION['ShiftsFilter'] = new ShiftsFilter(in_array('user_shifts_admin', $privileges), $room_ids, $type_ids); } + $_SESSION['ShiftsFilter'] = update_ShiftsFilter($_SESSION['ShiftsFilter'], in_array('user_shifts_admin', $privileges), $days); + $shiftsFilter = $_SESSION['ShiftsFilter']; - if (! isset($_SESSION['user_shifts']['filled'])) { - // User shift admins see free and occupied shifts by default - $_SESSION['user_shifts']['filled'] = in_array('user_shifts_admin', $privileges) ? [ - 0, - 1 - ] : [ - 0 - ]; + $shifts = Shifts_by_ShiftsFilter($shiftsFilter, $user); + if ($shifts === false) { + engelsystem_error("Unable to load shifts by filter."); } - foreach ([ - 'rooms', - 'types', - 'filled' - ] as $key) { - if (isset($_REQUEST[$key])) { - $filtered = array_filter($_REQUEST[$key], 'is_numeric'); - if (! empty($filtered)) { - $_SESSION['user_shifts'][$key] = $filtered; - } - unset($filtered); - } - if (! isset($_SESSION['user_shifts'][$key])) { - $_SESSION['user_shifts'][$key] = array_map('get_ids_from_array', $$key); - } - } - - if (isset($_REQUEST['rooms'])) { - if (isset($_REQUEST['new_style'])) { - $_SESSION['user_shifts']['new_style'] = true; - } else { - $_SESSION['user_shifts']['new_style'] = false; - } - } - if (! isset($_SESSION['user_shifts']['new_style'])) { - $_SESSION['user_shifts']['new_style'] = true; - } - foreach ([ - 'start', - 'end' - ] as $key) { - if (isset($_REQUEST[$key . '_day']) && in_array($_REQUEST[$key . '_day'], $days)) { - $_SESSION['user_shifts'][$key . '_day'] = $_REQUEST[$key . '_day']; - } - if (isset($_REQUEST[$key . '_time']) && preg_match('#^\d{1,2}:\d\d$#', $_REQUEST[$key . '_time'])) { - $_SESSION['user_shifts'][$key . '_time'] = $_REQUEST[$key . '_time']; - } - if (! isset($_SESSION['user_shifts'][$key . '_day'])) { - $time = date('Y-m-d', time() + ($key == 'end' ? 24 * 60 * 60 : 0)); - $_SESSION['user_shifts'][$key . '_day'] = in_array($time, $days) ? $time : ($key == 'end' ? max($days) : min($days)); - } - if (! isset($_SESSION['user_shifts'][$key . '_time'])) { - $_SESSION['user_shifts'][$key . '_time'] = date('H:i'); - } - } - if ($_SESSION['user_shifts']['start_day'] > $_SESSION['user_shifts']['end_day']) { - $_SESSION['user_shifts']['end_day'] = $_SESSION['user_shifts']['start_day']; - } - if ($_SESSION['user_shifts']['start_day'] == $_SESSION['user_shifts']['end_day'] && $_SESSION['user_shifts']['start_time'] >= $_SESSION['user_shifts']['end_time']) { - $_SESSION['user_shifts']['end_time'] = '23:59'; - } - - $starttime = now(); - if (isset($_SESSION['user_shifts']['start_day'])) { - $starttime = DateTime::createFromFormat("Y-m-d H:i", $_SESSION['user_shifts']['start_day'] . $_SESSION['user_shifts']['start_time']); - $starttime = $starttime->getTimestamp(); - } - - $endtime = now() + 24 * 60 * 60; - if (isset($_SESSION['user_shifts']['end_day'])) { - $endtime = DateTime::createFromFormat("Y-m-d H:i", $_SESSION['user_shifts']['end_day'] . $_SESSION['user_shifts']['end_time']); - $endtime = $endtime->getTimestamp(); - } - - if (! isset($_SESSION['user_shifts']['rooms']) || count($_SESSION['user_shifts']['rooms']) == 0) { - $_SESSION['user_shifts']['rooms'] = [ - 0 - ]; - } - - $SQL = "SELECT DISTINCT `Shifts`.*, `ShiftTypes`.`name`, `Room`.`Name` as `room_name`, nat2.`special_needs` > 0 AS 'has_special_needs' - 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(',', $_SESSION['user_shifts']['types']) . ") 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(',', $_SESSION['user_shifts']['rooms']) . ") - AND `start` BETWEEN " . $starttime . " AND " . $endtime; - - if (count($_SESSION['user_shifts']['filled']) == 1) { - if ($_SESSION['user_shifts']['filled'][0] == 0) { - $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`))"; - } elseif ($_SESSION['user_shifts']['filled'][0] == 1) { - $SQL .= " - AND (nat.`count` <= entries.`count` OR EXISTS (SELECT `SID` FROM `ShiftEntry` WHERE `UID` = '" . sql_escape($user['UID']) . "' AND `ShiftEntry`.`SID` = `Shifts`.`SID`))"; - } - } - $SQL .= " - ORDER BY `start`"; - - $shifts = sql_select($SQL); - $ownshifts_source = sql_select(" SELECT `ShiftTypes`.`name`, `Shifts`.* FROM `Shifts` INNER JOIN `ShiftTypes` ON (`ShiftTypes`.`id` = `Shifts`.`shifttype_id`) INNER JOIN `ShiftEntry` ON (`Shifts`.`SID` = `ShiftEntry`.`SID` AND `ShiftEntry`.`UID` = '" . sql_escape($user['UID']) . "') - WHERE `Shifts`.`RID` IN (" . implode(',', $_SESSION['user_shifts']['rooms']) . ") - AND `start` BETWEEN " . $starttime . " AND " . $endtime); + WHERE `Shifts`.`RID` IN (" . implode(',', $shiftsFilter->getRooms()) . ") + AND `start` BETWEEN " . $shiftsFilter->getStartTime() . " AND " . $shiftsFilter->getEndTime()); $ownshifts = []; foreach ($ownshifts_source as $ownshift) { $ownshifts[$ownshift['SID']] = $ownshift; @@ -198,368 +144,255 @@ function view_user_shifts() { /* * [0] => Array ( [SID] => 1 [start] => 1355958000 [end] => 1355961600 [RID] => 1 [name] => [URL] => [PSID] => [room_name] => test1 [has_special_needs] => 1 [is_full] => 0 ) */ - if ($_SESSION['user_shifts']['new_style']) { - $first = 15 * 60 * floor($starttime / (15 * 60)); - $maxshow = ceil(($endtime - $first) / (60 * 15)); - $block = []; - $todo = []; - $myrooms = $rooms; - - // delete un-selected rooms from array - foreach ($myrooms as $k => $v) { - if (array_search($v["id"], $_SESSION['user_shifts']['rooms']) === false) { - unset($myrooms[$k]); - } - // initialize $block array - $block[$v["id"]] = array_fill(0, $maxshow, 0); + $first = 15 * 60 * floor($shiftsFilter->getStartTime() / (15 * 60)); + $maxshow = ceil(($shiftsFilter->getEndTime() - $first) / (60 * 15)); + $block = []; + $todo = []; + $myrooms = $rooms; + + // delete un-selected rooms from array + foreach ($myrooms as $k => $v) { + if (array_search($v["id"], $shiftsFilter->getRooms()) === false) { + unset($myrooms[$k]); } - - // calculate number of parallel shifts in each timeslot for each room - foreach ($shifts as $k => $shift) { - $rid = $shift["RID"]; - $blocks = ($shift["end"] - $shift["start"]) / (15 * 60); - $firstblock = floor(($shift["start"] - $first) / (15 * 60)); - for ($i = $firstblock; $i < $blocks + $firstblock && $i < $maxshow; $i ++) { - $block[$rid][$i] ++; - } - $shifts[$k]['own'] = in_array($shift['SID'], array_keys($ownshifts)); + // initialize $block array + $block[$v["id"]] = array_fill(0, $maxshow, 0); + } + + // calculate number of parallel shifts in each timeslot for each room + foreach ($shifts as $k => $shift) { + $rid = $shift["RID"]; + $blocks = ($shift["end"] - $shift["start"]) / (15 * 60); + $firstblock = floor(($shift["start"] - $first) / (15 * 60)); + for ($i = $firstblock; $i < $blocks + $firstblock && $i < $maxshow; $i ++) { + $block[$rid][$i] ++; } - - $shifts_table = '
'; - foreach ($myrooms as $key => $room) { - $rid = $room["id"]; - if (array_sum($block[$rid]) == 0) { - // do not display columns without entries - unset($block[$rid]); - unset($myrooms[$key]); - continue; - } - $colspan = call_user_func_array('max', $block[$rid]); - if ($colspan == 0) { - $colspan = 1; - } - $todo[$rid] = array_fill(0, $maxshow, $colspan); - $shifts_table .= " 1) ? ' colspan="' . $colspan . '"' : '') . ">" . Room_name_render([ - 'RID' => $room['id'], - 'Name' => $room['name'] - ]) . "\n"; + $shifts[$k]['own'] = in_array($shift['SID'], array_keys($ownshifts)); + } + + $shifts_table = '
-
'; + foreach ($myrooms as $key => $room) { + $rid = $room["id"]; + if (array_sum($block[$rid]) == 0) { + // do not display columns without entries + unset($block[$rid]); + unset($myrooms[$key]); + continue; } - unset($block, $blocks, $firstblock, $colspan, $key, $room); - - $shifts_table .= ""; - for ($i = 0; $i < $maxshow; $i ++) { - $thistime = $first + ($i * 15 * 60); - if ($thistime % (24 * 60 * 60) == 23 * 60 * 60 && $endtime - $starttime > 24 * 60 * 60) { - $shifts_table .= ""; - foreach ($myrooms as $room) { - $rid = $room["id"]; - foreach ($shifts as $shift) { - if ($shift["RID"] == $rid) { - if (floor($shift["start"] / (15 * 60)) == $thistime / (15 * 60)) { - $blocks = ($shift["end"] - $shift["start"]) / (15 * 60); - if ($blocks < 1) { - $blocks = 1; - } - - $collides = in_array($shift['SID'], array_keys($ownshifts)); - if (! $collides) { - foreach ($ownshifts as $ownshift) { - if ($ownshift['start'] >= $shift['start'] && $ownshift['start'] < $shift['end'] || $ownshift['end'] > $shift['start'] && $ownshift['end'] <= $shift['end'] || $ownshift['start'] < $shift['start'] && $ownshift['end'] > $shift['end']) { - $collides = true; - break; - } + $colspan = call_user_func_array('max', $block[$rid]); + if ($colspan == 0) { + $colspan = 1; + } + $todo[$rid] = array_fill(0, $maxshow, $colspan); + $shifts_table .= " 1) ? ' colspan="' . $colspan . '"' : '') . ">" . Room_name_render([ + 'RID' => $room['id'], + 'Name' => $room['name'] + ]) . "\n"; + } + unset($block, $blocks, $firstblock, $colspan, $key, $room); + + $shifts_table .= ""; + for ($i = 0; $i < $maxshow; $i ++) { + $thistime = $first + ($i * 15 * 60); + if ($thistime % (24 * 60 * 60) == 23 * 60 * 60 && $shiftsFilter->getEndTime() - $shiftsFilter->getStartTime() > 24 * 60 * 60) { + $shifts_table .= ""; + foreach ($myrooms as $room) { + $rid = $room["id"]; + foreach ($shifts as $shift) { + if ($shift["RID"] == $rid) { + if (floor($shift["start"] / (15 * 60)) == $thistime / (15 * 60)) { + $blocks = ($shift["end"] - $shift["start"]) / (15 * 60); + if ($blocks < 1) { + $blocks = 1; + } + + $collides = in_array($shift['SID'], array_keys($ownshifts)); + if (! $collides) { + foreach ($ownshifts as $ownshift) { + if ($ownshift['start'] >= $shift['start'] && $ownshift['start'] < $shift['end'] || $ownshift['end'] > $shift['start'] && $ownshift['end'] <= $shift['end'] || $ownshift['start'] < $shift['start'] && $ownshift['end'] > $shift['end']) { + $collides = true; + break; } } - - $is_free = false; - $shifts_row = ''; - if (in_array('admin_shifts', $privileges)) { - $shifts_row .= '
' . table_buttons([ - button(page_link_to('user_shifts') . '&edit_shift=' . $shift['SID'], glyph('edit'), 'btn-xs'), - button(page_link_to('user_shifts') . '&delete_shift=' . $shift['SID'], glyph('trash'), 'btn-xs') - ]) . '
'; - } - $shifts_row .= Room_name_render([ - 'RID' => $room['id'], - 'Name' => $room['name'] - ]) . '
'; - $shifts_row .= '' . date('Y-m-d H:i', $shift['start']); - $shifts_row .= " – "; - $shifts_row .= date('H:i', $shift['end']); - $shifts_row .= "
"; - $shifts_row .= ShiftType($shift['shifttype_id'])['name']; - $shifts_row .= "
"; - if ($shift['title'] != '') { - $shifts_row .= $shift['title']; - $shifts_row .= "
"; - } - $shifts_row .= '
'; - $shifts_row .= '
'; - $query = "SELECT `NeededAngelTypes`.`count`, `AngelTypes`.`id`, `AngelTypes`.`restricted`, `UserAngelTypes`.`confirm_user_id`, `AngelTypes`.`name`, `UserAngelTypes`.`user_id` + } + + $is_free = false; + $shifts_row = ''; + if (in_array('admin_shifts', $privileges)) { + $shifts_row .= '
' . table_buttons([ + button(page_link_to('user_shifts') . '&edit_shift=' . $shift['SID'], glyph('edit'), 'btn-xs'), + button(page_link_to('user_shifts') . '&delete_shift=' . $shift['SID'], glyph('trash'), 'btn-xs') + ]) . '
'; + } + $shifts_row .= Room_name_render([ + 'RID' => $room['id'], + 'Name' => $room['name'] + ]) . '
'; + $shifts_row .= '' . date('Y-m-d H:i', $shift['start']); + $shifts_row .= " – "; + $shifts_row .= date('H:i', $shift['end']); + $shifts_row .= "
"; + $shifts_row .= ShiftType($shift['shifttype_id'])['name']; + $shifts_row .= "
"; + if ($shift['title'] != '') { + $shifts_row .= $shift['title']; + $shifts_row .= "
"; + } + $shifts_row .= '
'; + $shifts_row .= '
'; + $query = "SELECT `NeededAngelTypes`.`count`, `AngelTypes`.`id`, `AngelTypes`.`restricted`, `UserAngelTypes`.`confirm_user_id`, `AngelTypes`.`name`, `UserAngelTypes`.`user_id` FROM `NeededAngelTypes` JOIN `AngelTypes` ON (`NeededAngelTypes`.`angel_type_id` = `AngelTypes`.`id`) LEFT JOIN `UserAngelTypes` ON (`NeededAngelTypes`.`angel_type_id` = `UserAngelTypes`.`angeltype_id`AND `UserAngelTypes`.`user_id`='" . sql_escape($user['UID']) . "') WHERE `count` > 0 AND "; - if ($shift['has_special_needs']) { - $query .= "`shift_id` = '" . sql_escape($shift['SID']) . "'"; - } else { - $query .= "`room_id` = '" . sql_escape($shift['RID']) . "'"; - } - if (! empty($_SESSION['user_shifts']['types'])) { - $query .= " AND `angel_type_id` IN (" . implode(',', $_SESSION['user_shifts']['types']) . ") "; - } - $query .= " ORDER BY `AngelTypes`.`name`"; - $angeltypes = sql_select($query); - - if (count($angeltypes) > 0) { - foreach ($angeltypes as $angeltype) { - $entries = sql_select("SELECT * FROM `ShiftEntry` JOIN `User` ON (`ShiftEntry`.`UID` = `User`.`UID`) WHERE `SID`='" . sql_escape($shift['SID']) . "' AND `TID`='" . sql_escape($angeltype['id']) . "' ORDER BY `Nick`"); - $entry_list = []; - $freeloader = 0; - foreach ($entries as $entry) { - $style = ''; - if ($entry['freeloaded']) { - $freeloader ++; - $style = " text-decoration: line-through;"; - } - if (in_array('user_shifts_admin', $privileges)) { - $entry_list[] = "" . User_Nick_render($entry) . ' ' . table_buttons([ - button(page_link_to('user_shifts') . '&entry_id=' . $entry['id'], glyph('trash'), 'btn-xs') - ]) . ''; - } else { - $entry_list[] = "" . User_Nick_render($entry) . ""; - } + if ($shift['has_special_needs']) { + $query .= "`shift_id` = '" . sql_escape($shift['SID']) . "'"; + } else { + $query .= "`room_id` = '" . sql_escape($shift['RID']) . "'"; + } + if (! empty($shiftsFilter->getTypes())) { + $query .= " AND `angel_type_id` IN (" . implode(',', $shiftsFilter->getTypes()) . ") "; + } + $query .= " ORDER BY `AngelTypes`.`name`"; + $angeltypes = sql_select($query); + + if (count($angeltypes) > 0) { + foreach ($angeltypes as $angeltype) { + $entries = sql_select("SELECT * FROM `ShiftEntry` JOIN `User` ON (`ShiftEntry`.`UID` = `User`.`UID`) WHERE `SID`='" . sql_escape($shift['SID']) . "' AND `TID`='" . sql_escape($angeltype['id']) . "' ORDER BY `Nick`"); + $entry_list = []; + $freeloader = 0; + foreach ($entries as $entry) { + $style = ''; + if ($entry['freeloaded']) { + $freeloader ++; + $style = " text-decoration: line-through;"; } - if ($angeltype['count'] - count($entries) - $freeloader > 0) { - $inner_text = sprintf(ngettext("%d helper needed", "%d helpers needed", $angeltype['count'] - count($entries)), $angeltype['count'] - count($entries)); - // is the shift still running or alternatively is the user shift admin? - $user_may_join_shift = true; - - // you cannot join if user alread joined a parallel or this shift - $user_may_join_shift &= ! $collides; - - // you cannot join if user is not of this angel type - $user_may_join_shift &= isset($angeltype['user_id']); - - // you cannot join if you are not confirmed - if ($angeltype['restricted'] == 1 && isset($angeltype['user_id'])) { - $user_may_join_shift &= isset($angeltype['confirm_user_id']); - } - - // you can only join if the shift is in future or running - $user_may_join_shift &= time() < $shift['start']; - - // User shift admins may join anybody in every shift - $user_may_join_shift |= in_array('user_shifts_admin', $privileges); - if ($user_may_join_shift) { - $entry_list[] = '' . $inner_text . ' ' . button(page_link_to('user_shifts') . '&shift_id=' . $shift['SID'] . '&type_id=' . $angeltype['id'], _('Sign up'), 'btn-xs'); + if (in_array('user_shifts_admin', $privileges)) { + $entry_list[] = "" . User_Nick_render($entry) . ' ' . table_buttons([ + button(page_link_to('user_shifts') . '&entry_id=' . $entry['id'], glyph('trash'), 'btn-xs') + ]) . ''; + } else { + $entry_list[] = "" . User_Nick_render($entry) . ""; + } + } + if ($angeltype['count'] - count($entries) - $freeloader > 0) { + $inner_text = sprintf(ngettext("%d helper needed", "%d helpers needed", $angeltype['count'] - count($entries)), $angeltype['count'] - count($entries)); + // is the shift still running or alternatively is the user shift admin? + $user_may_join_shift = true; + + // you cannot join if user alread joined a parallel or this shift + $user_may_join_shift &= ! $collides; + + // you cannot join if user is not of this angel type + $user_may_join_shift &= isset($angeltype['user_id']); + + // you cannot join if you are not confirmed + if ($angeltype['restricted'] == 1 && isset($angeltype['user_id'])) { + $user_may_join_shift &= isset($angeltype['confirm_user_id']); + } + + // you can only join if the shift is in future or running + $user_may_join_shift &= time() < $shift['start']; + + // User shift admins may join anybody in every shift + $user_may_join_shift |= in_array('user_shifts_admin', $privileges); + if ($user_may_join_shift) { + $entry_list[] = '' . $inner_text . ' ' . button(page_link_to('user_shifts') . '&shift_id=' . $shift['SID'] . '&type_id=' . $angeltype['id'], _('Sign up'), 'btn-xs'); + } else { + if (time() > $shift['start']) { + $entry_list[] = $inner_text . ' (' . _('ended') . ')'; + } elseif ($angeltype['restricted'] == 1 && isset($angeltype['user_id']) && ! isset($angeltype['confirm_user_id'])) { + $entry_list[] = $inner_text . glyph('lock'); + } elseif ($angeltype['restricted'] == 1) { + $entry_list[] = $inner_text; + } elseif ($collides) { + $entry_list[] = $inner_text; } else { - if (time() > $shift['start']) { - $entry_list[] = $inner_text . ' (' . _('ended') . ')'; - } elseif ($angeltype['restricted'] == 1 && isset($angeltype['user_id']) && ! isset($angeltype['confirm_user_id'])) { - $entry_list[] = $inner_text . glyph('lock'); - } elseif ($angeltype['restricted'] == 1) { - $entry_list[] = $inner_text; - } elseif ($collides) { - $entry_list[] = $inner_text; - } else { - $entry_list[] = $inner_text . '
' . button(page_link_to('user_angeltypes') . '&action=add&angeltype_id=' . $angeltype['id'], sprintf(_('Become %s'), $angeltype['name']), 'btn-xs'); - } + $entry_list[] = $inner_text . '
' . button(page_link_to('user_angeltypes') . '&action=add&angeltype_id=' . $angeltype['id'], sprintf(_('Become %s'), $angeltype['name']), 'btn-xs'); } - - unset($inner_text); - $is_free = true; } - $shifts_row .= '' . AngelType_name_render($angeltype) . ': '; - $shifts_row .= join(", ", $entry_list); - $shifts_row .= '
'; + unset($inner_text); + $is_free = true; } - if (in_array('user_shifts_admin', $privileges)) { - $shifts_row .= ' ' . button(page_link_to('user_shifts') . '&shift_id=' . $shift['SID'] . '&type_id=' . $angeltype['id'], _("Add more angels"), 'btn-xs'); - } - } - if ($shift['own'] && ! in_array('user_shifts_admin', $privileges)) { - $class = 'own'; - } elseif ($collides && ! in_array('user_shifts_admin', $privileges)) { - $class = 'collides'; - } elseif ($is_free) { - $class = 'free'; - } else { - $class = 'occupied'; + + $shifts_row .= '' . AngelType_name_render($angeltype) . ': '; + $shifts_row .= join(", ", $entry_list); + $shifts_row .= '
'; } - $shifts_table .= '"; - for ($j = 0; $j < $blocks && $i + $j < $maxshow; $j ++) { - $todo[$rid][$i + $j] --; + if (in_array('user_shifts_admin', $privileges)) { + $shifts_row .= ' ' . button(page_link_to('user_shifts') . '&shift_id=' . $shift['SID'] . '&type_id=' . $angeltype['id'], _("Add more angels"), 'btn-xs'); } } - } - } - // fill up row with empty '; - } - } - $shifts_table .= "\n"; - } - $shifts_table .= '
-
"; - $shifts_table .= date('Y-m-dH:i', $thistime); - } elseif ($thistime % (60 * 60) == 0) { - $shifts_table .= "
"; - $shifts_table .= date("H:i", $thistime); - } else { - $shifts_table .= "
"; - } - $shifts_table .= "
"; + $shifts_table .= date('Y-m-dH:i', $thistime); + } elseif ($thistime % (60 * 60) == 0) { + $shifts_table .= "
"; + $shifts_table .= date("H:i", $thistime); + } else { + $shifts_table .= "
"; + } + $shifts_table .= "'; - $shifts_table .= $shifts_row; - $shifts_table .= " - while ($todo[$rid][$i] -- > 0) { - $shifts_table .= '
'; - } else { - $shifts_table = []; - foreach ($shifts as $shift) { - $info = []; - if ($_SESSION['user_shifts']['start_day'] != $_SESSION['user_shifts']['end_day']) { - $info[] = date("Y-m-d", $shift['start']); - } - $info[] = date("H:i", $shift['start']) . ' - ' . date("H:i", $shift['end']); - if (count($_SESSION['user_shifts']['rooms']) > 1) { - $info[] = Room_name_render([ - 'Name' => $shift['room_name'], - 'RID' => $shift['RID'] - ]); - } - - $shift_row = [ - 'info' => join('
', $info), - 'entries' => '' . $shift['name'] . '' . ($shift['title'] ? '
' . $shift['title'] : '') - ]; - - if (in_array('admin_shifts', $privileges)) { - $shift_row['info'] .= ' ' . table_buttons([ - button(page_link_to('user_shifts') . '&edit_shift=' . $shift['SID'], glyph('edit'), 'btn-xs'), - button(page_link_to('user_shifts') . '&delete_shift=' . $shift['SID'], glyph('trash'), 'btn-xs') - ]); - } - $shift_row['entries'] .= '
'; - $is_free = false; - $shift_has_special_needs = 0 < sql_num_query("SELECT `id` FROM `NeededAngelTypes` WHERE `shift_id` = " . $shift['SID']); - $query = "SELECT `NeededAngelTypes`.`count`, `AngelTypes`.`id`, `AngelTypes`.`restricted`, `UserAngelTypes`.`confirm_user_id`, `AngelTypes`.`name`, `UserAngelTypes`.`user_id` - FROM `NeededAngelTypes` - JOIN `AngelTypes` ON (`NeededAngelTypes`.`angel_type_id` = `AngelTypes`.`id`) - LEFT JOIN `UserAngelTypes` ON (`NeededAngelTypes`.`angel_type_id` = `UserAngelTypes`.`angeltype_id`AND `UserAngelTypes`.`user_id`='" . sql_escape($user['UID']) . "') - WHERE "; - if ($shift_has_special_needs) { - $query .= "`shift_id` = '" . sql_escape($shift['SID']) . "'"; - } else { - $query .= "`room_id` = '" . sql_escape($shift['RID']) . "'"; - } - $query .= " AND `count` > 0 "; - if (! empty($_SESSION['user_shifts']['types'])) { - $query .= "AND `angel_type_id` IN (" . implode(',', $_SESSION['user_shifts']['types']) . ") "; - } - $query .= "ORDER BY `AngelTypes`.`name`"; - $angeltypes = sql_select($query); - if (count($angeltypes) > 0) { - $my_shift = sql_num_query("SELECT * FROM `ShiftEntry` WHERE `SID`='" . sql_escape($shift['SID']) . "' AND `UID`='" . sql_escape($user['UID']) . "' LIMIT 1") > 0; - - foreach ($angeltypes as &$angeltype) { - $entries = sql_select("SELECT * FROM `ShiftEntry` JOIN `User` ON (`ShiftEntry`.`UID` = `User`.`UID`) WHERE `SID`='" . sql_escape($shift['SID']) . "' AND `TID`='" . sql_escape($angeltype['id']) . "' ORDER BY `Nick`"); - $entry_list = []; - $entry_nicks = []; - $freeloader = 0; - foreach ($entries as $entry) { - if (in_array('user_shifts_admin', $privileges)) { - $member = User_Nick_render($entry) . ' ' . table_buttons([ - button(page_link_to('user_shifts') . '&entry_id=' . $entry['id'], glyph('trash'), 'btn-xs') - ]); + if ($shift['own'] && ! in_array('user_shifts_admin', $privileges)) { + $class = 'own'; + } elseif ($collides && ! in_array('user_shifts_admin', $privileges)) { + $class = 'collides'; + } elseif ($is_free) { + $class = 'free'; } else { - $member = User_Nick_render($entry); - } - if ($entry['freeloaded']) { - $member = '' . $member . ''; - $freeloader ++; - } - $entry_list[] = $member; - $entry_nicks[] = $entry['Nick']; - } - $angeltype['taken'] = count($entries) - $freeloader; - $angeltype['angels'] = $entry_nicks; - - // do we need more angles of this type? - if ($angeltype['count'] - count($entries) + $freeloader > 0) { - $inner_text = sprintf(ngettext("%d helper needed", "%d helpers needed", $angeltype['count'] - count($entries) + $freeloader), $angeltype['count'] - count($entries) + $freeloader); - // is the shift still running or alternatively is the user shift admin? - $user_may_join_shift = true; - - /* you cannot join if user already joined this shift */ - $user_may_join_shift &= ! $my_shift; - - // you cannot join if user is not of this angel type - $user_may_join_shift &= isset($angeltype['user_id']); - - // you cannot join if you are not confirmed - if ($angeltype['restricted'] == 1 && isset($angeltype['user_id'])) { - $user_may_join_shift &= isset($angeltype['confirm_user_id']); + $class = 'occupied'; } - - // you can only join if the shift is in future or running - $user_may_join_shift &= time() < $shift['start']; - - // User shift admins may join anybody in every shift - $user_may_join_shift |= in_array('user_shifts_admin', $privileges); - if ($user_may_join_shift) { - $entry_list[] = '' . $inner_text . ' »'; - } else { - if (time() > $shift['end']) { - $entry_list[] = $inner_text . ' (vorbei)'; - } elseif ($angeltype['restricted'] == 1 && isset($angeltype['user_id']) && ! isset($angeltype['confirm_user_id'])) { - $entry_list[] = $inner_text . glyph("lock"); - } else { - $entry_list[] = $inner_text . ' ' . sprintf(_('Become %s'), $angeltype['name']) . ''; - } + $shifts_table .= ''; + $shifts_table .= $shifts_row; + $shifts_table .= ""; + for ($j = 0; $j < $blocks && $i + $j < $maxshow; $j ++) { + $todo[$rid][$i + $j] --; } - - unset($inner_text); - $is_free = true; } - - $shift_row['entries'] .= '' . $angeltype['name'] . ': '; - $shift_row['entries'] .= join(", ", $entry_list); - $shift_row['entries'] .= '
'; } - if (in_array('user_shifts_admin', $privileges)) { - $shift_row['entries'] .= '' . _('Add more angels') . ' »'; - } - $shifts_table[] = $shift_row; - $shift['angeltypes'] = $angeltypes; - $ical_shifts[] = $shift; + } + // fill up row with empty + while ($todo[$rid][$i] -- > 0) { + $shifts_table .= ''; } } - $shifts_table = table([ - 'info' => _("Time") . "/" . _("Room"), - 'entries' => _("Entries") - ], $shifts_table); + $shifts_table .= "\n"; } + $shifts_table .= ''; if ($user['api_key'] == "") { User_reset_api_key($user, false); } + $filled = [ + [ + 'id' => '1', + 'name' => _("occupied") + ], + [ + 'id' => '0', + 'name' => _("free") + ] + ]; + $start_day = date("Y-m-d", $shiftsFilter->getStartTime()); + $start_time = date("H:i", $shiftsFilter->getStartTime()); + $end_day = date("Y-m-d", $shiftsFilter->getEndTime()); + $end_time = date("H:i", $shiftsFilter->getEndTime()); + return page([ div('col-md-12', [ msg(), template_render('../templates/user_shifts.html', [ 'title' => shifts_title(), - 'room_select' => make_select($rooms, $_SESSION['user_shifts']['rooms'], "rooms", _("Rooms")), - 'start_select' => html_select_key("start_day", "start_day", array_combine($days, $days), $_SESSION['user_shifts']['start_day']), - 'start_time' => $_SESSION['user_shifts']['start_time'], - 'end_select' => html_select_key("end_day", "end_day", array_combine($days, $days), $_SESSION['user_shifts']['end_day']), - 'end_time' => $_SESSION['user_shifts']['end_time'], - 'type_select' => make_select($types, $_SESSION['user_shifts']['types'], "types", _("Angeltypes") . '1'), - 'filled_select' => make_select($filled, $_SESSION['user_shifts']['filled'], "filled", _("Occupancy")), - 'task_notice' => '1' . _("The tasks shown here are influenced by the preferences you defined in your settings!") . " " . _("Description of the jobs.") . "", - 'new_style_checkbox' => '', + 'room_select' => make_select($rooms, $shiftsFilter->getRooms(), "rooms", _("Rooms")), + 'start_select' => html_select_key("start_day", "start_day", array_combine($days, $days), $start_day), + 'start_time' => $start_time, + 'end_select' => html_select_key("end_day", "end_day", array_combine($days, $days), $end_day), + 'end_time' => $end_time, + 'type_select' => make_select($types, $shiftsFilter->getTypes(), "types", _("Angeltypes") . '1'), + 'filled_select' => make_select($filled, $shiftsFilter->getFilled(), "filled", _("Occupancy")), + 'task_notice' => '1' . _("The tasks shown here are influenced by the angeltypes you joined already!") . " " . _("Description of the jobs.") . "", 'shifts_table' => msg() . $shifts_table, 'ical_text' => '

' . _("iCal export") . '

' . sprintf(_("Export of shown shifts. iCal format or JSON format available (please keep secret, otherwise reset the api key)."), page_link_to_absolute('ical') . '&key=' . $user['api_key'], page_link_to_absolute('shifts_json_export') . '&key=' . $user['api_key'], page_link_to('user_myshifts') . '&reset') . '

', 'filter' => _("Filter") @@ -568,23 +401,6 @@ function view_user_shifts() { ]); } -function make_user_shifts_export_link($page, $key) { - $link = "&start_day=" . $_SESSION['user_shifts']['start_day']; - $link = "&start_time=" . $_SESSION['user_shifts']['start_time']; - $link = "&end_day=" . $_SESSION['user_shifts']['end_day']; - $link = "&end_time=" . $_SESSION['user_shifts']['end_time']; - foreach ($_SESSION['user_shifts']['rooms'] as $room) { - $link .= '&rooms[]=' . $room; - } - foreach ($_SESSION['user_shifts']['types'] as $type) { - $link .= '&types[]=' . $type; - } - foreach ($_SESSION['user_shifts']['filled'] as $filled) { - $link .= '&filled[]=' . $filled; - } - return page_link_to_absolute($page) . $link . '&export=user_shifts&key=' . $key; -} - function get_ids_from_array($array) { return $array["id"]; } diff --git a/includes/sys_page.php b/includes/sys_page.php index e336261d..27e3e8ba 100644 --- a/includes/sys_page.php +++ b/includes/sys_page.php @@ -18,6 +18,19 @@ function raw_output($output) { die(); } +/** + * Returns an int[] from given request param name. + * + * @param String $name + * Name of the request param + */ +function check_request_int_array($name) { + if (isset($_REQUEST[$name]) && is_array($_REQUEST[$name])) { + return array_filter($_REQUEST[$name], 'is_numeric'); + } + return []; +} + /** * Checks if given request item (name) can be parsed to a date. * If not parsable, given error message is put into msg() and null is returned. diff --git a/templates/user_shifts.html b/templates/user_shifts.html index de98b37a..e4aba6ce 100644 --- a/templates/user_shifts.html +++ b/templates/user_shifts.html @@ -45,7 +45,6 @@
%task_notice%
-
%new_style_checkbox%
-- cgit v1.3.1 From 6fff6a6c1a5a4ae6c6977c3aeb4ac532ba09a395 Mon Sep 17 00:00:00 2001 From: msquare Date: Wed, 5 Oct 2016 18:56:50 +0200 Subject: begin room view and shifts filter renderer --- db/update.sql | 2 + includes/controller/rooms_controller.php | 80 ++++++++++++++++++++++++++++++++ includes/engelsystem_provider.php | 1 + includes/model/Shifts_model.php | 8 ++++ includes/pages/admin_rooms.php | 2 +- includes/sys_menu.php | 28 +++++++++++ includes/sys_template.php | 4 ++ includes/view/Rooms_view.php | 7 +++ includes/view/ShiftsFilterRenderer.php | 65 ++++++++++++++++++++++++++ public/index.php | 3 ++ 10 files changed, 199 insertions(+), 1 deletion(-) create mode 100644 includes/view/ShiftsFilterRenderer.php (limited to 'includes/engelsystem_provider.php') diff --git a/db/update.sql b/db/update.sql index e69de29b..5c5688e7 100644 --- a/db/update.sql +++ b/db/update.sql @@ -0,0 +1,2 @@ +INSERT INTO `Privileges` (`id`, `name`, `desc`) VALUES (40, 'view_rooms', 'User can view rooms'); +INSERT INTO `GroupPrivileges` (`id`, `group_id`, `privilege_id`) VALUES (NULL, '-2', '40'); diff --git a/includes/controller/rooms_controller.php b/includes/controller/rooms_controller.php index 5d55e1b7..da5bdba1 100644 --- a/includes/controller/rooms_controller.php +++ b/includes/controller/rooms_controller.php @@ -1,7 +1,87 @@ setStartTime(time()); + $shiftsFilter->setEndTime(time() + 24 * 60 * 60); + + $shiftsFilterRenderer = new ShiftsFilterRenderer($shiftsFilter); + $shiftsFilterRenderer->enableDaySelection($days, EventConfig()); + + return [ + $room['Name'], + Room_view($room, $shiftsFilterRenderer) + ]; +} + +/** + * Dispatch different room actions. + */ +function rooms_controller() { + global $privileges; + + if (! isset($_REQUEST['action'])) { + $_REQUEST['action'] = 'list'; + } + + switch ($_REQUEST['action']) { + default: + case 'list': + redirect(page_link_to('admin_rooms')); + case 'view': + return room_controller(); + } +} function room_link($room) { + return page_link_to('rooms') . '&action=view&room_id=' . $room['RID']; +} + +function room_edit_link($room) { return page_link_to('admin_rooms') . '&show=edit&id=' . $room['RID']; } +/** + * Loads room by request param room_id + */ +function load_room() { + if (! test_request_int('room_id')) { + redirect(page_link_to()); + } + + $room = Room($_REQUEST['room_id']); + if ($room == null) { + redirect(page_link_to()); + } + + return $room; +} + ?> \ No newline at end of file diff --git a/includes/engelsystem_provider.php b/includes/engelsystem_provider.php index c6d34d1a..dbf7c54f 100644 --- a/includes/engelsystem_provider.php +++ b/includes/engelsystem_provider.php @@ -30,6 +30,7 @@ require_once realpath(__DIR__ . '/../includes/view/EventConfig_view.php'); require_once realpath(__DIR__ . '/../includes/view/Questions_view.php'); require_once realpath(__DIR__ . '/../includes/view/Rooms_view.php'); require_once realpath(__DIR__ . '/../includes/view/ShiftCalendarRenderer.php'); +require_once realpath(__DIR__ . '/../includes/view/ShiftsFilterRenderer.php'); require_once realpath(__DIR__ . '/../includes/view/Shifts_view.php'); require_once realpath(__DIR__ . '/../includes/view/ShiftEntry_view.php'); require_once realpath(__DIR__ . '/../includes/view/ShiftTypes_view.php'); diff --git a/includes/model/Shifts_model.php b/includes/model/Shifts_model.php index 8c251209..6721c30e 100644 --- a/includes/model/Shifts_model.php +++ b/includes/model/Shifts_model.php @@ -1,6 +1,14 @@ 0 AS 'has_special_needs' FROM `Shifts` diff --git a/includes/pages/admin_rooms.php b/includes/pages/admin_rooms.php index 186a676e..7a0f7a31 100644 --- a/includes/pages/admin_rooms.php +++ b/includes/pages/admin_rooms.php @@ -9,7 +9,7 @@ function admin_rooms() { $rooms = []; foreach ($rooms_source as $room) { $rooms[] = [ - 'name' => $room['Name'], + 'name' => Room_name_render($room), 'from_pentabarf' => $room['FromPentabarf'] == 'Y' ? '✓' : '', 'public' => $room['show'] == 'Y' ? '✓' : '', 'actions' => buttons([ diff --git a/includes/sys_menu.php b/includes/sys_menu.php index 112c490f..a5971ace 100644 --- a/includes/sys_menu.php +++ b/includes/sys_menu.php @@ -129,6 +129,8 @@ function make_navigation() { } } + $menu = make_room_navigation($menu); + $admin_menu = []; $admin_pages = [ "admin_arrive" => admin_arrive_title(), @@ -158,6 +160,32 @@ function make_navigation() { return toolbar($menu); } +/** + * Adds room navigation to the given menu. + * + * @param string[] $menu + * Rendered menu + */ +function make_room_navigation($menu) { + global $privileges; + + $rooms = Rooms(); + $room_menu = []; + if (in_array('admin_rooms', $privileges)) { + $room_menu[] = toolbar_item_link(page_link_to('admin_rooms'), 'list', _("Manage rooms")); + } + if (count($room_menu) > 0) { + $room_menu[] = toolbar_item_divider(); + } + foreach ($rooms as $room) { + $room_menu[] = toolbar_item_link(room_link($room), 'map-marker', $room['Name']); + } + if (count($room_menu > 0)) { + $menu[] = toolbar_dropdown('map-marker', _("Rooms"), $room_menu); + } + return $menu; +} + function make_menu() { return make_navigation(); } diff --git a/includes/sys_template.php b/includes/sys_template.php index 5b6caade..9bede1ee 100644 --- a/includes/sys_template.php +++ b/includes/sys_template.php @@ -60,6 +60,10 @@ function toolbar($items = [], $right = false) { return ''; } +function toolbar_pills($items) { + return ''; +} + /** * Render a link for a toolbar. * diff --git a/includes/view/Rooms_view.php b/includes/view/Rooms_view.php index c820e983..4dbf2956 100644 --- a/includes/view/Rooms_view.php +++ b/includes/view/Rooms_view.php @@ -1,4 +1,11 @@ render() + ]); +} function Room_name_render($room) { global $privileges; diff --git a/includes/view/ShiftsFilterRenderer.php b/includes/view/ShiftsFilterRenderer.php new file mode 100644 index 00000000..94d53bb3 --- /dev/null +++ b/includes/view/ShiftsFilterRenderer.php @@ -0,0 +1,65 @@ +shiftsFilter = $shiftsFilter; + } + + /** + * Renders the filter. + * + * @return Generated HTML + */ + public function render() { + $toolbar = []; + if ($this->daySelectionEnabled && ! empty($this->days)) { + $today = date("Y-m-d"); + $selected_day = date("Y-m-d", $this->shiftsFilter->getStartTime()); + $day_dropdown_items = []; + foreach ($this->days as $day) { + $day_dropdown_items[] = toolbar_item_link('', '', $day); + } + $toolbar[] = toolbar_dropdown('', $selected_day, $day_dropdown_items, 'active'); + } + return toolbar_pills($toolbar); + } + + /** + * Should the filter display a day selection. + */ + public function enableDaySelection($days, $event_config) { + $this->daySelectionEnabled = true; + $this->days = $days; + $this->event_config = $event_config; + } + + /** + * Should the filter display a day selection. + */ + public function isDaySelectionEnabled() { + return $this->daySelectionEnabled; + } +} + +?> \ No newline at end of file diff --git a/public/index.php b/public/index.php index 996c2b77..e1af1000 100644 --- a/public/index.php +++ b/public/index.php @@ -9,6 +9,7 @@ $free_pages = [ 'credits', 'ical', 'login', + 'rooms', 'shifts', 'shifts_json_export', 'shifts_json_export_all', @@ -68,6 +69,8 @@ if (isset($_REQUEST['p']) && preg_match("/^[a-z0-9_]*$/i", $_REQUEST['p']) && (i list($title, $content) = shifttypes_controller(); } elseif ($page == "admin_event_config") { list($title, $content) = event_config_edit_controller(); + } elseif ($page == "rooms") { + list($title, $content) = rooms_controller(); } elseif ($page == "news") { $title = news_title(); $content = user_news(); -- cgit v1.3.1 From cf8cc5f592d4935e857fb5434aaf00168bdcb4c5 Mon Sep 17 00:00:00 2001 From: msquare Date: Sat, 5 Nov 2016 10:06:06 +0100 Subject: change shift table to html5 --- includes/engelsystem_provider.php | 1 + includes/model/NeededAngelTypes_model.php | 2 +- includes/sys_template.php | 5 +- includes/view/ShiftCalendarLane.php | 63 +++++++ includes/view/ShiftCalendarRenderer.php | 286 +++++++++++++++++------------- public/css/theme0.css | 49 +++-- public/css/theme1.css | 49 +++-- public/css/theme2.css | 49 +++-- public/css/theme3.css | 49 +++-- shift_markup.html | 51 +----- themes/base.less | 71 +++++--- 11 files changed, 431 insertions(+), 244 deletions(-) create mode 100644 includes/view/ShiftCalendarLane.php (limited to 'includes/engelsystem_provider.php') diff --git a/includes/engelsystem_provider.php b/includes/engelsystem_provider.php index dbf7c54f..0f8aa425 100644 --- a/includes/engelsystem_provider.php +++ b/includes/engelsystem_provider.php @@ -29,6 +29,7 @@ require_once realpath(__DIR__ . '/../includes/view/AngelTypes_view.php'); require_once realpath(__DIR__ . '/../includes/view/EventConfig_view.php'); require_once realpath(__DIR__ . '/../includes/view/Questions_view.php'); require_once realpath(__DIR__ . '/../includes/view/Rooms_view.php'); +require_once realpath(__DIR__ . '/../includes/view/ShiftCalendarLane.php'); require_once realpath(__DIR__ . '/../includes/view/ShiftCalendarRenderer.php'); require_once realpath(__DIR__ . '/../includes/view/ShiftsFilterRenderer.php'); require_once realpath(__DIR__ . '/../includes/view/Shifts_view.php'); diff --git a/includes/model/NeededAngelTypes_model.php b/includes/model/NeededAngelTypes_model.php index 47c9626f..48f8ed20 100644 --- a/includes/model/NeededAngelTypes_model.php +++ b/includes/model/NeededAngelTypes_model.php @@ -57,7 +57,7 @@ function NeededAngelTypes_delete_by_room($room_id) { */ function NeededAngelTypes_by_shift($shiftId) { $needed_angeltypes_source = sql_select(" - SELECT `NeededAngelTypes`.*, `AngelTypes`.`name`, `AngelTypes`.`restricted` + SELECT `NeededAngelTypes`.*, `AngelTypes`.`id`, `AngelTypes`.`name`, `AngelTypes`.`restricted` FROM `NeededAngelTypes` JOIN `AngelTypes` ON `AngelTypes`.`id` = `NeededAngelTypes`.`angel_type_id` WHERE `shift_id`='" . sql_escape($shiftId) . "' diff --git a/includes/sys_template.php b/includes/sys_template.php index 9bede1ee..6c1727a4 100644 --- a/includes/sys_template.php +++ b/includes/sys_template.php @@ -42,8 +42,11 @@ function glyph_bool($boolean) { } function div($class, $content = [], $dom_id = "") { + if (is_array($content)) { + $content = join("\n", $content); + } $dom_id = $dom_id != '' ? ' id="' . $dom_id . '"' : ''; - return '' . join("\n", $content) . ''; + return '' . $content . ''; } function heading($content, $number = 1) { diff --git a/includes/view/ShiftCalendarLane.php b/includes/view/ShiftCalendarLane.php new file mode 100644 index 00000000..33fccec3 --- /dev/null +++ b/includes/view/ShiftCalendarLane.php @@ -0,0 +1,63 @@ +header = $header; + $this->firstBlockStartTime = $firstBlockStartTime; + $this->blockCount = $blockCount; + } + + /** + * Adds a shift to the lane, but only if it fits. + * Returns true on success. + * + * @param Shift $shift + * The shift to add + * @return boolean true on success + */ + public function addShift($shift) { + if ($this->shiftFits($shift)) { + $this->shifts[] = $shift; + return true; + } + return false; + } + + /** + * Returns true if given shift fits into this lane. + * + * @param Shift $shift + * The shift to fit into this lane + */ + public function shiftFits($newShift) { + foreach ($this->shifts as $laneShift) { + if (! ($newShift['start'] >= $laneShift['end'] || $newShift['end'] <= $laneShift['start'])) { + return false; + } + } + return true; + } + + public function getHeader() { + return $this->header; + } + + public function getShifts() { + return $this->shifts; + } +} +?> \ No newline at end of file diff --git a/includes/view/ShiftCalendarRenderer.php b/includes/view/ShiftCalendarRenderer.php index 2ba9b9e6..85aedfa0 100644 --- a/includes/view/ShiftCalendarRenderer.php +++ b/includes/view/ShiftCalendarRenderer.php @@ -7,72 +7,186 @@ class ShiftCalendarRenderer { /** * 15m * 60s/m = 900s */ - const MINUTES_PER_ROW = 900; + const SECONDS_PER_ROW = 900; - const EMPTY_CELL = ''; + /** + * Height of a block in pixel. + * Do not change - corresponds with theme/css + */ + const BLOCK_HEIGHT = 30; + + /** + * Distance between two shifts in pixels + */ + const MARGIN = 5; - private $shifts; + private $lanes; private $shiftsFilter; + private $firstBlockStartTime = null; + + private $blocksPerSlot = null; + public function __construct($shifts, ShiftsFilter $shiftsFilter) { - $this->shifts = $shifts; $this->shiftsFilter = $shiftsFilter; + $this->firstBlockStartTime = $this->calcFirstBlockStartTime($shifts); + $this->lanes = $this->assignShiftsToLanes($shifts); } - public function render() { - $rooms = $this->rooms(); - - $first_block_start_time = $this->calcFirstBlockStartTime(); - $blocks_per_slot = $this->calcBlocksPerSlot($first_block_start_time); + /** + * Assigns the shifts to different lanes per room if they collide + * + * @param Shift[] $shifts + * The shifts to assign + * + * @return Returns an array that assigns a room_id to an array of ShiftCalendarLane containing the shifts + */ + private function assignShiftsToLanes($shifts) { + // array that assigns a room id to a list of lanes (per room) + $lanes = []; - $slotSizes = $this->calcSlotSizes($rooms, $first_block_start_time, $blocks_per_slot); + foreach ($shifts as $shift) { + $room_id = $shift['RID']; + if (! isset($lanes[$room_id])) { + // initialize room with one lane + $header = Room_name_render([ + 'RID' => $room_id, + 'Name' => $shift['room_name'] + ]); + $lanes[$room_id] = [ + new ShiftCalendarLane($header, $this->getFirstBlockStartTime(), $this->getBlocksPerSlot()) + ]; + } + // Try to add the shift to the existing lanes for this room + $shift_added = false; + foreach ($lanes[$room_id] as $lane) { + $shift_added = $lane->addShift($shift); + if ($shift_added == true) { + break; + } + } + // If all lanes for this room are busy, create a new lane and add shift to it + if ($shift_added == false) { + $newLane = new ShiftCalendarLane("", $this->getFirstBlockStartTime(), $this->getBlocksPerSlot()); + if (! $newLane->addShift($shift)) { + engelsystem_error("Unable to add shift to new lane."); + } + $lanes[$room_id][] = $newLane; + } + } - return $this->renderTable($rooms, $slotSizes, $first_block_start_time, $blocks_per_slot); + return $lanes; + } + + public function getFirstBlockStartTime() { + return $this->firstBlockStartTime; } - private function renderTableHead($rooms, $slotSizes) { - $shifts_table = '' . _("Time") . ''; - foreach ($rooms as $room_id => $room_name) { - $colspan = $slotSizes[$room_id]; - $shifts_table .= " 1) ? ' colspan="' . $colspan . '"' : '') . ">" . Room_name_render([ - 'RID' => $room_id, - 'Name' => $room_name - ]) . "\n"; + public function getBlocksPerSlot() { + if ($this->blocksPerSlot == null) { + $this->blocksPerSlot = $this->calcBlocksPerSlot(); } - $shifts_table .= ""; - return $shifts_table; + return $this->blocksPerSlot; } - private function initTableBody($slotSizes, $first_block_start_time, $blocks_per_slot) { - // Slot sizes plus 1 for the time - $columns_needed = array_sum($slotSizes) + 1; - $table_line = array_fill(0, $columns_needed, ShiftCalendarRenderer::EMPTY_CELL); - $table = array_fill(0, $blocks_per_slot, $table_line); - - for ($block = 0; $block < $blocks_per_slot; $block ++) { - $thistime = $first_block_start_time + ($block * ShiftCalendarRenderer::MINUTES_PER_ROW); - if ($thistime % (24 * 60 * 60) == 23 * 60 * 60 && $this->shiftsFilter->getEndTime() - $this->shiftsFilter->getStartTime() > 24 * 60 * 60) { - $table[$block][0] = '' . date('Y-m-dH:i', $thistime) . ''; - } elseif ($thistime % (60 * 60) == 0) { - $table[$block][0] = '' . date('H:i', $thistime) . ''; - } else { - $table[$block][0] = ''; + /** + * Renders the whole calendar + * + * @return the generated html + */ + public function render() { + return div('shift-calendar', [ + $this->renderTimeLane(), + $this->renderShiftLanes() + ]); + } + + /** + * Renders the lanes containing the shifts + */ + private function renderShiftLanes() { + $html = ""; + foreach ($this->lanes as $room_id => $room_lanes) { + foreach ($room_lanes as $lane) { + $html .= $this->renderLane($lane); } } - - return $table; + return $html; } - private function calcRoomSlots($rooms, $slotSizes) { - $result = []; - $slot = 1; // 1 for the time - foreach (array_keys($rooms) as $room_id) { - $result[$room_id] = $slot; - $slot += $slotSizes[$room_id]; + /** + * Renders a single lane + * + * @param ShiftCalendarLane $lane + * The lane to render + */ + private function renderLane(ShiftCalendarLane $lane) { + $html = ""; + $rendered_until = $this->getFirstBlockStartTime(); + foreach ($lane->getShifts() as $shift) { + while ($rendered_until + ShiftCalendarRenderer::SECONDS_PER_ROW <= $shift['start']) { + $html .= $this->renderTick($rendered_until); + $rendered_until += ShiftCalendarRenderer::SECONDS_PER_ROW; + } + + list($shift_height, $shift_html) = $this->renderShift($shift); + $html .= $shift_html; + $rendered_until += $shift_height * ShiftCalendarRenderer::SECONDS_PER_ROW; + } + while ($rendered_until <= $this->shiftsFilter->getEndTime()) { + $html .= $this->renderTick($rendered_until); + $rendered_until += ShiftCalendarRenderer::SECONDS_PER_ROW; } - return $result; + return div('lane', [ + div('header', $lane->getHeader()), + $html + ]); + } + + /** + * Renders a tick/block for given time + * + * @param int $time + * unix timestamp + * @param boolean $label + * Should time labels be generated? + * @return rendered tick html + */ + private function renderTick($time, $label = false) { + if ($time % (24 * 60 * 60) == 23 * 60 * 60) { + if (! $label) { + return div('tick day'); + } + return div('tick day', [ + date('Y-m-dH:i', $time) + ]); + } elseif ($time % (60 * 60) == 0) { + if (! $label) { + return div('tick hour'); + } + return div('tick hour', [ + date('H:i', $time) + ]); + } + return div('tick'); + } + + /** + * Renders the left time lane including hour/day ticks + */ + private function renderTimeLane() { + $time_slot = [ + div('header', [ + _("Time") + ]) + ]; + for ($block = 0; $block < $this->getBlocksPerSlot(); $block ++) { + $thistime = $this->getFirstBlockStartTime() + ($block * ShiftCalendarRenderer::SECONDS_PER_ROW); + $time_slot[] = $this->renderTick($thistime, true); + } + return div('lane time', $time_slot); } private function collides() { @@ -172,15 +286,14 @@ class ShiftCalendarRenderer { $class = 'success'; } - $blocks = ceil(($shift["end"] - $shift["start"]) / ShiftCalendarRenderer::MINUTES_PER_ROW); + $blocks = ceil(($shift["end"] - $shift["start"]) / ShiftCalendarRenderer::SECONDS_PER_ROW); if ($blocks < 1) { $blocks = 1; } - $shift_length = ($shift["end"] - $shift["start"]) / (60 * 60); $shift_heading = date('H:i', $shift['start']) . ' ‐ ' . date('H:i', $shift['end']) . ' — ' . ShiftType($shift['shifttype_id'])['name']; return [ $blocks, - '' . div('panel panel-' . $class . '" style="min-height: ' . ($shift_length * 100) . 'px"', [ + '' . div('shift panel panel-' . $class . '" style="height: ' . ($blocks * ShiftCalendarRenderer::BLOCK_HEIGHT - ShiftCalendarRenderer::MARGIN) . 'px"', [ div('panel-heading', [ '' . $shift_heading . '', $header_buttons @@ -198,87 +311,18 @@ class ShiftCalendarRenderer { ]; } - private function renderTableBody($rooms, $slotSizes, $first_block_start_time, $blocks_per_slot) { - $table = $this->initTableBody($slotSizes, $first_block_start_time, $blocks_per_slot); - - $room_slots = $this->calcRoomSlots($rooms, $slotSizes); - - foreach ($this->shifts as $shift) { - list($blocks, $shift_content) = $this->renderShift($shift); - $start_block = floor(($shift['start'] - $first_block_start_time) / ShiftCalendarRenderer::MINUTES_PER_ROW); - $slot = $room_slots[$shift['RID']]; - while ($table[$start_block][$slot] != ShiftCalendarRenderer::EMPTY_CELL) { - $slot ++; - } - $table[$start_block][$slot] = $shift_content; - for ($block = 1; $block < $blocks; $block ++) { - $table[$start_block + $block][$slot] = ''; - } - } - - $result = ''; - foreach ($table as $table_line) { - $result .= '' . join('', $table_line) . ''; - } - $result .= ''; - return $result; - } - - private function renderTable($rooms, $slotSizes, $first_block_start_time, $blocks_per_slot) { - return div('shifts-table', [ - '', - $this->renderTableHead($rooms, $slotSizes), - $this->renderTableBody($rooms, $slotSizes, $first_block_start_time, $blocks_per_slot), - '
' - ]); - } - - /** - * Calculates the slots for each room that appears in the shifts - */ - private function rooms() { - $rooms = []; - foreach ($this->shifts as $shift) { - if (! isset($rooms[$shift['RID']])) { - $rooms[$shift['RID']] = $shift['room_name']; - } - } - return $rooms; - } - - private function calcFirstBlockStartTime() { + private function calcFirstBlockStartTime($shifts) { $start_time = $this->shiftsFilter->getEndTime(); - foreach ($this->shifts as $shift) { + foreach ($shifts as $shift) { if ($shift['start'] < $start_time) { $start_time = $shift['start']; } } - return ShiftCalendarRenderer::MINUTES_PER_ROW * floor(($start_time - 60 * 60) / ShiftCalendarRenderer::MINUTES_PER_ROW); - } - - private function calcBlocksPerSlot($first_block_start_time) { - return ceil(($this->shiftsFilter->getEndTime() - $first_block_start_time) / ShiftCalendarRenderer::MINUTES_PER_ROW); + return ShiftCalendarRenderer::SECONDS_PER_ROW * floor(($start_time - 60 * 60) / ShiftCalendarRenderer::SECONDS_PER_ROW); } - private function calcSlotSizes($rooms, $first_block_start_time, $blocks_per_slot) { - $parallel_blocks = []; - - // initialize $block array - foreach (array_keys($rooms) as $room_id) { - $parallel_blocks[$room_id] = array_fill(0, $blocks_per_slot, 0); - } - - // calculate number of parallel shifts in each timeslot for each room - foreach ($this->shifts as $shift) { - $room_id = $shift["RID"]; - $shift_blocks = ($shift["end"] - $shift["start"]) / ShiftCalendarRenderer::MINUTES_PER_ROW; - $firstblock = floor(($shift["start"] - $first_block_start_time) / ShiftCalendarRenderer::MINUTES_PER_ROW); - for ($block = $firstblock; $block < $shift_blocks + $firstblock && $block < $blocks_per_slot; $block ++) { - $parallel_blocks[$room_id][$block] ++; - } - } - - return array_map('max', $parallel_blocks); + private function calcBlocksPerSlot() { + return ceil(($this->shiftsFilter->getEndTime() - $this->getFirstBlockStartTime()) / ShiftCalendarRenderer::SECONDS_PER_ROW); } } diff --git a/public/css/theme0.css b/public/css/theme0.css index 0784042a..daba1eba 100644 --- a/public/css/theme0.css +++ b/public/css/theme0.css @@ -6730,25 +6730,46 @@ body { .footer a { color: #777777; } -#shifts.table td, -#shifts.table th { - background-color: #f0f0f0; +.shift-calendar { + display: flex; + flex-direction: row; + flex-wrap: nowrap; + align-itmes: stretch; + width: 100%; } -#shifts.table .row-hour { - border-top-color: #777777; +.shift-calendar .lane { + background: #f9f9f9; + min-width: 300px; + width: 300px; + flex-grow: 1; } -#shifts.table td.shift { - height: 1px; - padding: 0; +.shift-calendar .lane .header { + background: #fff; + height: 30px; + padding: 5px; +} +.shift-calendar .lane .tick { + height: 30px; + border-top: 1px solid #f4f4f4; +} +.shift-calendar .lane .tick.hour { + border-top: 2px solid #dddddd; + font-size: 0.9em; + padding-left: 5px; } -#shifts.table td.shift .panel { - margin: 0px 0px 0px 5px; +.shift-calendar .lane .tick.day { + border-top: 2px solid #337ab7; + font-size: 0.9em; + padding-left: 5px; } -.row-day { - border-top: 2px solid #777777; +.shift-calendar .lane.time { + min-width: 100px; + width: 100px; + flex-grow: 0; } -.row-header { - min-width: 90px; +.shift-calendar .shift { + margin: 0 5px 5px 0; + overflow: hidden; } .space-top { margin-top: 15px; diff --git a/public/css/theme1.css b/public/css/theme1.css index 795439df..e9b6b4cd 100644 --- a/public/css/theme1.css +++ b/public/css/theme1.css @@ -6753,25 +6753,46 @@ body { .footer a { color: #888888; } -#shifts.table td, -#shifts.table th { - background-color: #f0f0f0; +.shift-calendar { + display: flex; + flex-direction: row; + flex-wrap: nowrap; + align-itmes: stretch; + width: 100%; } -#shifts.table .row-hour { - border-top-color: #888888; +.shift-calendar .lane { + background: #080808; + min-width: 300px; + width: 300px; + flex-grow: 1; } -#shifts.table td.shift { - height: 1px; - padding: 0; +.shift-calendar .lane .header { + background: #fff; + height: 30px; + padding: 5px; +} +.shift-calendar .lane .tick { + height: 30px; + border-top: 1px solid #030303; +} +.shift-calendar .lane .tick.hour { + border-top: 2px solid #282828; + font-size: 0.9em; + padding-left: 5px; } -#shifts.table td.shift .panel { - margin: 0px 0px 0px 5px; +.shift-calendar .lane .tick.day { + border-top: 2px solid #428bca; + font-size: 0.9em; + padding-left: 5px; } -.row-day { - border-top: 2px solid #888888; +.shift-calendar .lane.time { + min-width: 100px; + width: 100px; + flex-grow: 0; } -.row-header { - min-width: 90px; +.shift-calendar .shift { + margin: 0 5px 5px 0; + overflow: hidden; } .space-top { margin-top: 15px; diff --git a/public/css/theme2.css b/public/css/theme2.css index 0112dc93..7646f08b 100644 --- a/public/css/theme2.css +++ b/public/css/theme2.css @@ -6730,25 +6730,46 @@ body { .footer a { color: #777777; } -#shifts.table td, -#shifts.table th { - background-color: #f0f0f0; +.shift-calendar { + display: flex; + flex-direction: row; + flex-wrap: nowrap; + align-itmes: stretch; + width: 100%; } -#shifts.table .row-hour { - border-top-color: #777777; +.shift-calendar .lane { + background: #f9f9f9; + min-width: 300px; + width: 300px; + flex-grow: 1; } -#shifts.table td.shift { - height: 1px; - padding: 0; +.shift-calendar .lane .header { + background: #fff; + height: 30px; + padding: 5px; +} +.shift-calendar .lane .tick { + height: 30px; + border-top: 1px solid #f4f4f4; +} +.shift-calendar .lane .tick.hour { + border-top: 2px solid #dddddd; + font-size: 0.9em; + padding-left: 5px; } -#shifts.table td.shift .panel { - margin: 0px 0px 0px 5px; +.shift-calendar .lane .tick.day { + border-top: 2px solid #758499; + font-size: 0.9em; + padding-left: 5px; } -.row-day { - border-top: 2px solid #777777; +.shift-calendar .lane.time { + min-width: 100px; + width: 100px; + flex-grow: 0; } -.row-header { - min-width: 90px; +.shift-calendar .shift { + margin: 0 5px 5px 0; + overflow: hidden; } .space-top { margin-top: 15px; diff --git a/public/css/theme3.css b/public/css/theme3.css index 4be828ef..014fee12 100644 --- a/public/css/theme3.css +++ b/public/css/theme3.css @@ -6739,25 +6739,46 @@ body { .footer a { color: #777777; } -#shifts.table td, -#shifts.table th { - background-color: #f0f0f0; +.shift-calendar { + display: flex; + flex-direction: row; + flex-wrap: nowrap; + align-itmes: stretch; + width: 100%; } -#shifts.table .row-hour { - border-top-color: #777777; +.shift-calendar .lane { + background: #f9f9f9; + min-width: 300px; + width: 300px; + flex-grow: 1; } -#shifts.table td.shift { - height: 1px; - padding: 0; +.shift-calendar .lane .header { + background: #fff; + height: 30px; + padding: 5px; +} +.shift-calendar .lane .tick { + height: 30px; + border-top: 1px solid #f4f4f4; +} +.shift-calendar .lane .tick.hour { + border-top: 2px solid #dddddd; + font-size: 0.9em; + padding-left: 5px; } -#shifts.table td.shift .panel { - margin: 0px 0px 0px 5px; +.shift-calendar .lane .tick.day { + border-top: 2px solid #f19224; + font-size: 0.9em; + padding-left: 5px; } -.row-day { - border-top: 2px solid #777777; +.shift-calendar .lane.time { + min-width: 100px; + width: 100px; + flex-grow: 0; } -.row-header { - min-width: 90px; +.shift-calendar .shift { + margin: 0 5px 5px 0; + overflow: hidden; } .space-top { margin-top: 15px; diff --git a/shift_markup.html b/shift_markup.html index 8d8fa63b..7ad5177a 100644 --- a/shift_markup.html +++ b/shift_markup.html @@ -4,52 +4,13 @@
-
10:00
+
Time
+
2016-12-27 00:00
@@ -67,7 +28,10 @@
-
+
+ Bottle Sorting (Hall H) +
+
@@ -99,7 +63,8 @@
-
+
+
diff --git a/themes/base.less b/themes/base.less index c5ff50b2..98c12514 100644 --- a/themes/base.less +++ b/themes/base.less @@ -10,32 +10,59 @@ body { color: @text-muted; } -#shifts.table { - td, th { - background-color: #f0f0f0; +.shift-calendar { + display: flex; + flex-direction: row; + flex-wrap: nowrap; + align-itmes: stretch; + display: flex; + flex-direction: row; + flex-wrap: nowrap; + align-itmes: stretch; + width: 100%; + + .lane { + background: @table-bg-accent; + flex-grow: 1; + min-width: 300px; + width: 300px; + flex-grow: 1; + + .header { + background: #fff; + height: 30px; + padding: 5px; + } + + .tick { + height: 30px; + border-top: 1px solid darken(@table-bg-accent, 2%); + } + + .tick.hour { + border-top: 2px solid @table-border-color; + font-size: 0.9em; + padding-left: 5px; + } + + .tick.day { + border-top: 2px solid @brand-primary; + font-size: 0.9em; + padding-left: 5px; + } } - .row-hour { - border-top-color: @gray-light; + .lane.time { + flex-grow: 0; + min-width: 100px; + width: 100px; + flex-grow: 0; } - td.shift { - height: 1px; - padding: 0; - - .panel { - margin: 0px 0px 0px 5px; - overflow: hidden; - } - } -} - -.row-day { - border-top: 2px solid @gray-light; -} - -.row-header { - min-width: 90px; + .shift { + margin: 0 5px 5px 0; + overflow: hidden; + } } .space-top { -- cgit v1.3.1 From db7f8c1ab3d4c53ce747db707f5b9480f5f0c024 Mon Sep 17 00:00:00 2001 From: msquare Date: Mon, 7 Nov 2016 20:50:15 +0100 Subject: split shift calendar renderer into different classes --- includes/engelsystem_provider.php | 1 + includes/view/ShiftCalendarRenderer.php | 127 +------------------- includes/view/ShiftCalendarShiftRenderer.php | 171 +++++++++++++++++++++++++++ 3 files changed, 175 insertions(+), 124 deletions(-) create mode 100644 includes/view/ShiftCalendarShiftRenderer.php (limited to 'includes/engelsystem_provider.php') diff --git a/includes/engelsystem_provider.php b/includes/engelsystem_provider.php index 0f8aa425..f3d4f5b1 100644 --- a/includes/engelsystem_provider.php +++ b/includes/engelsystem_provider.php @@ -31,6 +31,7 @@ require_once realpath(__DIR__ . '/../includes/view/Questions_view.php'); require_once realpath(__DIR__ . '/../includes/view/Rooms_view.php'); require_once realpath(__DIR__ . '/../includes/view/ShiftCalendarLane.php'); require_once realpath(__DIR__ . '/../includes/view/ShiftCalendarRenderer.php'); +require_once realpath(__DIR__ . '/../includes/view/ShiftCalendarShiftRenderer.php'); require_once realpath(__DIR__ . '/../includes/view/ShiftsFilterRenderer.php'); require_once realpath(__DIR__ . '/../includes/view/Shifts_view.php'); require_once realpath(__DIR__ . '/../includes/view/ShiftEntry_view.php'); diff --git a/includes/view/ShiftCalendarRenderer.php b/includes/view/ShiftCalendarRenderer.php index 85aedfa0..70948ec5 100644 --- a/includes/view/ShiftCalendarRenderer.php +++ b/includes/view/ShiftCalendarRenderer.php @@ -107,7 +107,7 @@ class ShiftCalendarRenderer { */ private function renderShiftLanes() { $html = ""; - foreach ($this->lanes as $room_id => $room_lanes) { + foreach ($this->lanes as $room_lanes) { foreach ($room_lanes as $lane) { $html .= $this->renderLane($lane); } @@ -122,6 +122,7 @@ class ShiftCalendarRenderer { * The lane to render */ private function renderLane(ShiftCalendarLane $lane) { + $shift_renderer = new ShiftCalendarShiftRenderer(); $html = ""; $rendered_until = $this->getFirstBlockStartTime(); foreach ($lane->getShifts() as $shift) { @@ -130,7 +131,7 @@ class ShiftCalendarRenderer { $rendered_until += ShiftCalendarRenderer::SECONDS_PER_ROW; } - list($shift_height, $shift_html) = $this->renderShift($shift); + list($shift_height, $shift_html) = $shift_renderer->render($shift); $html .= $shift_html; $rendered_until += $shift_height * ShiftCalendarRenderer::SECONDS_PER_ROW; } @@ -189,128 +190,6 @@ class ShiftCalendarRenderer { return div('lane time', $time_slot); } - private function collides() { - // TODO - return false; - } - - private function renderShift($shift) { - global $privileges; - - $collides = $this->collides(); - $is_free = false; - $shifts_row = ''; - $header_buttons = ""; - if (in_array('admin_shifts', $privileges)) { - $header_buttons = '
' . table_buttons([ - button(page_link_to('user_shifts') . '&edit_shift=' . $shift['SID'], glyph('edit'), 'btn-xs'), - button(page_link_to('user_shifts') . '&delete_shift=' . $shift['SID'], glyph('trash'), 'btn-xs') - ]) . '
'; - } - $info_text = ""; - if ($shift['title'] != '') { - $info_text = glyph('info-sign') . $shift['title'] . '
'; - } - - $angeltypes = NeededAngelTypes_by_shift($shift['SID']); - foreach ($angeltypes as $angeltype) { - $entry_list = []; - $freeloader = 0; - foreach ($angeltype['shift_entries'] as $entry) { - $style = ''; - if ($entry['freeloaded']) { - $freeloader ++; - $style = " text-decoration: line-through;"; - } - $entry_list[] = "" . User_Nick_render(User($entry['UID'])) . ""; - } - if ($angeltype['count'] - count($angeltype['shift_entries']) - $freeloader > 0) { - $inner_text = sprintf(ngettext("%d helper needed", "%d helpers needed", $angeltype['count'] - count($angeltype['shift_entries'])), $angeltype['count'] - count($angeltype['shift_entries'])); - // is the shift still running or alternatively is the user shift admin? - $user_may_join_shift = true; - - // you cannot join if user alread joined a parallel or this shift - $user_may_join_shift &= ! $collides; - - // you cannot join if user is not of this angel type - $user_may_join_shift &= isset($angeltype['user_id']); - - // you cannot join if you are not confirmed - if ($angeltype['restricted'] == 1 && isset($angeltype['user_id'])) { - $user_may_join_shift &= isset($angeltype['confirm_user_id']); - } - - // you can only join if the shift is in future or running - $user_may_join_shift &= time() < $shift['start']; - - // User shift admins may join anybody in every shift - $user_may_join_shift |= in_array('user_shifts_admin', $privileges); - if ($user_may_join_shift) { - $entry_list[] = '' . $inner_text . ' ' . button(page_link_to('user_shifts') . '&shift_id=' . $shift['SID'] . '&type_id=' . $angeltype['id'], _('Sign up'), 'btn-xs btn-primary'); - } else { - if (time() > $shift['start']) { - $entry_list[] = $inner_text . ' (' . _('ended') . ')'; - } elseif ($angeltype['restricted'] == 1 && isset($angeltype['user_id']) && ! isset($angeltype['confirm_user_id'])) { - $entry_list[] = $inner_text . glyph('lock'); - } elseif ($angeltype['restricted'] == 1) { - $entry_list[] = $inner_text; - } elseif ($collides) { - $entry_list[] = $inner_text; - } else { - $entry_list[] = $inner_text . '
' . button(page_link_to('user_angeltypes') . '&action=add&angeltype_id=' . $angeltype['id'], sprintf(_('Become %s'), $angeltype['name']), 'btn-xs'); - } - } - - unset($inner_text); - $is_free = true; - } - - $shifts_row .= '
  • '; - $shifts_row .= '' . AngelType_name_render($angeltype) . ': '; - $shifts_row .= join(", ", $entry_list); - $shifts_row .= '
  • '; - } - if (in_array('user_shifts_admin', $privileges)) { - $shifts_row .= '
  • ' . button(page_link_to('user_shifts') . '&shift_id=' . $shift['SID'] . '&type_id=' . $angeltype['id'], _("Add more angels"), 'btn-xs') . '
  • '; - } - if ($shifts_row != '') { - $shifts_row = '
      ' . $shifts_row . '
    '; - } - if (isset($shift['own']) && $shift['own'] && ! in_array('user_shifts_admin', $privileges)) { - $class = 'primary'; - } elseif ($collides && ! in_array('user_shifts_admin', $privileges)) { - $class = 'default'; - } elseif ($is_free) { - $class = 'danger'; - } else { - $class = 'success'; - } - - $blocks = ceil(($shift["end"] - $shift["start"]) / ShiftCalendarRenderer::SECONDS_PER_ROW); - if ($blocks < 1) { - $blocks = 1; - } - $shift_heading = date('H:i', $shift['start']) . ' ‐ ' . date('H:i', $shift['end']) . ' — ' . ShiftType($shift['shifttype_id'])['name']; - return [ - $blocks, - '' . div('shift panel panel-' . $class . '" style="height: ' . ($blocks * ShiftCalendarRenderer::BLOCK_HEIGHT - ShiftCalendarRenderer::MARGIN) . 'px"', [ - div('panel-heading', [ - '' . $shift_heading . '', - $header_buttons - ]), - div('panel-body', [ - $info_text, - Room_name_render([ - 'RID' => $shift['RID'], - 'Name' => $shift['room_name'] - ]) - ]), - $shifts_row, - div('shift-spacer') - ]) . '' - ]; - } - private function calcFirstBlockStartTime($shifts) { $start_time = $this->shiftsFilter->getEndTime(); foreach ($shifts as $shift) { diff --git a/includes/view/ShiftCalendarShiftRenderer.php b/includes/view/ShiftCalendarShiftRenderer.php new file mode 100644 index 00000000..ee6ebcf0 --- /dev/null +++ b/includes/view/ShiftCalendarShiftRenderer.php @@ -0,0 +1,171 @@ +collides(); + $is_free = false; + $shifts_row = ''; + $info_text = ""; + if ($shift['title'] != '') { + $info_text = glyph('info-sign') . $shift['title'] . '
    '; + } + + $angeltypes = NeededAngelTypes_by_shift($shift['SID']); + foreach ($angeltypes as $angeltype) { + $shifts_row .= $this->renderShiftNeededAngeltype($shift, $angeltype, $collides); + } + if (in_array('user_shifts_admin', $privileges)) { + $shifts_row .= '
  • ' . button(page_link_to('user_shifts') . '&shift_id=' . $shift['SID'] . '&type_id=' . $angeltype['id'], _("Add more angels"), 'btn-xs') . '
  • '; + } + if ($shifts_row != '') { + $shifts_row = '
      ' . $shifts_row . '
    '; + } + if (isset($shift['own']) && $shift['own'] && ! in_array('user_shifts_admin', $privileges)) { + $class = 'primary'; + } elseif ($collides && ! in_array('user_shifts_admin', $privileges)) { + $class = 'default'; + } elseif ($is_free) { + $class = 'danger'; + } else { + $class = 'success'; + } + + $blocks = ceil(($shift["end"] - $shift["start"]) / ShiftCalendarRenderer::SECONDS_PER_ROW); + if ($blocks < 1) { + $blocks = 1; + } + return [ + $blocks, + '' . div('shift panel panel-' . $class . '" style="height: ' . ($blocks * ShiftCalendarRenderer::BLOCK_HEIGHT - ShiftCalendarRenderer::MARGIN) . 'px"', [ + $this->renderShiftHead($shift), + div('panel-body', [ + $info_text, + Room_name_render([ + 'RID' => $shift['RID'], + 'Name' => $shift['room_name'] + ]) + ]), + $shifts_row, + div('shift-spacer') + ]) . '' + ]; + } + + /** + * Renders a list entry containing the needed angels for an angeltype + * + * @param Shift $shift + * The shift which is rendered + * @param Angeltype $angeltype + * The angeltype, containing informations about needed angeltypes and already signed up angels + * @param boolean $collides + * true if the shift collides with the users shifts + */ + private function renderShiftNeededAngeltype($shift, $angeltype, $collides) { + global $privileges; + + $entry_list = []; + $freeloader = 0; + foreach ($angeltype['shift_entries'] as $entry) { + $style = ''; + if ($entry['freeloaded']) { + $freeloader ++; + $style = " text-decoration: line-through;"; + } + $entry_list[] = "" . User_Nick_render(User($entry['UID'])) . ""; + } + if ($angeltype['count'] - count($angeltype['shift_entries']) - $freeloader > 0) { + $inner_text = sprintf(ngettext("%d helper needed", "%d helpers needed", $angeltype['count'] - count($angeltype['shift_entries'])), $angeltype['count'] - count($angeltype['shift_entries'])); + // is the shift still running or alternatively is the user shift admin? + $user_may_join_shift = true; + + // you cannot join if user alread joined a parallel or this shift + $user_may_join_shift &= ! $collides; + + // you cannot join if user is not of this angel type + $user_may_join_shift &= isset($angeltype['user_id']); + + // you cannot join if you are not confirmed + if ($angeltype['restricted'] == 1 && isset($angeltype['user_id'])) { + $user_may_join_shift &= isset($angeltype['confirm_user_id']); + } + + // you can only join if the shift is in future or running + $user_may_join_shift &= time() < $shift['start']; + + // User shift admins may join anybody in every shift + $user_may_join_shift |= in_array('user_shifts_admin', $privileges); + if ($user_may_join_shift) { + $entry_list[] = '' . $inner_text . ' ' . button(page_link_to('user_shifts') . '&shift_id=' . $shift['SID'] . '&type_id=' . $angeltype['id'], _('Sign up'), 'btn-xs btn-primary'); + } else { + if (time() > $shift['start']) { + $entry_list[] = $inner_text . ' (' . _('ended') . ')'; + } elseif ($angeltype['restricted'] == 1 && isset($angeltype['user_id']) && ! isset($angeltype['confirm_user_id'])) { + $entry_list[] = $inner_text . glyph('lock'); + } elseif ($angeltype['restricted'] == 1) { + $entry_list[] = $inner_text; + } elseif ($collides) { + $entry_list[] = $inner_text; + } else { + $entry_list[] = $inner_text . '
    ' . button(page_link_to('user_angeltypes') . '&action=add&angeltype_id=' . $angeltype['id'], sprintf(_('Become %s'), $angeltype['name']), 'btn-xs'); + } + } + + unset($inner_text); + $is_free = true; + } + + $shifts_row = '
  • '; + $shifts_row .= '' . AngelType_name_render($angeltype) . ': '; + $shifts_row .= join(", ", $entry_list); + $shifts_row .= '
  • '; + return $shifts_row; + } + + /** + * Renders the shift header + * + * @param Shift $shift + * The shift + */ + private function renderShiftHead($shift) { + global $privileges; + + $header_buttons = ""; + if (in_array('admin_shifts', $privileges)) { + $header_buttons = '
    ' . table_buttons([ + button(page_link_to('user_shifts') . '&edit_shift=' . $shift['SID'], glyph('edit'), 'btn-xs'), + button(page_link_to('user_shifts') . '&delete_shift=' . $shift['SID'], glyph('trash'), 'btn-xs') + ]) . '
    '; + } + $shift_heading = date('H:i', $shift['start']) . ' ‐ ' . date('H:i', $shift['end']) . ' — ' . ShiftType($shift['shifttype_id'])['name']; + return div('panel-heading', [ + '' . $shift_heading . '', + $header_buttons + ]); + } + + /** + * Does the shift collide with the user's shifts + */ + private function collides() { + // TODO + return false; + } +} + +?> \ No newline at end of file -- cgit v1.3.1