Stud.IP  4.0
 All Data Structures Namespaces Files Functions Variables Groups
Resource Class Reference
Inheritance diagram for Resource:
SimpleORMap StudipItem BrokenResource Building Location ResourceLabel Room

Public Member Functions

 store ()
 
 delete ()
 
 cbValidate ()
 
 __toString ()
 
 getFolder ($create_if_missing=true)
 
 setFolder (ResourceFolder $folder)
 
 createFolder ()
 
 getRequiredPropertyNames ()
 
 createSimpleBooking (User $user, DateTime $begin, DateTime $end, $preparation_time=0, $description= '', $internal_comment= '', $booking_type=0)
 
 createBookingFromRequest (User $user, ResourceRequest $request, $preparation_time=0, $description= '', $internal_comment= '', $booking_type=0, $prepend_preparation_time=false, $notify_lecturers=false)
 
 createBooking (User $user, $range_id=null, $time_ranges=[], $repetition_interval=null, $repetition_amount=0, $repetition_end_date=null, $preparation_time=0, $description= '', $internal_comment= '', $booking_type=0, $force_booking=false)
 
 createSimpleRequest (User $user, DateTime $begin, DateTime $end, $comment= '', $preparation_time=0)
 
 createRequest (User $user, $date_range_ids=null, $comment= '', $properties=[], $preparation_time=0)
 
 createLock (User $user, DateTime $begin, DateTime $end, $internal_comment= '')
 
 getGroupedProperties ($excluded_properties=[])
 
 propertyExists ($name= '')
 
 getPropertyObject (string $name)
 
 getInfolabelPrperties ()
 
 getProperty (string $name)
 
 getPropertyRelatedObject (string $name)
 
 setProperty (string $name, $state= '', $user=null)
 
 setPropertiesByName (array $properties, User $user)
 
 setPropertiesById (array $properties, User $user=null)
 
 isPropertyEditable (string $name, User $user)
 
 setPropertyByDefinitionId ($property_definition_id=null, $state=null)
 
 setPropertyRelatedObject (string $name, SimpleORMap $object)
 
 deleteProperty (string $name, User $user)
 
 getPictureUrl ()
 
 getDefaultPictureUrl ()
 
 getIcon ($role=Icon::ROLE_INFO)
 
 getPropertyArray ($only_requestable_properties=false)
 
 isAssigned (DateTime $begin, DateTime $end, $excluded_booking_ids=[])
 
 isReserved (DateTime $begin, DateTime $end, $excluded_reservation_ids=[])
 
 isLocked (DateTime $begin, DateTime $end, $excluded_lock_ids=[])
 
 isAvailable (DateTime $begin, DateTime $end, $excluded_booking_ids=[])
 
 isAvailableForRequest (ResourceRequest $request)
 
 getFullName ()
 
 setUserPermission (User $user, $perm= 'autor')
 
 deleteUserPermission (User $user)
 
 deleteAllPermissions ()
 
 getUserPermission (User $user, $time_range=[], $permanent_only=false)
 
 userHasPermission (?User $user, string $permission= 'user', array $time_range=[])
 
 userMayCreateChild (User $user)
 
 userHasRequestRights (User $user)
 
 userHasBookingRights (User $user, $begin=null, $end=null)
 
 bookingPlanVisibleForUser (?User $user, $time_range=[])
 
 findParentByClassName ($class_name= 'Resource')
 
 findChildrenByClassName ($class_name= 'Resource', $depth=0, $convert_objects=true, $order_by_name=true)
 
 addChild (Resource $resource)
 
 getOpenResourceRequests (DateTime $begin, DateTime $end)
 
 getResourceBookings (DateTime $begin, DateTime $end, array $booking_types=[0])
 
 getResourceLocks (DateTime $begin, DateTime $end)
 
 hasFiles ()
 
 getDerivedClassInstance ()
 
 checkHierarchy ()
 
 getActionLink ($action= 'show', $link_parameters=[])
 
 getActionURL ($action= 'show', $url_parameters=[])
 
 getItemName ($long_format=true)
 
 getItemURL ()
 
 getItemAvatarURL ()
 
 getLink ()
 
- Public Member Functions inherited from SimpleORMap
 __construct ($id=null)
 
 __clone ()
 
 getRelationOptions ($relation)
 
 getTableMetadata ()
 
 hasAutoIncrementColumn ()
 
 setId ($id)
 
 getId ()
 
 getNewId ()
 
 toArray ($only_these_fields=null)
 
 toRawArray ($only_these_fields=null)
 
 toArrayRecursive ($only_these_fields=null)
 
 getValue ($field)
 
 getRelationValue ($relation, $field)
 
 getDefaultValue ($field)
 
 setValue ($field, $value)
 
 __get ($field)
 
 __set ($field, $value)
 
 __isset ($field)
 
 offsetExists ($offset)
 
 offsetGet ($offset)
 
 offsetSet ($offset, $value)
 
 offsetUnset ($offset)
 
 getIterator ()
 
 count ()
 
 isField ($field)
 
 isAdditionalField ($field)
 
 isAliasField ($field)
 
 isI18nField ($field)
 
 setData ($data, $reset=false)
 
 isNew ()
 
 isDeleted ()
 
 setNew ($is_new)
 
 getWhereQuery ()
 
 restore ()
 
 store ()
 
 triggerChdate ()
 
 delete ()
 
 isDirty ()
 
 isFieldDirty ($field)
 
 revertValue ($field)
 
 getPristineValue ($field)
 
 initRelation ($relation)
 
 resetRelation ($relation)
 
 cleanup ()
 

Static Public Member Functions

static findChildren ($resource_id)
 
static getTranslatedClassName ($item_count=1)
 
static getRootResources ()
 
static getRequiredProperties ()
 
static getLinkForAction ($action= 'show', $id=null, $link_parameters=[])
 
static getURLForAction ($action= 'show', $id=null, $url_parameters=[])
 
- Static Public Member Functions inherited from SimpleORMap
static tableScheme ($db_table)
 
static expireTableScheme ()
 
static exists ($id)
 
static countBySql ($sql= '1', $params=[])
 
static create ($data)
 
static buildExisting ($data)
 
static import ($data)
 
static findBySQL ($sql, $params=[])
 
static findOneBySQL ($where, $params=[])
 
static findThru ($foreign_key_value, $options)
 
static findEachBySQL ($callable, $sql, $params=[])
 
static findMany ($pks=[], $order= '', $order_params=[])
 
static findEachMany ($callable, $pks=[], $order= '', $order_params=[])
 
static findAndMapBySQL ($callable, $where, $params=[])
 
static findAndMapMany ($callable, $pks=[], $order= '', $order_params=[])
 
static deleteBySQL ($where, $params=[])
 
static toObject ($id_or_object)
 
static __callStatic ($name, $arguments)
 

Static Protected Member Functions

static configure ($config=[])
 
static buildPathForAction ($action= 'show', $id=null)
 
- Static Protected Member Functions inherited from SimpleORMap
static db_table ()
 
static db_fields ()
 
static pk ()
 
static default_values ()
 
static serialized_fields ()
 
static alias_fields ()
 
static i18n_fields ()
 
static additional_fields ()
 
static has_many ()
 
static has_one ()
 
static belongs_to ()
 
static has_and_belongs_to_many ()
 
static registered_callbacks ()
 
static known_slots ()
 
static notification_map ()
 
static getter_setter_map ()
 
static configure ($config=[])
 
static config ($key)
 
static registerCallback ($types, $cb)
 
static unregisterCallback ($types, $cb)
 

Static Protected Attributes

static $permission_cache
 
- Static Protected Attributes inherited from SimpleORMap
static $config = []
 
static $reserved_slots = ['value','newid','iterator','tablemetadata', 'relationvalue','wherequery','relationoptions','data','new','id']
 
static $performs_batch_operation = false
 

Additional Inherited Members

- Data Fields inherited from SimpleORMap
const ID_SEPARATOR = '_'
 
- Static Public Attributes inherited from SimpleORMap
static $schemes = null
 
- Protected Member Functions inherited from SimpleORMap
 _getId ($field)
 
 _setId ($field, $value)
 
 _getAdditionalValueFromRelation ($field)
 
 _setAdditionalValueFromRelation ($field, $value)
 
 _getAdditionalValue ($field)
 
 _setAdditionalValue ($field, $value)
 
 parseRelationOptions ($type, $name, $options)
 
 storeRelations ($only_these=null)
 
 deleteRelations ()
 
 initializeContent ()
 
 applyCallbacks ($type)
 
 cbAutoIncrementColumn ($type)
 
 cbAutoKeyCreation ()
 
 cbNotificationMapper ($cb_type)
 
 cbAfterInitialize ($cb_type)
 
 setSerializedValue ($field, $value)
 
 setI18nValue ($field, $value)
 
- Protected Attributes inherited from SimpleORMap
 $content = []
 
 $content_db = []
 
 $is_new = true
 
 $is_deleted = false
 
 $relations = []
 
 $additional_data = []
 

Detailed Description

The Resource class is the base class of the new Room and Resource management system in Stud.IP. It provides core functionality for handling general resources and can be derived for handling special resources.

Member Function Documentation

__toString ( )
See Also
StudipItem::__toString

Implements StudipItem.

addChild ( Resource  $resource)

Adds a resource as child resource to this resource.

Parameters
Resource$resourceThe child resource.
Returns
bool True on success, false on failure.
bookingPlanVisibleForUser ( ?User  $user,
  $time_range = [] 
)

Determines if the booking plan of the resource is visible for a specified user.

Parameters
?User$user The user whose permission to view the booking plan shall be determined. May be null.
DateTime[]$time_range An optional time range for the permission check.
Returns
bool True, if the user can see the resource booking plan, false otherwise.
See Also
Resource::getUserPermission
static buildPathForAction (   $action = 'show',
  $id = null 
)
staticprotected

Returns the part of the URL for getLink and getURL which will be placed inside the calls to URLHelper::getLink and URLHelper::getURL in these methods.

Parameters
string$actionThe action for the resource.
string$idThe ID of the resource.
Returns
string The URL path for the specified action.
Exceptions
InvalidArgumentExceptionIf $resource_id is empty.
cbValidate ( )
checkHierarchy ( )

Checks if the place in the resource hierarchy (resource tree) is correct for this resource. This method has no function in this class but can be filled with logic in one of the classes derived from Resource.

Returns
bool True, if this resource is correctly placed, false otherwise.
Exceptions
NoResourceClassExceptionif the class name of this resource is not a derived class of the Resource class.
static configure (   $config = [])
staticprotected
createBooking ( User  $user,
  $range_id = null,
  $time_ranges = [],
  $repetition_interval = null,
  $repetition_amount = 0,
  $repetition_end_date = null,
  $preparation_time = 0,
  $description = '',
  $internal_comment = '',
  $booking_type = 0,
  $force_booking = false 
)

A factory method for creating a ResourceBooking object for this resource.

Parameters
User$userThe user who wishes to create a resource booking.
string$range_idThe ID of the user (or the Stud.IP object) which owns the ResourceBooking.
array[][]$time_ranges The time ranges for the booking. At least one time range has to be specified using unix timestamps or DateTime objects. This array has the following structure: [ [ 'begin' => The begin timestamp or DateTime object. 'end' => The end timestamp or DateTime object. ] ]
DateInterval | null$repetition_intervalThe repetition interval for the new booking. This must be a DateInterval object if repetitions shall be stored. Otherwise this parameter must be set to null.
int$repeat_amountThe amount of repetitions. This parameter is only regarded if $repetition_interval contains a DateInterval object. In case repetitions are specified by their end date set this parameter to 0.
DateTime | string | null$repetition_end_dateThe end date of the repetition. This can either be an unix timestamp or a DateTime object and will only be regarded if $repetition_interval contains a DateInterval object. In case repetitions are specified by their amount set this parameter to null.
int$repetition_amount
int$preparation_timeThe preparation time which is needed before the real start time. This will be substracted from the begin timestamp and stored in an extra column of the resource_bookings table.
string$descriptionAn optional description for the booking. This fields was previously known as "user_free_name".
string$internal_commentAn optional comment for the booking which is intended to be used internally in the room and resource administration staff.
int$booking_typeThe booking type. 0 = normal booking 1 = reservation 2 = lock booking
bool$force_bookingIf this parameter is set to true, overlapping bookings are removed before storing this booking.
Returns
ResourceBooking object.
Exceptions
InvalidArgumentExceptionIf no time ranges are specified or if there is an error regarding the time ranges.
ResourceBookingRangeExceptionIf $range_id is not set.
ResourceBookingOverlapExceptionIf the booking overlaps with another booking or a resource lock.
ResourcePermissionExceptionIf the specified user does not have sufficient permissions to create a resource booking.
ResourceBookingExceptionIf the repetition interval is invalid or if the resource booking cannot be stored.
createBookingFromRequest ( User  $user,
ResourceRequest  $request,
  $preparation_time = 0,
  $description = '',
  $internal_comment = '',
  $booking_type = 0,
  $prepend_preparation_time = false,
  $notify_lecturers = false 
)

Creates bookings from a request.

Parameters
User$user
ResourceRequest$requestThe request from which a resource booking shall be built.
int$preparation_time
string$description
string$internal_comment
int$booking_type
bool$prepend_preparation_time. If this is set to true, the preparation time will end before the start of the requested time. If $prepend_preparation_time is set to false (the default) the preparation time starts with the start of the requested time.
bool$notify_lecturers
Returns
ResourceBooking[] A list of resource bookings matching the request.
Exceptions
ResourceRequestExceptionif the request could not be marked as resolved.
ResourceUnavailableExceptionif the resource cannot be assigned in at least one of the time ranges specified by the resource request.
createFolder ( )
createLock ( User  $user,
DateTime  $begin,
DateTime  $end,
  $internal_comment = '' 
)

Creates a lock booking for this resource.

Parameters
User$userThe user who wishes to create a lock booking.
DateTime$beginThe begin of the lock time range.
DateTime$endThe end of the lock time range.
string$internal_commentAn optional comment for the lock booking which is intended to be used internally in the room and resource administration staff.
Returns
ResourceBooking A ResourceBooking object.
Exceptions
ResourceUnavailableExceptionIf a lock booking already exists in the specified time range.
AccessDeniedExceptionIf the user does not have sufficient permissions to lock this resource.
createRequest ( User  $user,
  $date_range_ids = null,
  $comment = '',
  $properties = [],
  $preparation_time = 0 
)

This method creates a resource request for this resource.

Parameters
User$userThe user who wishes to create a request.
string | array$date_range_idsOne or more IDs of Stud.IP objects which can provide at least one time range. Objects which fulfill this requirement are course dates (CourseDate objects), cycle dates (SeminarCycleDate objects) and courses (Course objects). If only one ID is provided it can be passed as string. If multiple IDs are provided they have to be passed as array.
string$commentA comment for the resource request.
mixed[]$properties The wishable properties for the resource request. The format of the array is as follows: [ 'property name' => 'property state' ]
int$preparation_timeThe requested preparation time before the begin of the requested time range. This parameter must be specified in seconds. Only positive values are accepted.
Returns
ResourceRequest A resource request object.
Exceptions
InvalidArgumentExceptionIf $date_range_id is not set. or no object which can provide at least one time range can be found with the specified ID.
ResourceNoTimeRangeExceptionIf no time range can be found by looking at the object, specified by its ID in $date_range_id.
ResourceUnavailableExceptionIf the resource is not available in the selected time range.
ResourceRequestExceptionIf the resource request cannot be stored.
createSimpleBooking ( User  $user,
DateTime  $begin,
DateTime  $end,
  $preparation_time = 0,
  $description = '',
  $internal_comment = '',
  $booking_type = 0 
)

This is a simplified version of the createBooking method.

Parameters
User$user
DateTime$begin
DateTime$end
int$preparation_time
string$description
string$internal_comment
int$booking_type
Returns
ResourceBooking
See Also
Resource::createBooking
createSimpleRequest ( User  $user,
DateTime  $begin,
DateTime  $end,
  $comment = '',
  $preparation_time = 0 
)

This method creates a simple request for this resource. A simple request is not bound to a date, metadate or course object and its time ranges. Instead the time range is specified directly. Note that simple resource requests do not support recurrence.

Parameters
User$userThe user who wishes to create a simple request.
DateTime$beginThe begin timestamp of the request.
DateTime$endThe end timestamp of the request.
string$commentA comment for the resource request.
int$preparation_timeThe requested preparation time before the begin of the requested time range. This parameter must be specified in seconds. Only positive values are accepted.
Returns
ResourceRequest A resource request object.
Exceptions
AccessDeniedExceptionIf the user is not permitted to request this resource.
InvalidArgumentExceptionIf the the timestamps provided by $begin and $end are invalid or if $begin is greater than or equal to $end which results in an invalid time range.
ResourceUnavailableExceptionIf the resource is not available in the selected time range.
ResourceRequestExceptionIf the resource request cannot be stored.
delete ( )
deleteAllPermissions ( )

Deletes all permissions of all users for this resource.

Returns
bool True
deleteProperty ( string  $name,
User  $user 
)

Deletes a property for a resource.

Parameters
string$nameThe name of the property to be deleted.
User$userThe user who wishes to delete the property.
Returns
number
deleteUserPermission ( User  $user)

Deletes the permission a specified user has on this resource.

Parameters
User$userThe user whose permission shall be deleted.
Returns
bool True
static findChildren (   $resource_id)
static

Returns the children of a resource. The children are converted to an instance of the derived class, if they are not instances of the default Resource class.

findChildrenByClassName (   $class_name = 'Resource',
  $depth = 0,
  $convert_objects = true,
  $order_by_name = true 
)

This method searches the hierarchy below this resource to find resources matching the specified class name. Via the optional parameter $depth the search can be limited to a specific amount of layers.

Parameters
string$class_nameThe name of the resource class where resources shall be found to.
int$depthThe (optional) maximum depth below this resource which shall be searched.
bool$convert_objectsTrue, if objects shall be converted to $class_name (default), false otherwise.
bool$order_by_nameOrder the children by name. Defaults to true.
Returns
Resource[] An array of resource objects or an empty array if no matching resources can be found.
findParentByClassName (   $class_name = 'Resource')

Retrieves a parent resource object that matches the specified class name. The search stops when either a parent resource with the class name is found or when the root resource object is reached.

Parameters
string$class_nameThe class name of the parent.
Returns
Resource|null Either a resource object or null in case a matching parent resource cannot be found.
getActionLink (   $action = 'show',
  $link_parameters = [] 
)

Returns the link for an action for this resource. This is the non-static variant of Resource::getLinkForAction.

Parameters
string$actionThe action which shall be executed. For default Resources the actions 'show', 'add', 'edit' and 'delete' are defined.
array$link_parametersOptional parameters for the link.
Returns
string
getActionURL (   $action = 'show',
  $url_parameters = [] 
)

Returns the URL for an action for this resource. This is the non-static variant of Resource::getURLForAction.

Parameters
string$actionThe action which shall be executed. For default Resources the actions 'show', 'add', 'edit' and 'delete' are defined.
array$url_parametersOptional parameters for the URL.
Returns
string
getDefaultPictureUrl ( )

Returns the default picture for the resource class.

Classes derived from Resource should re-implement this method if they want to get a different default picture than the resource icon. The call to getPictureUrl will call the getDefaultPictureUrl method from the derived class.

Returns
string The URL to the picture.
getDerivedClassInstance ( )

Converts a Resource object to an object of a specialised resource class.

Returns
Resource|other An object of a specialised resource class or a Resource object, if the resource is a standard resource with the class_name 'Resource' in its resource category. If the derived resource class is not available, an instance of BrokenResource is returned.
getFolder (   $create_if_missing = true)

Retrieves the folder for this resource.

Parameters
bool$create_if_missingWhether to create a folder (true) or not (false) in case no folder exists for this resource. Defaults to true.
Returns
ResourceFolder|null Either a ResourceFolder instance or null in case no such instance can be retrieved or created.
getFullName ( )

Returns the full (localised) name of the resource.

Returns
string The full name of the resource.
getGroupedProperties (   $excluded_properties = [])

Retrieves the properties grouped by their property groups and in the order specified in that group.

Parameters
string[]excluded_properties An array with the names of the properties that shall be excluded from the result set.
Returns
array An array with the group names as keys and the properties in the second array dimension. The structure of the array is as follows: [ group1 name => [ property1, property2, ... ], group2 name => [ ... ] ]
getIcon (   $role = Icon::ROLE_INFO)

Returns the Icon for the resource class.

Classes derived from Resource should re-implement this method if they want to get a different icon than the resource icon.

Parameters
string$role
Returns
Icon The icon for the resource.
getInfolabelPrperties ( )

Returns all info-label properties

Returns
SimpleCollection
getItemAvatarURL ( )

Returns the URL to the avatar image or icon of the object, if applicable.

Returns
string|null Either the URL to the object's avatar or icon or null, if the object does not have an avatar.

Implements StudipItem.

getItemName (   $long_format = true)

Returns a human-readable name of the object.

Parameters
bool$long_formatIf set to true, a long format that has the object type as a prefix (course, room etc.) is returned. Otherwise only the name is returned.
Returns
string A human-readable string of the object's name.

Implements StudipItem.

getItemURL ( )

Returns an URL that points to a page describing or displaying the object.

Returns
string|null Either the URL to a descriptive page for the object or null, if the object does not have such an URL.

Implements StudipItem.

getLink ( )

Creates a StudipLink object that links to a page with information about the StudipItem object.

Returns
StudipLink A StudipLink object for the information page of the StudipItem object.

Implements StudipItem.

static getLinkForAction (   $action = 'show',
  $id = null,
  $link_parameters = [] 
)
static

Returns the appropriate link for the resource action that shall be executed on a resource.

Parameters
string$actionThe action which shall be executed. For default Resources the actions 'show', 'add', 'edit' and 'delete' are defined.
string$idThe ID of the resource on which the specified action shall be executed.
array$link_parametersOptional parameters for the link.
Returns
string The Link for the resource action.
Exceptions
InvalidArgumentExceptionIf $resource_id is empty.
getOpenResourceRequests ( DateTime  $begin,
DateTime  $end 
)

Get all resource requests for the resource in a given timeframe.

Parameters
DateTime$beginBegin of timeframe.
DateTime$endEnd of timeframe.
Returns
ResourceRequest[] An array of ResourceRequest objects.
getPictureUrl ( )

Returns the path for the resource's image. If the resource has no image the path for a general resource icon will be returned.

Classes derived from the Resource class should only re-implement this method if they have an alternative storage method for resource pictures than the Stud.IP file system.

Returns
string The URL to the resource picture.
getProperty ( string  $name)

Returns the state of the property specified by $name. If the property has not been set for this resource, but is defined for this resource's category, a new ResourceProperty object will be created, stored and its state will be returned.

Parameters
string$nameThe name of the resource property.
Returns
string|null The state of the specified property or null if the propery can't be found.
getPropertyArray (   $only_requestable_properties = false)

Returns all properties in a two-dimensional array with the following property data inside of the second dimension: [ 'name' => (the property's name) 'display_name' => (the display name of the property) 'type' => (the property's type) 'state' => (the property's state) 'requestable' => (if the property is requestable or not (true or false)) ]

Parameters
bool$only_requestable_propertiesIf only requestable properties shall be returned set this to true. If all properties shall be returned, set this to false.
Returns
array[] A two-dimensional array containing property data.
getPropertyObject ( string  $name)

Retrieves a ResourceProperty object for a property of this resource which has the specified name. If the property has not been set for this resource, but is defined for this resource's category, a new ResourceProperty object will be created, stored and returned.

Parameters
string$nameThe name of the resource property.
Returns
ResourceProperty|null Either a ResourceProperty object for the resource property matching the specified name or null, if no resource property with the specified name can be found.
Exceptions
InvalidResourceCategoryExceptionIf this resource category doesn't match the category of the resource object.
getPropertyRelatedObject ( string  $name)

Retrieves an object by the state of a property of this resource, specified by the property's name. This method is useful for properties of type user, institute or fileref. Those properties store IDs of User, Institute or FileRef objects. Therefore the IDs can be resolved directly to get the corresponding User, Institute or FileRef object directly.

Parameters
string$nameThe name of the resource property.
Returns
SimpleORMap|null A SimpleORMap-based object or null, if no such object can be retrieved from the property's state.
static getRequiredProperties ( )
static

A method for overloaded classes so that they can define properties that are required for that resource class.

Returns
string[] An array with the names of the required properties. Example: The properties with the names "foo", "bar" and "baz" are required properties. The array would have the following content: [ 'foo', 'bar', 'baz' ]
getRequiredPropertyNames ( )

Returns a list of property names that are required for the resource class.

Returns
string[] An array with the property names.
getResourceBookings ( DateTime  $begin,
DateTime  $end,
array  $booking_types = [0] 
)

Get all resource bookings for the resource in a given timeframe.

Parameters
DateTime$beginBegin of timeframe.
DateTime$endEnd of timeframe.
array$booking_types
Returns
ResourceBooking[] An array of ResourceBooking objects.
getResourceLocks ( DateTime  $begin,
DateTime  $end 
)

Get all resource locks for the resource in a given timeframe.

Parameters
DateTime$beginBegin of timeframe.
DateTime$endEnd of timeframe.
Returns
ResourceBooking[] An array of ResourceBooking objects.
static getRootResources ( )
static

Retrieves all resources which don't have a parent resource assigned. Such resources are called root resources since they are roots of a resource hierarchy (or a resource tree).

Returns
Resource[] An array of Resource objects which are root resources.
static getTranslatedClassName (   $item_count = 1)
static

Returns a translation of the resource class name. The translated name can be singular or plural, depending on the value of the parameter $item_count.

Parameters
int$item_countThe amount of items the translation shall be made for. This is only used to determine, if a singular or a plural form shall be returned.
Returns
string The translated form of the class name, either in singular or plural.
static getURLForAction (   $action = 'show',
  $id = null,
  $url_parameters = [] 
)
static

Returns the appropriate URL for the resource action that shall be executed on a resource.

Parameters
string$actionThe action which shall be executed. For default Resources the actions 'show', 'add', 'edit' and 'delete' are defined.
string$idThe ID of the resource on which the specified action shall be executed.
array$url_parametersOptional parameters for the URL.
Returns
string The URL for the resource action.
Exceptions
InvalidArgumentExceptionIf $resource_id is empty.
getUserPermission ( User  $user,
  $time_range = [],
  $permanent_only = false 
)

Retrieves the permission level a specified user has on this resource.

Setting the optional $time_range parameter will also enable checks for temporary global permissions.

Parameters
User$userThe user whose permission shall be retrieved.
array$time_range(DateTime) This is an optional parameter that can be used to pass two DateTime objects to this method. The first object will be treated as the begin timestamp and the second one as the end timestamp.
bool$permanent_onlyWhether to retrieve only permanent permissions (true) or permanent and temporary permissions (false). Defaults to false.
Returns
string The permission level, expressed as string. The level can be 'user', 'autor', 'tutor' or 'admin'.
hasFiles ( )

Determines if files are attached to this resource. If a folder exists for this resource its files are counted. Depending on whether the folder has files in it or not this method returns true or false.

Returns
bool True, if there are files attached to this resource, false otherwise.
isAssigned ( DateTime  $begin,
DateTime  $end,
  $excluded_booking_ids = [] 
)

Shortcut method for ResourceBooking::countByResourceAndTimeRanges. Determines whether normal resource bookings exist in the specified time range.

Parameters
DateTime$beginTime range start timestamp.
DateTime$endTime range end timestamp.
array$excluded_booking_idsThe IDs of bookings that shall be excluded from the determination of the "assigned" status.
Returns
bool True, if the resource is assigned in the specified time range, false otherwise.
isAvailable ( DateTime  $begin,
DateTime  $end,
  $excluded_booking_ids = [] 
)

Determines, if the resource is available (not assigned or locked) in a specified time range.

Parameters
DateTime$beginTime range start timestamp.
DateTime$endTime range end timestamp.
array$excluded_booking_idsThe IDs of available bookings that shall be excluded from the determination of the "available" status.
Returns
bool True, if the resource is available in the specified time range, false otherwise.
isAvailableForRequest ( ResourceRequest  $request)

Determines, if the resource is available (not assigned or locked) in the time ranges specified by a resource request.

Parameters
ResourceRequest$requestA resource request object.
Returns
bool True, if the resource is available in the time ranges of the resource request, false otherwise.
isLocked ( DateTime  $begin,
DateTime  $end,
  $excluded_lock_ids = [] 
)

Shortcut method for ResourceBooking::countByResourceAndTimeRanges. Determines whether resource locks exist in the specified time range.

Parameters
DateTime$beginTime range start timestamp.
DateTime$endTime range end timestamp.
array$excluded_lock_idsThe IDs of lock bookings that shall be excluded from the determination of the "locked" status.
Returns
bool True, if the resource is locked in the specified time range, false otherwise.
isPropertyEditable ( string  $name,
User  $user 
)

Determines if the specified user has sufficient permissions to edit the property specified by its name.

Parameters
string$nameThe name of the resource property.
user$userThe user whose edit permissions shall be checked.
Returns
bool True, if the user has edit permissions for the property, false otherwise.
isReserved ( DateTime  $begin,
DateTime  $end,
  $excluded_reservation_ids = [] 
)

Shortcut method for ResourceBooking::countByResourceAndTimeRanges. Determines whether resource reservations exist in the specified time range.

Parameters
DateTime$beginTime range start timestamp.
DateTime$endTime range end timestamp.
array$excluded_reservation_idsThe IDs of reservation bookings that shall be excluded from the determination of the "reserved" status.
Returns
bool True, if the resource is reserved in the specified time range, false otherwise.
propertyExists (   $name = '')

Determines wheter this resource has a property with the specified name.

Parameters
string$nameThe name of the resource property.
Returns
bool True, if this resource has a property with the specified name, false otherwise.
setFolder ( ResourceFolder  $folder)
setPropertiesById ( array  $properties,
User  $user = null 
)

Sets the properties (specified by their IDs) to the specified values.

Parameters
array$propertiesThe properties array in the format "key-value". The array keys must contain the property-ID while the items of the array contain the values. Example: ['1' => 'foo']: Sets the value 'foo' for the property with the ID '1'.
User | null$userThe user who wishes to set the properties. If this is left empty, the current user will be used.
Returns
array If properties cannot be set, their ids (as key) and the error messages (if any) are returned. The array has the following structure: [ (property-ID) => (error message or empty string) ]
setPropertiesByName ( array  $properties,
User  $user 
)

Sets the properties (specified by their names) to the specified values.

Parameters
array$propertiesThe properties array in the format "key-value". The array keys must contain the property name while the items of the array contain the values. Example: ['bar' => 'foo']: Sets the value 'foo' for the property with the name 'bar'.
User | null$userThe user who wishes to set the properties. If this is left empty, the current user will be used.
Returns
array If properties cannot be set, their names (as key) and the error messages (if any) are returned. The array has the following structure: [ (property name) => (error message or empty string) ]
setProperty ( string  $name,
  $state = '',
  $user = null 
)

Sets a specified property of this resource to the specified state. If the property has not been set for this resource, but is defined for this resource's category, a new ResourceProperty object will be created, stored and its state will be returned.

Parameters
string$nameThe name of the resource property.
mixed$stateThe state of the resource property.
User | null$userThe user who wishes to set the property.
Returns
bool True, if the property state could be set, false otherwise.
setPropertyByDefinitionId (   $property_definition_id = null,
  $state = null 
)

Sets the state of a property by its definition_id rather than its name.

Parameters
string$property_definition_idThe definition-ID of the property.
string$stateThe state of the property.
Returns
bool True, if the property state can be stored, false otherwise.
Exceptions
ResourcePropertyStateExceptionIf the provided state is invalid for the specified resource property.
setPropertyRelatedObject ( string  $name,
SimpleORMap  $object 
)

Sets the property state by specifying an SimpleORMap object. This method is meant for resource properties of type user, institute or fileref.

Parameters
string$nameThe name of the resource property.
SimpleORMap$objectThe object for the resource property.
Returns
bool True, if the property has been saved, false otherwise.
setUserPermission ( User  $user,
  $perm = 'autor' 
)

Sets the permission for one user for this resource.

Parameters
User$userThe user whose permission shall be set.
string$permThe permission level for the specified user. The levels 'user', 'autor', 'tutor' and 'admin' are allowed.
Returns
bool True, if the permission has been stored successfully, false otherwise.
store ( )

The SORM store method is overloaded to assure that the right level attribute is stored.

userHasBookingRights ( User  $user,
  $begin = null,
  $end = null 
)

Determines whether the user may book the resource or not. An optional time range can be set to check the user's temporary permissions on another date than the current date.

Parameters
User$userThe user whose booking permissions shall be checked.
int | string | DateTime$beginThe begin timestamp of the optional time range.
int | string | DateTime$endThe end timestamp of the optional time range.
Returns
bool True, if the user may book the resource, false otherwise.
userHasPermission ( ?User  $user,
string  $permission = 'user',
array  $time_range = [] 
)

Determines if a user has the specified permission.

Parameters
?User$user The user whose permissions shall be checked on this resource object. May be null.
string$permissionThe permission level.
$time_range
Returns
bool True, if the specified user has the specified permission, false otherwise.
userHasRequestRights ( User  $user)

Checks if the specified user has sufficient permissions to make resource requests, according to the setting RESOURCES_MIN_REQUEST_PERMISSION. This permission check is only relevant for creating requests that are not bound to a course.

Parameters
User$userThe user whose request permissions shall be checked.
Returns
bool True, if the user has request permissions, false otherwise.
userMayCreateChild ( User  $user)

Determines whether the user may create a child resource on this resource.

Parameters
User$userThe user whose permission to create a child resource shall be checked.
Returns
bool True, if the user may create a child resource on this resource, false otherwise.

Field Documentation

$permission_cache
staticprotected

This is a cache for permissions that users have on resources. It is meant to reduce the database requests in cases where the same permission is queried a lot of times.


The documentation for this class was generated from the following file: