Skip to content
Snippets Groups Projects
Commit 198c2fea authored by Jan-Hendrik Willms's avatar Jan-Hendrik Willms
Browse files

always return valid default and some cleaning up, fixes #3676

Closes #3676

Merge request studip/studip!2552
parent 9c4acc18
No related branches found
No related tags found
No related merge requests found
...@@ -190,13 +190,15 @@ class Resources_RoomPlanningController extends AuthenticatedController ...@@ -190,13 +190,15 @@ class Resources_RoomPlanningController extends AuthenticatedController
); );
} }
$week_timestamp = Request::get('timestamp');
$default_date = Request::get('defaultDate'); $week_timestamp = Request::int('timestamp');
$this->date = new DateTime(); $default_date = Request::get('defaultDate');
$this->date = new DateTime();
if ($week_timestamp) { if ($week_timestamp) {
$this->date->setTimestamp($week_timestamp); $this->date->setTimestamp($week_timestamp);
} elseif ($default_date) { } 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(); $week_timestamp = $this->date->getTimestamp();
} else { } else {
$week_timestamp = $this->date->getTimestamp(); $week_timestamp = $this->date->getTimestamp();
...@@ -220,14 +222,14 @@ class Resources_RoomPlanningController extends AuthenticatedController ...@@ -220,14 +222,14 @@ class Resources_RoomPlanningController extends AuthenticatedController
} }
$views = new ViewsWidget(); $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)) { if ($this->resource->userHasPermission($this->user)) {
$views->addLink( $views->addLink(
_('Standard Zeitfenster'), _('Standard Zeitfenster'),
URLHelper::getURL( URLHelper::getURL(
'', '',
[ [
'defaultDate' => Request::get('defaultDate', date('Y-m-d')) 'defaultDate' => $this->date->format('Y-m-d')
] ]
), ),
null, null,
...@@ -240,7 +242,7 @@ class Resources_RoomPlanningController extends AuthenticatedController ...@@ -240,7 +242,7 @@ class Resources_RoomPlanningController extends AuthenticatedController
'', '',
[ [
'allday' => true, 'allday' => true,
'defaultDate' => Request::get('defaultDate', date('Y-m-d')) 'defaultDate' => $this->date->format('Y-m-d')
] ]
), ),
null, null,
...@@ -260,13 +262,13 @@ class Resources_RoomPlanningController extends AuthenticatedController ...@@ -260,13 +262,13 @@ class Resources_RoomPlanningController extends AuthenticatedController
'resources/room_planning/booking_plan/' . $this->resource->id, 'resources/room_planning/booking_plan/' . $this->resource->id,
[ [
'display_all_requests' => '1', 'display_all_requests' => '1',
'allday' => Request::get('allday', false) 'allday' => Request::bool('allday', false)
] ]
), ),
$this->url_for( $this->url_for(
'resources/room_planning/booking_plan/' . $this->resource->id, 'resources/room_planning/booking_plan/' . $this->resource->id,
[ [
'allday' => Request::get('allday', false) 'allday' => Request::bool('allday', false)
] ]
), ),
[] []
...@@ -275,16 +277,14 @@ class Resources_RoomPlanningController extends AuthenticatedController ...@@ -275,16 +277,14 @@ class Resources_RoomPlanningController extends AuthenticatedController
$sidebar->addWidget($options); $sidebar->addWidget($options);
} }
$dpicker = new SidebarWidget(); $sidebar->addWidget(new TemplateWidget(
$dpicker->setTitle('Datum'); _('Datum'),
$picker_html = $this->get_template_factory()->render( $this->get_template_factory()->open('resources/room_planning/_sidebar_date_selection.php'),
'resources/room_planning/_sidebar_date_selection.php' ['date' => $this->date]
); ));
$dpicker->addElement(new WidgetElement($picker_html));
$sidebar->addWidget($dpicker);
$actions = new ActionsWidget(); $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) { if ($this->user_has_booking_permissions) {
$actions->addLink( $actions->addLink(
_('Neue Buchung'), _('Neue Buchung'),
......
...@@ -83,13 +83,10 @@ class RoomManagement_PlanningController extends AuthenticatedController ...@@ -83,13 +83,10 @@ class RoomManagement_PlanningController extends AuthenticatedController
} }
$sidebar->addWidget($views); $sidebar->addWidget($views);
$dpicker = new SidebarWidget(); $sidebar->addWidget(new TemplateWidget(
$dpicker->setTitle('Datum'); _('Datum'),
$picker_html = $this->get_template_factory()->render( $this->get_template_factory()->open('resources/room_planning/_sidebar_date_selection.php')
'resources/room_planning/_sidebar_date_selection.php' ));
);
$dpicker->addElement(new WidgetElement($picker_html));
$sidebar->addWidget($dpicker);
$clipboards = Clipboard::getClipboardsForUser($GLOBALS['user']->id); $clipboards = Clipboard::getClipboardsForUser($GLOBALS['user']->id);
if (!empty($clipboards)) { if (!empty($clipboards)) {
......
<?php <?php
if(Request::submitted('defaultDate')){ if (!isset($date)) {
$submitted_date = explode('-', Request::get('defaultDate')); $date = new DateTime();
$default_date = $submitted_date[2] . '.' . $submitted_date[1] . '.' . $submitted_date[0]; }
} else {
$default_date = strftime('%x', time());
}
?> ?>
<?= \Studip\LinkButton::create( <?= \Studip\LinkButton::create(
_('Heute'), _('Heute'),
URLHelper::getURL('', ['defaultDate' => date('Y-m-d', time())]) URLHelper::getURL('', ['defaultDate' => date('Y-m-d')])
); ?> ); ?>
<input id="booking-plan-jmpdate" type="text" <input id="booking-plan-jmpdate" type="text"
name="booking-plan-jmpdate" value="<?= $default_date; ?>"> name="booking-plan-jmpdate" value="<?= $date->format('d.m.Y') ?>">
...@@ -72,7 +72,7 @@ ...@@ -72,7 +72,7 @@
in_array(Request::get("defaultView"), ['dayGridMonth','timeGridWeek','timeGridDay']) in_array(Request::get("defaultView"), ['dayGridMonth','timeGridWeek','timeGridDay'])
? Request::get("defaultView") ? Request::get("defaultView")
: 'timeGridWeek', : 'timeGridWeek',
'defaultDate' => Request::get("defaultDate"), 'defaultDate' => $date->format('Y-m-d'),
'eventSources' => [ 'eventSources' => [
[ [
'url' => URLHelper::getURL( 'url' => URLHelper::getURL(
......
...@@ -328,58 +328,58 @@ class Request implements ArrayAccess, IteratorAggregate ...@@ -328,58 +328,58 @@ class Request implements ArrayAccess, IteratorAggregate
{ {
$value = self::get($param); $value = self::get($param);
if (!$value) { if ($value) {
//In case the first field is not set // Combine the format specifications and the
//use the default value, if any: // values into one string each.
if ($default instanceof DateTime) { $combined_format = $format;
return $default; $combined_value = $value;
} else {
$datetime = new DateTime(); // The second format and value is only added
$datetime->setTimestamp(0); // when $second_param and $second_format are set
return $datetime; // 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 // The time zone may not be set in the fields
//values into one string each. // so we use the default timezone from a new
$combined_format = $format; // DateTime object:
$combined_value = $value; $value = new DateTime();
$time_zone = $value->getTimezone();
//The second format and value is only added
//when $second_param and $second_format are set // Now we return a DateTime object created from the
//and a second value could be retrieved. // specified date value(s):
if ($second_param && $second_format) { $result = DateTime::createFromFormat(
$second_value = Request::get($second_param); $combined_format,
if ($second_value) { $combined_value,
$combined_format .= ' ' . $second_format; $time_zone
$combined_value .= ' ' . $second_value; );
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 ( // In case the first field is not set
$result // use the default value, if any:
&& !$second_param if ($default instanceof DateTime) {
&& !$second_format return $default;
&& !preg_match('/[aAghGHisvu]/', $format) // Ensure no time in format
) {
$result->setTime(0, 0);
} }
return $result; return false;
} }
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment