aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJan-Hendrik Willms <tleilax+studip@gmail.com>2024-06-25 13:05:00 +0000
committerJan-Hendrik Willms <tleilax+github@gmail.com>2024-06-27 09:43:13 +0200
commit39f9804202fc9c0ccd718a934701957706ddc955 (patch)
tree0f4cb98f912a6d32106f72337d7c30af7dacbf82
parent0c0b8d1ef083ca390dc58ee2ca4dbabce54d374b (diff)
always return valid default and some cleaning up, fixes #3676
Closes #3676 Merge request studip/studip!2552
-rw-r--r--app/controllers/resources/room_planning.php34
-rw-r--r--app/controllers/room_management/planning.php11
-rw-r--r--app/views/resources/room_planning/_sidebar_date_selection.php13
-rw-r--r--app/views/resources/room_planning/booking_plan.php2
-rw-r--r--lib/classes/Request.class.php88
5 files changed, 71 insertions, 77 deletions
diff --git a/app/controllers/resources/room_planning.php b/app/controllers/resources/room_planning.php
index d0a0b89..86205bd 100644
--- a/app/controllers/resources/room_planning.php
+++ b/app/controllers/resources/room_planning.php
@@ -184,13 +184,15 @@ class Resources_RoomPlanningController extends AuthenticatedController
);
}
- $week_timestamp = Request::get('timestamp');
- $default_date = Request::get('defaultDate');
- $this->date = new DateTime();
+
+ $week_timestamp = Request::int('timestamp');
+ $default_date = Request::get('defaultDate');
+ $this->date = new DateTime();
+
if ($week_timestamp) {
$this->date->setTimestamp($week_timestamp);
} elseif ($default_date) {
- $this->date = Request::getDateTime('defaultDate');
+ $this->date = Request::getDateTime('defaultDate', 'Y-m-d', null, null, $this->date);
$week_timestamp = $this->date->getTimestamp();
} else {
$week_timestamp = $this->date->getTimestamp();
@@ -214,14 +216,14 @@ class Resources_RoomPlanningController extends AuthenticatedController
}
$views = new ViewsWidget();
- if ($GLOBALS['user']->id && ($GLOBALS['user']->id != 'nobody')) {
+ if ($GLOBALS['user']->id && $GLOBALS['user']->id !== 'nobody') {
if ($this->resource->userHasPermission($this->user)) {
$views->addLink(
_('Standard Zeitfenster'),
URLHelper::getURL(
'',
[
- 'defaultDate' => Request::get('defaultDate', date('Y-m-d'))
+ 'defaultDate' => $this->date->format('Y-m-d')
]
),
null,
@@ -234,7 +236,7 @@ class Resources_RoomPlanningController extends AuthenticatedController
'',
[
'allday' => true,
- 'defaultDate' => Request::get('defaultDate', date('Y-m-d'))
+ 'defaultDate' => $this->date->format('Y-m-d')
]
),
null,
@@ -254,13 +256,13 @@ class Resources_RoomPlanningController extends AuthenticatedController
'resources/room_planning/booking_plan/' . $this->resource->id,
[
'display_all_requests' => '1',
- 'allday' => Request::get('allday', false)
+ 'allday' => Request::bool('allday', false)
]
),
$this->url_for(
'resources/room_planning/booking_plan/' . $this->resource->id,
[
- 'allday' => Request::get('allday', false)
+ 'allday' => Request::bool('allday', false)
]
),
[]
@@ -269,16 +271,14 @@ class Resources_RoomPlanningController extends AuthenticatedController
$sidebar->addWidget($options);
}
- $dpicker = new SidebarWidget();
- $dpicker->setTitle('Datum');
- $picker_html = $this->get_template_factory()->render(
- 'resources/room_planning/_sidebar_date_selection.php'
- );
- $dpicker->addElement(new WidgetElement($picker_html));
- $sidebar->addWidget($dpicker);
+ $sidebar->addWidget(new TemplateWidget(
+ _('Datum'),
+ $this->get_template_factory()->open('resources/room_planning/_sidebar_date_selection.php'),
+ ['date' => $this->date]
+ ));
$actions = new ActionsWidget();
- if ($GLOBALS['user']->id && ($GLOBALS['user']->id != 'nobody')) {
+ if ($GLOBALS['user']->id && $GLOBALS['user']->id !== 'nobody') {
if ($this->user_has_booking_permissions) {
$actions->addLink(
_('Neue Buchung'),
diff --git a/app/controllers/room_management/planning.php b/app/controllers/room_management/planning.php
index 681ca82..482cb25 100644
--- a/app/controllers/room_management/planning.php
+++ b/app/controllers/room_management/planning.php
@@ -72,13 +72,10 @@ class RoomManagement_PlanningController extends AuthenticatedController
}
$sidebar->addWidget($views);
- $dpicker = new SidebarWidget();
- $dpicker->setTitle('Datum');
- $picker_html = $this->get_template_factory()->render(
- 'resources/room_planning/_sidebar_date_selection.php'
- );
- $dpicker->addElement(new WidgetElement($picker_html));
- $sidebar->addWidget($dpicker);
+ $sidebar->addWidget(new TemplateWidget(
+ _('Datum'),
+ $this->get_template_factory()->open('resources/room_planning/_sidebar_date_selection.php')
+ ));
//Add clipboard widget:
$clipboard_widget = new RoomClipboardWidget();
diff --git a/app/views/resources/room_planning/_sidebar_date_selection.php b/app/views/resources/room_planning/_sidebar_date_selection.php
index b7693d4..d1ac876 100644
--- a/app/views/resources/room_planning/_sidebar_date_selection.php
+++ b/app/views/resources/room_planning/_sidebar_date_selection.php
@@ -1,15 +1,12 @@
<?php
- if(Request::submitted('defaultDate')){
- $submitted_date = explode('-', Request::get('defaultDate'));
- $default_date = $submitted_date[2] . '.' . $submitted_date[1] . '.' . $submitted_date[0];
- } else {
- $default_date = strftime('%x', time());
- }
+if (!isset($date)) {
+ $date = new DateTime();
+}
?>
<?= \Studip\LinkButton::create(
_('Heute'),
- URLHelper::getURL('', ['defaultDate' => date('Y-m-d', time())])
+ URLHelper::getURL('', ['defaultDate' => date('Y-m-d')])
); ?>
<input id="booking-plan-jmpdate" type="text"
- name="booking-plan-jmpdate" value="<?= $default_date; ?>">
+ name="booking-plan-jmpdate" value="<?= $date->format('d.m.Y') ?>">
diff --git a/app/views/resources/room_planning/booking_plan.php b/app/views/resources/room_planning/booking_plan.php
index d314218..f3b8461 100644
--- a/app/views/resources/room_planning/booking_plan.php
+++ b/app/views/resources/room_planning/booking_plan.php
@@ -72,7 +72,7 @@
in_array(Request::get("defaultView"), ['dayGridMonth','timeGridWeek','timeGridDay'])
? Request::get("defaultView")
: 'timeGridWeek',
- 'defaultDate' => Request::get("defaultDate"),
+ 'defaultDate' => $date->format('Y-m-d'),
'eventSources' => [
[
'url' => URLHelper::getURL(
diff --git a/lib/classes/Request.class.php b/lib/classes/Request.class.php
index 766ef0b..ba67e95 100644
--- a/lib/classes/Request.class.php
+++ b/lib/classes/Request.class.php
@@ -301,58 +301,58 @@ class Request implements ArrayAccess, IteratorAggregate
{
$value = self::get($param);
- if (!$value) {
- //In case the first field is not set
- //use the default value, if any:
- if ($default instanceof DateTime) {
- return $default;
- } else {
- $datetime = new DateTime();
- $datetime->setTimestamp(0);
- return $datetime;
+ if ($value) {
+ // Combine the format specifications and the
+ // values into one string each.
+ $combined_format = $format;
+ $combined_value = $value;
+
+ // The second format and value is only added
+ // when $second_param and $second_format are set
+ // and a second value could be retrieved.
+ if ($second_param && $second_format) {
+ $second_value = Request::get($second_param);
+ if ($second_value) {
+ $combined_format .= ' ' . $second_format;
+ $combined_value .= ' ' . $second_value;
+ }
}
- }
- //Combine the format specifications and the
- //values into one string each.
- $combined_format = $format;
- $combined_value = $value;
-
- //The second format and value is only added
- //when $second_param and $second_format are set
- //and a second value could be retrieved.
- if ($second_param && $second_format) {
- $second_value = Request::get($second_param);
- if ($second_value) {
- $combined_format .= ' ' . $second_format;
- $combined_value .= ' ' . $second_value;
+ // The time zone may not be set in the fields
+ // so we use the default timezone from a new
+ // DateTime object:
+ $value = new DateTime();
+ $time_zone = $value->getTimezone();
+
+ // Now we return a DateTime object created from the
+ // specified date value(s):
+ $result = DateTime::createFromFormat(
+ $combined_format,
+ $combined_value,
+ $time_zone
+ );
+
+ if ($result !== false) {
+ if (
+ !$second_param
+ && !$second_format
+ && !preg_match('/[aAghGHisvu]/', $format) // Ensure no time in format
+ ) {
+ $result->setTime(0, 0);
+ }
+
+ return $result;
}
}
- //The time zone may not be set in the fields
- //so we use the default timezone from a new
- //DateTime object:
- $value = new DateTime();
- $time_zone = $value->getTimezone();
-
- //Now we return a DateTime object created from the
- //specified date value(s):
- $result = DateTime::createFromFormat(
- $combined_format,
- $combined_value,
- $time_zone
- );
- if (
- $result
- && !$second_param
- && !$second_format
- && !preg_match('/[aAghGHisvu]/', $format) // Ensure no time in format
- ) {
- $result->setTime(0, 0);
+ // In case the first field is not set
+ // use the default value, if any:
+ if ($default instanceof DateTime) {
+ return $default;
}
- return $result;
+ return false;
}