Class SloodleUser

Description

A class to represent a single user, including Moodle and Sloodle data.

  • usedby: SloodleLSLRequest - Stores and processes user data incoming from an HTTP request

Located in /lib/sl_userlib.php (line 29)


	
			
Variable Summary
Method Summary
 void SloodleUser ()
 mixed create_moodle_user ( $firstname,  $lastname,  $email)
 bool create_sloodle_user ([string $uuid = ''], [string $avname = ''], [int $userid = 0], [string $loginposition = ''], [string $loginpositionexpires = ''], [string $loginpositionregion = ''], [string $loginsecuritytoken = ''])
 mixed find_linked_moodle_user ([bool $use_cache = FALSE], [bool $cache_data = TRUE])
 mixed find_linked_sloodle_user ([bool $cache_data = TRUE])
 mixed find_sloodle_user (string $uuid, string $name, [bool $cache_data = TRUE])
 void find_sloodle_user_by_login_position (mixed $position, [bool $cache_data = TRUE])
 mixed generate_login_position (int $expires)
 bool has_login_security_token ([bool $use_cache = FALSE])
 void is_user_in_course (int $course_id, [bool $use_cache = FALSE], bool 2)
 mixed link_users ()
 bool regenerate_login_security_token ([bool $cache_data = TRUE])
 void set_moodle_user_id (int $id)
 void set_sloodle_user_id (int $id)
 mixed users_linked ([bool $use_cache = FALSE])
Variables
array $enrolled_courses_cache = NULL (line 99)

Cache of courses which the Moodle user is enrolled in Used by some functions fetching database data about a Moodle user's courses.

It is an array which caches the list of courses the Moodle user is enrolled in Note that update is *not* automatic, but you can manually call {@link: update_enrolled_courses_cache_from_db()}. After construction, it will always be a numeric array of integers (but may be empty) Each element will be a course ID (integer).

object $moodle_user_cache = NULL (line 86)

Moodle user data cache.

Used by various functions fetching database data about a Moodle user. Contents can also be used in subsequent function calls to prevent the need for an additional database query (typically by specifying a $use_cache parameter). Update is *not* automatic. It can be updated manually by calling {@link: update_moodle_user_cache_from_db()}. Unlike the Sloodle equivalent, this cannot be used to update the database After construction, it will always be an object.

int $moodle_user_id = 0 (line 52)

Integer ID of a Moodle user entry in the database.

Value 0 represents no user.

object $sloodle_user_cache = NULL (line 70)

Sloodle user data cache.

Used by various functions fetching database data about a Sloodle user. Contents can also be used in subsequent function calls to prevent the need for an additional database query (typically by specifying a $use_cache parameter). Update is *not* automatic. It can be updated manually by calling {@link: update_sloodle_user_cache_from_db()}. Data placed here can also be used to edit the database using {@link: insert_sloodle_user_cache_to_db()} or {@link: update_sloodle_user_cache_to_db()}. After construction, it will always be an object.

int $sloodle_user_id = 0 (line 42)

Integer ID of a Sloodle user entry in the database.

Value 0 represents no user.

Methods
Constructor SloodleUser (line 109)

Class constructor.

  • access: public
void SloodleUser ()
create_moodle_user (line 453)

Create a Moodle user account with the specified first name, last name and email address.

  • return: True if successful, or a string error message if something goes wrong.
  • access: public
mixed create_moodle_user ( $firstname,  $lastname,  $email)
  • $firstname
  • $lastname
  • $email
create_sloodle_user (line 347)

Create a new Sloodle user.

All parameters are optional. To enable loginzone authentication, you *must* specify position and expiry time. Note that, if no login security token is specified, it is generated automatically. If successful, the new ID is stored and the user data is cached.

  • return: True if successful, or false if not.
  • access: public
bool create_sloodle_user ([string $uuid = ''], [string $avname = ''], [int $userid = 0], [string $loginposition = ''], [string $loginpositionexpires = ''], [string $loginpositionregion = ''], [string $loginsecuritytoken = ''])
  • string $uuid: avatar UUID
  • string $avname: avatar name
  • int $userid: ID of Moodle user to be linked with this Sloodle user
  • string $loginposition: a position vector of format <x,y,z>, representing the allocated loginzone position
  • string $loginpositionexpires: an indication of when the allocated loginposition expires (format unknown)
  • string $loginpositionregion: the name of the region in which the loginzone is (NOT IN USE YET!)
  • string $loginsecuritytoken: a security token (random letters/numbers) used to allow secure authentication
delete_login_position (line 379)

Clears the login position from the currently selected Sloodle user.

This function will user the user identified by {@link:$sloodle_user_id}, retrieve all the user data, remove the login position values, and update the database.

  • return: True if successful, false if the database query fails, or a string if an error occurs.
  • access: public
mixed delete_login_position ()
delete_sloodle_user (line 243)

Deletes the Sloodle user identified by {@link:$sloodle_user_id}.

  • return: True if successful, false on failure, or a string error message if something goes wrong
  • access: public
mixed delete_sloodle_user ()
find_linked_moodle_user (line 611)

Find the Moodle user linked to the current Sloodle user.

Stores the Moodle user ID in {@link:$moodle_user_id}.

  • return: True if successful, false if no link was found, or a string if an error occurs
  • access: public
mixed find_linked_moodle_user ([bool $use_cache = FALSE], [bool $cache_data = TRUE])
  • bool $use_cache: If true (not default) this function will use the local Sloodle user cache instead of querying the database again.
  • bool $cache_data: If true (default) then the Moodle user data is automatically cached by this function
find_linked_sloodle_user (line 579)

Find the Sloodle user linked to the current Moodle user.

Stores the Sloodle user ID in {@link:$sloodle_user_id}.

  • return: True if successful, false if no link was found, or a string if an error occurs
  • access: public
mixed find_linked_sloodle_user ([bool $cache_data = TRUE])
  • bool $cache_data: If true (default) then the Sloodle user data is automatically cached by this function.
find_sloodle_user (line 548)

Attempts to find a Sloodle user by their UUID and/or avatar nam.

Note: the UUID takes precedence, but the name can be used as a fall-back. The ID of the user is stored in {@link:$sloodle_user_id}.

  • return: True if successful, false if user was not found, or a string is some other error occurred.
  • access: public
mixed find_sloodle_user (string $uuid, string $name, [bool $cache_data = TRUE])
  • string $uuid: The UUID of the avatar
  • string $name: The name of the avatar
  • bool $cache_data: If true (default) then the user data is stored in the cache variable, {@link:$sloodle_user_cache}.
find_sloodle_user_by_login_position (line 660)

Attempt to find a Sloodle user by their loginzone position If successful, the user ID is stored in {@link:$sloodle_user_id} and the function returns true.

If no user was found for the given position, false is returned (this may occur if the LoginZone position has expired). If an error occurs, then a string containing an error message is returned.

  • access: public
void find_sloodle_user_by_login_position (mixed $position, [bool $cache_data = TRUE])
  • mixed $position: A vector, either as a string ("<x,y,z>") or an associative array.
  • bool $cache_data: If true (default) then the user data is cached. Otherwise it is discarded.
generate_login_position (line 402)

Generates a new login position for the current Sloodle user.

Stores the new login position in the database, and refreshes the user cache

  • return: A numerical array containing the new position if successful, FALSE on failure, or a string if an error occurs
  • access: public
mixed generate_login_position (int $expires)
  • int $expires: A timestamp indicating when the position should expire.
get_moodle_user_id (line 146)

Accessor: gets the Moodle user ID member, {@link: $moodle_user_id}.

  • access: public
int get_moodle_user_id ()
get_sloodle_user_id (line 125)

Accessor: gets the Sloodle user ID member, {@link: $sloodle_user_id}.

  • access: public
int get_sloodle_user_id ()
has_login_security_token (line 770)

Checks if the current Sloodle user has a login security token

  • return: True if the user has a login security token, or false otherwise.
  • access: public
bool has_login_security_token ([bool $use_cache = FALSE])
  • bool $use_cache: If true then the cached user data will be used instead of querying the database.
insert_sloodle_user_cache_to_db (line 317)

Use the Sloodle user cache to insert a new entry in the Sloodle user database table.

Uses the object entirely as-is, except that the 'id' field is ignored. The ID of the new entry is stored in {@link:$sloodle_user_id}.

  • return: True if successful, or false on failure.
  • access: public
bool insert_sloodle_user_cache_to_db ()
is_user_in_course (line 831)

Checks if the current Moodle user is already enrolled in the specified course.

  • access: public
void is_user_in_course (int $course_id, [bool $use_cache = FALSE], bool 2)
  • int $course_id: ID number of a course to check.
  • bool $use_cache: If true (not default) then the function uses the enrolled courses cache, instead of querying the database for new data.
  • bool 2: True if the user is enrolled, or false if not.
link_users (line 200)

Links the current Sloodle and Moodle accounts together.

NOTE: does not remove any other links to the Moodle account.

  • return: True if successful, false on failure, or a string error message if something goes wrong
  • access: public
mixed link_users ()
login_moodle_user (line 728)

Performs an internal login of the current Moodle user.

Stores all the user data in the global $USER variable. Note: if login fails, $USER is unchanged. Additionally, note that this function will not perform automatic registration.

  • return: True if successful, or false otherwise.
  • access: public
bool login_moodle_user ()
regenerate_login_security_token (line 747)

Generates a new login security token for the current Sloodle user

  • return: True if successful, or false if an error occurs (such as there being no current Sloodle user)
  • access: public
bool regenerate_login_security_token ([bool $cache_data = TRUE])
  • bool $cache_data: If true (default) then the new login security token will be stored in the Sloodle user cache (as well as the database).
set_moodle_user_id (line 157)

Accessor: sets the Moodle user ID member, {@link: $moodle_user_id}.

  • access: public
void set_moodle_user_id (int $id)
  • int $id: The integer ID of a Moodle user entry (or 0 for no entry).
set_sloodle_user_id (line 136)

Accessor: sets the Sloodle user ID member, {@link: $sloodle_user_id}.

  • access: public
void set_sloodle_user_id (int $id)
  • int $id: The integer ID of a Sloodle user entry (or 0 for no entry).
unlink_sloodle_user (line 221)

Completely unlinks the Sloodle user from any Moodle account.

  • return: True if successful, false on failure, or a string error message if something goes wrong
  • access: public
mixed unlink_sloodle_user ()
update_enrolled_courses_cache_from_db (line 801)

Use the database to update the cache of courses which the current Moodle user is enrolled in.

Note that admins are considered by this function to be enrolled in all courses.

  • return: if successul, or false otherwise.
  • access: public
True update_enrolled_courses_cache_from_db ()
update_moodle_user_cache_from_db (line 273)

Update the Moodle user cache ({@link:$moodle_user_cache}) from the database

  • return: True if successful, false on failure, or a string error message if something goes wrong
  • access: public
mixed update_moodle_user_cache_from_db ()
update_sloodle_user_cache_from_db (line 257)

Updates the Sloodle user cache ({@link:$sloodle_user_cache}) from the database

  • return: True if successful, false on failure, or a string error message if something goes wrong
  • access: public
mixed update_sloodle_user_cache_from_db ()
update_sloodle_user_cache_to_db (line 291)

Use the Sloodle user cache to update an entry in the Sloodle users database table.

Uses the object-entirely as-is, so the 'id' field must be accurate. Ignores anu unset fields.

  • return: True if successful, false if the query fails, or a string error message if something goes wrong
  • access: public
mixed update_sloodle_user_cache_to_db ()
users_linked (line 171)

Determines whether or not the current Sloodle and Moodle users are linked.

  • return: Ture if users are linked, false if not, or a string error message if something goes wrong.
  • access: public
mixed users_linked ([bool $use_cache = FALSE])
  • bool $use_cache: If true (not default) then the Sloodle and Moodle user caches ({@link:$sloodle_user_cache} and {@link:$moodle_user_cache})will be used instead of querying the database.

Documentation generated on Tue, 04 Mar 2008 15:08:56 +0000 by phpDocumentor 1.4.0