Source for file linker.php

Documentation is available at linker.php

  1. <?php
  2.     /**
  3.     * Sloodle choice linker (for Sloodle 0.3).
  4.     * Allows an SL object to access a Moodle choice instance.
  5.     *
  6.     * @package sloodlechoice
  7.     * @copyright Copyright (c) 2007-8 Sloodle (various contributors)
  8.     * @license http://www.gnu.org/licenses/gpl-3.0.html GNU GPL v3
  9.     *
  10.     * @contributor Peter R. Bloomfield
  11.     */
  12.     
  13.     // This script should be called with the following parameters:
  14.     //  sloodlecontrollerid = ID of a Sloodle Controller through which to access Moodle
  15.     //  sloodlepwd = the prim password or object-specific session key to authenticate the request
  16.     //  sloodlemoduleid = ID of a choice
  17.     //
  18.     // If called with only the above parameters, then summary information about the choice is fetched.
  19.     // Status code 10001 will be returned, with the first few data lines having the following format:
  20.     //   <choice_name>
  21.     //   <choice_text>
  22.     //   <is_available>|<timestamp_open>|<timestamp_close>
  23.     //   <num_unanswered>
  24.     //
  25.     // Following that will be one line for each available option, with the following format:
  26.     //   <option_id>|<option_text>|<num_selected>
  27.     //  
  28.     // The "num_unanswered" and "num_selected" values will be -1 if they are not allowed to be shown.
  29.     // The "is_available" will be 1 if the choice is open and accepting answers, or 0 otherwise.
  30.     // The timestamp values indicate when the choice opens and closes respectively, but will be 0 if there is no opening or closing time.
  31.     //
  32.     //
  33.     // An option can be selected by including the following parameters
  34.     //  sloodleuuid = UUID of the avatar
  35.     //  sloodleavname = name of the avatar
  36.     //  sloodleoptionid = the ID of a particular option (unique site-wide)
  37.     //
  38.     // If successful, the return code will be 10011, 10012, or 10013, depending what has been done. No data.
  39.     // See the status codes list for further information.
  40.     //
  41.     
  42.  
  43.     /** Lets Sloodle know we are in a linker script. */
  44.     define('SLOODLE_LINKER_SCRIPT'true);
  45.     
  46.     /** Grab the Sloodle/Moodle configuration. */
  47.     require_once('../../sl_config.php');
  48.     /** Include the Sloodle PHP API. */
  49.     require_once(SLOODLE_LIBROOT.'/sloodle_session.php');
  50.     
  51.     // Authenticate the request, and load a choice module
  52.     $sloodle new SloodleSession();
  53.     $sloodle->authenticate_request();
  54.     $sloodle->load_module('choice'true);
  55.  
  56.     // Has an option been specified?
  57.     $sloodleoptionid $sloodle->request->optional_param('sloodleoptionid');
  58.     if ($sloodleoptionid === null{
  59.         // No - we are simply querying for choice data
  60.         $sloodle->response->set_status_code(10001);
  61.         $sloodle->response->set_status_descriptor('CHOICE_QUERY');
  62.         
  63.         // Check availability and results
  64.         $isavailable '0';
  65.         if ($sloodle->module->is_open()) $isavailable '1';
  66.         $canshowresults $sloodle->module->can_show_results();
  67.         
  68.         // Add the data to the response
  69.         $sloodle->response->add_data_line($sloodle->module->get_name());
  70.         $sloodle->response->add_data_line(stripslashes(strip_tags($sloodle->module->get_intro())));
  71.         $sloodle->response->add_data_line(array($isavailable$sloodle->module->get_opening_time()$sloodle->module->get_closing_time()));
  72.         if ($canshowresults$sloodle->response->add_data_line($sloodle->module->get_num_unanswered());
  73.         else $sloodle->response->add_data_line('-1');
  74.         // Go through each option
  75.         foreach ($sloodle->module->options as $optionid => $option{
  76.             // Prepare a data array for this option
  77.             $optiondata array();
  78.             $optiondata[$optionid;
  79.             $optiondata[stripslashes(strip_tags($option->text));
  80.             if ($canshowresults$optiondata[$option->numselections;
  81.             else $optiondata[= -1;
  82.             
  83.             $sloodle->response->add_data_line($optiondata);
  84.         }
  85.         
  86.     else {
  87.         // Yes - validate the user, and permit auto-registration/enrolment
  88.         $sloodle->validate_user();
  89.         $sloodle->response->set_status_descriptor('CHOICE_SELECT');
  90.         
  91.         // Attempt to select the option
  92.         $result $sloodle->module->select_option($sloodleoptionid);
  93.         if (!$result{
  94.             $sloodle->response->set_status_code(-10016);
  95.             $sloodle->response->add_data_line('Unknown error selecting option.');
  96.         else {
  97.             $sloodle->response->set_status_code($result);
  98.         }
  99.     }
  100.     
  101.     // Output our response
  102.     sloodle_debug('<pre>')// For debug mode, lets us see the response in a browser
  103.     $sloodle->response->render_to_output();
  104.     sloodle_debug('</pre>');
  105.     
  106. ?>

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