} if (!($course = get_record("course", "id", $hotpot->course))) { error("Course is misconfigured"); } if (!($cm = get_coursemodule_from_instance("hotpot", $hotpot->id, $course->id))) { error("Course Module ID was incorrect"); } } // get the roles context for this course $sitecontext = get_context_instance(CONTEXT_SYSTEM); $modulecontext = get_context_instance(CONTEXT_MODULE, $cm->id); // set homeurl of couse (for error messages) $course_homeurl = "{$CFG->wwwroot}/course/view.php?id={$course->id}"; require_login($course); // check user can access this hotpot activity if (!hotpot_is_visible($cm)) { print_error("activityiscurrentlyhidden"); } // get report mode if (has_capability('mod/hotpot:viewreport', $modulecontext)) { $mode = optional_param('mode', 'overview', PARAM_ALPHA); } else { // ordinary students have no choice $mode = 'overview'; } // assemble array of form data $formdata = array('mode' => $mode, 'reportusers' => has_capability('mod/hotpot:viewreport', $modulecontext) ? optional_param('reportusers', get_user_preferences('hotpot_reportusers', 'allusers'), PARAM_ALPHANUM) : 'this', 'reportattempts' => optional_param('reportattempts', get_user_preferences('hotpot_reportattempts', 'all'), PARAM_ALPHA), 'reportformat' => optional_param('reportformat', 'htm', PARAM_ALPHA), 'reportshowlegend' => optional_param('reportshowlegend', get_user_preferences('hotpot_reportshowlegend', '0'), PARAM_INT), 'reportencoding' => optional_param('reportencoding', get_user_preferences('hotpot_reportencoding', ''), PARAM_ALPHANUM), 'reportwrapdata' => optional_param('reportwrapdata', get_user_preferences('hotpot_reportwrapdata', '1'), PARAM_INT)); foreach ($formdata as $name => $value) { set_user_preference("hotpot_{$name}", $value); } /// Start the report
} else { if (isset($USER->display[$course->id])) { $displaysection = $USER->display[$course->id]; } else { $displaysection = 0; } } // Get all hotpot instances in this course $hotpots = array(); if ($hotpot_instances = hotpot_get_all_instances_in_course('hotpot', $course)) { foreach ($hotpot_instances as $hotpot_instance) { if ($displaysection > 0 && $hotpot_instance->section > 0 && $displaysection != $hotpot_instance->section) { // do nothing (user is not diplaying this section) } else { $cm = get_coursemodule_from_instance('hotpot', $hotpot_instance->id); if ($cm && hotpot_is_visible($cm)) { $hotpots[$hotpot_instance->id] = $hotpot_instance; } } } } if (empty($hotpots)) { notice(get_string('thereareno', 'moodle', $strmodulenameplural), $next_url); exit; } $hotpotids = implode(',', array_keys($hotpots)); if (has_capability('mod/hotpot:grade', $sitecontext)) { // array of hotpots to be regraded $regrade_hotpots = array(); // do we need to regrade any or all of the hotpots? $regrade = optional_param('regrade', 0, PARAM_SEQUENCE);
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 = "\n SELECT\n cm.id AS coursemodule,\n cm.course AS course,\n cm.module AS module,\n cm.instance AS instance,\n -- cm.section AS section,\n cm.visible AS visible,\n {$groupmode}\n -- cs.section AS sectionnumber,\n cs.section AS section,\n cs.sequence AS sequence,\n cs.visible AS sectionvisible,\n thismodule.*\n FROM\n {$CFG->prefix}course_modules cm,\n {$CFG->prefix}course_sections cs,\n {$CFG->prefix}modules m,\n {$CFG->prefix}{$modulename} thismodule\n WHERE\n m.name = '{$modulename}' AND\n m.id = cm.module AND\n cm.course = '{$course->id}' AND\n cm.section = cs.id AND\n cm.instance = thismodule.id\n "; 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; }
/** * @global object * @global object * @param string $modulename * @param object $course * @return array */ function hotpot_get_all_instances_in_course($modulename, $course) { /// called from index.php global $CFG, $DB; $instances = array(); $query = "\n SELECT\n cm.id AS coursemodule,\n cm.course AS course,\n cm.module AS module,\n cm.instance AS instance,\n -- cm.section AS section,\n cm.visible AS visible,\n cm.groupmode,\n -- cs.section AS sectionnumber,\n cs.section AS section,\n cs.sequence AS sequence,\n cs.visible AS sectionvisible,\n thismodule.*\n FROM\n {course_modules} cm,\n {course_sections} cs,\n {modules} m,\n {" . $modulename . "} thismodule\n WHERE\n m.name = :modulename AND\n m.id = cm.module AND\n cm.course = :courseid AND\n cm.section = cs.id AND\n cm.instance = thismodule.id\n "; $params = array('modulename' => $modulename, 'courseid' => $course->id); if ($rawmods = $DB->get_records_sql($query, $params)) { // 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; }