/mod/hotpot/lib.php
PHP | 2724 lines | 2065 code | 344 blank | 315 comment | 360 complexity | 7153cb35f1f596cfbf3cf05a9839527b MD5 | raw file
Possible License(s): BSD-3-Clause, LGPL-2.0, LGPL-2.1
Large files files are truncated, but you can click here to view the full file
- <?PHP // $Id: lib.php,v 1.79.2.27 2012/05/19 11:04:52 moodlerobot Exp $
-
- //////////////////////////////////
- /// CONFIGURATION settings
-
- if (!isset($CFG->hotpot_showtimes)) {
- set_config("hotpot_showtimes", 0);
- }
- if (!isset($CFG->hotpot_excelencodings)) {
- set_config("hotpot_excelencodings", "");
- }
-
- //////////////////////////////////
- /// CONSTANTS and GLOBAL VARIABLES
-
- $CFG->hotpotroot = "$CFG->dirroot/mod/hotpot";
- $CFG->hotpottemplate = "$CFG->hotpotroot/template";
- if (!empty($_SERVER['HTTP_USER_AGENT'])) {
- $CFG->hotpotismobile = preg_match('/Alcatel|ATTWS|DoCoMo|Doris|Hutc3G|J-PHONE|Java|KDDI|KGT|LGE|MOT|Nokia|portalmmm|ReqwirelessWeb|SAGEM|SHARP|SIE-|SonyEricsson|Teleport|UP\.Browser|UPG1|Wapagsim/', $_SERVER['HTTP_USER_AGENT']);
- } else {
- $CFG->hotpotismobile = false;
- }
-
- define("HOTPOT_JS", "$CFG->wwwroot/mod/hotpot/hotpot-full.js");
-
- define("HOTPOT_NO", "0");
- define("HOTPOT_YES", "1");
-
- define ("HOTPOT_TEXTSOURCE_QUIZ", "0");
- define ("HOTPOT_TEXTSOURCE_FILENAME", "1");
- define ("HOTPOT_TEXTSOURCE_FILEPATH", "2");
- define ("HOTPOT_TEXTSOURCE_SPECIFIC", "3");
-
- define("HOTPOT_LOCATION_COURSEFILES", "0");
- define("HOTPOT_LOCATION_SITEFILES", "1");
-
- $HOTPOT_LOCATION = array (
- HOTPOT_LOCATION_COURSEFILES => get_string("coursefiles"),
- HOTPOT_LOCATION_SITEFILES => get_string("sitefiles"),
- );
-
- define("HOTPOT_OUTPUTFORMAT_BEST", "1");
- define("HOTPOT_OUTPUTFORMAT_V3", "10");
- define("HOTPOT_OUTPUTFORMAT_V4", "11");
- define("HOTPOT_OUTPUTFORMAT_V5", "12");
- define("HOTPOT_OUTPUTFORMAT_V5_PLUS", "13");
- define("HOTPOT_OUTPUTFORMAT_V6", "14");
- define("HOTPOT_OUTPUTFORMAT_V6_PLUS", "15");
- define("HOTPOT_OUTPUTFORMAT_FLASH", "20");
- define("HOTPOT_OUTPUTFORMAT_MOBILE", "30");
-
- $HOTPOT_OUTPUTFORMAT = array (
- HOTPOT_OUTPUTFORMAT_BEST => get_string("outputformat_best", "hotpot"),
- HOTPOT_OUTPUTFORMAT_V6_PLUS => get_string("outputformat_v6_plus", "hotpot"),
- HOTPOT_OUTPUTFORMAT_V6 => get_string("outputformat_v6", "hotpot"),
- HOTPOT_OUTPUTFORMAT_V5_PLUS => get_string("outputformat_v5_plus", "hotpot"),
- HOTPOT_OUTPUTFORMAT_V5 => get_string("outputformat_v5", "hotpot"),
- HOTPOT_OUTPUTFORMAT_V4 => get_string("outputformat_v4", "hotpot"),
- HOTPOT_OUTPUTFORMAT_V3 => get_string("outputformat_v3", "hotpot"),
- HOTPOT_OUTPUTFORMAT_FLASH => get_string("outputformat_flash", "hotpot"),
- HOTPOT_OUTPUTFORMAT_MOBILE => get_string("outputformat_mobile", "hotpot"),
- );
- $HOTPOT_OUTPUTFORMAT_DIR = array (
- HOTPOT_OUTPUTFORMAT_V6_PLUS => 'v6',
- HOTPOT_OUTPUTFORMAT_V6 => 'v6',
- HOTPOT_OUTPUTFORMAT_V5_PLUS => 'v5',
- HOTPOT_OUTPUTFORMAT_V5 => 'v5',
- HOTPOT_OUTPUTFORMAT_V4 => 'v4',
- HOTPOT_OUTPUTFORMAT_V3 => 'v3',
- HOTPOT_OUTPUTFORMAT_FLASH => 'flash',
- HOTPOT_OUTPUTFORMAT_MOBILE => 'mobile',
- );
- foreach ($HOTPOT_OUTPUTFORMAT_DIR as $format=>$dir) {
- if (is_file("$CFG->hotpottemplate/$dir.php") && is_dir("$CFG->hotpottemplate/$dir")) {
- // do nothing ($format is available)
- } else {
- // $format is not available, so remove it
- unset($HOTPOT_OUTPUTFORMAT[$format]);
- unset($HOTPOT_OUTPUTFORMAT_DIR[$format]);
- }
- }
- define("HOTPOT_NAVIGATION_BAR", "1");
- define("HOTPOT_NAVIGATION_FRAME", "2");
- define("HOTPOT_NAVIGATION_IFRAME", "3");
- define("HOTPOT_NAVIGATION_BUTTONS", "4");
- define("HOTPOT_NAVIGATION_GIVEUP", "5");
- define("HOTPOT_NAVIGATION_NONE", "6");
-
- $HOTPOT_NAVIGATION = array (
- HOTPOT_NAVIGATION_BAR => get_string("navigation_bar", "hotpot"),
- HOTPOT_NAVIGATION_FRAME => get_string("navigation_frame", "hotpot"),
- HOTPOT_NAVIGATION_IFRAME => get_string("navigation_iframe", "hotpot"),
- HOTPOT_NAVIGATION_BUTTONS => get_string("navigation_buttons", "hotpot"),
- HOTPOT_NAVIGATION_GIVEUP => get_string("navigation_give_up", "hotpot"),
- HOTPOT_NAVIGATION_NONE => get_string("navigation_none", "hotpot"),
- );
-
- define("HOTPOT_JCB", "1");
- define("HOTPOT_JCLOZE", "2");
- define("HOTPOT_JCROSS", "3");
- define("HOTPOT_JMATCH", "4");
- define("HOTPOT_JMIX", "5");
- define("HOTPOT_JQUIZ", "6");
- define("HOTPOT_TEXTOYS_RHUBARB", "7");
- define("HOTPOT_TEXTOYS_SEQUITUR", "8");
-
- $HOTPOT_QUIZTYPE = array(
- HOTPOT_JCB => 'JCB',
- HOTPOT_JCLOZE => 'JCloze',
- HOTPOT_JCROSS => 'JCross',
- HOTPOT_JMATCH => 'JMatch',
- HOTPOT_JMIX => 'JMix',
- HOTPOT_JQUIZ => 'JQuiz',
- HOTPOT_TEXTOYS_RHUBARB => 'Rhubarb',
- HOTPOT_TEXTOYS_SEQUITUR => 'Sequitur'
- );
-
- define("HOTPOT_JQUIZ_MULTICHOICE", "1");
- define("HOTPOT_JQUIZ_SHORTANSWER", "2");
- define("HOTPOT_JQUIZ_HYBRID", "3");
- define("HOTPOT_JQUIZ_MULTISELECT", "4");
-
- define("HOTPOT_GRADEMETHOD_HIGHEST", "1");
- define("HOTPOT_GRADEMETHOD_AVERAGE", "2");
- define("HOTPOT_GRADEMETHOD_FIRST", "3");
- define("HOTPOT_GRADEMETHOD_LAST", "4");
-
- $HOTPOT_GRADEMETHOD = array (
- HOTPOT_GRADEMETHOD_HIGHEST => get_string("gradehighest", "quiz"),
- HOTPOT_GRADEMETHOD_AVERAGE => get_string("gradeaverage", "quiz"),
- HOTPOT_GRADEMETHOD_FIRST => get_string("attemptfirst", "quiz"),
- HOTPOT_GRADEMETHOD_LAST => get_string("attemptlast", "quiz"),
- );
-
- define("HOTPOT_STATUS_INPROGRESS", "1");
- define("HOTPOT_STATUS_TIMEDOUT", "2");
- define("HOTPOT_STATUS_ABANDONED", "3");
- define("HOTPOT_STATUS_COMPLETED", "4");
-
- $HOTPOT_STATUS = array (
- HOTPOT_STATUS_INPROGRESS => get_string("inprogress", "hotpot"),
- HOTPOT_STATUS_TIMEDOUT => get_string("timedout", "hotpot"),
- HOTPOT_STATUS_ABANDONED => get_string("abandoned", "hotpot"),
- HOTPOT_STATUS_COMPLETED => get_string("completed", "hotpot"),
- );
-
- define("HOTPOT_FEEDBACK_NONE", "0");
- define("HOTPOT_FEEDBACK_WEBPAGE", "1");
- define("HOTPOT_FEEDBACK_FORMMAIL", "2");
- define("HOTPOT_FEEDBACK_MOODLEFORUM", "3");
- define("HOTPOT_FEEDBACK_MOODLEMESSAGING", "4");
-
- $HOTPOT_FEEDBACK = array (
- HOTPOT_FEEDBACK_NONE => get_string("feedbacknone", "hotpot"),
- HOTPOT_FEEDBACK_WEBPAGE => get_string("feedbackwebpage", "hotpot"),
- HOTPOT_FEEDBACK_FORMMAIL => get_string("feedbackformmail", "hotpot"),
- HOTPOT_FEEDBACK_MOODLEFORUM => get_string("feedbackmoodleforum", "hotpot"),
- HOTPOT_FEEDBACK_MOODLEMESSAGING => get_string("feedbackmoodlemessaging", "hotpot"),
- );
- if (empty($CFG->messaging)) { // Moodle 1.4 (and less)
- unset($HOTPOT_FEEDBACK[HOTPOT_FEEDBACK_MOODLEMESSAGING]);
- }
-
- define("HOTPOT_DISPLAYNEXT_QUIZ", "0");
- define("HOTPOT_DISPLAYNEXT_COURSE", "1");
- define("HOTPOT_DISPLAYNEXT_INDEX", "2");
-
- /**
- * If start and end date for the quiz are more than this many seconds apart
- * they will be represented by two separate events in the calendar
- */
- define("HOTPOT_MAX_EVENT_LENGTH", "432000"); // 5 days maximum
-
- //////////////////////////////////
- /// CORE FUNCTIONS
-
-
- // possible return values:
- // false:
- // display moderr.html (if exists) OR "Could not update" and return to couse view
- // string:
- // display as error message and return to course view
- // true (or non-zero number):
- // continue to $hotpot->redirect (if set) OR hotpot/view.php (to displsay quiz)
-
- // $hotpot is an object containing the values of the form in mod.html
- // i.e. all the fields in the 'hotpot' table, plus the following:
- // $hotpot->course : an id in the 'course' table
- // $hotpot->coursemodule : an id in the 'course_modules' table
- // $hotpot->section : an id in the 'course_sections' table
- // $hotpot->module : an id in the 'modules' table
- // $hotpot->modulename : always 'hotpot'
- // $hotpot->instance : an id in the 'hotpot' table
- // $hotpot->mode : 'add' or 'update'
- // $hotpot->sesskey : unique string required for Moodle's session management
-
- function hotpot_add_instance(&$hotpot) {
- if (hotpot_set_form_values($hotpot)) {
- if ($result = insert_record('hotpot', $hotpot)) {
- $hotpot->id = $result;
- hotpot_update_events($hotpot);
- hotpot_grade_item_update(stripslashes_recursive($hotpot));
- }
- } else {
- $result= false;
- }
- return $result;
- }
-
- function hotpot_update_instance(&$hotpot) {
- if (hotpot_set_form_values($hotpot)) {
- $hotpot->id = $hotpot->instance;
- if ($result = update_record('hotpot', $hotpot)) {
- hotpot_update_events($hotpot);
- //hotpot_grade_item_update(stripslashes_recursive($hotpot));
- hotpot_update_grades(stripslashes_recursive($hotpot));
- }
- } else {
- $result= false;
- }
- return $result;
- }
- function hotpot_update_events($hotpot) {
-
- // remove any previous calendar events for this hotpot
- delete_records('event', 'modulename', 'hotpot', 'instance', $hotpot->id);
-
- $event = new stdClass();
- $event->description = addslashes($hotpot->summary);
- $event->courseid = $hotpot->course;
- $event->groupid = 0;
- $event->userid = 0;
- $event->modulename = 'hotpot';
- $event->instance = $hotpot->id;
- $event->timestart = $hotpot->timeopen;
- if ($cm = get_coursemodule_from_id('hotpot', $hotpot->id)) {
- $event->visible = hotpot_is_visible($cm);
- } else {
- $event->visible = 1;
- }
-
- if ($hotpot->timeclose && $hotpot->timeopen) {
- // we have both a start and an end date
- $event->eventtype = 'open';
- $event->timeduration = ($hotpot->timeclose - $hotpot->timeopen);
-
- if ($event->timeduration > HOTPOT_MAX_EVENT_LENGTH) { /// Long durations create two events
-
- $event->name = addslashes($hotpot->name).' ('.get_string('hotpotopens', 'hotpot').')';
- $event->timeduration = 0;
- add_event($event);
-
- $event->timestart = $hotpot->timeclose;
- $event->eventtype = 'close';
- $event->name = addslashes($hotpot->name).' ('.get_string('hotpotcloses', 'hotpot').')';
- unset($event->id);
- add_event($event);
- } else { // single event with duration
- $event->name = $hotpot->name;
- add_event($event);
- }
- } elseif ($hotpot->timeopen) { // only an open date
- $event->name = addslashes($hotpot->name).' ('.get_string('hotpotopens', 'hotpot').')';
- $event->eventtype = 'open';
- $event->timeduration = 0;
- add_event($event);
- } elseif ($hotpot->timeclose) { // only a closing date
- $event->name = addslashes($hotpot->name).' ('.get_string('hotpotcloses', 'hotpot').')';
- $event->timestart = $hotpot->timeclose;
- $event->eventtype = 'close';
- $event->timeduration = 0;
- add_event($event);
- }
- }
-
- function hotpot_set_form_values(&$hotpot) {
- $ok = true;
- $hotpot->errors = array(); // these will be reported by moderr.html
-
- if (empty($hotpot->reference)) {
- $ok = false;
- $hotpot->errors['reference']= get_string('error_nofilename', 'hotpot');
- }
-
- if (empty($hotpot->studentfeedbackurl) || $hotpot->studentfeedbackurl=='http://') {
- $hotpot->studentfeedbackurl = '';
- switch ($hotpot->studentfeedback) {
- case HOTPOT_FEEDBACK_WEBPAGE:
- $ok = false;
- $hotpot->errors['studentfeedbackurl']= get_string('error_nofeedbackurlwebpage', 'hotpot');
- break;
- case HOTPOT_FEEDBACK_FORMMAIL:
- $ok = false;
- $hotpot->errors['studentfeedbackurl']= get_string('error_nofeedbackurlformmail', 'hotpot');
- break;
- }
- }
-
- $time = time();
- $hotpot->timecreated = $time;
- $hotpot->timemodified = $time;
-
- if (empty($hotpot->mode)) {
- // moodle 1.9 (from mod_form.lib)
- if ($hotpot->add) {
- $hotpot->mode = 'add';
- } else if ($hotpot->update) {
- $hotpot->mode = 'update';
- } else {
- $hotpot->mode = '';
- }
- }
- if ($hotpot->quizchain==HOTPOT_YES) {
- switch ($hotpot->mode) {
- case 'add':
- $ok = hotpot_add_chain($hotpot);
- break;
- case 'update':
- $ok = hotpot_update_chain($hotpot);
- break;
- }
- } else { // $hotpot->quizchain==HOTPOT_NO
- hotpot_set_name_summary_reference($hotpot);
- }
-
- if (isset($hotpot->displaynext)) {
- switch ($hotpot->displaynext) {
- // N.B. redirection only works for Moodle 1.5+
- case HOTPOT_DISPLAYNEXT_COURSE:
- $hotpot->redirect = true;
- $hotpot->redirecturl = "view.php?id=$hotpot->course";
- break;
- case HOTPOT_DISPLAYNEXT_INDEX:
- $hotpot->redirect = true;
- $hotpot->redirecturl = "../mod/hotpot/index.php?id=$hotpot->course";
- break;
- default:
- // use Moodle default action (i.e. go on to display the hotpot quiz)
- }
- } else {
- $hotpot->displaynext = HOTPOT_DISPLAYNEXT_QUIZ;
- }
-
- // if ($ok && $hotpot->setdefaults) {
- if ($ok) {
- set_user_preference('hotpot_timeopen', $hotpot->timeopen);
- set_user_preference('hotpot_timeclose', $hotpot->timeclose);
- set_user_preference('hotpot_navigation', $hotpot->navigation);
- set_user_preference('hotpot_outputformat', $hotpot->outputformat);
- set_user_preference('hotpot_studentfeedback', $hotpot->studentfeedback);
- set_user_preference('hotpot_studentfeedbackurl', $hotpot->studentfeedbackurl);
- set_user_preference('hotpot_forceplugins', $hotpot->forceplugins);
- set_user_preference('hotpot_shownextquiz', $hotpot->shownextquiz);
- set_user_preference('hotpot_review', $hotpot->review);
- set_user_preference('hotpot_grade', $hotpot->grade);
- set_user_preference('hotpot_grademethod', $hotpot->grademethod);
- set_user_preference('hotpot_attempts', $hotpot->attempts);
- set_user_preference('hotpot_subnet', $hotpot->subnet);
- set_user_preference('hotpot_displaynext', $hotpot->displaynext);
- if ($hotpot->mode=='add') {
- set_user_preference('hotpot_quizchain', $hotpot->quizchain);
- set_user_preference('hotpot_namesource', $hotpot->namesource);
- set_user_preference('hotpot_summarysource', $hotpot->summarysource);
- }
- }
- return $ok;
- }
- function hotpot_get_chain(&$cm) {
- // get details of course_modules in this section
- $course_module_ids = get_field('course_sections', 'sequence', 'id', $cm->section);
- if (empty($course_module_ids)) {
- $hotpot_modules = array();
- } else {
- $hotpot_modules = get_records_select('course_modules', "id IN ($course_module_ids) AND module=$cm->module");
- if (empty($hotpot_modules)) {
- $hotpot_modules = array();
- }
- }
-
- // get ids of hotpot modules in this section
- $ids = array();
- foreach ($hotpot_modules as $hotpot_module) {
- $ids[] = $hotpot_module->instance;
- }
-
- // get details of hotpots in this section
- if (empty($ids)) {
- $hotpots = array();
- } else {
- $hotpots = get_records_list('hotpot', 'id', implode(',', $ids));
- }
-
- $found = false;
- $chain = array();
-
- // loop through course_modules in this section
- $ids = explode(',', $course_module_ids);
- foreach ($ids as $id) {
-
- // check this course_module is a hotpot activity
- if (isset($hotpot_modules[$id])) {
-
- // store details of this course module and hotpot activity
- $hotpot_id = $hotpot_modules[$id]->instance;
- $chain[$id] = &$hotpot_modules[$id];
- $chain[$id]->hotpot = &$hotpots[$hotpot_id];
-
- // set $found, if this is the course module we're looking for
- if (isset($cm->coursemodule)) {
- if ($id==$cm->coursemodule) {
- $found = true;
- }
- } else {
- if ($id==$cm->id) {
- $found = true;
- }
- }
-
- // is this the end of a chain
- if (empty($hotpots[$hotpot_id]->shownextquiz)) {
- if ($found) {
- break; // out of loop
- } else {
- // restart chain (target cm has not been found yet)
- $chain = array();
- }
- }
- }
- } // end foreach $ids
-
- 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)) {
- error('Course module record contains invalid section');
- }
- $cm->sectionvisible = $section->visible;
- }
- if (empty($cm->sectionvisible)) {
- $visible = HOTPOT_NO;
- } else {
- $visible = HOTPOT_YES;
- if (empty($cm->visible)) {
- if ($chain = hotpot_get_chain($cm)) {
- $startofchain = array_shift($chain);
- $visible = $startofchain->visible;
- }
- }
- }
- return $visible;
- }
- function hotpot_add_chain(&$hotpot) {
- /// add a chain of hotpot actiivities
-
- global $CFG, $course;
-
- $ok = true;
- $hotpot->names = array();
- $hotpot->summaries = array();
- $hotpot->references = array();
-
- $xml_quiz = new hotpot_xml_quiz($hotpot, false, false, false, false, false);
-
- if (isset($xml_quiz->error)) {
- $hotpot->errors['reference'] = $xml_quiz->error;
- $ok = false;
-
- } else if (is_dir($xml_quiz->filepath)) {
-
- // get list of hotpot files in this folder
- if ($dh = @opendir($xml_quiz->filepath)) {
- while (false !== ($file = @readdir($dh))) {
- if (preg_match('/\.(jbc|jcl|jcw|jmt|jmx|jqz|htm|html)$/', $file)) {
- $hotpot->references[] = "$xml_quiz->reference/$file";
- }
- }
- closedir($dh);
-
- // get titles
- foreach ($hotpot->references as $i=>$reference) {
- $filepath = $xml_quiz->fileroot.'/'.$reference;
- hotpot_get_titles_and_next_ex($hotpot, $filepath);
- $hotpot->names[$i] = $hotpot->exercisetitle;
- $hotpot->summaries[$i] = $hotpot->exercisesubtitle;
- }
-
- } else {
- $ok = false;
- $hotpot->errors['reference'] = get_string('error_couldnotopenfolder', 'hotpot', $hotpot->reference);
- }
-
- } else if (is_file($xml_quiz->filepath)) {
-
- $filerootlength = strlen($xml_quiz->fileroot) + 1;
-
- while ($xml_quiz->filepath) {
- hotpot_get_titles_and_next_ex($hotpot, $xml_quiz->filepath, true);
- $hotpot->names[] = $hotpot->exercisetitle;
- $hotpot->summaries[] = $hotpot->exercisesubtitle;
- $hotpot->references[] = substr($xml_quiz->filepath, $filerootlength);
-
- if ($hotpot->nextexercise) {
- $filepath = $xml_quiz->fileroot.'/'.$xml_quiz->filesubdir.$hotpot->nextexercise;
-
- // check file is not already in chain
- $reference = substr($filepath, $filerootlength);
- if (in_array($reference, $hotpot->references)) {
- $filepath = '';
- }
- } else {
- $filepath = '';
- }
- if ($filepath && file_exists($filepath) && is_file($filepath) && is_readable($filepath)) {
- $xml_quiz->filepath = $filepath;
- } else {
- $xml_quiz->filepath = false; // finish while loop
- }
- } // end while
-
- } else {
- $ok = false;
- $hotpot->errors['reference'] = get_string('error_notfileorfolder', 'hotpot', $hotpot->reference);
- }
-
- if (empty($hotpot->references) && empty($hotpot->errors['reference'])) {
- $ok = false;
- $hotpot->errors['reference'] = get_string('error_noquizzesfound', 'hotpot', $hotpot->reference);
- }
-
- if ($ok) {
- $hotpot->visible = HOTPOT_YES;
-
- if (trim($hotpot->name)=='') {
- $hotpot->name = get_string("modulename", $hotpot->modulename);
- }
- $hotpot->specificname = $hotpot->name;
- $hotpot->specificsummary = $hotpot->summary;
-
- // add all except last activity in chain
-
- $i_max = count($hotpot->references)-1;
- for ($i=0; $i<$i_max; $i++) {
-
- hotpot_set_name_summary_reference($hotpot, $i);
- $hotpot->reference = addslashes($hotpot->reference);
-
- if (!$hotpot->instance = insert_record("hotpot", $hotpot)) {
- error("Could not add a new instance of $hotpot->modulename", "view.php?id=$hotpot->course");
- }
-
- // store (hotpot table) id of start of chain
- if ($i==0) {
- $hotpot->startofchain = $hotpot->instance;
- }
-
- if (isset($course->groupmode)) {
- $hotpot->groupmode = $course->groupmode;
- }
-
- if (! $hotpot->coursemodule = add_course_module($hotpot)) {
- error("Could not add a new course module");
- }
- if (! $sectionid = add_mod_to_section($hotpot) ) {
- error("Could not add the new course module to that section");
- }
-
- if (! set_field("course_modules", "section", $sectionid, "id", $hotpot->coursemodule)) {
- error("Could not update the course module with the correct section");
- }
-
- add_to_log($hotpot->course, "course", "add mod",
- "../mod/$hotpot->modulename/view.php?id=$hotpot->coursemodule",
- "$hotpot->modulename $hotpot->instance"
- );
- add_to_log($hotpot->course, $hotpot->modulename, "add",
- "view.php?id=$hotpot->coursemodule",
- "$hotpot->instance", $hotpot->coursemodule
- );
-
- // hide tail of chain
- if ($hotpot->shownextquiz==HOTPOT_YES) {
- $hotpot->visible = HOTPOT_NO;
- }
- } // end for ($hotpot->references)
-
- // settings for final activity in chain
- hotpot_set_name_summary_reference($hotpot, $i);
- $hotpot->reference = addslashes($hotpot->references[$i]);
- $hotpot->shownextquiz = HOTPOT_NO;
-
- if (isset($hotpot->startofchain)) {
- // redirection only works for Moodle 1.5+
- $hotpot->redirect = true;
- $hotpot->redirecturl = "$CFG->wwwroot/mod/hotpot/view.php?hp=$hotpot->startofchain";
- }
- } // end if $ok
-
- return $ok;
- }
- function hotpot_set_name_summary_reference(&$hotpot, $chain_index=NULL) {
-
- $xml_quiz = NULL;
-
- $textfields = array('name', 'summary');
- foreach ($textfields as $textfield) {
-
- $textsource = $textfield.'source';
-
- // are we adding a chain?
- if (isset($chain_index)) {
-
- switch ($hotpot->$textsource) {
- case HOTPOT_TEXTSOURCE_QUIZ:
- if ($textfield=='name') {
- $hotpot->exercisetitle = $hotpot->names[$chain_index];
- } else if ($textfield=='summary') {
- $hotpot->exercisesubtitle = $hotpot->summaries[$chain_index];
- }
- break;
- case HOTPOT_TEXTSOURCE_SPECIFIC:
- $specifictext = 'specific'.$textfield;
- if (empty($hotpot->$specifictext) && trim($hotpot->$specifictext)=='') {
- $hotpot->$textfield = '';
- } else {
- $hotpot->$textfield = $hotpot->$specifictext.' ('.($chain_index+1).')';
- }
- break;
- }
- $hotpot->reference = $hotpot->references[$chain_index];
- }
-
- if ($hotpot->$textsource==HOTPOT_TEXTSOURCE_QUIZ) {
- if (empty($xml_quiz) && !isset($chain_index)) {
- $xml_quiz = new hotpot_xml_quiz($hotpot, false, false, false, false, false);
- hotpot_get_titles_and_next_ex($hotpot, $xml_quiz->filepath);
- }
- if ($textfield=='name') {
- $hotpot->$textfield = addslashes($hotpot->exercisetitle);
- } else if ($textfield=='summary') {
- $hotpot->$textfield = addslashes($hotpot->exercisesubtitle);
- }
- }
- switch ($hotpot->$textsource) {
- case HOTPOT_TEXTSOURCE_FILENAME:
- $hotpot->$textfield = basename($hotpot->reference);
- break;
- case HOTPOT_TEXTSOURCE_FILEPATH:
- $hotpot->$textfield = '';
- // continue to next lines
- default:
- if (empty($hotpot->$textfield)) {
- $hotpot->$textfield = str_replace('/', ' ', $hotpot->reference);
- }
- } // end switch
- } // end foreach
- }
- function hotpot_get_titles_and_next_ex(&$hotpot, $filepath, $get_next=false) {
-
- $hotpot->exercisetitle = '';
- $hotpot->exercisesubtitle = '';
- $hotpot->nextexercise = '';
-
- // read the quiz file source
- if ($source = file_get_contents($filepath)) {
-
- $next = '';
- $title = '';
- $subtitle = '';
-
- if (preg_match('|\.html?$|', $filepath)) {
- // html file
- if (preg_match('|<h2[^>]*class="ExerciseTitle"[^>]*>(.*?)</h2>|is', $source, $matches)) {
- $title = trim(strip_tags($matches[1]));
- }
- if (empty($title)) {
- if (preg_match('|<title[^>]*>(.*?)</title>|is', $source, $matches)) {
- $title = trim(strip_tags($matches[1]));
- }
- }
- if (preg_match('|<h3[^>]*class="ExerciseSubtitle"[^>]*>(.*?)</h3>|is', $source, $matches)) {
- $subtitle = trim(strip_tags($matches[1]));
- }
- if ($get_next) {
- if (preg_match('|<div[^>]*class="NavButtonBar"[^>]*>(.*?)</div>|is', $source, $matches)) {
- $navbuttonbar = $matches[1];
- if (preg_match_all('|<button[^>]*onclick="'."location='([^']*)'".'[^"]*"[^>]*>|is', $navbuttonbar, $matches)) {
- $lastbutton = count($matches[0])-1;
- $next = $matches[1][$lastbutton];
- }
- }
- }
-
- } else {
- // xml file (...maybe)
- $xml_tree = new hotpot_xml_tree($source);
- $xml_tree->filetype = '';
-
- $keys = array_keys($xml_tree->xml);
- foreach ($keys as $key) {
- if (preg_match('/^(hotpot|textoys)-(\w+)-file$/i', $key, $matches)) {
- $xml_tree->filetype = 'xml';
- $xml_tree->xml_root = "['$key']['#']";
- $xml_tree->quiztype = strtolower($matches[2]);
- break;
- }
- }
- if ($xml_tree->filetype=='xml') {
-
- $title = strip_tags($xml_tree->xml_value('data,title'));
- $subtitle = $xml_tree->xml_value('hotpot-config-file,'.$xml_tree->quiztype.',exercise-subtitle');
-
- if ($get_next) {
- $include = $xml_tree->xml_value('hotpot-config-file,global,include-next-ex');
- if (!empty($include)) {
- $next = $xml_tree->xml_value("hotpot-config-file,$xml_tree->quiztype,next-ex-url");
- if (is_array($next)) {
- $next = $next[0]; // in case "next-ex-url" was repeated in the xml file
- }
- }
- }
- }
- }
-
- $hotpot->nextexercise = $next;
- $hotpot->exercisetitle = (empty($title) || is_array($title)) ? basename($filepath) : $title;
- $hotpot->exercisesubtitle = (empty($subtitle) || is_array($subtitle)) ? $hotpot->exercisetitle : $subtitle;
- }
- }
- function hotpot_get_all_instances_in_course($modulename, $course) {
- /// called from index.php
-
- global $CFG;
- $instances = array();
-
- if (isset($CFG->release) && substr($CFG->release, 0, 3)>=1.2) {
- $groupmode = 'cm.groupmode,';
- } else {
- $groupmode = '';
- }
-
- $query = "
- SELECT
- cm.id AS coursemodule,
- cm.course AS course,
- cm.module AS module,
- cm.instance AS instance,
- -- cm.section AS section,
- cm.visible AS visible,
- $groupmode
- -- cs.section AS sectionnumber,
- cs.section AS section,
- cs.sequence AS sequence,
- cs.visible AS sectionvisible,
- thismodule.*
- FROM
- {$CFG->prefix}course_modules cm,
- {$CFG->prefix}course_sections cs,
- {$CFG->prefix}modules m,
- {$CFG->prefix}$modulename thismodule
- WHERE
- m.name = '$modulename' AND
- m.id = cm.module AND
- cm.course = '$course->id' AND
- cm.section = cs.id AND
- cm.instance = thismodule.id
- ";
- if ($rawmods = get_records_sql($query)) {
-
- // cache $isteacher setting
-
- $isteacher = has_capability('mod/hotpot:viewreport', get_context_instance(CONTEXT_COURSE, $course->id));
-
- $explodesection = array();
- $order = array();
-
- foreach ($rawmods as $rawmod) {
-
- if (empty($explodesection[$rawmod->section])) {
- $explodesection[$rawmod->section] = true;
-
- $coursemodules = explode(',', $rawmod->sequence);
- foreach ($coursemodules as $i=>$coursemodule) {
- $order[$coursemodule] = sprintf('%d.%04d', $rawmod->section, $i);
- }
- }
-
- if ($isteacher) {
- $visible = true;
- } else if ($modulename=='hotpot') {
- $visible = hotpot_is_visible($rawmod);
- } else {
- $visible = $rawmod->visible;
- }
-
- if ($visible) {
- $instances[$order[$rawmod->coursemodule]] = $rawmod;
- }
-
- } // end foreach $modinfo
-
- ksort($instances);
- $instances = array_values($instances);
- }
-
- return $instances;
- }
-
- function hotpot_update_chain(&$hotpot) {
- /// update a chain of hotpot actiivities
-
- $ok = true;
- if ($hotpot_modules = hotpot_get_chain($hotpot)) {
-
- // skip updating of these fields
- $skipfields = array('id', 'course', 'name', 'reference', 'summary', 'shownextquiz');
- $fields = array();
-
- foreach ($hotpot_modules as $hotpot_module) {
-
- if ($hotpot->instance==$hotpot_module->id) {
- // don't need to update this hotpot
-
- } else {
- // shortcut to hotpot record
- $thishotpot = &$hotpot_module->hotpot;
-
- // get a list of fields to update (first time only)
- if (empty($fields)) {
- $fields = array_keys(get_object_vars($thishotpot));
- }
-
- // assume update is NOT required
- $require_update = false;
-
- // update field values (except $skipfields)
- foreach($fields as $field) {
- if (in_array($field, $skipfields) || $thishotpot->$field==$hotpot->$field) {
- // update not required for this field
- } else {
- $require_update = true;
- $thishotpot->$field = $hotpot->$field;
- }
- }
-
- // update $thishotpot, if required
- if ($require_update && !update_record("hotpot", $thishotpot)) {
- error("Could not update the $hotpot->modulename", "view.php?id=$hotpot->course");
- }
- }
- } // end foreach $ids
- }
- return $ok;
- }
- function hotpot_delete_instance($id) {
- /// Given an ID of an instance of this module,
- /// this function will permanently delete the instance
- /// and any data that depends on it.
-
- if (! $hotpot = get_record("hotpot", "id", $id)) {
- return false;
- }
-
- if (! delete_records("hotpot", "id", "$id")) {
- return false;
- }
-
- delete_records("hotpot_questions", "hotpot", "$id");
- if ($attempts = get_records_select("hotpot_attempts", "hotpot='$id'")) {
- $ids = implode(',', array_keys($attempts));
- delete_records_select("hotpot_attempts", "id IN ($ids)");
- delete_records_select("hotpot_details", "attempt IN ($ids)");
- delete_records_select("hotpot_responses", "attempt IN ($ids)");
- }
-
- // remove calendar events for this hotpot
- delete_records('event', 'modulename', 'hotpot', 'instance', $id);
-
- // remove grade item for this hotpot
- hotpot_grade_item_delete($hotpot);
-
- return true;
- }
- function hotpot_delete_and_notify($table, $select, $strtable) {
- $count = max(0, count_records_select($table, $select));
- if ($count) {
- delete_records_select($table, $select);
- $count -= max(0, count_records_select($table, $select));
- if ($count) {
- notify(get_string('deleted')." $count x $strtable");
- }
- }
- }
-
- function hotpot_user_complete($course, $user, $mod, $hotpot) {
- /// Print a detailed representation of what a user has done with
- /// a given particular instance of this module, for user activity reports.
-
- $report = hotpot_user_outline($course, $user, $mod, $hotpot);
- if (empty($report)) {
- print get_string("noactivity", "hotpot");
- } else {
- $date = userdate($report->time, get_string('strftimerecentfull'));
- print $report->info.' '.get_string('mostrecently').': '.$date;
- }
- return true;
- }
-
- function hotpot_user_outline($course, $user, $mod, $hotpot) {
- /// Return a small object with summary information about what a
- /// user has done with a given particular instance of this module
- /// Used for user activity reports.
- /// $report->time = the time they did it
- /// $report->info = a short text description
-
- $report = NULL;
- if ($records = get_records_select("hotpot_attempts", "hotpot='$hotpot->id' AND userid='$user->id'", "timestart ASC", "*")) {
- $report = new stdClass();
- $scores = array();
- foreach ($records as $record){
- if (empty($report->time)) {
- $report->time = $record->timestart;
- }
- $scores[] = hotpot_format_score($record);
- }
- if (empty($scores)) {
- $report->time = 0;
- $report->info = get_string('noactivity', 'hotpot');
- } else {
- $report->info = get_string('score', 'quiz').': '.implode(', ', $scores);
- }
- }
- return $report;
- }
-
- function hotpot_format_score($record, $undefined=' ') {
- if (isset($record->score)) {
- $score = $record->score;
- } else {
- $score = $undefined;
- }
- return $score;
- }
-
- function hotpot_format_status($record, $undefined=' ') {
- global $HOTPOT_STATUS;
-
- if (isset($record->status) || isset($HOTPOT_STATUS[$record->status])) {
- $status = $HOTPOT_STATUS[$record->status];
- } else {
- $status = $undefined;
- }
- return $status;
- }
-
- function hotpot_print_recent_activity($course, $isteacher, $timestart) {
- /// Given a course and a time, this module should find recent activity
- /// that has occurred in hotpot activities and print it out.
- /// Return true if there was output, or false is there was none.
-
- global $CFG;
- $result = false;
-
- $records = get_records_sql("
- SELECT
- h.id AS id,
- h.name AS name,
- COUNT(*) AS count_attempts
- FROM
- {$CFG->prefix}hotpot h,
- {$CFG->prefix}hotpot_attempts a
- WHERE
- h.course = $course->id
- AND h.id = a.hotpot
- AND a.id = a.clickreportid
- AND a.starttime > $timestart
- GROUP BY
- h.id, h.name
- ");
- // note that PostGreSQL requires h.name in the GROUP BY clause
-
- if($records) {
- $names = array();
- foreach ($records as $id => $record){
- if ($cm = get_coursemodule_from_instance('hotpot', $record->id, $course->id)) {
- $context = get_context_instance(CONTEXT_MODULE, $cm->id);
-
- if (has_capability('mod/hotpot:viewreport', $context)) {
- $href = "$CFG->wwwroot/mod/hotpot/view.php?hp=$id";
- $name = ' <a href="'.$href.'">'.$record->name.'</a>';
- if ($record->count_attempts > 1) {
- $name .= " ($record->count_attempts)";
- }
- $names[] = $name;
- }
- }
- }
- if (count($names) > 0) {
- print_headline(get_string('modulenameplural', 'hotpot').':');
-
- if ($CFG->version >= 2005050500) { // Moodle 1.5+
- echo '<div class="head"><div class="name">'.implode('<br />', $names).'</div></div>';
- } else { // Moodle 1.4.x (or less)
- echo '<font size="1">'.implode('<br />', $names).'</font>';
- }
- $result = true;
- }
- }
- return $result; // True if anything was printed, otherwise false
- }
-
- function hotpot_get_recent_mod_activity(&$activities, &$index, $sincetime, $courseid, $cmid="", $userid="", $groupid="") {
- // Returns all quizzes since a given time.
-
- global $CFG;
-
- // If $cmid or $userid are specified, then this restricts the results
- $cm_select = empty($cmid) ? "" : " AND cm.id = '$cmid'";
- $user_select = empty($userid) ? "" : " AND u.id = '$userid'";
-
- $records = get_records_sql("
- SELECT
- a.*,
- h.name, h.course,
- cm.instance, cm.section,
- u.firstname, u.lastname, u.picture
- FROM
- {$CFG->prefix}hotpot_attempts a,
- {$CFG->prefix}hotpot h,
- {$CFG->prefix}course_modules cm,
- {$CFG->prefix}user u
- WHERE
- a.timefinish > '$sincetime'
- AND a.id = a.clickreportid
- AND a.userid = u.id $user_select
- AND a.hotpot = h.id $cm_select
- AND cm.instance = h.id
- AND cm.course = '$courseid'
- AND h.course = cm.course
- ORDER BY
- a.timefinish ASC
- ");
-
- if (!empty($records)) {
- foreach ($records as $record) {
- if (empty($groupid) || groups_is_member($groupid, $record->userid)) {
-
- unset($activity);
-
- $activity->type = "hotpot";
- $activity->defaultindex = $index;
- $activity->instance = $record->hotpot;
-
- $activity->name = $record->name;
- $activity->section = $record->section;
-
- $activity->content->attemptid = $record->id;
- $activity->content->attempt = $record->attempt;
- $activity->content->score = $record->score;
- $activity->content->timestart = $record->timestart;
- $activity->content->timefinish = $record->timefinish;
-
- $activity->user->userid = $record->userid;
- $activity->user->fullname = fullname($record);
- $activity->user->picture = $record->picture;
-
- $activity->timestamp = $record->timefinish;
-
- $activities[] = $activity;
-
- $index++;
- }
- } // end foreach
- }
- }
-
- function hotpot_print_recent_mod_activity($activity, $courseid, $detail=false) {
- /// Basically, this function prints the results of "hotpot_get_recent_activity"
-
- global $CFG, $THEME, $USER;
-
- if (isset($THEME->cellcontent2)) {
- $bgcolor = ' bgcolor="'.$THEME->cellcontent2.'"';
- } else {
- $bgcolor = '';
- }
-
- if (is_object($courseid) && isset($courseid->id)) {
- $courseid = $courseid->id; // shouldn't happen !!
- }
-
- print '<table border="0" cellpadding="3" cellspacing="0">';
-
- print '<tr><td'.$bgcolor.' class="forumpostpicture" width="35" valign="top">';
- print_user_picture($activity->user->userid, $courseid, $activity->user->picture);
- print '</td><td width="100%"><font size="2">';
-
- if ($detail) {
- // activity icon
- $src = "$CFG->modpixpath/$activity->type/icon.gif";
- print '<img src="'.$src.'" class="icon" alt="'.$activity->type.'" /> ';
-
- // link to activity
- $href = "$CFG->wwwroot/mod/hotpot/view.php?hp=$activity->instance";
- print '<a href="'.$href.'">'.$activity->name.'</a> - ';
- }
- if (has_capability('mod/hotpot:viewreport',get_context_instance(CONTEXT_COURSE, $courseid))) {
- // score (with link to attempt details)
- $href = "$CFG->wwwroot/mod/hotpot/review.php?hp=$activity->instance&attempt=".$activity->content->attemptid;
- print '<a href="'.$href.'">('.hotpot_format_score($activity->content).')</a> ';
-
- // attempt number
- print get_string('attempt', 'quiz').' - '.$activity->content->attempt.'<br />';
- }
-
- // link to user
- $href = "$CFG->wwwroot/user/view.php?id=$activity->user->userid&course=$courseid";
- print '<a href="'.$href.'">'.$activity->user->fullname.'</a> ';
-
- // time and date
- print ' - ' . userdate($activity->timestamp);
-
- // duration
- $duration = format_time($activity->content->timestart - $activity->content->timefinish);
- print " ($duration)";
-
- print "</font></td></tr>";
- print "</table>";
- }
-
- function hotpot_cron () {
- /// Function to be run periodically according to the moodle cron
- /// This function searches for things that need to be done, such
- /// as sending out mail, toggling flags etc ...
-
- global $CFG;
-
- return true;
- }
-
- function hotpot_grades($hotpotid) {
- /// Must return an array of grades for a given instance of this module,
- /// indexed by user. It also returns a maximum allowed grade.
-
- $hotpot = get_record('hotpot', 'id', $hotpotid);
- $return->grades = hotpot_get_grades($hotpot);
- $return->maxgrade = $hotpot->grade;
-
- return $return;
- }
- function hotpot_get_grades($hotpot, $user_ids='') {
- global $CFG;
-
- $grades = array();
-
- $weighting = $hotpot->grade / 100;
- $precision = hotpot_get_precision($hotpot);
-
- // set the SQL string to determine the $grade
- $grade = "";
- switch ($hotpot->grademethod) {
- case HOTPOT_GRADEMETHOD_HIGHEST:
- $grade = "ROUND(MAX(score) * $weighting, $precision) AS grade";
- break;
- case HOTPOT_GRADEMETHOD_AVERAGE:
- // the 'AVG' function skips abandoned quizzes, so use SUM(score)/COUNT(id)
- $grade = "ROUND(SUM(score)/COUNT(id) * $weighting, $precision) AS grade";
- break;
- case HOTPOT_GRADEMETHOD_FIRST:
- $grade = "ROUND(score * $weighting, $precision)";
- $grade = sql_concat('timestart', "'_'", $grade);
- $grade = "MIN($grade) AS grade";
- break;
- case HOTPOT_GRADEMETHOD_LAST:
- $grade = "ROUND(score * $weighting, $precision)";
- $grade = sql_concat('timestart', "'_'", $grade);
- $grade = "MAX($grade) AS grade";
- break;
- }
-
- if ($grade) {
- $userid_condition = empty($user_ids) ? '' : "AND userid IN ($user_ids) ";
- $grades = get_records_sql_menu("
- SELECT userid, $grade
- FROM {$CFG->prefix}hotpot_attempts
- WHERE timefinish>0 AND hotpot='$hotpot->id' $userid_condition
- GROUP BY userid
- ");
- if ($grades) {
- if ($hotpot->grademethod==HOTPOT_GRADEMETHOD_FIRST || $hotpot->grademethod==HOTPOT_GRADEMETHOD_LAST) {
- // remove left hand characters in $grade (up to and including the underscore)
- foreach ($grades as $userid=>$grade) {
- $grades[$userid] = substr($grades[$userid], strpos($grades[$userid], '_')+1);
- }
- }
- }
- }
-
- return $grades;
- }
- function hotpot_get_precision(&$hotpot) {
- return ($hotpot->grademethod==HOTPOT_GRADEMETHOD_AVERAGE || $hotpot->grade<100) ? 1 : 0;
- }
-
- /**
- * Return grade for given user or all users.
- *
- * @param object $hotpot
- * @param int $userid optional user id, 0 means all users
- * @return array array of grades, false if none
- */
- function hotpot_get_user_grades($hotpot, $userid=0) {
- $grades = array();
- if ($hotpotgrades = hotpot_get_grades($hotpot, $userid)) {
- foreach ($hotpotgrades as $hotpotuserid => $hotpotgrade) {
- $grades[$hotpotuserid] = new stdClass();
- $grades[$hotpotuserid]->id = $hotpotuserid;
- $grades[$hotpotuserid]->userid = $hotpotuserid;
- $grades[$hotpotuserid]->rawgrade = $hotpotgrade;
- }
- }
- if (count($grades)) {
- return $grades;
- } else {
- 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 means all users
- */
- function hotpot_update_grades($hotpot=null, $userid=0, $nullifnone=true) {
- global $CFG;
- if (! function_exists('grade_update')) {
- require_once($CFG->libdir.'/gradelib.php');
- }
- 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 {
- // no grades and no userid
- hotpot_grade_item_update($hotpot);
- }
- }
- }
-
- /**
- * Update/create grade item for given hotpot
- *
- * @param object $hotpot object with extra cmidnumber
- * @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) {
- global $CFG;
- 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;
- $params['grademin'] = 0;
-
- } else {
- $params['gradetype'] = GRADE_TYPE_NONE;
- // Note: when adding a new activity, a gradeitem will *not*
- // be created in the grade book if gradetype==GRADE_TYPE_NONE
- // A gradeitem will be created later if gradetype changes to GRADE_TYPE_VALUE
- // However, the gradeitem will *not* be deleted if the activity's
- // gradet…
Large files files are truncated, but you can click here to view the full file