diff --git a/app/routes/Consultations.php b/app/routes/Consultations.php deleted file mode 100644 index 1bd82c9072f3262eb899831515ab0bebb556cd1a..0000000000000000000000000000000000000000 --- a/app/routes/Consultations.php +++ /dev/null @@ -1,195 +0,0 @@ -<?php -namespace RESTAPI\Routes; - -/** - * @author Jan-Hendrik Willms <tleilax+studip@gmail.com> - * @license GPL2 or any later version - * @deprecated Since Stud.IP 5.0. Will be removed in Stud.IP 5.2. - */ -class Consultations extends \RESTAPI\RouteMap -{ - /* - * @get /consultations - * @get /consultations/blocks - * @get /consultations/slots - * @get /consultations/bookings - * - * @get /users/:user_id/consultations/slots - * @get /users/:user_id/consultations/bookings - */ - public function getDiscovery() - { - $routes = $this->router->getRoutes(true); - foreach ($routes as $uri_template => $methods) { - foreach ($methods as $method => $route) { - $routes[$uri_template][$method] = $route['description']; - } - } - return $routes; - } - - /** - * @get /consultations/blocks/:block_id - */ - public function getBlock($block_id) - { - return self::blockToJSON($this->requireBlock($block_id)); - } - - /** - * @get /consultations/slots/bulk - */ - public function getManySlots() - { - $ids = \Request::intArray('ids'); - if (!$ids) { - $this->halt(400, 'No ids provided'); - } - - return \ConsultationSlot::findAndMapMany( - function ($slot) { - return self::slotToJSON($slot); - }, - $ids - ); - } - - /** - * @get /consultations/slots/:slot_id - */ - public function getSlot($slot_id) - { - return self::slotToJSON($this->requireSlot($slot_id)); - } - - /** - * @get /consultations/bookings/:booking_id - */ - public function getBooking($booking_id) - { - return self::bookingToJSON($this->requireBooking($booking_id)); - } - - /** - * @delete /consultations/bookings/:booking_id - */ - public function deleteBooking($booking_id) - { - $booking = $this->requireBooking($booking_id); - - if ($GLOBALS['user']->id === $booking->user_id) { - $booking->delete(); - } elseif ($GLOBALS['user']->id === $booking->slot->block->teacher_id) { - } else { - $this->halt(403); - } - - - } - - /** - * Finds and returns the block with the given id. If no block exists with - * the given id, a 404 is issued. - * - * @param int $block_id Id of the block - */ - private function requireBlock($block_id) - { - $block = \ConsultationBlock::find($block_id); - if (!$block) { - $this->notFound(); - } - return $block; - } - - /** - * Converts the block to it's JSON representation. - * - * @param ConsultationBlock $block - * @return array - */ - private static function blockToJSON(\ConsultationBlock $block) - { - return [ - 'id' => (int) $block->id, - 'teacher_id' => $block->teacher_id, - 'start' => (int) $block->start, - 'end' => (int) $block->end, - 'room' => (string) $block->room, - 'note' => (string) $block->note, - 'size' => (int) $block->size, - 'course_id' => $block->course_id ?: null, - 'mkdate' => (int) $block->mkdate, - 'chdate' => (int) $block->chdate, - ]; - } - - /** - * Finds and returns the slot with the given id. If no slot exists with - * the given id, a 404 is issued. - * - * @param int $slot_id Id of the slot - */ - private function requireSlot($slot_id) - { - $slot = \ConsultationSlot::find($slot_id); - if (!$slot) { - $this->notFound(); - } - return $slot; - } - - /** - * Converts the slot to it's JSON representation. - * - * @param ConsultationSlot $slot - * @return array - */ - private static function slotToJSON(\ConsultationSlot $slot) - { - return [ - 'id' => (int) $slot->id, - 'block_id' => (int) $slot->block_id, - 'start_time' => (int) $slot->start_time, - 'end_time' => (int) $slot->end_time, - 'note' => (string) $slot->note, - 'mkdate' => (int) $slot->mkdate, - 'chdate' => (int) $slot->chdate, - - 'booking_count' => count($slot->bookings), - ]; - } - - /** - * Finds and returns the booking with the given id. If no booking exists - * with the given id, a 404 is issued. - * - * @param int $booking_id Id of the booking - */ - private function requireBooking($booking_id) - { - $booking = \ConsultationBooking::find($booking_id); - if (!$booking) { - $this->notFound(); - } - return $booking; - } - - /** - * Converts the booking to it's JSON representation. - * - * @param ConsultationBooking $booking - * @return array - */ - private static function bookingToJSON(\ConsultationBooking $booking) - { - return [ - 'id' => (int) $booking->id, - 'slot_id' => $booking->slot_id, - 'user_id' => $booking->user_id, - 'reason' => (string) $booking->reason, - 'mkdate' => (int) $booking->mkdate, - 'chdate' => (int) $booking->chate, - ]; - } -} diff --git a/lib/classes/restapi/Router.php b/lib/classes/restapi/Router.php index d6a331c98a6fa57e5192d665ef24debc8f6876cc..34db554d437bd5f75edcfad1defed2f4ae835c78 100644 --- a/lib/classes/restapi/Router.php +++ b/lib/classes/restapi/Router.php @@ -415,7 +415,6 @@ class Router 'Activity', 'Blubber', 'Clipboard', - 'Consultations', 'Contacts', 'Course', 'Discovery', diff --git a/resources/assets/javascripts/bootstrap/consultations.js b/resources/assets/javascripts/bootstrap/consultations.js index 6897a09b087a50e1c339622b6839047a2a03a242..dec8f4aee8676d652a38b6d7f85261fd0f52a1eb 100644 --- a/resources/assets/javascripts/bootstrap/consultations.js +++ b/resources/assets/javascripts/bootstrap/consultations.js @@ -9,16 +9,17 @@ $(document).on('click', '.consultation-delete-check:not(.ignore)', event => { return false; } - STUDIP.api.GET('consultations/slots/bulk', {data: {ids: ids}}).done(slots => { - let bookings = 0; - slots.forEach(slot => bookings += slot.booking_count); - if (bookings === 0) { + let requests = ids.map(id => { + return STUDIP.jsonapi.GET(`consultation-slots/${id}/bookings`).then(result => result.data.length); + }); + $.when(...requests).done((...results) => { + if (results.some(result => result > 0)) { + $(event.target).addClass('ignore').click().removeClass('ignore'); + } else { STUDIP.Dialog.confirm($gettext('Wollen Sie diese Termine wirklich löschen?')).done(() => { $('<input type="hidden" name="delete" value="1"/>').appendTo(form); form.submit(); }); - } else { - $(event.target).addClass('ignore').click().removeClass('ignore'); } });