<?php //$Id$
-// This file keeps track of upgrades to
-// the hotpot module
-//
-// Sometimes, changes between versions involve
-// alterations to database structures and other
-// major things that may break installations.
-//
-// The upgrade function in this file will attempt
-// to perform all the necessary actions to upgrade
-// your older installtion to the current version.
-//
-// If there's something it cannot do itself, it
-// will tell you what you need to do.
-//
-// The commands in here will all be database-neutral,
-// using the functions defined in lib/ddllib.php
+// This file keeps track of upgrades to the hotpot module
function xmldb_hotpot_upgrade($oldversion=0) {
$result = true;
-/// And upgrade begins here. For each one, you'll need one
-/// block of code similar to the next one. Please, delete
-/// this comment lines once this file start handling proper
-/// upgrade code.
+ // update hotpot grades from sites earlier than Moodle 1.9, 27th March 2008
+ if ($result && $oldversion < 2007101511) {
-/// if ($result && $oldversion < YYYYMMDD00) { //New version in version.php
-/// $result = result of "/lib/ddllib.php" function calls
-/// }
+ // ensure "hotpot_update_grades" function is available
+ require_once $CFG->dirroot.'/mod/hotpot/lib.php';
+
+ // disable display of debugging messages
+ $db_debug_save = $db->debug;
+ $db->debug = false;
+
+ notify('Processing hotpot grades, this may take a while if there are many hotpots...', 'notifysuccess');
+ hotpot_update_grades();
+
+ // restore $db->debug
+ $db->debug = $db_debug_save;
+ }
return $result;
}
return $found ? $chain : false;
}
function hotpot_is_visible(&$cm) {
+ global $CFG, $COURSE;
+
+ // check grouping
+ $modulecontext = get_context_instance(CONTEXT_MODULE, $cm->id);
+ if (empty($CFG->enablegroupings) || empty($cm->groupmembersonly) || has_capability('moodle/site:accessallgroups', $modulecontext)) {
+ // groupings not applicable
+ } else if (!isguestuser() && groups_has_membership($cm)) {
+ // user is in one of the groups in the allowed grouping
+ } else {
+ // user is not in the required grouping and does not have sufficiently privileges to view this hotpot activity
+ return false;
+ }
+
+ // check if user can view hidden activities
+ if (isset($COURSE->context)) {
+ $coursecontext = &$COURSE->context;
+ } else {
+ $coursecontext = get_context_instance(CONTEXT_COURSE, $cm->course);
+ }
+ if (has_capability('moodle/course:viewhiddenactivities', $coursecontext)) {
+ return true; // user can view hidden activities
+ }
+
if (!isset($cm->sectionvisible)) {
- if ($section = get_record('course_sections', 'id', $cm->section)) {
- $cm->sectionvisible = $section->visible;
- } else {
+ if (! $section = get_record('course_sections', 'id', $cm->section)) {
error('Course module record contains invalid section');
}
+ $cm->sectionvisible = $section->visible;
}
if (empty($cm->sectionvisible)) {
return false;
}
}
+
/**
* Update grades in central gradebook
+ * this function is called from db/upgrade.php
+ * it is initially called with no arguments, which forces it to get a list of all hotpots
+ * it then iterates through the hotpots, calling itself to create a grade record for each hotpot
*
* @param object $hotpot null means all hotpots
- * @param int $userid specific user only, 0 mean all
+ * @param int $userid specific user only, 0 means all users
*/
function hotpot_update_grades($hotpot=null, $userid=0, $nullifnone=true) {
global $CFG;
- if (! function_exists('grade_update')) { //workaround for buggy PHP versions
+ if (! function_exists('grade_update')) {
require_once($CFG->libdir.'/gradelib.php');
}
- if ($hotpot) {
+ if (is_null($hotpot)) {
+ // update (=create) grades for all hotpots
+ $sql = "
+ SELECT h.*, cm.idnumber as cmidnumber
+ FROM {$CFG->prefix}hotpot h, {$CFG->prefix}course_modules cm, {$CFG->prefix}modules m
+ WHERE m.name='hotpot' AND m.id=cm.module AND cm.instance=h.id"
+ ;
+ if ($rs = get_recordset_sql($sql)) {
+ while ($hotpot = rs_fetch_next_record($rs)) {
+ hotpot_update_grades($hotpot, 0, false);
+ }
+ rs_close($rs);
+ }
+ } else {
+ // update (=create) grade for a single hotpot
if ($grades = hotpot_get_user_grades($hotpot, $userid)) {
hotpot_grade_item_update($hotpot, $grades);
} else if ($userid && $nullifnone) {
+ // no grades for this user, but we must force the creation of a "null" grade record
$grade = new object();
$grade->userid = $userid;
$grade->rawgrade = null;
hotpot_grade_item_update($hotpot, $grade);
} else {
- hotpot_grade_item_update($hotpot);
- }
- } else {
- $sql = "SELECT h.*, cm.idnumber as cmidnumber
- FROM {$CFG->prefix}hotpot h, {$CFG->prefix}course_modules cm, {$CFG->prefix}modules m
- WHERE m.name='hotpot' AND m.id=cm.module AND cm.instance=s.id";
- if ($rs = get_recordset_sql($sql)) {
- while ($hotpot = rs_fetch_next_record($rs)) {
- hotpot_update_grades($hotpot, 0, false);
- }
- rs_close($rs);
+ // no grades and no userid
+ hotpot_grade_item_update($hotpot);
}
}
}
+
/**
* Update/create grade item for given hotpot
*
* @param mixed optional array/object of grade(s); 'reset' means reset grades in gradebook
* @return object grade_item
*/
-function hotpot_grade_item_update($hotpot, $grades=NULL) {
+function hotpot_grade_item_update($hotpot, $grades=null) {
global $CFG;
- if (!function_exists('grade_update')) { //workaround for buggy PHP versions
+ if (! function_exists('grade_update')) {
require_once($CFG->libdir.'/gradelib.php');
}
-
$params = array('itemname' => $hotpot->name);
if (array_key_exists('cmidnumber', $hotpot)) {
//cmidnumber may not be always present
$params['idnumber'] = $hotpot->cmidnumber;
}
-
if ($hotpot->grade > 0) {
$params['gradetype'] = GRADE_TYPE_VALUE;
$params['grademax'] = $hotpot->grade;
} else {
$params['gradetype'] = GRADE_TYPE_NONE;
}
-
return grade_update('mod/hotpot', $hotpot->course, 'mod', 'hotpot', $hotpot->id, 0, $grades, $params);
}
+
/**
* Delete grade item for given hotpot
*
*/
function hotpot_grade_item_delete($hotpot) {
global $CFG;
- require_once($CFG->libdir.'/gradelib.php');
-
- return grade_update('mod/hotpot', $hotpot->course, 'mod', 'hotpot', $hotpot->id, 0, NULL, array('deleted'=>1));
+ if (! function_exists('grade_update')) {
+ require_once($CFG->libdir.'/gradelib.php');
+ }
+ return grade_update('mod/hotpot', $hotpot->course, 'mod', 'hotpot', $hotpot->id, 0, null, array('deleted'=>1));
}
function hotpot_get_participants($hotpotid) {
}
if ($query) {
- $search = '#'.'(file|src|thesound)='."([^&]+)".'#ise';
+ $search = '#'.'(file|src|thesound|mp3)='."([^&]+)".'#ise';
$replace = "'\\1='.hotpot_convert_url('".$baseurl."','".$reference."','\\2')";
$query = preg_replace($search, $replace, $query);
}