summaryrefslogtreecommitdiff
path: root/includes/controller/rooms_controller.php
diff options
context:
space:
mode:
authormsquare <msquare@notrademark.de>2017-11-28 15:43:51 +0100
committerGitHub <noreply@github.com>2017-11-28 15:43:51 +0100
commit599f2fd264bfc7b1b6826fe206442806e317340f (patch)
tree50cf84d7d07d11bd65b45c2c17f37632f6cd8eff /includes/controller/rooms_controller.php
parenta5fc5bd0979e8de1fce8a8addd351a6e7bd6aeb8 (diff)
parenteda7f7788ea8012bd8be46405c56a666c11f3fa5 (diff)
Merge pull request #365 from engelsystem/feature-igel-rewrite
Feature igel rewrite
Diffstat (limited to 'includes/controller/rooms_controller.php')
-rw-r--r--includes/controller/rooms_controller.php171
1 files changed, 96 insertions, 75 deletions
diff --git a/includes/controller/rooms_controller.php b/includes/controller/rooms_controller.php
index bba38bb5..d6da9709 100644
--- a/includes/controller/rooms_controller.php
+++ b/includes/controller/rooms_controller.php
@@ -1,7 +1,7 @@
<?php
-use Engelsystem\ShiftsFilterRenderer;
+
use Engelsystem\ShiftsFilter;
-use Engelsystem\ShiftCalendarRenderer;
+use Engelsystem\ShiftsFilterRenderer;
/**
* Room controllers for managing everything room related.
@@ -9,93 +9,114 @@ use Engelsystem\ShiftCalendarRenderer;
/**
* View a room with its shifts.
+ *
+ * @return array
*/
-function room_controller() {
- global $privileges;
-
- if (! in_array('view_rooms', $privileges)) {
- redirect(page_link_to());
- }
-
-
- $room = load_room();
-
- if($room['show'] != 'Y' && !in_array('admin_rooms', $privileges)) {
- redirect(page_link_to());
- }
-
- $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;
+function room_controller()
+{
+ global $privileges;
+
+ if (!in_array('view_rooms', $privileges)) {
+ redirect(page_link_to());
}
- }
-
- $shiftsFilter = new ShiftsFilter(true, [
- $room['RID']
- ], AngelType_ids());
- $selected_day = date("Y-m-d");
- if (! empty($days)) {
- $selected_day = $days[0];
- }
- if (isset($_REQUEST['shifts_filter_day'])) {
- $selected_day = $_REQUEST['shifts_filter_day'];
- }
- $shiftsFilter->setStartTime(parse_date("Y-m-d H:i", $selected_day . ' 00:00'));
- $shiftsFilter->setEndTime(parse_date("Y-m-d H:i", $selected_day . ' 23:59'));
-
- $shiftsFilterRenderer = new ShiftsFilterRenderer($shiftsFilter);
- $shiftsFilterRenderer->enableDaySelection($days);
-
- $shiftCalendarRenderer = shiftCalendarRendererByShiftFilter($shiftsFilter);
-
- return [
- $room['Name'],
- Room_view($room, $shiftsFilterRenderer, $shiftCalendarRenderer)
- ];
+
+ $request = request();
+ $room = load_room(false);
+ if ($room['show'] != 'Y' && !in_array('admin_rooms', $privileges)) {
+ redirect(page_link_to());
+ }
+
+ $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(
+ true,
+ [$room['RID']],
+ AngelType_ids()
+ );
+ $selected_day = date('Y-m-d');
+ if (!empty($days)) {
+ $selected_day = $days[0];
+ }
+ if ($request->has('shifts_filter_day')) {
+ $selected_day = $request->input('shifts_filter_day');
+ }
+ $shiftsFilter->setStartTime(parse_date('Y-m-d H:i', $selected_day . ' 00:00'));
+ $shiftsFilter->setEndTime(parse_date('Y-m-d H:i', $selected_day . ' 23:59'));
+
+ $shiftsFilterRenderer = new ShiftsFilterRenderer($shiftsFilter);
+ $shiftsFilterRenderer->enableDaySelection($days);
+
+ $shiftCalendarRenderer = shiftCalendarRendererByShiftFilter($shiftsFilter);
+
+ return [
+ $room['Name'],
+ Room_view($room, $shiftsFilterRenderer, $shiftCalendarRenderer)
+ ];
}
/**
* Dispatch different room actions.
+ *
+ * @return array
*/
-function rooms_controller() {
- 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 rooms_controller()
+{
+ $request = request();
+ $action = $request->input('action');
+ if (!$request->has('action')) {
+ $action = 'list';
+ }
+
+ switch ($action) {
+ case 'view':
+ return room_controller();
+ case 'list':
+ default:
+ redirect(page_link_to('admin_rooms'));
+ }
}
-function room_link($room) {
- return page_link_to('rooms') . '&action=view&room_id=' . $room['RID'];
+/**
+ * @param array $room
+ * @return string
+ */
+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'];
+/**
+ * @param array $room
+ * @return string
+ */
+function room_edit_link($room)
+{
+ return page_link_to('admin_rooms', ['show' => 'edit', 'id' => $room['RID']]);
}
/**
* Loads room by request param room_id
+ *
+ * @param bool $onlyVisible
+ * @return array
*/
-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;
-}
+function load_room($onlyVisible = true)
+{
+ if (!test_request_int('room_id')) {
+ redirect(page_link_to());
+ }
-?> \ No newline at end of file
+ $room = Room(request()->input('room_id'), $onlyVisible);
+ if ($room == null) {
+ redirect(page_link_to());
+ }
+
+ return $room;
+}