Stud.IP  5.4
ResourceManager Class Reference

Public Member Functions

 createGlobalLock (User $user, DateTime $begin, DateTime $end, $ignore_bookings=false)
 

Static Public Member Functions

static createCategory ( $name=null, $description=null, $class_name='Resource', $is_system_category=false, $iconnr='1', $properties=[])
 
static createLocationCategory ( $name=null, $description=null, $additional_properties=[])
 
static createBuildingCategory ( $name=null, $description=null, $additional_properties=[])
 
static createRoomCategory ( $name=null, $description=null, $additional_properties=[])
 
static copyResource (Resource $resource, $copy_hierarchy=true, $new_parent_id=null)
 
static moveResource (Resource $target, Resource $destination)
 
static countUserResources (User $user, $level='user', $time=null, $class_names=[])
 
static getUserResources (User $user, $level='user', $time=null, $class_names=[], $convert_objects=true)
 
static validateCoordinates (string $coordinate_string)
 
static getPositionArray (ResourceProperty $property)
 
static getPositionString (ResourceProperty $property, $with_altitude=false)
 
static getMapUrlForResourcePosition (ResourceProperty $property)
 
static getGlobalResourcePermission (User $user=null)
 
static userHasResourcePermissions (User $user=null, $level='admin', $time=null)
 
static getLowerPermissionLevels ($level='user')
 
static getHigherPermissionLevels ($level='user')
 
static comparePermissionLevels ( $level='user', $other_level='user')
 
static userHasGlobalPermission (User $user=null, $requested_permission='user')
 
static countResourcesWithPermissions (User $user, $requested_permission='user', $exclude_temporary_permissions=false)
 
static userHasSpecialPermissions (User $user, $requested_permission='user')
 
static getTimeRangesFromRangeId ($range_id=null)
 
static getUserInactivityInterval (User $user, DateTime $time)
 
static getBookingPlanObjects (Resource $resource, $time_ranges=[], $allowed_booking_types=[], $included_requests=null)
 
static getAllResourceClassNames ($excluded_classes=[])
 
static getHierarchyNames (Resource $resource)
 
static getHierarchy (Resource $resource)
 

Static Protected Member Functions

static getUserResourcesSqlData (User $user, $level='user', $time=null, $class_names=[])
 

Detailed Description

The ResourceManager class contains methods that simplify the use of Resources.

Member Function Documentation

◆ comparePermissionLevels()

static comparePermissionLevels (   $level = 'user',
  $other_level = 'user' 
)
static

Compares two resource permission levels and returns an integer telling if the first level is less than (-1), equal (0) or greater than (1) the second level.

Parameters
string$levelThe first permission level.
string$other_levelThe second permission level.
Exceptions
InvalidArgumentExceptionif $level or $other_level are either not set or if they contain invalid permission level strings.
Returns
integer -1 if $level is less than $other_level, 0 if both are equal, 1 if $level is greater than $other_level.

◆ copyResource()

static copyResource ( Resource  $resource,
  $copy_hierarchy = true,
  $new_parent_id = null 
)
static

Creates a copy of a resource and stores the copy in the database.

Parameters
Resource$resourceThe resource which shall be copied.
bool$copy_hierarchyTrue, if the resource's children shall also be copied (default). False otherwise.
string$new_parent_idIf this is set the original parent_id will be overwritten with the ID in $new_parent_id.
Exceptions
ResourceExceptionIf the copy cannot be stored.
Returns
Resource A copy of the resource.

◆ countResourcesWithPermissions()

static countResourcesWithPermissions ( User  $user,
  $requested_permission = 'user',
  $exclude_temporary_permissions = false 
)
static

Counts the resources where the specified user has explicit permissions set, optionally limiting the result to permanent permissions.

Parameters
User$userThe user whose resource permissions shall be checked.
string$requested_permissionThe required minimum permission level for the user.
Returns
int The amount of resources where the specified user has explicit permissions for.

◆ countUserResources()

static countUserResources ( User  $user,
  $level = 'user',
  $time = null,
  $class_names = [] 
)
static

Counts all resources for which the specified user has permanent or temporary permissions.

Parameters
User$userThe user whose resources shall be retrieved.
string$levelThe minimum permission level the user must have on a resource so that it will be included in the result set.
DateTime | int | null$timeThe timestamp for the check on temporary permissions. If this parameter is not set the current timestamp will be used.
string[]$class_names A list of resource classes that will be used to filter the result set so that only resources being a member of one of the specified resource classes will be retrieved.

◆ createBuildingCategory()

static createBuildingCategory (   $name = null,
  $description = null,
  $additional_properties = [] 
)
static

Simplifies the creation of a building resource category.

Parameters
string$nameThe name of the new resource category.
string$descriptionThe description of the new resource category.
string[]$additional_properties A two-dimensional array with the names and requestable, protected and system flags. See ResourceManager::createCategory for a description of the format of the second array dimension.
Exceptions
ResourceCategoryExceptionIn case if no name is set or a resource property doesn't exist, if the category's name is ambigous or if the new category cannot be stored, a ResourceCategoryException is thrown.
Returns
ResourceCategory A new ResourceCategory object.

◆ createCategory()

static createCategory (   $name = null,
  $description = null,
  $class_name = 'Resource',
  $is_system_category = false,
  $iconnr = '1',
  $properties = [] 
)
static

Simplifies the creation of a resource category.

Parameters
string$nameThe name of the new resource category.
string$descriptionThe description of the new resource category.
string$class_nameThe class (derived from Resource) which shall be used for resources created with the new category.
bool$is_system_categoryTrue, if the category shall be a system category, false otherwise.
string$iconnrThe number of the icon for the resource category.
mixed[]$properties A two-dimensional array with the names and requestable, protected and system flags. The second dimension of the array must have the following structure: [ property name (string), requestable flag (boolean), protected flag (boolean), system-flag (boolean) ].
Exceptions
ResourceCategoryExceptionIn case if no name is set or a resource property doesn't exist, if the category's name is ambigous or if the new category cannot be stored, a ResourceCategoryException is thrown.
Returns
ResourceCategory A new ResourceCategory object.

◆ createGlobalLock()

createGlobalLock ( User  $user,
DateTime  $begin,
DateTime  $end,
  $ignore_bookings = false 
)

This method allows locking the resource management globally. The user who creates the lock must have admin permissions and the time interval must not lie in another global resource lock interval.

Parameters
User$userThe user who wishes to lock the room and resource management globally.
DateTime$beginThe begin timestamp of the lock.
DateTime$endThe end timestamp of the lock.
Exceptions
InvalidArgumentExceptionIf $begin lies after $end or if $begin is equal to $end.
ResourcePermissionExceptionIf the specified user does not have sufficient permissions to lock the resource management globally.
GlobalResourceLockExceptionIf the resource lock could not be stored.
Returns
GlobalResourceLock object.

◆ createLocationCategory()

static createLocationCategory (   $name = null,
  $description = null,
  $additional_properties = [] 
)
static

Simplifies the creation of a location resource category.

Parameters
string$nameThe name of the new resource category.
string$descriptionThe description of the new resource category.
string[]$additional_properties A two-dimensional array with the names and requestable, protected and system flags. See ResourceManager::createCategory for a description of the format of the second array dimension.
Exceptions
ResourceCategoryExceptionIn case if no name is set or a resource property doesn't exist, if the category's name is ambigous or if the new category cannot be stored, a ResourceCategoryException is thrown.
Returns
ResourceCategory A new ResourceCategory object.

◆ createRoomCategory()

static createRoomCategory (   $name = null,
  $description = null,
  $additional_properties = [] 
)
static

Simplifies the creation of a room resource category.

Parameters
string$nameThe name of the new resource category.
string$descriptionThe description of the new resource category.
string[]$additional_properties A two-dimensional array with the names and requestable, protected and system flags. See ResourceManager::createCategory for a description of the format of the second array dimension.
Exceptions
ResourceCategoryExceptionIn case if no name is set or a resource property doesn't exist, if the category's name is ambigous or if the new category cannot be stored, a ResourceCategoryException is thrown.
Returns
ResourceCategory A new ResourceCategory object.

◆ getAllResourceClassNames()

static getAllResourceClassNames (   $excluded_classes = [])
static

◆ getBookingPlanObjects()

static getBookingPlanObjects ( Resource  $resource,
  $time_ranges = [],
  $allowed_booking_types = [],
  $included_requests = null 
)
static

Retrieves booking plan objects like resource bookings and requests.

Parameters
string | null$included_request_typesIf this parameter is a string, it can have the values 'all' for retrieving all requests or the ID of a user so that only requests of that user are retrieved.

◆ getGlobalResourcePermission()

static getGlobalResourcePermission ( User  $user = null)
static

Returns the resource management global permissions for a user, determined by the assigned roles and by the user's global permissions. This method does the mapping from the old resource management permissions to the new resource management permissions.

◆ getHierarchy()

static getHierarchy ( Resource  $resource)
static

Returns the hierarchy elements from the root to the specified resource.

Parameters
Resource$roomThe resource to start with.
Returns
Resource[] An array with the hierarchy elements, starting with the top resource.

◆ getHierarchyNames()

static getHierarchyNames ( Resource  $resource)
static

Returns the names of all hierarchy elements from the root to the specified resource.

Parameters
Resource$roomThe resource to start with.
Returns
string[] An array with the names of the hierarchy elements, starting with the top resource's name.

◆ getHigherPermissionLevels()

static getHigherPermissionLevels (   $level = 'user')
static

Returns all permission levels higher than the specified level.

◆ getLowerPermissionLevels()

static getLowerPermissionLevels (   $level = 'user')
static

Returns all permission levels lower than the specified level.

◆ getMapUrlForResourcePosition()

static getMapUrlForResourcePosition ( ResourceProperty  $property)
static

◆ getPositionArray()

static getPositionArray ( ResourceProperty  $property)
static

◆ getPositionString()

static getPositionString ( ResourceProperty  $property,
  $with_altitude = false 
)
static

◆ getTimeRangesFromRangeId()

static getTimeRangesFromRangeId (   $range_id = null)
static

Get time ranges by looking at the object specified by its ID. This method works with CourseDate, SeminarCycleDate and Course objects.

Parameters
string$range_idThe ID of a Stud.IP object.
Returns
Array An Array consisting of arrays of DateTime objects. The structure of the array is as follows: [ [ begin timestamp DateTime object end timestamp DateTime object ], ... ]

◆ getUserInactivityInterval()

static getUserInactivityInterval ( User  $user,
DateTime  $time 
)
static

Determines the last booking of the user and calculates the timespan from the last booking until now.

Returns
DateInterval|null|false Either a date interval from the last activity to the provided DateTime object or null in case the user has never been active. False is returned in case the timestamp comparison fails.
See also
DateTime::diff in the PHP Documentation.

◆ getUserResources()

static getUserResources ( User  $user,
  $level = 'user',
  $time = null,
  $class_names = [],
  $convert_objects = true 
)
static

Retrieves all resources for which the specified user has permanent or temporary permissions.

Parameters
User$userThe user whose resources shall be retrieved.
string$levelThe minimum permission level the user must have on a resource so that it will be included in the result set.
DateTime | int | null$timeThe timestamp for the check on temporary permissions. If this parameter is not set the current timestamp will be used.
string[]$class_names A list of resource classes that will be used to filter the result set so that only resources being a member of one of the specified resource classes will be retrieved.
bool$convert_objectsIf the resource objects in the result set shall be converted to objects of the derived resource classes set this to true, otherwise false. Defaults to true.
Returns
Resource[] An array of Resource objects or objects of derived resource classes.

◆ getUserResourcesSqlData()

static getUserResourcesSqlData ( User  $user,
  $level = 'user',
  $time = null,
  $class_names = [] 
)
staticprotected

Helper method that creates the identical SQL query for the countUserResources and findUserResources methods.

◆ moveResource()

static moveResource ( Resource  $target,
Resource  $destination 
)
static

Moves a resource below another resource and does checks to prevent resource hierarchies with misplaced resource objects. This is just a convenience method which calls the addChild method of the destination resource.

Parameters
Resource$targetThe resource which shall be moved.
Resource$destinationThe resource where $target shall be a new child.
Exceptions
InvalidArgumentExceptionIf $target cannot be placed below $destination.
Returns
bool True, if $target was successful placed below $destination.

◆ userHasGlobalPermission()

static userHasGlobalPermission ( User  $user = null,
  $requested_permission = 'user' 
)
static

Checks if the specified user has the specified permission level for the resource management system.

Parameters
User | null$userThe user whose global resource permissions shall be checked.
string$requested_permissionThe required permission level for the user.
Returns
bool True, if the user has the required permission level, false otherwise.

◆ userHasResourcePermissions()

static userHasResourcePermissions ( User  $user = null,
  $level = 'admin',
  $time = null 
)
static

Determines if the specified user has the specified permission level set for at least one resource.

Parameters
User$userThe users whose resource permissions shall be retrieved.
string$levelThe permission level the user should have on at least one resource.
string | int | DateTime | null$timeThe timestamp for the temporary permission level check. If this is not set the current timestamp will be used.

◆ userHasSpecialPermissions()

static userHasSpecialPermissions ( User  $user,
  $requested_permission = 'user' 
)
static

Checks if the specified user has the specified permission level on at least one specific resource.

Parameters
User$userThe user whose resource permissions shall be checked.
string$requested_permissionThe required permission level for the user.
Returns
bool True, if the user has the required permission level for at least one resource, false otherwise.

◆ validateCoordinates()

static validateCoordinates ( string  $coordinate_string)
static

Check if the coordinate are in appropriate CRSWGS_84 format.

  • latitude: up to 2 digits, decimal point, 1 to 10 digits for fraction
  • longitude: up to 3 digits, decimal point, 1 to 10 digits for fraction
  • altitude: up to 5 digits, decimal point, 1 to 10 digits for fraction
Parameters
string$coordinate_string
Returns
bool

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