Source for file block_sloodle_menu.php

Documentation is available at block_sloodle_menu.php

  1. <?php
  2.  
  3. /**
  4. * Defines the Sloodle menu block class.
  5. @package sloodle
  6. @contributor Peter R. Bloomfield
  7. */
  8.  
  9. /** Include the current Sloodle configuration, if possible. */
  10. @include_once($CFG->dirroot .'/mod/sloodle/sl_config.php');
  11. if (defined('SLOODLE_LIBROOT')) {
  12.     /** Inlcude the current general Sloodle functionality. */
  13.     require_once(SLOODLE_LIBROOT.'/general.php');
  14.     /** Include the Sloodle course functionality. */
  15.     require_once(SLOODLE_LIBROOT.'/course.php');
  16. }
  17.  
  18. /** Include the old Sloodle configuration, in case the module is out-dated. */
  19. if (!defined('SLOODLE_VERSION')) {
  20.     @include_once($CFG->dirroot .'/mod/sloodle/config.php');
  21.     if (defined('SLOODLE_DIRROOT')) {
  22.         /** Include the old general Sloodle functionality. */
  23.         require_once(SLOODLE_DIRROOT.'/lib/sl_generallib.php');
  24.     }
  25. }
  26.  
  27. /** Define the Sloodle Menu Block version. */
  28. define('SLOODLE_MENU_VERSION'0.3);
  29.  
  30. /**
  31. * Defines the block class.
  32. @package sloodle
  33. */
  34. class block_sloodle_menu extends block_base {
  35.  
  36.     /**
  37.     * Perform block initialisation.
  38.     * @return void 
  39.     */
  40.     function init({
  41.         global $CFG;
  42.         
  43.         $this->title get_string('blockname''block_sloodle_menu');
  44.         $this->content_type BLOCK_TYPE_TEXT;
  45.         $this->version 2008060200;
  46.     }
  47.     
  48.     /**
  49.     * Indicates whether or not this module has a global configuration page.
  50.     * @return bool True if there is a global configuration page, or false otherwise.
  51.     */
  52.     function has_config({
  53.         return false;
  54.     }
  55.     
  56.     /**
  57.     * Indicates whether or not to hide the header of this block.
  58.     * @return bool True to hide the header, or false to show it.
  59.     */
  60.     function hide_header({
  61.         return false;
  62.     }
  63.  
  64.     /**
  65.     * Defines *and* returns the content of this block.
  66.     * @return object 
  67.     */
  68.     function get_content({
  69.         global $CFG$COURSE$USER;
  70.         
  71.         // Construct the content
  72.         $this->content new stdClass;
  73.         $this->content->text '';
  74.         $this->content->footer '';
  75.         
  76.         // If no course has been specified, then we are using the site course
  77.         if (!isset($COURSE)) {
  78.             $COURSE get_site();
  79.         }
  80.         
  81.         // If the user is not logged in or if they are using guest access, then we can't show anything
  82.         if (!isloggedin(|| isguest()) {
  83.             return $this->content;
  84.         }
  85.         
  86.         // Get the context instance for this course
  87.         $course_context get_context_instance(CONTEXT_COURSE$COURSE->id);
  88.         
  89.         // This version of the menu isn't compatible with older version of the Sloodle module
  90.         if (SLOODLE_VERSION 0.3{
  91.             $this->content->text get_string('oldmodule''block_sloodle_menu');
  92.             return $this->content;
  93.         }
  94.         
  95.         // Has the Sloodle activity module been installed?
  96.         if (!(function_exists("sloodle_is_installed"&& sloodle_is_installed())) {
  97.             $this->content->text get_string('sloodlenotinstalled''block_sloodle_menu');
  98.             return $this->content;
  99.         }
  100.         
  101.         // Get the Sloodle course data
  102.         $sloodle_course new SloodleCourse();
  103.         if (!$sloodle_course->load((int)$COURSE->id)) {
  104.             $this->content->text get_string('failedloadcourse''block_sloodle_menu');
  105.             return $this->content;
  106.         }
  107.         
  108.         // Add the Sloodle and Sloodle Menu version info to the footer of the block
  109.         $this->content->footer '<span style="color:#565656;font-style:italic; font-size:10pt;">'.get_string('sloodlemenuversion''block_sloodle_menu').': '.(string)SLOODLE_MENU_VERSION.'</span>';
  110.         $this->content->footer .= '<br/><span style="color:#888888;font-style:italic;font-size:8pt;">'.get_string('sloodleversion''block_sloodle_menu').': '.(string)SLOODLE_VERSION.'</span>';
  111.         
  112.         // Attempt to find a Sloodle user for the Moodle user
  113.         $dbquery "    SELECT * FROM {$CFG->prefix}sloodle_users
  114.                         WHERE userid = {$USER->id} AND NOT (avname = '' AND uuid = '')
  115.                     ";
  116.         $dbresult get_records_sql($dbquery);
  117.         $sl_avatar_name "";
  118.         if (!is_array($dbresult|| count($dbresult== 0$userresult FALSE;
  119.         else if (count($dbresult1$userresult "Multiple avatars associated with your Moodle account.";
  120.         else {
  121.             $userresult TRUE;
  122.             reset($dbresult);
  123.             $cur current($dbresult);
  124.             $sl_avatar_name $cur->avname;
  125.         }
  126.         
  127.         if ($userresult === TRUE{
  128.             // Success
  129.             // Make sure there was a name
  130.             if (empty($sl_avatar_name)) $sl_avatar_name '('.get_string('nameunknown''block_sloodle_menu').')';
  131.             $this->content->text .= '<center><span style="font-size:10pt;font-style:italic;color:#777777;">'.get_string('youravatar''block_sloodle_menu').':</span><br/>';
  132.             
  133.             // Make the avatar name a link if the user management page exists
  134.             $this->content->text .= "<a href=\"{$CFG->wwwroot}/mod/sloodle/view/view_user.php?id={$USER->id}&amp;course={$COURSE->id}\">$sl_avatar_name</a>";
  135.             $this->content->text .= '<br/></center>';
  136.             
  137.         else if (is_string($userresult)) {
  138.             // An error occurred
  139.             $this->content->text .= '<center><span style="font-size:10pt;font-style:italic;color:#777777;">'.get_string('youravatar''block_sloodle_menu').':</span><br/>ERROR ('.$userresult.')</center>';
  140.             
  141.         else {
  142.             // No avatar linked yet
  143.             $this->content->text .= '<center><span style="font-style:italic;">('.get_string('noavatar''block_sloodle_menu').')</span></center>';
  144.         }
  145.         
  146.         // Add links to common Sloodle stuff
  147.         $this->content->text .= '<div style="padding:1px; margin-top:4px; margin-bottom:4px; border-top:solid 1px #cccccc; border-bottom:solid 1px #cccccc;">';
  148.  
  149.         // Add the Sloodle profile link
  150.         $this->content->text .= "<img src=\"{$CFG->wwwroot}/blocks/sloodle_menu/img/user.gif\" width=\"16\" height=\"16\"/> ";
  151.         $this->content->text .= "<a href=\"{$CFG->wwwroot}/mod/sloodle/view/view_user.php?id={$USER->id}&amp;course={$COURSE->id}\">".get_string('mysloodleprofile''block_sloodle_menu')."</a><br/>";
  152.  
  153.         // Show a link to all Sloodle activities on this course
  154.         //TODO: possibly show number of visible Sloodle activities?
  155.         $this->content->text .= "<img src=\"{$CFG->wwwroot}/blocks/sloodle_menu/img/boxes.gif\" width=\"16\" height=\"16\"/> ";
  156.         $this->content->text .= "<a href=\"{$CFG->wwwroot}/mod/sloodle/index.php?id={$COURSE->id}\">".get_string('sloodleactivities''block_sloodle_menu')."</a><br/>";
  157.  
  158.         // Show a link to the LoginZone for this course
  159.         $this->content->text .= "<img src=\"{$CFG->wwwroot}/blocks/sloodle_menu/img/loginzone.gif\" width=\"16\" height=\"16\"/> ";
  160.         // Do we have LoginZone data for this course?
  161.         if ($sloodle_course->has_loginzone_data()) {
  162.             $this->content->text .= "<a href=\"{$CFG->wwwroot}/mod/sloodle/classroom/loginzone.php?id={$COURSE->id}\">".get_string('courseloginzone''block_sloodle_menu')."</a><br/>";
  163.         else {
  164.             $this->content->text .= "<a href=\"{$CFG->wwwroot}/mod/sloodle/classroom/loginzone.php?id={$COURSE->id}\" style=\"color:red; text-decoration:line-through;\" title=\"".get_string('courseloginzone:nodata','block_sloodle_menu')."\">".get_string('courseloginzone''block_sloodle_menu')."</a><br/>";
  165.         }
  166.         
  167.         $this->content->text .= '<hr>';
  168.         
  169.         // Add a user management link if the user can view hidden user details
  170.         if (has_capability('moodle/user:viewhiddendetails'$course_context)) {
  171.             $this->content->text .= "<img src=\"{$CFG->wwwroot}/blocks/sloodle_menu/img/user_mng.gif\" width=\"16\" height=\"16\"/> ";
  172.             $this->content->text .= "<a href=\"{$CFG->wwwroot}/mod/sloodle/view/view_users.php?course={$COURSE->id}\">".get_string('usermanagement''block_sloodle_menu')."</a><br/>";            
  173.         }
  174.         
  175.         // Add a link to Sloodle course settings, if the user can update the course
  176.         if (has_capability('moodle/course:update'$course_context)) {
  177.             $this->content->text .= "<img src=\"{$CFG->wwwroot}/blocks/sloodle_menu/img/page.gif\" width=\"16\" height=\"16\"/> ";
  178.             $this->content->text .= "<a href=\"{$CFG->wwwroot}/mod/sloodle/view/view_course.php?id={$COURSE->id}\">".get_string('editcourse''block_sloodle_menu')."</a><br>\n";
  179.         }
  180.         
  181.         // Add a module configuration link if the user has authority to administer the module
  182.         if (has_capability('moodle/site:config'$course_context)) {
  183.             
  184.             // The address of the configuration page depends on our version of Moodle
  185.             if ($CFG->version 2007101500{
  186.                 // < 1.9
  187.                 $address "/admin/module.php?module=sloodle";
  188.             else {
  189.                 // >= 1.9
  190.                 $address "/admin/settings.php?section=modsettingsloodle";
  191.             }
  192.         
  193.             $this->content->text .= "<img src=\"{$CFG->wwwroot}/blocks/sloodle_menu/img/configure.gif\" width=\"16\" height=\"16\"/> ";
  194.             $this->content->text .= "<a href=\"{$CFG->wwwroot}$address\">".get_string('sloodleconfig''block_sloodle_menu')."</a><br/>";
  195.         }
  196.         
  197.         $this->content->text .= '</div>';
  198.         
  199.         return $this->content;
  200.     }
  201. }
  202.  
  203. ?>

Documentation generated on Mon, 16 Jun 2008 15:56:09 +0100 by phpDocumentor 1.4.0