From f9b8dbafdc245e1e43910d49d5cfff172a36fcab Mon Sep 17 00:00:00 2001 From: Moritz Strohm Date: Fri, 25 Feb 2022 16:55:45 +0100 Subject: fixed PHP8 errors in Location and ResourceRequest classes --- lib/models/resources/Location.class.php | 78 +++++++++++++------------- lib/models/resources/ResourceRequest.class.php | 10 ++-- 2 files changed, 45 insertions(+), 43 deletions(-) diff --git a/lib/models/resources/Location.class.php b/lib/models/resources/Location.class.php index 9191053..2983318 100644 --- a/lib/models/resources/Location.class.php +++ b/lib/models/resources/Location.class.php @@ -23,10 +23,10 @@ class Location extends Resource protected static $required_properties = [ 'geo_coordinates' ]; - + protected static function configure($config = []) { - if (!is_array($config['additional_fields'])) { + if (!array_key_exists('additional_fields', $config) || !is_array($config['additional_fields'])) { $config['additional_fields'] = []; } foreach (self::$required_properties as $property) { @@ -35,18 +35,18 @@ class Location extends Resource 'set' => 'setProperty' ]; } - + $config['additional_fields']['buildings']['get'] = 'findBuildings'; - + $config['additional_fields']['director'] = [ 'get' => 'getPropertyRelatedObject', 'set' => 'setPropertyRelatedObject' ]; - + $config['registered_callbacks']['before_store'][] = 'cbValidate'; parent::configure($config); } - + public static function getTranslatedClassName($item_count = 1) { return ngettext( @@ -55,7 +55,7 @@ class Location extends Resource $item_count ); } - + /** * Returns all locations which are stored in the database. * @@ -70,7 +70,7 @@ class Location extends Resource ORDER BY sort_position DESC, name ASC, mkdate ASC" ); } - + /** * Returns the part of the URL for getLink and getURL which will be * placed inside the calls to URLHelper::getLink and URLHelper::getURL @@ -83,7 +83,7 @@ class Location extends Resource _('Zuer Erstellung der URL fehlt eine Standort-ID!') ); } - + switch ($action) { case 'show': return 'dispatch.php/resources/location/index/' . $id; @@ -99,7 +99,7 @@ class Location extends Resource return parent::buildPathForAction($action, $id); } } - + /** * Returns the appropriate link for the location action that shall be * executed on a location. @@ -124,8 +124,8 @@ class Location extends Resource $link_parameters ); } - - + + /** * Returns the appropriate URL for the location action that shall be * executed on a location. @@ -150,17 +150,17 @@ class Location extends Resource $url_parameters ); } - + public function getRequiredPropertyNames() { return self::$required_properties; } - + public function __toString() { return $this->getFullName(); } - + public function cbValidate() { if ($this->parent_id) { @@ -172,7 +172,7 @@ class Location extends Resource ) ); } - + if (!is_a($this->category->class_name, get_class($this), true)) { //Only resources with the Location category can be handled //with this class! @@ -184,7 +184,7 @@ class Location extends Resource ); } } - + /** * Returns the full (localised) name of the location. * @@ -197,30 +197,30 @@ class Location extends Resource $this->name ); } - + public function getDefaultPictureUrl() { return $this->getIcon()->asImagePath(); } - + public function getIcon($role = Icon::ROLE_INFO) { return Icon::create('place', $role); } - + public function checkHierarchy() { //We must check if this location has locations as children //or rooms, buildings or locations as parents. //In any of those cases the hierarchy is invalid! - + $children = $this->findChildrenByClassName('Location'); if (count($children) > 0) { //At least one child anywhere below this location //resource is a location, too. return false; } - + $parents = ResourceManager::getHierarchy($this); //We do not need to check this element: array_shift($parents); @@ -232,12 +232,12 @@ class Location extends Resource return false; } } - + //If code execution reaches this point then //the hierarchy around this location is valid. return true; } - + /** * Returns the link for an action for this building. * This is the non-static variant of Building::getLinkForAction. @@ -257,7 +257,7 @@ class Location extends Resource $link_parameters ); } - + /** * Returns the URL for an action for this location. * This is the non-static variant of Location::getURLForAction. @@ -276,9 +276,9 @@ class Location extends Resource $url_parameters ); } - + // Relation methods: - + /** * Retrieves the buildings which are associated to this location * by looking up the child resources of this location. @@ -289,14 +289,14 @@ class Location extends Resource public function findBuildings() { $buildings = parent::findChildrenByClassName('Building'); - + $result = []; foreach ($buildings as $building) { $result[] = Building::toObject($building); } return $result; } - + /** * Adds a child resource to this location. The child resource * must not be a resource of the Location class. @@ -317,7 +317,7 @@ class Location extends Resource } return parent::addChild($resource); } - + public function createSimpleBooking( User $user, DateTime $begin, @@ -330,7 +330,7 @@ class Location extends Resource { return null; } - + public function createBookingFromRequest( User $user, ResourceRequest $request, @@ -344,7 +344,7 @@ class Location extends Resource { return null; } - + public function createBooking( User $user, $range_id = null, @@ -361,7 +361,7 @@ class Location extends Resource { return null; } - + public function createSimpleRequest( User $user, DateTime $begin, @@ -372,7 +372,7 @@ class Location extends Resource { return null; } - + public function createRequest( User $user, $date_range_ids = null, @@ -383,7 +383,7 @@ class Location extends Resource { return null; } - + public function createLock( User $user, DateTime $begin, @@ -393,7 +393,7 @@ class Location extends Resource { return null; } - + public function isAssigned( DateTime $begin, DateTime $end, @@ -402,7 +402,7 @@ class Location extends Resource { return false; } - + public function isReserved( DateTime $begin, DateTime $end, @@ -411,7 +411,7 @@ class Location extends Resource { return false; } - + public function isLocked( DateTime $begin, DateTime $end, @@ -420,7 +420,7 @@ class Location extends Resource { return true; } - + public function isAvailable( DateTime $begin, DateTime $end, diff --git a/lib/models/resources/ResourceRequest.class.php b/lib/models/resources/ResourceRequest.class.php index 9ac4983..e5bf331 100644 --- a/lib/models/resources/ResourceRequest.class.php +++ b/lib/models/resources/ResourceRequest.class.php @@ -1143,8 +1143,8 @@ class ResourceRequest extends SimpleORMap implements PrivacyObject, Studip\Calen if ($with_range) { $interval['range'] = 'CourseDate'; $interval['range_id'] = $this->termin_id; - $interval['booked_room'] = $this->date->room_booking->resource_id; - $interval['booking_id'] = $this->date->room_booking->id; + $interval['booked_room'] = $this->date->room_booking ? $this->date->room_booking->resource_id : ''; + $interval['booking_id'] = $this->date->room_booking ? $this->date->room_booking->id : ''; } return [$interval]; } elseif ($this->metadate_id) { @@ -1230,8 +1230,10 @@ class ResourceRequest extends SimpleORMap implements PrivacyObject, Studip\Calen if ($interval['range'] == 'CourseDate') { $date = call_user_func([$interval['range'], 'find'], $interval['range_id']); - if ($room_obj = Room::find($date->room_booking->resource_id)) { - $room = $room_obj->name; + if ($date->room_booking) { + if ($room_obj = Room::find($date->room_booking->resource_id)) { + $room = $room_obj->name; + } } } -- cgit v1.0