dirroot .'/mod/sloodle/sl_config.php');
if (isset($plugin_backup)) $plugin = $plugin_backup;
if (defined('SLOODLE_LIBROOT')) {
/** Inlcude the current general Sloodle functionality. */
require_once(SLOODLE_LIBROOT.'/general.php');
/** Include the Sloodle course functionality. */
require_once(SLOODLE_LIBROOT.'/course.php');
}
/** Include the old Sloodle configuration, in case the module is out-dated. */
if (!defined('SLOODLE_VERSION')) {
@include_once($CFG->dirroot .'/mod/sloodle/config.php');
if (defined('SLOODLE_DIRROOT')) {
/** Include the old general Sloodle functionality. */
require_once(SLOODLE_DIRROOT.'/lib/sl_generallib.php');
}
}
/** Define the Sloodle Menu Block version. */
define('SLOODLE_MENU_VERSION', 2.0);
/**
* Defines the block class.
* @package sloodle
*/
class block_sloodle_menu extends block_base
{
/**
* Perform block initialisation.
* @return void
*/
function init()
{
global $CFG;
if (empty($plugin)) $plugin = new stdClass();
include($CFG->dirroot.'/blocks/sloodle_menu/version.php');
$this->title = get_string('blockname', 'block_sloodle_menu');
$this->content_type = BLOCK_TYPE_TEXT;
$this->version = $plugin->version;
$this->release = $plugin->release;
}
/**
* Indicates whether or not this module has a global configuration page.
* @return bool True if there is a global configuration page, or false otherwise.
*/
function has_config()
{
return false;
}
/**
* Indicates whether or not to hide the header of this block.
* @return bool True to hide the header, or false to show it.
*/
function hide_header()
{
return false;
}
/**
* Defines *and* returns the content of this block.
* @return object
*/
function get_content()
{
global $CFG, $COURSE, $USER;
// Construct the content
$this->content = new stdClass;
$this->content->text = '';
$this->content->footer = '';
// If no course has been specified, then we are using the site course
if (!isset($COURSE)) {
$COURSE = get_site();
}
// If the user is not logged in or if they are using guest access, then we can't show anything
if (!isloggedin() || isguestuser()) {
return $this->content;
}
// Get the context instance for this course
//$course_context = get_context_instance(CONTEXT_COURSE, $COURSE->id);
$course_context = context_course::instance($COURSE->id, IGNORE_MISSING);
// This version of the menu isn't compatible with older version of the Sloodle module
if (defined('SLOODLE_VERSION') && SLOODLE_VERSION < 0.4) {
$this->content->text = get_string('oldmodule', 'block_sloodle_menu');
return $this->content;
}
// Has the Sloodle activity module been installed?
if (!(function_exists("sloodle_is_installed") && sloodle_is_installed())) {
$this->content->text = get_string('sloodlenotinstalled', 'block_sloodle_menu');
return $this->content;
}
// Get the Sloodle course data
$sloodle_course = new SloodleCourse();
if (!$sloodle_course->load((int)$COURSE->id)) {
$this->content->text = get_string('failedloadcourse', 'block_sloodle_menu');
return $this->content;
}
// Add the Sloodle and Sloodle Menu version info to the footer of the block
$this->content->footer = ''.get_string('sloodlemenuversion', 'block_sloodle_menu').': '.(string)SLOODLE_MENU_VERSION.'';
$this->content->footer .= '
'.get_string('sloodleversion', 'block_sloodle_menu').': '.(string)SLOODLE_VERSION.'';
// Attempt to find a Sloodle user for the Moodle user
$dbquery = "SELECT * FROM {$CFG->prefix}sloodle_users WHERE userid = ? AND NOT (avname='' AND uuid='') ";
$dbresult = sloodle_get_records_sql_params($dbquery, array($USER->id));
$sl_avatar_name = "";
if (!is_array($dbresult) || count($dbresult) == 0) $userresult = FALSE;
else if (count($dbresult) > 1) $userresult = "Multiple avatars associated with your Moodle account.";
else {
$userresult = TRUE;
reset($dbresult);
$cur = current($dbresult);
$sl_avatar_name = $cur->avname;
}
if ($userresult === TRUE) {
// Success
// Make sure there was a name
if (empty($sl_avatar_name)) $sl_avatar_name = '('.get_string('nameunknown', 'block_sloodle_menu').')';
$this->content->text .= '