Source for file object_config.php

Documentation is available at object_config.php

  1. <?php
  2.     /**
  3.     * Demo 1.0 configuration form.
  4.     *
  5.     * This is a fragment of HTML which gives the form elements for configuration of the SLOODLE demo object, v1.0.
  6.     * ONLY the basic form elements should be included.
  7.     * The "form" tags and submit button are already specified outside.
  8.     * The $auth_obj and $sloodleauthid variables will identify the object being configured.
  9.     *
  10.     * The name of each form element becomes the name of a configuration parameter which is passed (via link message) to your scripts in SL.
  11.     * For example, a form element called "sloodlemoduleid" will pass a value to your script in SL called "sloodlemoduleid".
  12.     *
  13.     *
  14.     * @package sloodle
  15.     * @copyright Copyright (c) 2009 Sloodle (various contributors)
  16.     * @license http://www.gnu.org/licenses/gpl-3.0.html GNU GPL v3
  17.     *
  18.     * @contributor Peter R. Bloomfield
  19.     *
  20.     */
  21.     
  22.     // IMPORTANT: make sure this is called from within a Sloodle script
  23.     if (!defined('SLOODLE_VERSION')) {
  24.         error('Not called from within a Sloodle script.');
  25.         exit();
  26.     }
  27.     
  28.     // Execute everything within a function to ensure we don't mess up the data in the other file
  29.     sloodle_display_config_form($sloodleauthid$auth_obj);
  30.     
  31.     
  32.     
  33.     function sloodle_display_config_form($sloodleauthid$auth_obj)
  34.     {
  35.     //--------------------------------------------------------
  36.     // SETUP
  37.         
  38.         // Determine which course is being accessed
  39.         $courseid $auth_obj->course->get_course_id();
  40.         
  41.         // If your object is going to link into an existing module in Moodle, e.g. chatrooms, then you need to get a list all such module instances in the course.
  42.         // We will be using chatrooms for this example.
  43.         // First, we need to figure out what the ID number for the 'chat' type is.
  44.         $rec get_record('modules''name''chat');
  45.         if (!$rec{
  46.             sloodle_debug("Failed to get chatroom module type.");
  47.             exit();
  48.         }
  49.         $chatmoduleid $rec->id;
  50.         
  51.         // Get all visible chatrooms in the current course
  52.         $recs get_records_select('course_modules'"course = $courseid AND module = $chatmoduleid AND visible = 1");
  53.         if (!$recs{
  54.             // No visible chatrooms -- output an error message
  55.             error(get_string('nochatrooms','sloodle'))// This comes from the SLOODLE language pack
  56.             exit();
  57.         }
  58.         // Go through each chatroom we were given
  59.         $chatrooms array();
  60.         foreach ($recs as $cm{
  61.             // Fetch the chatroom instance
  62.             $inst get_record('chat''id'$cm->instance);
  63.             if (!$instcontinue;
  64.             // Store the chatroom details
  65.             $chatrooms[$cm->id$inst->name;
  66.         }
  67.         // Sort the list by name
  68.         natcasesort($chatrooms);
  69.         
  70.         // We now have an alphabetically-sorted array, associating course module instance IDs with chatroom names.
  71.         // We can use that to let the user know what chatrooms are available.
  72.         
  73.     //--------------------------------------------------------
  74.     // FORM
  75.     
  76.         // If the object is already configured, then we need to get its current configuration.
  77.         // This function will grab an array of configuration settings from the database.
  78.         $settings SloodleController::get_object_configuration($sloodleauthid);
  79.         
  80.         // Use the "sloodle_get_value" function to extract specific settings from the array.
  81.         // The second argument names the parameter, and the 3rd gives the default initial value.
  82.         $sloodlemoduleid = (int)sloodle_get_value($settings'sloodlemoduleid'0);
  83.         $sloodlerandomtext sloodle_get_value($settings'sloodlerandomtext''foobar');
  84.         $sloodleshowhovertext = (int)sloodle_get_value($settings'sloodleshowhovertext'1);
  85.         
  86.     
  87.     ///// GENERAL CONFIGURATION /////
  88.         // We will now display the configuration form.
  89.     
  90.         // Create a new section box for general configuration options
  91.         print_box_start('generalbox boxaligncenter');
  92.         echo '<h3>'.get_string('generalconfiguration','sloodle').'</h3>';
  93.         
  94.         // Display a drop-down menu (using a Moodle function) to let the user choose the module.
  95.         // In this case, we are showing them a list of chatrooms.
  96.         // This is a very common part of the configuration form.
  97.         echo get_string('selectchatroom','sloodle').': ';
  98.         choose_from_menu($chatrooms'sloodlemoduleid'$sloodlemoduleid'');
  99.         echo "<br><br>\n";
  100.     
  101.         // Display a text box for some random text
  102.         echo 'Enter some text: '// Ideally this should be replaced by "get_string(...)"
  103.         echo '<input type="text" name="sloodlerandomtext" id="sloodlerandomtext" value="'.$sloodlerandomtext.'" size="20" maxlength="20" />';
  104.         echo "<br><br>\n";
  105.         
  106.         // Display a yes/no drop down menu.
  107.         // NOTE: we can't use checkboxes! Yes/no responses must be done as drop-down menus.
  108.         echo 'Show hover text? '// Ideally this should be replaced by "get_string(...)"
  109.         choose_from_menu_yesno('sloodleshowhovertext'$sloodleshowhovertext);
  110.         echo "<br>\n";
  111.         
  112.         // Close the general section
  113.         print_box_end();
  114.         
  115.         
  116.     ///// ACCESS LEVELS /////
  117.         // This is common to nearly all objects, although variations are possible.
  118.         // There are 3 access settings, in two categories:
  119.         //  In-world: use and control
  120.         //  Server: access
  121.         //
  122.         // The in-world 'use' setting determines who can generally use the object, whether it is public, limited to an SL group, or owner-only. (Public by default)
  123.         // The in-world 'control' setting determines who has authority to control the object, which can similarly be public, group, or owner-only. (Owner-only by default)
  124.         // The server access lets you limit usage to avatars which are registered or enrolled, or to members of staff. By default though, it is public.
  125.         //
  126.         // The following function displays the appropriate form data.
  127.         // We pass in the existing settings so that it can setup defaults.
  128.         // The subsequent 3 parameters determine if each type of access setting should be visible, in the order specified above.
  129.         // They are optional, and all default to true if not specified.
  130.     
  131.         sloodle_print_access_level_options($settingstruetruetrue);
  132.         
  133.     }
  134.     
  135. ?>

Documentation generated on Fri, 17 Jul 2009 11:02:15 +0100 by phpDocumentor 1.4.0