File/lib/general.php

Description

Sloodle general library.

Provides various utility functionality for general Sloodle purposes.

  • copyright: Copyright (c) 2007-8 Sloodle (various contributors)
  • contributor: Edmund Edgar
  • contributor: Peter R. Bloomfield
  • filesource: Source Code for this file
  • license: GNU GPL v3
Includes
 require_once (SLOODLE_LIBROOT.'/mail.php') (line 21)

Include our email functionality.

Functions
sloodle_add_to_log (line 138)

Old logging function

  • todo: May require update?
void sloodle_add_to_log ([ $courseid = null], [ $module = null], [ $action = null], [ $url = null], [ $cmid = null], [ $info = null])
  • $courseid
  • $module
  • $action
  • $url
  • $cmid
  • $info
sloodle_array_to_vector (line 272)

Converts an array vector to a string vector.

Array vector should be associative, containing elements 'x', 'y', and 'z'. Converts to a string vector of format "<x,y,z>".

string sloodle_array_to_vector ( $arr)
  • $arr
sloodle_autoenrol_enabled_site (line 84)

Determines whether or not auto-enrolment is allowed for the site.

  • return: True if auto-enrolment is allowed on the site, or false otherwise.
bool sloodle_autoenrol_enabled_site ()
sloodle_autoreg_enabled_site (line 75)

Determines whether or not auto-registration is allowed for the site.

  • return: True if auto-reg is allowed on the site, or false otherwise.
bool sloodle_autoreg_enabled_site ()
sloodle_check_course_module_instance_type (line 320)

Determines if the specified course module instance is of the named type.

For example, this can check if a particular instance is a "forum" or a "chat".

  • return: True if the module is of the specified type, or false otherwise
bool sloodle_check_course_module_instance_type (int $id, string $module_name)
  • int $id: The integer ID of a course module instance
  • string $module_name: Module type to check (must be the exact name of an installed module, e.g. 'sloodle' or 'quiz')
sloodle_describe_approx_time (line 741)

Returns a very approximate natural language description of a period of time (in minutes, hours, days, or weeks).

Can also be used to describe how long ago something happened, in which case anything less than 1 minute is treated as 'now'.

string sloodle_describe_approx_time (int $secs, [bool $ago = false])
  • int $secs: Number of seconds in period of time
  • bool $ago: If true (not default), then the time will be described in past tense, e.g. "3 days ago", as opposed to simply "3 days".
sloodle_finished_login_coordinates (line 390)

Generates teleport coordinates for a user who has already finished the LoginZone process.

  • return: bool An associative array vector containing a teleport location, or false if the operation fails.
array, sloodle_finished_login_coordinates (string $pos, string $size)
  • string $pos: A string vector giving the position of the LoginZone
  • string $size: A string vector giving the size of the LoginZone
sloodle_get_config (line 55)

Gets a Sloodle configuration value from Moodle's "config" table.

This function does not necessarily need to be used. All configuration data is available as named members of Moodle's $CFG global variable. NOTE: in Sloodle debug mode, this function will terminate the script with an error if the name is not prefixed with "sloodle_".

  • return: A string containing the configuration value, or false if the query failed (e.g. if the named value didn't exist)
  • see: sloodle_set_config()
mixed sloodle_get_config (string $name)
  • string $name: The name of the value to be stored (should be prefixed with "sloodle_")
sloodle_get_course_module_instance (line 283)

Obtains the identified course module instance database record.

  • return: A database record if successful, or false if it could not be found
mixed sloodle_get_course_module_instance (int $id)
  • int $id: The integer ID of a course module instance
sloodle_get_files (line 844)

Gets an array of files within the given directory.

Ignores anything which starts with a .

  • return: A numeric array of file names sorted alphabetically, or false if an error occurred (such as the input value not being a directory)
array|false sloodle_get_files (string $dir, [bool $relative = true])
  • string $dir: The directory to search WITHOUT a trailing slash. (Note: cannot search the current directory or higher in the file hierarchy)
  • bool $relative: If TRUE (default) the array of results will be relative to the input directory. Otherwise, they will include the input directory path.
sloodle_get_installed_object_types (line 896)

Gets all object types and versions available in this installation.

Creates a 2-dimensional associative array. The top level is the object name, and the second is the object version (both as strings). The associated value is the path to the configuration form script, or boolean false if the object has no configuration options.

  • return: Returns a 2d associative array if successful, or false if an error occurs
array|false sloodle_get_installed_object_types ()
sloodle_get_module_id (line 341)

Obtains the ID number of the specified module (type not instance).

  • return: Integer containing module ID, or false if it is not installed
mixed sloodle_get_module_id (string $name)
  • string $name: The name of the module type to check, e.g. 'sloodle' or 'forum'
sloodle_get_subdirectories (line 812)

Gets an array of subdirectories within the given directory.

Ignores anything which starts with a .

  • return: A numeric array of subdirectory names sorted alphabetically, or false if an error occurred (such as the input value not being a directory)
array|false sloodle_get_subdirectories (string $dir, [bool $relative = true])
  • string $dir: The directory to search WITHOUT a trailing slash. (Note: cannot search the current directory or higher in the file hierarchy)
  • bool $relative: If TRUE (default) the array of results will be relative to the input directory. Otherwise, they will include the input directory path.
sloodle_get_value (line 661)

Extracts a value from a name-value associative array if it is set.

(The array should associate name to value).

  • return: The value from the input array, or the $default parameter
mixed sloodle_get_value (array $settings, string $name, [mixed $default = null])
  • array $settings: The array of names and values
  • string $name: The name of the value to retrieve
  • mixed $default: The default value to return if the specified value was not found
sloodle_get_web_path (line 792)

Gets the basic URL of the current web-page being accessed.

Includes the protocol, hostname, and script path/name.

string sloodle_get_web_path ()
sloodle_is_course_module_instance_visible (line 294)

Determines whether or not the specified course module instance is visible.

Checks that the instance itself and the course section are both valid.

  • return: True if visible, or false if invisible or not found
bool sloodle_is_course_module_instance_visible (int $id)
  • int $id: The integer ID of a course module instance.
sloodle_is_installed (line 179)

Determines whether or not Sloodle is installed.

Queries Moodle's modules table for a Sloodle entry. NOTE: does not check for the presence of the Sloodle files.

  • return: True if Sloodle is installed, or false otherwise.
bool sloodle_is_installed ()
sloodle_login_notification (line 572)

Stores a pending login notification for an auto-registered user.

A cron job will process the pending notification queue.

  • return: True if successful, or false otherwise
bool sloodle_login_notification (string $destination, string $avatar, string $username, string $password)
  • string $destination: Identifies the destination of the notification (for SL, this will be the object UUID. The send function will construct the email address)
  • string $avatar: Identifier for the avatar being notified
  • string $username: The username to notify the user of
  • string $password: The (plaintext) password to notify the user of
sloodle_login_zone_bounds (line 471)

Calculates the maximum and minimum bounds of the specified LoginZone Returns the bounds as a numeric array of two associate array vectors: ($max, $min).

(Or returns false if no LoginZone position/size could be found in the Moodle configuration table).

array sloodle_login_zone_bounds (string $pos, string $size)
  • string $pos: A string vector giving the position of the LoginZone
  • string $size: A string vector giving the size of the LoginZone
sloodle_parse_object_identifier (line 874)

Extracts the object name and version number from an object identifier.

  • return: A numeric array of name then version number.
array sloodle_parse_object_identifier (string $objid)
  • string $objid: An object identifier, such as "chat-1.0"
sloodle_position_is_in_login_zone (line 358)

Checks if the specified position is in the current (site-wide) loginzone.

  • return: True if position is in LoginZone, or false if not
  • see: sloodle_login_zone_coordinates()
  • todo: Update or remove... no longer valid
bool sloodle_position_is_in_login_zone (mixed $pos)
  • mixed $pos: A string vector or an associated array vector
sloodle_print_access_level_options (line 678)

Outputs the standard form elements for access levels in object configuration.

Each part can be optionally hidden, and default values can be provided. (Note: the server access level must be communicated from the object back to Moodle... rubbish implementation, but it works!)

void sloodle_print_access_level_options (array $current_config, [bool $show_use_object = true], [bool $show_control_object = true], [bool $show_server = true])
  • array $current_config: An associative array of setting names to values, containing defaults. (Ignored if null).
  • bool $show_use_object: Determines whether or not the "Use Object" setting is shown
  • bool $show_control_object: Determines whether or not the "Control Object" setting is shown
  • bool $show_server: Determines whether or not the server access setting is shown
sloodle_process_login_notifications (line 611)

Processes pending login notifications, up to a certain limit.

Retrieves the requests one-at-a-time for processing. This is slower, but ensures minimal damage if the process is terminated, e.g. due to server timeout.

void sloodle_process_login_notifications ([int $limit = 25])
  • int $limit: The maximum number of pending requests to process.
sloodle_random_position_in_zone (line 413)

Generates a random position within a cuboid zone of the specified size.

(Note: leaves a 2 metre margin round the outside)

  • return: An associative vector array
array sloodle_random_position_in_zone (array $size)
  • array $size: Associative array giving the size of the zone
sloodle_random_prim_password (line 237)

Generates a random prim password (7 to 9 digit number).

  • return: The password as a string
string sloodle_random_prim_password ()
sloodle_random_security_token (line 191)

Generates a random login security token.

Uses mixed-case letters and numbers to generate a random 16-character string.

string sloodle_random_security_token ()
sloodle_random_web_password (line 215)

Generates a random web password Uses mixed-case letters and numbers to generate a random 8-character string.

string sloodle_random_web_password ()
sloodle_round_vector (line 436)

Rounds the specified 3d vector integer values.

Can handle/return a string vector, or an array vector. (Output type matches input type).

mixed sloodle_round_vector (mixed $pos)
  • mixed $pos: Either a string vector or an array vector
sloodle_send_login_notification (line 598)

Send a login notification.

  • return: True if successful, or false otherwise
bool sloodle_send_login_notification (string $destination, string $avatar, string $username, string $password)
  • string $destination: Identifies the destination of the notification (for SL, this will be the object UUID. The target email address will be constructed)
  • string $avatar: Identifier for the avatar being notified
  • string $username: The username to notify the user of
  • string $password: The (plaintext) password to notify the user of
sloodle_send_xmlrpc_message (line 96)

Sends an XMLRPC message into Second Life.

  • return: True if successful, or false if an error occurs
bool sloodle_send_xmlrpc_message (string $channel, int $intval, string $strval)
  • string $channel: A string containing a UUID identifying the XMLRPC channel in SL to be used
  • int $intval: An integer value to be sent in the message
  • string $strval: A string value to be sent in the message
sloodle_set_config (line 34)

Sets a Sloodle configuration value.

This data will be stored in Moodle's "config" table, so it will persist even after Sloodle is uninstalled. After being set, it will be available (read-only) as a named member of Moodle's $CFG variable. NOTE: in Sloodle debug mode, this function will terminate the script with an error if the name is not prefixed with "sloodle_".

  • return: True on success, or false on failure (may fail if database query encountered an error)
  • see: sloodle_get_config()
bool sloodle_set_config (string $name, string $value)
  • string $name: The name of the value to be stored (should be prefixed with "sloodle_")
  • string $value: The string representation of the value to be stored
sloodle_validate_prim_password (line 499)

Checks if the given prim password is valid.

  • return: True if it is valid, or false otherwise.
bool sloodle_validate_prim_password (string $password)
  • string $password: The password string to check
sloodle_validate_prim_password_verbose (line 525)

Checks if the given prim password is valid, and provides feedback.

An array is written to by reference, each element containing error codes. Each error code is a word. The full text of the error message may be obtained from the string file by looking for "primpass:errorcode".

  • return: True if the prim password is valid, or false otherwise
bool sloodle_validate_prim_password_verbose (string $password, array &$errors)
  • string $password: The password to validate
  • array &$errors: An array (passed by reference) which will contain any error messages
sloodle_vector_to_array (line 252)

Converts a string vector to an array vector.

String vector should be of format "<x,y,z>". Converts to associative array with members 'x', 'y', and 'z'. Returns false if input parameter was not of correct format.

mixed sloodle_vector_to_array (string $vector)
  • string $vector: A string vector of format "<x,y,z>".

Documentation generated on Mon, 07 Jul 2008 12:32:25 +0100 by phpDocumentor 1.4.0