From 8f774c51437fb8fafa3037395bf1bfbd1f5a1e75 Mon Sep 17 00:00:00 2001 From: Moritz Strohm Date: Wed, 10 Jul 2024 17:35:10 +0200 Subject: course/timesrooms: provide link to the course whose booking overlap an attempted booking in the current course --- app/controllers/course/timesrooms.php | 36 +++++++++++++++++++--- app/controllers/resources/booking.php | 2 ++ app/controllers/resources/room_request.php | 2 ++ lib/exceptions/Exception.php | 8 +++++ lib/exceptions/ResourceBookingException.php | 26 ++++++++++++++++ lib/exceptions/ResourceBookingOverlapException.php | 26 ++++++++++++++++ .../resources/ResourceBookingException.php | 24 --------------- .../resources/ResourceBookingOverlapException.php | 24 --------------- lib/models/resources/Resource.php | 11 +++++-- lib/models/resources/ResourceBooking.php | 9 +++++- 10 files changed, 112 insertions(+), 56 deletions(-) create mode 100644 lib/exceptions/ResourceBookingException.php create mode 100644 lib/exceptions/ResourceBookingOverlapException.php delete mode 100644 lib/exceptions/resources/ResourceBookingException.php delete mode 100644 lib/exceptions/resources/ResourceBookingOverlapException.php diff --git a/app/controllers/course/timesrooms.php b/app/controllers/course/timesrooms.php index 5eab38a..de333f3 100644 --- a/app/controllers/course/timesrooms.php +++ b/app/controllers/course/timesrooms.php @@ -1,5 +1,8 @@ * @license GPL2 or any later version @@ -528,11 +531,34 @@ class Course_TimesroomsController extends AuthenticatedController try { $failure = !$termin->bookRoom($room, $preparation_time ?: 0); } catch (ResourceBookingException|ResourceBookingOverlapException $e) { - PageLayout::postError(sprintf( - _('Der angegebene Raum konnte für den Termin %1$s nicht gebucht werden: %2$s'), - '' . htmlReady($termin->getFullName()) . '', - $e->getMessage() - )); + $course = $e->getRange(); + $link = null; + + if ($course instanceof Course) { + if ($course->isEditableByUser($GLOBALS['user']->id)) { + //Link to the times/rooms page: + $link = new LinkElement( + _('Direkt zur Veranstaltung'), + URLHelper::getURL('dispatch.php/course/timesrooms/index', ['cid' => $course->id]), + Icon::create('link-intern') + ); + } elseif ($course->isAccessibleToUser($GLOBALS['user']->id)) { + //Link to the details page: + $link = new LinkElement( + _('Direkt zur Veranstaltung'), + URLHelper::getURL('course/details/index', ['cid' => $course->id]), + Icon::create('link-intern') + ); + } + } + PageLayout::postError( + sprintf( + _('Der angegebene Raum konnte für den Termin %1$s nicht gebucht werden: %2$s'), + '' . htmlReady($termin->getFullName()) . '', + $e->getMessage() + ), + $link ? [$link->render()] : [] + ); } } if ($failure) { diff --git a/app/controllers/resources/booking.php b/app/controllers/resources/booking.php index a4722ed..6a9381b 100644 --- a/app/controllers/resources/booking.php +++ b/app/controllers/resources/booking.php @@ -15,6 +15,8 @@ * @since 4.5 */ +use Studip\ResourceBookingOverlapException; + /** * Resources_BookingController contains functionality for resource bookings. diff --git a/app/controllers/resources/room_request.php b/app/controllers/resources/room_request.php index 4c51beb..c6be31b 100644 --- a/app/controllers/resources/room_request.php +++ b/app/controllers/resources/room_request.php @@ -15,6 +15,8 @@ * @since 4.5 */ +use Studip\ResourceBookingException; + /** * Resources_RequestController contains resource request functionality. diff --git a/lib/exceptions/Exception.php b/lib/exceptions/Exception.php index 606c03c..dd4febe 100644 --- a/lib/exceptions/Exception.php +++ b/lib/exceptions/Exception.php @@ -42,6 +42,14 @@ class Exception extends \Exception } /** + * @return \Range|null The range for the exception or null if the exception is not associated to a range. + */ + public function getRange() : ?\Range + { + return $this->range; + } + + /** * Converts the content of the exception into an Information object. * * @return Information An Information representation of the exception. diff --git a/lib/exceptions/ResourceBookingException.php b/lib/exceptions/ResourceBookingException.php new file mode 100644 index 0000000..bc85f91 --- /dev/null +++ b/lib/exceptions/ResourceBookingException.php @@ -0,0 +1,26 @@ + + * @copyright 2017-2024 + * @license http://www.gnu.org/licenses/gpl-2.0.html GPL version 2 + * @category Stud.IP + */ + +namespace Studip; + +/** + * This exception is thrown when a general error occurs when dealing with + * ResourceBooking objects. + */ +class ResourceBookingException extends Exception +{ + +} diff --git a/lib/exceptions/ResourceBookingOverlapException.php b/lib/exceptions/ResourceBookingOverlapException.php new file mode 100644 index 0000000..e965d66 --- /dev/null +++ b/lib/exceptions/ResourceBookingOverlapException.php @@ -0,0 +1,26 @@ + + * @copyright 2017-2024 + * @license http://www.gnu.org/licenses/gpl-2.0.html GPL version 2 + * @category Stud.IP + */ + +namespace Studip; + +/** + * This exception is thrown when a resource booking overlaps with + * other resource bookings or with a resource lock. + */ +class ResourceBookingOverlapException extends Exception +{ + +} diff --git a/lib/exceptions/resources/ResourceBookingException.php b/lib/exceptions/resources/ResourceBookingException.php deleted file mode 100644 index 3dcf483..0000000 --- a/lib/exceptions/resources/ResourceBookingException.php +++ /dev/null @@ -1,24 +0,0 @@ - - * @copyright 2017 - * @license http://www.gnu.org/licenses/gpl-2.0.html GPL version 2 - * @category Stud.IP - */ - -/** - * This exception is thrown when a general error occurs when dealing with - * ResourceBooking objects. - */ -class ResourceBookingException extends InvalidArgumentException -{ - -} diff --git a/lib/exceptions/resources/ResourceBookingOverlapException.php b/lib/exceptions/resources/ResourceBookingOverlapException.php deleted file mode 100644 index 697cfc5..0000000 --- a/lib/exceptions/resources/ResourceBookingOverlapException.php +++ /dev/null @@ -1,24 +0,0 @@ - - * @copyright 2017 - * @license http://www.gnu.org/licenses/gpl-2.0.html GPL version 2 - * @category Stud.IP - */ - -/** - * This exception is thrown when a resource booking overlaps with - * other resource bookings or with a resource lock. - */ -class ResourceBookingOverlapException extends InvalidArgumentException -{ - -} diff --git a/lib/models/resources/Resource.php b/lib/models/resources/Resource.php index 7c870d9..557f736 100644 --- a/lib/models/resources/Resource.php +++ b/lib/models/resources/Resource.php @@ -1,5 +1,8 @@ format('d.m.Y H:i'), $end->format('H:i'), $e->getMessage() - ) + ), + 0, + $e->getRange() ); } else { throw new ResourceBookingException( @@ -876,7 +881,9 @@ class Resource extends SimpleORMap implements StudipItem $begin->format('d.m.Y H:i'), $end->format('d.m.Y H:i'), $e->getMessage() - ) + ), + 0, + $e->getRange() ); } } catch (Exception $e) { diff --git a/lib/models/resources/ResourceBooking.php b/lib/models/resources/ResourceBooking.php index 977cf32..4b049c1 100644 --- a/lib/models/resources/ResourceBooking.php +++ b/lib/models/resources/ResourceBooking.php @@ -1,5 +1,7 @@ format('H:i'), $course->getFullName() ); + $last_course = $course; } else { $time_interval_overlaps[] = sprintf( _('Gebucht im Bereich vom %1$s bis %2$s'), @@ -592,6 +596,7 @@ class ResourceBooking extends SimpleORMap implements PrivacyObject, Studip\Calen $time_interval['end']->format('d.m.Y H:i'), $course->getFullName() ); + $last_course = $course; } else { $time_interval_overlaps[] = sprintf( _('Gebucht im Bereich vom %1$s bis zum %2$s'), @@ -605,7 +610,9 @@ class ResourceBooking extends SimpleORMap implements PrivacyObject, Studip\Calen } if ($time_interval_overlaps) { throw new ResourceBookingOverlapException( - implode(', ', $time_interval_overlaps) + implode(', ', $time_interval_overlaps), + 0, + $last_course ); } -- cgit v1.0