begin room view and shifts filter renderer
This commit is contained in:
parent
27c9650dc4
commit
6fff6a6c1a
|
@ -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');
|
|
@ -1,7 +1,87 @@
|
||||||
<?php
|
<?php
|
||||||
|
use Engelsystem\ShiftsFilterRenderer;
|
||||||
|
use Engelsystem\ShiftsFilter;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Room controllers for managing everything room related.
|
||||||
|
*/
|
||||||
|
|
||||||
|
/**
|
||||||
|
* View a room with its shifts.
|
||||||
|
*/
|
||||||
|
function room_controller() {
|
||||||
|
global $privileges, $user;
|
||||||
|
|
||||||
|
if (! in_array('view_rooms', $privileges)) {
|
||||||
|
redirect(page_link_to());
|
||||||
|
}
|
||||||
|
|
||||||
|
$room = load_room();
|
||||||
|
$all_shifts = Shifts_by_room($room);
|
||||||
|
$days = [];
|
||||||
|
foreach ($all_shifts as $shift) {
|
||||||
|
$day = date("Y-m-d", $shift['start']);
|
||||||
|
if (! in_array($day, $days)) {
|
||||||
|
$days[] = $day;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
$shiftsFilter = new ShiftsFilter(false, [
|
||||||
|
$room['RID']
|
||||||
|
], []);
|
||||||
|
$shiftsFilter->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) {
|
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'];
|
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;
|
||||||
|
}
|
||||||
|
|
||||||
?>
|
?>
|
|
@ -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/Questions_view.php');
|
||||||
require_once realpath(__DIR__ . '/../includes/view/Rooms_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/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/Shifts_view.php');
|
||||||
require_once realpath(__DIR__ . '/../includes/view/ShiftEntry_view.php');
|
require_once realpath(__DIR__ . '/../includes/view/ShiftEntry_view.php');
|
||||||
require_once realpath(__DIR__ . '/../includes/view/ShiftTypes_view.php');
|
require_once realpath(__DIR__ . '/../includes/view/ShiftTypes_view.php');
|
||||||
|
|
|
@ -1,6 +1,14 @@
|
||||||
<?php
|
<?php
|
||||||
use Engelsystem\ShiftsFilter;
|
use Engelsystem\ShiftsFilter;
|
||||||
|
|
||||||
|
function Shifts_by_room($room) {
|
||||||
|
$result = sql_select("SELECT * FROM `Shifts` WHERE `RID`=" . sql_escape($room['RID']));
|
||||||
|
if ($result === false) {
|
||||||
|
engelsystem_error("Unable to load shifts.");
|
||||||
|
}
|
||||||
|
return $result;
|
||||||
|
}
|
||||||
|
|
||||||
function Shifts_by_ShiftsFilter(ShiftsFilter $shiftsFilter, $user) {
|
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 DISTINCT `Shifts`.*, `ShiftTypes`.`name`, `Room`.`Name` as `room_name`, nat2.`special_needs` > 0 AS 'has_special_needs'
|
||||||
FROM `Shifts`
|
FROM `Shifts`
|
||||||
|
|
|
@ -9,7 +9,7 @@ function admin_rooms() {
|
||||||
$rooms = [];
|
$rooms = [];
|
||||||
foreach ($rooms_source as $room) {
|
foreach ($rooms_source as $room) {
|
||||||
$rooms[] = [
|
$rooms[] = [
|
||||||
'name' => $room['Name'],
|
'name' => Room_name_render($room),
|
||||||
'from_pentabarf' => $room['FromPentabarf'] == 'Y' ? '✓' : '',
|
'from_pentabarf' => $room['FromPentabarf'] == 'Y' ? '✓' : '',
|
||||||
'public' => $room['show'] == 'Y' ? '✓' : '',
|
'public' => $room['show'] == 'Y' ? '✓' : '',
|
||||||
'actions' => buttons([
|
'actions' => buttons([
|
||||||
|
|
|
@ -129,6 +129,8 @@ function make_navigation() {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
$menu = make_room_navigation($menu);
|
||||||
|
|
||||||
$admin_menu = [];
|
$admin_menu = [];
|
||||||
$admin_pages = [
|
$admin_pages = [
|
||||||
"admin_arrive" => admin_arrive_title(),
|
"admin_arrive" => admin_arrive_title(),
|
||||||
|
@ -158,6 +160,32 @@ function make_navigation() {
|
||||||
return toolbar($menu);
|
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() {
|
function make_menu() {
|
||||||
return make_navigation();
|
return make_navigation();
|
||||||
}
|
}
|
||||||
|
|
|
@ -60,6 +60,10 @@ function toolbar($items = [], $right = false) {
|
||||||
return '<ul class="nav navbar-nav' . ($right ? ' navbar-right' : '') . '">' . join("\n", $items) . '</ul>';
|
return '<ul class="nav navbar-nav' . ($right ? ' navbar-right' : '') . '">' . join("\n", $items) . '</ul>';
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function toolbar_pills($items) {
|
||||||
|
return '<ul class="nav nav-pills">' . join("\n", $items) . '</ul>';
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Render a link for a toolbar.
|
* Render a link for a toolbar.
|
||||||
*
|
*
|
||||||
|
|
|
@ -1,4 +1,11 @@
|
||||||
<?php
|
<?php
|
||||||
|
use Engelsystem\ShiftsFilterRenderer;
|
||||||
|
|
||||||
|
function Room_view($room, ShiftsFilterRenderer $shiftsFilterRenderer) {
|
||||||
|
return page_with_title(glyph('map-marker') . $room['Name'], [
|
||||||
|
$shiftsFilterRenderer->render()
|
||||||
|
]);
|
||||||
|
}
|
||||||
|
|
||||||
function Room_name_render($room) {
|
function Room_name_render($room) {
|
||||||
global $privileges;
|
global $privileges;
|
||||||
|
|
|
@ -0,0 +1,65 @@
|
||||||
|
<?php
|
||||||
|
|
||||||
|
namespace Engelsystem;
|
||||||
|
|
||||||
|
class ShiftsFilterRenderer {
|
||||||
|
|
||||||
|
/**
|
||||||
|
* The shiftFilter to render.
|
||||||
|
*
|
||||||
|
* @var ShiftsFilter
|
||||||
|
*/
|
||||||
|
private $shiftsFilter;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Should the filter display a day selection.
|
||||||
|
*
|
||||||
|
* @var boolean
|
||||||
|
*/
|
||||||
|
private $daySelectionEnabled = false;
|
||||||
|
|
||||||
|
private $days = [];
|
||||||
|
|
||||||
|
private $event_config = null;
|
||||||
|
|
||||||
|
public function __construct(ShiftsFilter $shiftsFilter) {
|
||||||
|
$this->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;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
?>
|
|
@ -9,6 +9,7 @@ $free_pages = [
|
||||||
'credits',
|
'credits',
|
||||||
'ical',
|
'ical',
|
||||||
'login',
|
'login',
|
||||||
|
'rooms',
|
||||||
'shifts',
|
'shifts',
|
||||||
'shifts_json_export',
|
'shifts_json_export',
|
||||||
'shifts_json_export_all',
|
'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();
|
list($title, $content) = shifttypes_controller();
|
||||||
} elseif ($page == "admin_event_config") {
|
} elseif ($page == "admin_event_config") {
|
||||||
list($title, $content) = event_config_edit_controller();
|
list($title, $content) = event_config_edit_controller();
|
||||||
|
} elseif ($page == "rooms") {
|
||||||
|
list($title, $content) = rooms_controller();
|
||||||
} elseif ($page == "news") {
|
} elseif ($page == "news") {
|
||||||
$title = news_title();
|
$title = news_title();
|
||||||
$content = user_news();
|
$content = user_news();
|
||||||
|
|
Loading…
Reference in New Issue