Skip to content

Commit

Permalink
BOOK: adjust deletion of booking objects. (#21705)
Browse files Browse the repository at this point in the history
If a booking object is deleted all reservations and calendar entries
related to the booking object will be deleted too. Those steps were
missing before, therefore the entry was still visible in the calendar.

Mantis Ticket: https://mantis.ilias.de/view.php?id=21705
  • Loading branch information
lukastocker committed Oct 12, 2023
1 parent 174e982 commit c9a3387
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 0 deletions.
11 changes: 11 additions & 0 deletions Modules/BookingManager/Objects/class.ilBookingObject.php
Original file line number Diff line number Diff line change
Expand Up @@ -410,6 +410,17 @@ public function delete(): int
return 0;
}

public function deleteReservationAndCalEntry(int $object_id): void
{
$reservation_db = new ilBookingReservationDBRepository($this->db);
$reservation_id = $reservation_db->getReservationIdByBookingObjectId($object_id);
$reservation = new ilBookingReservation($reservation_id);
$entry = new ilCalendarEntry($reservation->getCalendarEntry());

$reservation_db->delete($reservation_id);
$entry->delete();
}

/**
* Get nr of available items for a set of object ids
* @param int[] $a_obj_ids
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -536,6 +536,7 @@ public function delete(): void
$lng = $this->lng;

$obj = new ilBookingObject($this->object_id);
$obj->deleteReservationAndCalEntry($this->object_id);
$obj->delete();

$this->tpl->setOnScreenMessage('success', $lng->txt('book_object_deleted'), true);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -328,4 +328,14 @@ public function getCachedContextObjBookingInfo(
return ($row["context_obj_id"] == $context_obj_id);
});
}

public function getReservationIdByBookingObjectId(int $booking_object_id): int
{
$query = "SELECT booking_reservation_id FROM booking_reservation " . PHP_EOL
. " WHERE object_id = " . $this->db->quote($booking_object_id, "integer");
$res = $this->db->query($query);
$ret = $this->db->fetchAssoc($res);

return (int) $ret['booking_reservation_id'];
}
}

0 comments on commit c9a3387

Please sign in to comment.