Source for file sl_profile_linker.php
Documentation is available at sl_profile_linker.php
* Sloodle classroom profile linker.
* Allows in-world objects (typically Sloodle Sets) to interact with Sloodle classroom setup profiles in the Moodle database.
* @package sloodleclassroom
* @copyright Copyright (c) 2006-7 Sloodle (various contributors)
* @license http://www.gnu.org/licenses/gpl-3.0.html GNU GPL v3
* @contributor Edmund Edgar
* @contributor Peter R. Bloomfield
// Classroom profiles consist of a series of object entries.
// Each object entry consists of the object name, and relative position to the Sloodle Set.
// This script is expected to be called from in-world objects.
// The following parameters are required:
// sloodlepwd = prim password for authenticating the request
// sloodleuuid = UUID of the user making the request (optional if 'sloodleavname' is specified)
// sloodleavname = avatar name of the user making the request (optional if 'sloodleuuid' is specified)
// sloodlecourseid = the ID of the course which the profile is in
// sloodlecmd = the operation ('command') to be carried out
// Certain modes also require the following parameters:
// sloodleprofilename = the name of the profile being handled
// sloodleentries = the entries to be added to the profile
// The mode of the script is determined by the 'sloodlecmd' parameters.
// 'newprofile' creates a new profile with the name given in 'sloodleprofilename'.
// 'saveentries' will erase all existing entries, and add new object entries specified in 'sloodleentries' to the profile named in 'sloodleprofilename'.
// 'listentries' will list all object entries in the profile named in 'sloodleprofilename'.
// 'listprofiles' will list all profiles in the identified course.
// When saving entries to a profile, the format of each entry in 'sloodleentries' should be as follows:
// The position should be given as a string vector "<x,y,z>".
// Note that object names should be unique within a given profile.
// Multiple entries should be separate by a double pipe ||.
// For example, three entries might look like this:
// "Sloodle WebIntercom|<1.4,0.9,2.6>||Sloodle Registration Booth|<2.1,3.0,3.5>||Sloodle MetaGloss|<0.0,1.2,2.6>"
// There is not response data.
// When adding a new profile, the response code will be 1 for success, and the ID and name of the profile will be given on the sole data line, e.g.:
// When returning the entries in a given profile, each line contain the entry ID, name and position, e.g.:
// 6|Sloodle WebIntercom|<1.4,0.9,2.6>
// 7|Sloodle Registration Booth|<2.1,3.0,3.5>
// 11|Sloodle MetaGloss|<0.0,1.2,2.6>
// When returning the available profiles for the course, each one will be returned by id and name on its own line, e.g.:
// Some specific error codes which may be returned:
// -901 = unknown profile error
// -902 = profile does not exist
// -903 = profile already exists (i.e. cannot be created again)
// -904 = unknown profile command
// In some cases, error code -103 may be returned if no data was found.
require_once('../config.php');
require_once(SLOODLE_DIRROOT.
'/sl_debug.php');
require_once(SLOODLE_DIRROOT.
'/lib/sl_lsllib.php');
require_once(SLOODLE_DIRROOT.
'/lib/sl_classroomlib.php');
// Create an LSL handler and process the basic request data
$lsl->request->process_request_data();
// Make sure the course id was specified
$lsl->request->required_param('sloodlecourseid', PARAM_INT);
// Ensure the request is authenticated
$lsl->request->authenticate_request();
// Attempt to login the user
$lsl->login_by_request();
// Make sure the user is authorized to manage profiles for this course
if (!(isadmin() ||
isteacher($lsl->request->get_course_id()))) {
// User is not authorized
$lsl->response->set_status_code(-
331);
$lsl->response->set_status_descriptor('USER_AUTH');
$lsl->response->add_data_line('User is not authorised to manage Sloodle classroom profiles for this course.');
$lsl->response->render_to_output();
// Obtain the additional parameters
$sloodlecmd =
strtolower($lsl->request->required_param('sloodlecmd', PARAM_RAW));
$sloodleprofilename =
optional_param('sloodleprofilename', NULL, PARAM_RAW);
if ($sloodleprofilename !=
NULL) $sloodleprofilename =
trim($sloodleprofilename);
$sloodleentries =
optional_param('sloodleentries', NULL, PARAM_RAW);
// Check which mode we're in
// We are to create a new profile
// Make sure the profile name was specified
$lsl->request->required_param('sloodleprofilename', PARAM_RAW);
// Check that the named profile does not already exist for this course
// Construct a new profile object
$profile =
new stdClass();
$profile->name =
$sloodleprofilename;
$profile->courseid =
$lsl->request->get_course_id();
// Insert it into the database
$lsl->response->set_status_code(-
901);
$lsl->response->set_status_descriptor('PROFILE');
$lsl->response->add_data_line('Failed to add profile to database.');
$lsl->response->set_status_code(1);
$lsl->response->set_status_code(-
903);
$lsl->response->set_status_descriptor('OK');
$lsl->response->add_data_line(array($id, $sloodleprofilename));
// We are to list the profiles in the current course
// Make sure it was successful
if (!is_array($profiles)) $profiles =
array();
foreach ($profiles as $p) {
$lsl->response->add_data_line(array($p->id, $p->name));
// Construct the rest of the response
$lsl->response->set_status_code(1);
$lsl->response->set_status_descriptor('OK');
// We are to list all entries in the given profile
// Make sure the profile name was specified
$lsl->request->required_param('sloodleprofilename', PARAM_RAW);
// Attempt to fetch the named profile
// Make sure it was successful
$lsl->response->set_status_code(-
103);
$lsl->response->set_status_descriptor('SYSTEM');
$lsl->response->add_data_line("Failed to find profile '$sloodleprofilename' in specified course.");
// Fetch all entries in the profile
// Make sure it was successful
if (!is_array($entries)) $entries =
array();
foreach ($entries as $e) {
// Add this entry to the response
$lsl->response->add_data_line(array($e->id, $e->name, $e->relative_position));
// Construct the rest of the response
$lsl->response->set_status_code(1);
$lsl->response->set_status_descriptor('OK');
// We are to save a new list of entries in the profile
// Make sure the profile name was specified
$lsl->request->required_param('sloodleprofilename', PARAM_RAW);
// Make sure the entries string was specified
if ($sloodleentries ==
NULL ||
empty($sloodleentries)) {
$lsl->response->set_status_code(-
811);
$lsl->response->set_status_descriptor('REQUEST');
$lsl->response->add_data_line('Expected parameter \'sloodleentries\' not specified.');
// Attempt to fetch the named profile
// Make sure it was successful
$lsl->response->set_status_code(-
103);
$lsl->response->set_status_descriptor('SYSTEM');
$lsl->response->add_data_line("Failed to find profile '$sloodleprofilename' in specified course.");
// Fetch all entries in the profile
// Yes - convert it to an associative array of name to entry
foreach ($raw_entries as $e) {
// No - just an empty array
// Split the entries list into each individual entry command
$new_entries_str =
explode("||", $sloodleentries);
$new_entries =
array(); // This will store our new entries that we create
foreach ($new_entries_str as $nes) {
// Extract all parts of the entry
// Make sure we have the expected number of parts
if (count($parts) !=
2) {
// Construct a new profile entry object
$this_entry =
new stdClass();
$this_entry->sloodle_classroom_setup_profile_id =
$profile->id;
$this_entry->name =
$parts[0];
$this_entry->relative_position =
$parts[1];
// Add the entry to the list of entries
$new_entries[] =
$this_entry;
$lsl->response->set_status_code(1);
$lsl->response->set_status_descriptor('OK');
$lsl->response->set_status_code(-
901);
$lsl->response->set_status_descriptor('PROFILE');
$lsl->response->add_data_line('Failed to save profile entries.');
$lsl->response->set_status_code(-
904);
$lsl->response->set_status_descriptor('PROFILE');
$lsl->response->add_data_line("Unknown profile command: '$sloodleprofilecmd'");
$lsl->response->render_to_output();
Documentation generated on Tue, 04 Mar 2008 15:08:50 +0000 by phpDocumentor 1.4.0