protected function definition() { global $CFG, $OUTPUT; $mform =& $this->_form; $indicators = $this->_customdata['indicators']; $mform->addElement('hidden', 'id', $this->_customdata['id']); // TODO: general course-level report settings. $mform->addElement('header', 'general', get_string('pluginname', 'coursereport_engagement')); $mform->addElement('header', 'weightings', get_string('weighting', 'coursereport_engagement')); $mform->addElement('static', 'weightings_desc', get_string('indicator', 'coursereport_engagement')); foreach ($indicators as $name => $path) { $grouparray = array(); $grouparray[] =& $mform->createElement('text', "weighting_{$name}", '', array('size' => 3)); $grouparray[] =& $mform->createElement('static', '', '', '%'); $mform->addGroup($grouparray, "weight_group_{$name}", get_string('pluginname', "engagementindicator_{$name}"), ' ', false); } $pluginman = plugin_manager::instance(); $instances = get_plugin_list('engagementindicator'); foreach ($indicators as $name => $path) { $plugin = coursereport_engagement_get_plugin_info($pluginman, 'engagementindicator_' . $name); $file = "{$CFG->dirroot}/mod/engagement/indicator/{$name}/thresholds_form.php"; if (file_exists($file) && $plugin->is_enabled()) { require_once $file; $class = "engagementindicator_{$name}_thresholds_form"; $subform = new $class(); $mform->addElement('header', 'general', get_string('pluginname', "engagementindicator_{$name}")); $subform->definition_inner($mform); } } $this->add_action_buttons(); }
function coursereport_engagement_get_course_summary($courseid) { global $CFG, $DB; $risks = array(); // TODO: We want this to rely on enabled indicators in the course... require_once $CFG->libdir . '/pluginlib.php'; require_once $CFG->dirroot . '/course/report/engagement/locallib.php'; $pluginman = plugin_manager::instance(); $instances = get_plugin_list('engagementindicator'); if (!($weightings = $DB->get_records_menu('coursereport_engagement', array('course' => $courseid), '', 'indicator, weight'))) { // Setup default weightings, all equal. $weight = sprintf('%.2f', 1 / count($instances)); foreach ($instances as $name => $path) { $record = new stdClass(); $record->course = $courseid; $record->indicator = $name; $record->weight = $weight; $record->configdata = null; $wid = $DB->insert_record('coursereport_engagement', $record); $weightings[$name] = $weight; } } foreach ($instances as $name => $path) { $plugin = coursereport_engagement_get_plugin_info($pluginman, 'engagementindicator_' . $name); if ($plugin->is_enabled() && file_exists("{$path}/indicator.class.php")) { require_once "{$path}/indicator.class.php"; $classname = "indicator_{$name}"; $indicator = new $classname($courseid); $indicatorrisks = $indicator->get_course_risks(); $weight = isset($weightings[$name]) ? $weightings[$name] : 0; foreach ($indicatorrisks as $userid => $risk) { if (!isset($risks[$userid])) { $risks[$userid] = 0; } $risks[$userid] += $risk->risk * $weight; } } } return $risks; }
} $stradministration = get_string('administration'); $strreports = get_string('reports'); $renderer = $PAGE->get_renderer('coursereport_engagement'); echo $OUTPUT->header(); $heading = $userid ? 'userreport' : 'coursereport'; $info = new stdClass(); $info->course = $course->shortname; if (isset($user)) { $info->user = fullname($user); } echo $OUTPUT->heading(get_string($heading, 'coursereport_engagement', $info)); $pluginman = plugin_manager::instance(); $indicators = get_plugin_list('engagementindicator'); foreach ($indicators as $name => $path) { $plugin = coursereport_engagement_get_plugin_info($pluginman, 'engagementindicator_' . $name); if (!$plugin->is_enabled()) { unset($indicators[$name]); } } $weightings = $DB->get_records_menu('coursereport_engagement', array('course' => $id), '', 'indicator, weight'); $data = array(); if (!$userid) { // Course report. foreach ($indicators as $name => $path) { if (file_exists("{$path}/indicator.class.php")) { require_once "{$path}/indicator.class.php"; $classname = "indicator_{$name}"; $indicator = new $classname($id); $indicatorrisks = $indicator->get_course_risks(); $weight = isset($weightings[$name]) ? $weightings[$name] : 0;