diff --git a/app/controllers/resources/room_planning.php b/app/controllers/resources/room_planning.php index 3fd1dd3f329e15456fb093e7a1599625d47dad53..593201a875d5381c411e9f5ffc0135cac0de7caa 100644 --- a/app/controllers/resources/room_planning.php +++ b/app/controllers/resources/room_planning.php @@ -190,13 +190,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(); @@ -220,14 +222,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, @@ -240,7 +242,7 @@ class Resources_RoomPlanningController extends AuthenticatedController '', [ 'allday' => true, - 'defaultDate' => Request::get('defaultDate', date('Y-m-d')) + 'defaultDate' => $this->date->format('Y-m-d') ] ), null, @@ -260,13 +262,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) ] ), [] @@ -275,16 +277,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 3da7904324039a3fbdde1aad3c691db783cd06d9..a63e4ab19f0378cb693daac7e6c01b434f3e7bda 100644 --- a/app/controllers/room_management/planning.php +++ b/app/controllers/room_management/planning.php @@ -83,13 +83,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') + )); $clipboards = Clipboard::getClipboardsForUser($GLOBALS['user']->id); if (!empty($clipboards)) { diff --git a/app/views/resources/room_planning/_sidebar_date_selection.php b/app/views/resources/room_planning/_sidebar_date_selection.php index b7693d4f6af3399ea5f9b64c2634bb042943438c..d1ac876f293537dbd6936e1afe8f72a4a09dd850 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 312d9a3dcf8526303da050217583e09a228991f3..e3addfa490975185916aa644f083c76e9b30e489 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.php b/lib/classes/Request.php index d72a6a991d53cfe0da2c532f93ce5477df593202..b844cfc9037c61a15ebf4ef20bdf2e770a06f6f2 100644 --- a/lib/classes/Request.php +++ b/lib/classes/Request.php @@ -328,58 +328,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; }