/** * Unit test to set and get grading areas */ public function test_set_and_get_grading_area() { global $DB; $this->resetAfterTest(true); //sleep(2); // to make sure the microtime will always return unique values // No sleeping in tests!!! --skodak $areaname1 = 'area1-' . (string) microtime(true); $areaname2 = 'area2-' . (string) microtime(true); $fakecontext = (object) array('id' => 42, 'contextlevel' => CONTEXT_MODULE, 'instanceid' => 22, 'path' => '/1/3/15/42', 'depth' => 4); // non-existing area $gradingman = get_grading_manager($fakecontext, 'mod_foobar', $areaname1); $this->assertNull($gradingman->get_active_method()); // creates area implicitly and sets active method $this->assertTrue($gradingman->set_active_method('rubric')); $this->assertEquals('rubric', $gradingman->get_active_method()); // repeat setting of already set active method $this->assertFalse($gradingman->set_active_method('rubric')); // switch the manager to another area $gradingman->set_area($areaname2); $this->assertNull($gradingman->get_active_method()); // switch back and ask again $gradingman->set_area($areaname1); $this->assertEquals('rubric', $gradingman->get_active_method()); // attempting to set an invalid method $this->setExpectedException('moodle_exception'); $gradingman->set_active_method('no_one_should_ever_try_to_implement_a_method_with_this_silly_name'); }
/** * Unit test to get draft instance and create new instance. */ public function test_get_or_create_instance() { global $DB; $this->resetAfterTest(true); // Create fake areas. $fakearea = (object) array('contextid' => 1, 'component' => 'mod_assign', 'areaname' => 'submissions', 'activemethod' => 'guide'); $fakearea1id = $DB->insert_record('grading_areas', $fakearea); $fakearea->contextid = 2; $fakearea2id = $DB->insert_record('grading_areas', $fakearea); // Create fake definitions. $fakedefinition = (object) array('areaid' => $fakearea1id, 'method' => 'guide', 'name' => 'fakedef', 'status' => gradingform_controller::DEFINITION_STATUS_READY, 'timecreated' => 0, 'usercreated' => 1, 'timemodified' => 0, 'usermodified' => 1); $fakedef1id = $DB->insert_record('grading_definitions', $fakedefinition); $fakedefinition->areaid = $fakearea2id; $fakedef2id = $DB->insert_record('grading_definitions', $fakedefinition); // Create fake guide instance in first area. $fakeinstance = (object) array('definitionid' => $fakedef1id, 'raterid' => 1, 'itemid' => 1, 'rawgrade' => null, 'status' => 0, 'feedback' => null, 'feedbackformat' => 0, 'timemodified' => 0); $fakeinstanceid = $DB->insert_record('grading_instances', $fakeinstance); $manager1 = get_grading_manager($fakearea1id); $manager2 = get_grading_manager($fakearea2id); $controller1 = $manager1->get_controller('guide'); $controller2 = $manager2->get_controller('guide'); $instance1 = $controller1->get_or_create_instance(0, 1, 1); $instance2 = $controller2->get_or_create_instance(0, 1, 1); // Definitions should not be the same. $this->assertEquals(false, $instance1->get_data('definitionid') == $instance2->get_data('definitionid')); }
/** * Extends the module navigation * * This function is called when the context for the page is an activity module with the * FEATURE_ADVANCED_GRADING and there is an area with the active grading method set to the given plugin. * * @param global_navigation $navigation {@link global_navigation} * @param navigation_node $node {@link navigation_node} */ public function extend_navigation(global_navigation $navigation, navigation_node $node = null) { if (has_capability('moodle/grade:managegradingforms', $this->get_context())) { // no need for preview if user can manage forms, he will have link to manage.php in settings instead return; } if ($this->is_form_defined() && ($options = $this->get_options()) && !empty($options['alwaysshowdefinition'])) { $node->add(get_string('gradingof', 'gradingform_rubric', get_grading_manager($this->get_areaid())->get_area_title()), new moodle_url('/grade/grading/form/' . $this->get_method_name() . '/preview.php', array('areaid' => $this->get_areaid())), settings_navigation::TYPE_CUSTOM); } }
/** * Returns the definitions for the requested course module ids * @param array of ints $cmids * @param string $areaname * @param boolean $activeonly default is false, if true, only the active method is returned * @return array of areas with definitions for each requested course module id * @since Moodle 2.5 */ public static function get_definitions($cmids, $areaname, $activeonly = false) { global $DB, $CFG; require_once "{$CFG->dirroot}/grade/grading/form/lib.php"; $params = self::validate_parameters(self::get_definitions_parameters(), array('cmids' => $cmids, 'areaname' => $areaname, 'activeonly' => $activeonly)); $warnings = array(); $areas = array(); foreach ($params['cmids'] as $cmid) { $context = context_module::instance($cmid); try { self::validate_context($context); } catch (Exception $e) { $warnings[] = array('item' => 'module', 'itemid' => $cmid, 'message' => 'No access rights in module context', 'warningcode' => '1'); continue; } // Check if the user has managegradingforms capability. $isgradingmethodmanager = false; if (has_capability('moodle/grade:managegradingforms', $context)) { $isgradingmethodmanager = true; } $module = get_coursemodule_from_id('', $cmid, 0, false, MUST_EXIST); $componentname = "mod_" . $module->modname; // Get the grading manager. $gradingmanager = get_grading_manager($context, $componentname, $params['areaname']); // Get the controller for each grading method. $methods = array(); if ($params['activeonly'] == true) { $methods[] = $gradingmanager->get_active_method(); } else { $methods = array_keys($gradingmanager->get_available_methods(false)); } $area = array(); $area['cmid'] = $cmid; $area['contextid'] = $context->id; $area['component'] = $componentname; $area['activemethod'] = $gradingmanager->get_active_method(); $area['definitions'] = array(); foreach ($methods as $method) { $controller = $gradingmanager->get_controller($method); $def = $controller->get_definition(true); if ($def == false) { continue; } if ($isgradingmethodmanager == false) { $isviewable = true; if ($def->status != gradingform_controller::DEFINITION_STATUS_READY) { $warnings[] = array('item' => 'module', 'itemid' => $cmid, 'message' => 'Capability moodle/grade:managegradingforms required to view draft definitions', 'warningcode' => '1'); $isviewable = false; } if (!empty($def->options)) { $options = json_decode($def->options); if (isset($options->alwaysshowdefinition) && $options->alwaysshowdefinition == 0) { $warnings[] = array('item' => 'module', 'itemid' => $cmid, 'message' => 'Capability moodle/grade:managegradingforms required to preview definition', 'warningcode' => '1'); $isviewable = false; } } if ($isviewable == false) { continue; } } $definition = array(); $definition['id'] = $def->id; $definition['method'] = $method; $definition['name'] = $def->name; $definition['description'] = $def->description; $definition['descriptionformat'] = $def->descriptionformat; $definition['status'] = $def->status; $definition['copiedfromid'] = $def->copiedfromid; $definition['timecreated'] = $def->timecreated; $definition['usercreated'] = $def->usercreated; $definition['timemodified'] = $def->timemodified; $definition['usermodified'] = $def->usermodified; $definition['timecopied'] = $def->timecopied; // Format the description text field. $formattedtext = external_format_text($definition['description'], $definition['descriptionformat'], $context->id, $componentname, 'description', $def->id); $definition['description'] = $formattedtext[0]; $definition['descriptionformat'] = $formattedtext[1]; $details = $controller->get_external_definition_details(); $items = array(); foreach ($details as $key => $value) { $items[$key] = self::format_text($def->{$key}, $context->id, $componentname, $def->id); } $definition[$method] = $items; $area['definitions'][] = $definition; } $areas[] = $area; } $result = array('areas' => $areas, 'warnings' => $warnings); return $result; }
/** * Removes all data associated with the given context * * This is called by {@link context::delete_content()} * * @param int $contextid context id */ public static function delete_all_for_context($contextid) { global $DB; $areaids = $DB->get_fieldset_select('grading_areas', 'id', 'contextid = ?', array($contextid)); $methods = array_keys(self::available_methods(false)); foreach ($areaids as $areaid) { $manager = get_grading_manager($areaid); foreach ($methods as $method) { $controller = $manager->get_controller($method); $controller->delete_definition(); } } $DB->delete_records_list('grading_areas', 'id', $areaids); }
} // publish the form as a template if (!empty($shareform)) { require_capability('moodle/grade:sharegradingforms', context_system::instance()); $controller = $manager->get_controller($method); $definition = $controller->get_definition(); if (!$confirmed) { // let the user confirm they understand what they are doing (haha ;-) echo $output->header(); echo $output->confirm(get_string('manageactionshareconfirm', 'core_grading', s($definition->name)), new moodle_url($PAGE->url, array('shareform' => $shareform, 'confirmed' => 1)), $PAGE->url); echo $output->footer(); die; } else { require_sesskey(); $newareaid = $manager->create_shared_area($method); $targetarea = get_grading_manager($newareaid); $targetcontroller = $targetarea->get_controller($method); $targetcontroller->update_definition($controller->get_definition_copy($targetcontroller)); $DB->set_field('grading_definitions', 'timecopied', time(), array('id' => $definition->id)); redirect(new moodle_url($PAGE->url, array('message' => get_string('manageactionsharedone', 'core_grading')))); } } // delete the form definition if (!empty($deleteform)) { $controller = $manager->get_controller($method); $definition = $controller->get_definition(); if (!$confirmed) { // let the user confirm they understand the consequences (also known as WTF-effect) echo $output->header(); echo $output->confirm(markdown_to_html(get_string('manageactiondeleteconfirm', 'core_grading', array('formname' => s($definition->name), 'component' => $manager->get_component_title(), 'area' => $manager->get_area_title()))), new moodle_url($PAGE->url, array('deleteform' => $deleteform, 'confirmed' => 1)), $PAGE->url); echo $output->footer();
/** * Prepares the data for the grading form. * * @param $course * @param $assignment * @param $submission * @param $user * @param $coursemodule * @param assignment_base $assignmentinstance * @global $USER * @global $CFG * @return array */ private function get_mform_data_object($course, $assignment, $submission, $user, $coursemodule, $assignmentinstance) { global $USER, $CFG; $context = context_module::instance($coursemodule->id); // Get grading information to see whether we should be allowed to make changed at all. $grading_info = grade_get_grades($course->id, 'mod', 'assignment', $assignment->id, array($user->id)); $locked = $grading_info->items[0]->grades[$user->id]->locked; $overridden = $grading_info->items[0]->grades[$user->id]->overridden; $gradingdisabled = $locked || $overridden; $mformdata = new stdClass(); $mformdata->context = $context; $mformdata->maxbytes = $course->maxbytes; $mformdata->courseid = $course->id; $mformdata->teacher = $USER; $mformdata->assignment = $assignment; $mformdata->submission = $submission; $mformdata->lateness = assignment_display_lateness($submission->timemodified, $assignment->timedue); $mformdata->user = $user; $mformdata->offset = false; $mformdata->userid = $user->id; $mformdata->cm = $coursemodule; $mformdata->grading_info = $grading_info; $mformdata->enableoutcomes = $CFG->enableoutcomes; $mformdata->grade = $assignment->grade; $mformdata->gradingdisabled = $gradingdisabled; // TODO set nextid to the nextnode id. $mformdata->nextid = false; $mformdata->submissioncomment = $submission->submissioncomment; $mformdata->submissioncommentformat = FORMAT_HTML; $mformdata->submission_content = $assignmentinstance->print_user_files($user->id, true); if ($assignment->assignmenttype == 'upload') { $mformdata->fileui_options = array('subdirs' => 1, 'maxbytes' => $assignment->maxbytes, 'maxfiles' => $assignment->var1, 'accepted_types' => '*', 'return_types' => FILE_INTERNAL); } else { if ($assignment->assignmenttype == 'uploadsingle') { $mformdata->fileui_options = array('subdirs' => 0, 'maxbytes' => $CFG->userquota, 'maxfiles' => 1, 'accepted_types' => '*', 'return_types' => FILE_INTERNAL); } } $advancedgradingwarning = false; $gradingmanager = get_grading_manager($context, 'mod_assignment', 'submission'); if ($gradingmethod = $gradingmanager->get_active_method()) { // This returns a gradingform_controller instance, not grading_controller as docs // say. /* @var gradingform_controller $controller */ $controller = $gradingmanager->get_controller($gradingmethod); if ($controller->is_form_available()) { $itemid = null; if (!empty($submission->id)) { $itemid = $submission->id; } if ($gradingdisabled && $itemid) { $mformdata->advancedgradinginstance = $controller->get_current_instance($USER->id, $itemid); return array($mformdata, $advancedgradingwarning); } else { if (!$gradingdisabled) { $instanceid = optional_param('advancedgradinginstanceid', 0, PARAM_INT); $mformdata->advancedgradinginstance = $controller->get_or_create_instance($instanceid, $USER->id, $itemid); return array($mformdata, $advancedgradingwarning); } } return array($mformdata, $advancedgradingwarning); } else { $advancedgradingwarning = $controller->form_unavailable_notification(); return array($mformdata, $advancedgradingwarning); } } return array($mformdata, $advancedgradingwarning); }
function view_feedback($submission=NULL) { global $USER, $CFG, $DB, $OUTPUT, $PAGE; require_once($CFG->libdir.'/gradelib.php'); require_once("$CFG->dirroot/grade/grading/lib.php"); if (!$submission) { /// Get submission for this assignment $userid = $USER->id; $submission = $this->get_submission($userid); } else { $userid = $submission->userid; } // Check the user can submit $canviewfeedback = ($userid == $USER->id && has_capability('mod/assignment:submit', $this->context, $USER->id, false)); // If not then check if the user still has the view cap and has a previous submission $canviewfeedback = $canviewfeedback || (!empty($submission) && $submission->userid == $USER->id && has_capability('mod/assignment:view', $this->context)); // Or if user can grade (is a teacher or admin) $canviewfeedback = $canviewfeedback || has_capability('mod/assignment:grade', $this->context); if (!$canviewfeedback) { // can not view or submit assignments -> no feedback return; } $grading_info = grade_get_grades($this->course->id, 'mod', 'assignment', $this->assignment->id, $userid); $item = $grading_info->items[0]; $grade = $item->grades[$userid]; if ($grade->hidden or $grade->grade === false) { // hidden or error return; } if ($grade->grade === null and empty($grade->str_feedback)) { // No grade to show yet if ($this->count_responsefiles($userid)) { // but possibly response files are present echo $OUTPUT->heading(get_string('responsefiles', 'assignment'), 3); $responsefiles = $this->print_responsefiles($userid, true); echo $OUTPUT->box($responsefiles, 'generalbox boxaligncenter'); } return; } $graded_date = $grade->dategraded; $graded_by = $grade->usermodified; /// We need the teacher info if (!$teacher = $DB->get_record('user', array('id'=>$graded_by))) { print_error('cannotfindteacher'); } /// Print the feedback echo $OUTPUT->heading(get_string('submissionfeedback', 'assignment'), 3); echo '<table cellspacing="0" class="feedback">'; echo '<tr>'; echo '<td class="left picture">'; echo $OUTPUT->user_picture($teacher); echo '</td>'; echo '<td class="topic">'; echo '<div class="from">'; echo '<div class="fullname">'.fullname($teacher).'</div>'; echo '<div class="time">'.userdate($graded_date).'</div>'; echo '</div>'; echo '</td>'; echo '</tr>'; echo '<tr>'; echo '<td class="left side"> </td>'; echo '<td class="content">'; $gradestr = '<div class="grade">'. get_string("grade").': '.$grade->str_long_grade. '</div>'; if (!empty($submission) && $controller = get_grading_manager($this->context, 'mod_assignment', 'submission')->get_active_controller()) { $controller->set_grade_range(make_grades_menu($this->assignment->grade)); echo $controller->render_grade($PAGE, $submission->id, $item, $gradestr, has_capability('mod/assignment:grade', $this->context)); } else { echo $gradestr; } echo '<div class="clearer"></div>'; echo '<div class="comment">'; echo $grade->str_feedback; echo '</div>'; echo '</tr>'; echo '<tr>'; echo '<td class="left side"> </td>'; echo '<td class="content">'; echo $this->print_responsefiles($userid, true); echo '</tr>'; echo '</table>'; }
function get_pass_ratio($cmid, $emarkingid, $extracategory, $ids) { global $DB, $CFG; if (!($emarking = $DB->get_record('emarking', array('id' => $emarkingid)))) { print_error('Prueba inválida'); } if (!($cm = get_coursemodule_from_id('emarking', $cmid))) { print_error('Módulo inválido'); } // Validate course if (!($course = $DB->get_record('course', array('id' => $emarking->course)))) { print_error('Curso inválido'); } // Getting context $context = context_module::instance($cmid); $emarkingids = '' . $emarking->id; // check for parallel courses if ($CFG->emarking_parallelregex) { $parallels = emarking_get_parallel_courses($course, $extracategory, $CFG->emarking_parallelregex); } else { $parallels = false; } // Form that lets you choose if you want to add to the report the other courses $emarkingsform = new emarking_gradereport_form(null, array('course' => $course, 'cm' => $cm, 'parallels' => $parallels, 'id' => $emarkingids)); // Get the IDs from the parallel courses $totalemarkings = 1; if ($parallels && count($parallels) > 0) { foreach ($parallels as $pcourse) { $assid = ''; if ($emarkingsform->get_data() && property_exists($emarkingsform->get_data(), "emarkingid_{$pcourse->id}")) { eval("\$assid = \$emarkingsform->get_data()->emarkingid_{$pcourse->id};"); if ($assid > 0) { $emarkingids .= ',' . $assid; $totalemarkings++; } } } } // counts the total of disticts categories $sqlcats = "select count(distinct(c.category)) as categories\n\tfrom {emarking} as a\n\tinner join {course} as c on (a.course = c.id)\n\twhere a.id in ({$emarkingids})"; $totalcategories = $DB->count_records_sql($sqlcats); // Get the grading manager, then method and finally controller $gradingmanager = get_grading_manager($context, 'mod_emarking', 'attempt'); $gradingmethod = $gradingmanager->get_active_method(); $rubriccontroller = $gradingmanager->get_controller($gradingmethod); $definition = $rubriccontroller->get_definition(); // Search for stats regardig the exames (eg: max, min, number of students,etc) $sql = "select *,\n\tcase\n\twhen categoryid is null then 'TOTAL'\n\twhen emarkingid is null then concat('SUBTOTAL ', categoryname)\n\telse coursename\n\tend as seriesname\n\tfrom (\n\tselect \tcategoryid as categoryid,\n\tcategoryname,\n\temarkingid as emarkingid,\n\tmodulename,\n\tcoursename,\n\tcount(*) as students,\n\tsum(pass) as pass,\n\tround((sum(pass) / count(*)) * 100,2) as pass_ratio,\n\tSUBSTRING_INDEX(\n\tSUBSTRING_INDEX(\n\tgroup_concat(grade order by grade separator ',')\n\t, ','\n\t, 25/100 * COUNT(*) + 1)\n\t, ','\n\t, -1\n\t) as percentile_25,\n\tSUBSTRING_INDEX(\n\tSUBSTRING_INDEX(\n\tgroup_concat(grade order by grade separator ',')\n\t, ','\n\t, 50/100 * COUNT(*) + 1)\n\t, ','\n\t, -1\n\t) as percentile_50,\n\tSUBSTRING_INDEX(\n\tSUBSTRING_INDEX(\n\tgroup_concat(grade order by grade separator ',')\n\t, ','\n\t, 75/100 * COUNT(*) + 1)\n\t, ','\n\t, -1\n\t) as percentile_75,\n\tmin(grade) as minimum,\n\tmax(grade) as maximum,\n\tround(avg(grade),2) as average,\n\tround(stddev(grade),2) as stdev,\n\tsum(histogram_01) as histogram_1,\n\tsum(histogram_02) as histogram_2,\n\tsum(histogram_03) as histogram_3,\n\tsum(histogram_04) as histogram_4,\n\tsum(histogram_05) as histogram_5,\n\tsum(histogram_06) as histogram_6,\n\tsum(histogram_07) as histogram_7,\n\tsum(histogram_08) as histogram_8,\n\tsum(histogram_09) as histogram_9,\n\tsum(histogram_10) as histogram_10,\n\tsum(histogram_11) as histogram_11,\n\tsum(histogram_12) as histogram_12,\n\tround(sum(rank_1)/count(*),3) as rank_1,\n\tround(sum(rank_2)/count(*),3) as rank_2,\n\tround(sum(rank_3)/count(*),3) as rank_3,\n\tmin(mingrade) as mingradeemarking,\n\tmin(maxgrade) as maxgradeemarking\n\tfrom (\n\tselect\n\tround(ss.grade,2) as grade, -- Nota final (calculada o manual via calificador)\n\ti.grademax as maxgrade, -- Nota máxima del emarking\n\ti.grademin as mingrade, -- Nota mínima del emarking\n\tcase when ss.grade is null then 0 -- Indicador de si la nota es null\n\telse 1\n\tend as attended,\n\tcase when ss.grade >= i.gradepass then 1\n\telse 0\n\tend as pass,\n\tcase when ss.grade >= 0 AND ss.grade < i.grademin + (i.grademax - i.grademin) / 12 * 1 then 1 else 0 end as histogram_01,\n\tcase when ss.grade >= i.grademin + (i.grademax - i.grademin) / 12 * 1 AND ss.grade < i.grademin + (i.grademax - i.grademin) / 12 * 2 then 1 else 0 end as histogram_02,\n\tcase when ss.grade >= i.grademin + (i.grademax - i.grademin) / 12 * 2 AND ss.grade < i.grademin + (i.grademax - i.grademin) / 12 * 3 then 1 else 0 end as histogram_03,\n\tcase when ss.grade >= i.grademin + (i.grademax - i.grademin) / 12 * 3 AND ss.grade < i.grademin + (i.grademax - i.grademin) / 12 * 4 then 1 else 0 end as histogram_04,\n\tcase when ss.grade >= i.grademin + (i.grademax - i.grademin) / 12 * 4 AND ss.grade < i.grademin + (i.grademax - i.grademin) / 12 * 5 then 1 else 0 end as histogram_05,\n\tcase when ss.grade >= i.grademin + (i.grademax - i.grademin) / 12 * 5 AND ss.grade < i.grademin + (i.grademax - i.grademin) / 12 * 6 then 1 else 0 end as histogram_06,\n\tcase when ss.grade >= i.grademin + (i.grademax - i.grademin) / 12 * 6 AND ss.grade < i.grademin + (i.grademax - i.grademin) / 12 * 7 then 1 else 0 end as histogram_07,\n\tcase when ss.grade >= i.grademin + (i.grademax - i.grademin) / 12 * 7 AND ss.grade < i.grademin + (i.grademax - i.grademin) / 12 * 8 then 1 else 0 end as histogram_08,\n\tcase when ss.grade >= i.grademin + (i.grademax - i.grademin) / 12 * 8 AND ss.grade < i.grademin + (i.grademax - i.grademin) / 12 * 9 then 1 else 0 end as histogram_09,\n\tcase when ss.grade >= i.grademin + (i.grademax - i.grademin) / 12 * 9 AND ss.grade < i.grademin + (i.grademax - i.grademin) / 12 * 10 then 1 else 0 end as histogram_10,\n\tcase when ss.grade >= i.grademin + (i.grademax - i.grademin) / 12 * 10 AND ss.grade < i.grademin + (i.grademax - i.grademin) / 12 * 11 then 1 else 0 end as histogram_11,\n\tcase when ss.grade >= i.grademin + (i.grademax - i.grademin) / 12 * 11 then 1 else 0 end as histogram_12,\n\tcase when ss.grade - i.grademin < (i.grademax - i.grademin) / 3 then 1 else 0 end as rank_1,\n\tcase when ss.grade - i.grademin >= (i.grademax - i.grademin) / 3 AND ss.grade - i.grademin < (i.grademax - i.grademin) / 2 then 1 else 0 end as rank_2,\n\tcase when ss.grade - i.grademin >= (i.grademax - i.grademin) / 2 then 1 else 0 end as rank_3,\n\tc.category as categoryid,\n\tcc.name as categoryname,\n\ti.iteminstance as emarkingid,\n\ta.name as modulename,\n\tc.fullname as coursename\n\tfrom {grade_items} as i\n\tinner join {emarking} as a on (i.itemtype = 'mod' AND i.itemmodule = 'emarking' and i.iteminstance in ( '.{$ids}.') AND i.iteminstance = a.id)\n\tinner join {course} as c on (i.courseid = c.id)\n\tinner join {course_categories} as cc on (c.category = cc.id)\n\tinner join {emarking_submission} as ss on (a.id = ss.emarking)\n\twhere ss.grade is not null AND ss.status >= 20\n\torder by emarkingid asc, ss.grade asc) as G\n\tgroup by categoryid, emarkingid\n\twith rollup) as T"; $emarkingstats = $DB->get_recordset_sql($sql); $data = array(); foreach ($emarkingstats as $stats) { if ($totalcategories == 1 && !strncmp($stats->seriesname, 'SUBTOTAL', 8)) { continue; } if ($totalemarkings == 1 && !strncmp($stats->seriesname, 'TOTAL', 5)) { continue; } $histogram_courses = ''; $histogram_totals = ''; $histograms = array(); $histograms_totals = array(); $histogramlabels = array(); if (!strncmp($stats->seriesname, 'SUBTOTAL', 8) || !strncmp($stats->seriesname, 'TOTAL', 5)) { $histogram_totals .= "'{$stats->seriesname}',"; } else { $histogram_courses .= "'{$stats->seriesname} (N={$stats->students})',"; } for ($i = 1; $i <= 12; $i++) { $histogramvalue = ''; eval("\$histogramvalue = \$stats->histogram_{$i};"); if (!strncmp($stats->seriesname, 'SUBTOTAL', 8) || !strncmp($stats->seriesname, 'TOTAL', 5)) { if (!isset($histograms_totals[$i])) { $histograms_totals[$i] = $histogramvalue . ','; } else { $histograms_totals[$i] .= $histogramvalue . ','; } } else { if (!isset($histograms[$i])) { $histograms[$i] = $histogramvalue . ','; } else { $histograms[$i] .= $histogramvalue . ','; } } if ($i % 2 != 0) { if ($i <= 6) { $histogramlabels[$i] = '< ' . ($stats->mingradeemarking + ($stats->maxgradeemarking - $stats->mingradeemarking) / 12 * $i); } else { $histogramlabels[$i] = '>= ' . ($stats->mingradeemarking + ($stats->maxgradeemarking - $stats->mingradeemarking) / 12 * ($i - 1)); } } else { $histogramlabels[$i] = ''; } } $pass_ratio[] = array('seriesname' => $stats->seriesname . "(N=" . $stats->students . ")", 'rank1' => $stats->rank_1, 'rank2' => $stats->rank_2, 'rank3' => $stats->rank_3); // "['$stats->seriesname (N=$stats->students)',$stats->rank_1,$stats->rank_2,$stats->rank_3],"; } return $pass_ratio; }
// move the new outcome into correct category and fix sortorder if needed if ($grade_item) { $outcome_item->set_parent($grade_item->categoryid); $outcome_item->move_after_sortorder($grade_item->sortorder); } else if (isset($fromform->gradecat)) { $outcome_item->set_parent($fromform->gradecat); } } } } if (plugin_supports('mod', $fromform->modulename, FEATURE_ADVANCED_GRADING, false) and has_capability('moodle/grade:managegradingforms', $modcontext)) { require_once($CFG->dirroot.'/grade/grading/lib.php'); $gradingman = get_grading_manager($modcontext, 'mod_'.$fromform->modulename); $showgradingmanagement = false; foreach ($gradingman->get_available_areas() as $areaname => $aretitle) { $formfield = 'advancedgradingmethod_'.$areaname; if (isset($fromform->{$formfield})) { $gradingman->set_area($areaname); $methodchanged = $gradingman->set_active_method($fromform->{$formfield}); if (empty($fromform->{$formfield})) { // going back to the simple direct grading is not a reason // to open the management screen $methodchanged = false; } $showgradingmanagement = $showgradingmanagement || $methodchanged; } } }
/** * Returns the user's advanced grades for the specified grade item. * * @param grade_item $gradeitem * @param array $userids The user ids whose grades should be retrieved. * @return array|null */ protected function get_user_grades_advanced($gradeitem, array $userids) { // Users container. $users = array_fill_keys($userids, array()); // Grades container. $grades = array(); foreach ($users as $userid => $unused) { $grades[$userid] = (object) array('id' => $userid, 'userid' => $userid, 'rawgrade' => null); } $areaname = $gradeitem->gradingarea; $gradingman = get_grading_manager($df->context, 'mod_dataform', $areaname); $controller = $gradingman->get_active_controller(); if (empty($controller)) { return array(); } // Now get the gradefordisplay. $gradesmenu = make_grades_menu($gradeitem->grade); $controller->set_grade_range($gradesmenu, $gradeitem->grade > 0); $grade->gradefordisplay = $controller->render_grade($PAGE, $grade->id, $gradingitem, $grade->grade, $cangrade); //} else { // $grade->gradefordisplay = $this->display_grade($grade->grade, false); //} return $grades; }
/** * Get module information data required for updating the module. * * @param stdClass $cm course module object * @param stdClass $course course object * @return array required data for updating a module * @since Moodle 3.2 */ function get_moduleinfo_data($cm, $course) { global $CFG; list($cm, $context, $module, $data, $cw) = can_update_moduleinfo($cm); $data->coursemodule = $cm->id; $data->section = $cw->section; // The section number itself - relative!!! (section column in course_sections) $data->visible = $cm->visible; //?? $cw->visible ? $cm->visible : 0; // section hiding overrides $data->cmidnumber = $cm->idnumber; // The cm IDnumber $data->groupmode = groups_get_activity_groupmode($cm); // locked later if forced $data->groupingid = $cm->groupingid; $data->course = $course->id; $data->module = $module->id; $data->modulename = $module->name; $data->instance = $cm->instance; $data->completion = $cm->completion; $data->completionview = $cm->completionview; $data->completionexpected = $cm->completionexpected; $data->completionusegrade = is_null($cm->completiongradeitemnumber) ? 0 : 1; $data->showdescription = $cm->showdescription; $data->tags = core_tag_tag::get_item_tags_array('core', 'course_modules', $cm->id); if (!empty($CFG->enableavailability)) { $data->availabilityconditionsjson = $cm->availability; } if (plugin_supports('mod', $data->modulename, FEATURE_MOD_INTRO, true)) { $draftid_editor = file_get_submitted_draft_itemid('introeditor'); $currentintro = file_prepare_draft_area($draftid_editor, $context->id, 'mod_' . $data->modulename, 'intro', 0, array('subdirs' => true), $data->intro); $data->introeditor = array('text' => $currentintro, 'format' => $data->introformat, 'itemid' => $draftid_editor); } if (plugin_supports('mod', $data->modulename, FEATURE_ADVANCED_GRADING, false) and has_capability('moodle/grade:managegradingforms', $context)) { require_once $CFG->dirroot . '/grade/grading/lib.php'; $gradingman = get_grading_manager($context, 'mod_' . $data->modulename); $data->_advancedgradingdata['methods'] = $gradingman->get_available_methods(); $areas = $gradingman->get_available_areas(); foreach ($areas as $areaname => $areatitle) { $gradingman->set_area($areaname); $method = $gradingman->get_active_method(); $data->_advancedgradingdata['areas'][$areaname] = array('title' => $areatitle, 'method' => $method); $formfield = 'advancedgradingmethod_' . $areaname; $data->{$formfield} = $method; } } if ($items = grade_item::fetch_all(array('itemtype' => 'mod', 'itemmodule' => $data->modulename, 'iteminstance' => $data->instance, 'courseid' => $course->id))) { // Add existing outcomes. foreach ($items as $item) { if (!empty($item->outcomeid)) { $data->{'outcome_' . $item->outcomeid} = 1; } else { if (isset($item->gradepass)) { $decimalpoints = $item->get_decimals(); $data->gradepass = format_float($item->gradepass, $decimalpoints); } } } // set category if present $gradecat = false; foreach ($items as $item) { if ($gradecat === false) { $gradecat = $item->categoryid; continue; } if ($gradecat != $item->categoryid) { //mixed categories $gradecat = false; break; } } if ($gradecat !== false) { // do not set if mixed categories present $data->gradecat = $gradecat; } } return array($cm, $context, $module, $data, $cw); }
/** * Validates that there is a rubric set for the emarking activity. If there * isn't it shows a message and optionally buttons to create or import a rubric. * Optionally it will stop the page processing if no rubric is present. * * @param context $context * emarking context * @param boolean $die * die if there is no rubric * @param boolean $showrubricbuttons * show buttons to create and import rubric * @return multitype:unknown list($gradingmanager, $gradingmethod, $definition, * $rubriccontroller) */ function emarking_validate_rubric(context $context, $die, $showrubricbuttons) { global $OUTPUT, $CFG, $COURSE; require_once $CFG->dirroot . '/grade/grading/lib.php'; // Get rubric instance. $gradingmanager = get_grading_manager($context, 'mod_emarking', 'attempt'); $gradingmethod = $gradingmanager->get_active_method(); $definition = null; $rubriccontroller = null; if ($gradingmethod !== 'rubric') { $gradingmanager->set_active_method('rubric'); $gradingmethod = $gradingmanager->get_active_method(); } $rubriccontroller = $gradingmanager->get_controller($gradingmethod); $definition = $rubriccontroller->get_definition(); $managerubricurl = $gradingmanager->get_management_url(); $importrubricurl = new moodle_url("/mod/emarking/marking/importrubric.php", array("id" => $context->instanceid)); // Validate that activity has a rubric ready. if ($gradingmethod !== 'rubric' || !$definition || $definition == null) { if ($showrubricbuttons) { echo $OUTPUT->notification(get_string('rubricneeded', 'mod_emarking'), 'notifyproblem'); if (has_capability("mod/emarking:addinstance", $context)) { echo "<table>"; echo "<tr><td>" . $OUTPUT->single_button($managerubricurl, get_string('createrubric', 'mod_emarking'), "GET") . "</td>"; echo "<td>" . $OUTPUT->single_button($importrubricurl, get_string('importrubric', 'mod_emarking'), "GET") . "</td></tr>"; echo "</table>"; } } if ($die) { echo $OUTPUT->footer(); die; } } if (isset($definition->status)) { if ($definition->status == 10) { echo $OUTPUT->notification(get_string('rubricdraft', 'mod_emarking'), 'notifyproblem'); if (has_capability("mod/emarking:addinstance", $context)) { echo $OUTPUT->single_button($managerubricurl, get_string('completerubric', 'mod_emarking')); } } } return array($gradingmanager, $gradingmethod, $definition, $rubriccontroller); }
/** * Returns the instances and fillings for the requested definition id * * @param int $definitionid * @param int $since only return instances with timemodified >= since * @return array of grading instances with fillings for the definition id * @since Moodle 2.6 */ public static function get_gradingform_instances($definitionid, $since = 0) { global $DB, $CFG; require_once "{$CFG->dirroot}/grade/grading/form/lib.php"; $params = self::validate_parameters(self::get_gradingform_instances_parameters(), array('definitionid' => $definitionid, 'since' => $since)); $instances = array(); $warnings = array(); $definition = $DB->get_record('grading_definitions', array('id' => $params['definitionid']), 'areaid,method', MUST_EXIST); $area = $DB->get_record('grading_areas', array('id' => $definition->areaid), 'contextid,component', MUST_EXIST); $context = context::instance_by_id($area->contextid); require_capability('moodle/grade:managegradingforms', $context); $gradingmanager = get_grading_manager($definition->areaid); $controller = $gradingmanager->get_controller($definition->method); $activeinstances = $controller->get_all_active_instances($params['since']); $details = $controller->get_external_instance_filling_details(); if ($details == null) { $warnings[] = array('item' => 'definition', 'itemid' => $params['definitionid'], 'message' => 'Fillings unavailable because get_external_instance_filling_details is not defined', 'warningcode' => '1'); } $getfilling = null; if (method_exists('gradingform_' . $definition->method . '_instance', 'get_' . $definition->method . '_filling')) { $getfilling = 'get_' . $definition->method . '_filling'; } else { $warnings[] = array('item' => 'definition', 'itemid' => $params['definitionid'], 'message' => 'Fillings unavailable because get_' . $definition->method . '_filling is not defined', 'warningcode' => '1'); } foreach ($activeinstances as $activeinstance) { $instance = array(); $instance['id'] = $activeinstance->get_id(); $instance['raterid'] = $activeinstance->get_data('raterid'); $instance['itemid'] = $activeinstance->get_data('itemid'); $instance['rawgrade'] = $activeinstance->get_data('rawgrade'); $instance['status'] = $activeinstance->get_data('status'); $instance['feedback'] = $activeinstance->get_data('feedback'); $instance['feedbackformat'] = $activeinstance->get_data('feedbackformat'); // Format the feedback text field. $formattedtext = external_format_text($activeinstance->get_data('feedback'), $activeinstance->get_data('feedbackformat'), $context->id, $area->component, 'feedback', $params['definitionid']); $instance['feedback'] = $formattedtext[0]; $instance['feedbackformat'] = $formattedtext[1]; $instance['timemodified'] = $activeinstance->get_data('timemodified'); if ($details != null && $getfilling != null) { $fillingdata = $activeinstance->{$getfilling}(); $filling = array(); foreach ($details as $key => $value) { $filling[$key] = self::format_text($fillingdata[$key], $context->id, $area->component, $params['definitionid']); } $instance[$definition->method] = $filling; } $instances[] = $instance; } $result = array('instances' => $instances, 'warnings' => $warnings); return $result; }
/** * Common create/update module module actions that need to be processed as soon as a module is created/updaded. * For example:create grade parent category, add outcomes, rebuild caches, regrade, save plagiarism settings... * Please note this api does not trigger events as of MOODLE 2.6. Please trigger events before calling this api. * * @param object $moduleinfo the module info * @param object $course the course of the module * * @return object moduleinfo update with grading management info */ function edit_module_post_actions($moduleinfo, $course) { global $CFG; require_once $CFG->libdir . '/gradelib.php'; $modcontext = context_module::instance($moduleinfo->coursemodule); $hasgrades = plugin_supports('mod', $moduleinfo->modulename, FEATURE_GRADE_HAS_GRADE, false); $hasoutcomes = plugin_supports('mod', $moduleinfo->modulename, FEATURE_GRADE_OUTCOMES, true); // Sync idnumber with grade_item. if ($hasgrades && ($grade_item = grade_item::fetch(array('itemtype' => 'mod', 'itemmodule' => $moduleinfo->modulename, 'iteminstance' => $moduleinfo->instance, 'itemnumber' => 0, 'courseid' => $course->id)))) { if ($grade_item->idnumber != $moduleinfo->cmidnumber) { $grade_item->idnumber = $moduleinfo->cmidnumber; $grade_item->update(); } } if ($hasgrades) { $items = grade_item::fetch_all(array('itemtype' => 'mod', 'itemmodule' => $moduleinfo->modulename, 'iteminstance' => $moduleinfo->instance, 'courseid' => $course->id)); } else { $items = array(); } // Create parent category if requested and move to correct parent category. if ($items and isset($moduleinfo->gradecat)) { if ($moduleinfo->gradecat == -1) { $grade_category = new grade_category(); $grade_category->courseid = $course->id; $grade_category->fullname = $moduleinfo->name; $grade_category->insert(); if ($grade_item) { $parent = $grade_item->get_parent_category(); $grade_category->set_parent($parent->id); } $moduleinfo->gradecat = $grade_category->id; } $gradecategory = $grade_item->get_parent_category(); foreach ($items as $itemid => $unused) { $items[$itemid]->set_parent($moduleinfo->gradecat); if ($itemid == $grade_item->id) { // Use updated grade_item. $grade_item = $items[$itemid]; } if (!empty($moduleinfo->add)) { if (grade_category::aggregation_uses_aggregationcoef($gradecategory->aggregation)) { if ($gradecategory->aggregation == GRADE_AGGREGATE_WEIGHTED_MEAN) { $grade_item->aggregationcoef = 1; } else { $grade_item->aggregationcoef = 0; } $grade_item->update(); } } } } require_once $CFG->libdir . '/grade/grade_outcome.php'; // Add outcomes if requested. if ($hasoutcomes && ($outcomes = grade_outcome::fetch_all_available($course->id))) { $grade_items = array(); // Outcome grade_item.itemnumber start at 1000, there is nothing above outcomes. $max_itemnumber = 999; if ($items) { foreach ($items as $item) { if ($item->itemnumber > $max_itemnumber) { $max_itemnumber = $item->itemnumber; } } } foreach ($outcomes as $outcome) { $elname = 'outcome_' . $outcome->id; if (property_exists($moduleinfo, $elname) and $moduleinfo->{$elname}) { // So we have a request for new outcome grade item? if ($items) { $outcomeexists = false; foreach ($items as $item) { if ($item->outcomeid == $outcome->id) { $outcomeexists = true; break; } } if ($outcomeexists) { continue; } } $max_itemnumber++; $outcome_item = new grade_item(); $outcome_item->courseid = $course->id; $outcome_item->itemtype = 'mod'; $outcome_item->itemmodule = $moduleinfo->modulename; $outcome_item->iteminstance = $moduleinfo->instance; $outcome_item->itemnumber = $max_itemnumber; $outcome_item->itemname = $outcome->fullname; $outcome_item->outcomeid = $outcome->id; $outcome_item->gradetype = GRADE_TYPE_SCALE; $outcome_item->scaleid = $outcome->scaleid; $outcome_item->insert(); // Move the new outcome into correct category and fix sortorder if needed. if ($grade_item) { $outcome_item->set_parent($grade_item->categoryid); $outcome_item->move_after_sortorder($grade_item->sortorder); } else { if (isset($moduleinfo->gradecat)) { $outcome_item->set_parent($moduleinfo->gradecat); } } $gradecategory = $outcome_item->get_parent_category(); if ($outcomeexists == false) { if (grade_category::aggregation_uses_aggregationcoef($gradecategory->aggregation)) { if ($gradecategory->aggregation == GRADE_AGGREGATE_WEIGHTED_MEAN) { $outcome_item->aggregationcoef = 1; } else { $outcome_item->aggregationcoef = 0; } $outcome_item->update(); } } } } } if (plugin_supports('mod', $moduleinfo->modulename, FEATURE_ADVANCED_GRADING, false) and has_capability('moodle/grade:managegradingforms', $modcontext)) { require_once $CFG->dirroot . '/grade/grading/lib.php'; $gradingman = get_grading_manager($modcontext, 'mod_' . $moduleinfo->modulename); $showgradingmanagement = false; foreach ($gradingman->get_available_areas() as $areaname => $aretitle) { $formfield = 'advancedgradingmethod_' . $areaname; if (isset($moduleinfo->{$formfield})) { $gradingman->set_area($areaname); $methodchanged = $gradingman->set_active_method($moduleinfo->{$formfield}); if (empty($moduleinfo->{$formfield})) { // Going back to the simple direct grading is not a reason to open the management screen. $methodchanged = false; } $showgradingmanagement = $showgradingmanagement || $methodchanged; } } // Update grading management information. $moduleinfo->gradingman = $gradingman; $moduleinfo->showgradingmanagement = $showgradingmanagement; } rebuild_course_cache($course->id, true); if ($hasgrades) { grade_regrade_final_grades($course->id); } require_once $CFG->libdir . '/plagiarismlib.php'; plagiarism_save_form_elements($moduleinfo); return $moduleinfo; }
/** * Validates that there is a rubric set for the emarking activity * * @param unknown $context * emarking context * @param string $die * die if there is no rubric * @param string $showform * @return multitype:unknown list($gradingmanager, $gradingmethod) */ function emarking_validate_rubric($context, $die = true, $showform = true) { global $OUTPUT, $CFG, $COURSE; require_once $CFG->dirroot . '/grade/grading/lib.php'; // Get rubric instance $gradingmanager = get_grading_manager($context, 'mod_emarking', 'attempt'); $gradingmethod = $gradingmanager->get_active_method(); $definition = null; if ($gradingmethod === 'rubric') { $rubriccontroller = $gradingmanager->get_controller($gradingmethod); $definition = $rubriccontroller->get_definition(); } $managerubricurl = $gradingmanager->get_management_url(); // Validate that activity has a rubric ready if ($gradingmethod !== 'rubric' || !$definition || $definition == null) { if ($showform) { echo $OUTPUT->notification(get_string('rubricneeded', 'mod_emarking'), 'notifyproblem'); if (has_capability("mod/emarking:addinstance", $context)) { echo $OUTPUT->single_button($managerubricurl, get_string('createrubric', 'mod_emarking')); } } if ($die) { echo $OUTPUT->footer(); die; } } if (isset($definition->status)) { if ($definition->status == 10) { echo $OUTPUT->notification(get_string('rubricdraft', 'mod_emarking'), 'notifyproblem'); if (has_capability("mod/emarking:addinstance", $context)) { echo $OUTPUT->single_button($managerubricurl, get_string('completerubric', 'mod_emarking')); } } } return array($gradingmanager, $gradingmethod); }
/** * Override the default is_enabled to disable this plugin if advanced grading is active * * @return bool */ public function is_enabled() { if ($this->enabledcache === null) { $gradingmanager = get_grading_manager($this->assignment->get_context(), 'mod_assign', 'submissions'); $controller = $gradingmanager->get_active_controller(); $active = !empty($controller); if ($active) { $this->enabledcache = false; } else { $this->enabledcache = parent::is_enabled(); } } return $this->enabledcache; }
/** * * @param number $userid * @param number $levelid * @param string $levelfeedback * @param object $submission * @param object $draft * @param string $emarking * @param string $context * @param string $generalfeedback * @param string $delete * @param number $cmid * @return multitype:boolean |NULL|multitype:number NULL */ function emarking_set_finalgrade($userid = 0, $levelid = 0, $levelfeedback = '', $submission = null, $draft = null, $emarking = null, $context = null, $generalfeedback = null, $delete = false, $cmid = 0) { global $USER, $DB, $CFG; require_once $CFG->dirroot . '/grade/grading/lib.php'; // Validate parameters if ($userid == 0 || $levelid == 0 && $cmid == 0 || $draft == null || $submission == null || $context == null) { return array(false, false, false); } if ($levelid > 0) { // Firstly get the rubric definition id and criterion id from the level $rubricinfo = $DB->get_record_sql("\n\t\t\t\tSELECT c.definitionid, l.definition, l.criterionid, l.score, c.description\n\t\t\t\tFROM {gradingform_rubric_levels} as l\n\t\t\t\tINNER JOIN {gradingform_rubric_criteria} as c on (l.criterionid = c.id)\n\t\t\t\tWHERE l.id = ?", array($levelid)); } elseif ($cmid > 0) { // Firstly get the rubric definition id and criterion id from the level $rubricinfo = $DB->get_record_sql("\n\t\t\t\tSELECT\n\t\t\t\td.id as definitionid\n\t\t\t\tFROM {course_modules} AS c\n\t\t\t\tinner join {context} AS mc on (c.id = ? AND c.id = mc.instanceid)\n\t\t\t\tinner join {grading_areas} AS ar on (mc.id = ar.contextid)\n\t\t\t\tinner join {grading_definitions} AS d on (ar.id = d.areaid)\n\t\t\t\t", array($cmid)); } else { return null; } // Get the grading manager, then method and finally controller $gradingmanager = get_grading_manager($context, 'mod_emarking', 'attempt'); $gradingmethod = $gradingmanager->get_active_method(); $controller = $gradingmanager->get_controller($gradingmethod); $controller->set_grade_range(array("{$emarking->grademin}" => $emarking->grademin, "{$emarking->grade}" => $emarking->grade), true); $definition = $controller->get_definition(); // Get the grading instance we should already have $gradinginstancerecord = $DB->get_record('grading_instances', array('itemid' => $draft->id, 'definitionid' => $definition->id)); // Use the last marking rater id to get the instance $raterid = $USER->id; $itemid = null; if ($gradinginstancerecord) { if ($gradinginstancerecord->raterid > 0) { $raterid = $gradinginstancerecord->raterid; } $itemid = $gradinginstancerecord->id; } // Get or create grading instance (in case submission has not been graded) $gradinginstance = $controller->get_or_create_instance($itemid, $raterid, $draft->id); $rubricscores = $controller->get_min_max_score(); // Get the fillings and replace the new one accordingly $fillings = $gradinginstance->get_rubric_filling(); if ($levelid > 0) { if ($delete) { if (!($minlevel = $DB->get_record_sql(' SELECT id, score FROM {gradingform_rubric_levels} WHERE criterionid = ? ORDER BY score ASC LIMIT 1', array($rubricinfo->criterionid)))) { return array(false, false, false); } $newfilling = array("remark" => '', "levelid" => $minlevel->id); } else { $newfilling = array("remark" => $levelfeedback, "levelid" => $levelid); } if (isset($fillings['criteria'][$rubricinfo->criterionid]['levelid']) && isset($fillings['criteria'][$rubricinfo->criterionid]['remark'])) { $previouslvlid = $fillings['criteria'][$rubricinfo->criterionid]['levelid']; $previouscomment = $fillings['criteria'][$rubricinfo->criterionid]['remark']; } else { $previouslvlid = 0; $previouscomment = null; } $fillings['criteria'][$rubricinfo->criterionid] = $newfilling; } else { $previouslvlid = 0; $previouscomment = null; } $fillings['raterid'] = $raterid; $gradinginstance->update($fillings); $rawgrade = $gradinginstance->get_grade(); $previousfeedback = ''; $previousfeedback = $draft->generalfeedback == null ? '' : $draft->generalfeedback; if ($generalfeedback == null) { $generalfeedback = $previousfeedback; } $totalscore = emarking_get_totalscore($draft, $controller, $fillings); $finalgrade = emarking_calculate_grade($emarking, $totalscore, $rubricscores['maxscore']); $pendingregrades = $DB->count_records('emarking_regrade', array('draft' => $draft->id, 'accepted' => 0)); // Calculate grade for draft $draft->grade = $finalgrade; $draft->generalfeedback = $generalfeedback; $draft->status = $pendingregrades == 0 ? EMARKING_STATUS_GRADING : EMARKING_STATUS_REGRADING; $draft->timemodified = time(); $DB->update_record('emarking_draft', $draft); // Adds an entry in the grades history $grade_history = new stdClass(); $grade_history->draftid = $draft->id; $grade_history->grade = $finalgrade; $grade_history->score = $totalscore; $grade_history->bonus = 0; $grade_history->marker = $USER->id; $grade_history->timecreated = time(); $grade_history->timemodified = time(); $DB->insert_record('emarking_grade_history', $grade_history); // Aggregate grade for submission $drafts = $DB->get_records("emarking_draft", array("emarkingid" => $submission->emarking, "submissionid" => $submission->id)); $submission->generalfeedback = ''; $submission->grade = 0; foreach ($drafts as $d) { $submission->generalfeedback .= $d->generalfeedback; $submission->grade += $d->grade; } $submission->grade = $submission->grade / count($drafts); $submission->timemodified = time(); $DB->update_record('emarking_submission', $submission); return array($finalgrade, $previouslvlid, $previouscomment); }
$data->completion = $cm->completion; $data->completionview = $cm->completionview; $data->completionexpected = $cm->completionexpected; $data->completionusegrade = is_null($cm->completiongradeitemnumber) ? 0 : 1; $data->showdescription = $cm->showdescription; if (!empty($CFG->enableavailability)) { $data->availabilityconditionsjson = $cm->availability; } if (plugin_supports('mod', $data->modulename, FEATURE_MOD_INTRO, true)) { $draftid_editor = file_get_submitted_draft_itemid('introeditor'); $currentintro = file_prepare_draft_area($draftid_editor, $context->id, 'mod_' . $data->modulename, 'intro', 0, array('subdirs' => true), $data->intro); $data->introeditor = array('text' => $currentintro, 'format' => $data->introformat, 'itemid' => $draftid_editor); } if (plugin_supports('mod', $data->modulename, FEATURE_ADVANCED_GRADING, false) and has_capability('moodle/grade:managegradingforms', $context)) { require_once $CFG->dirroot . '/grade/grading/lib.php'; $gradingman = get_grading_manager($context, 'mod_' . $data->modulename); $data->_advancedgradingdata['methods'] = $gradingman->get_available_methods(); $areas = $gradingman->get_available_areas(); foreach ($areas as $areaname => $areatitle) { $gradingman->set_area($areaname); $method = $gradingman->get_active_method(); $data->_advancedgradingdata['areas'][$areaname] = array('title' => $areatitle, 'method' => $method); $formfield = 'advancedgradingmethod_' . $areaname; $data->{$formfield} = $method; } } if ($items = grade_item::fetch_all(array('itemtype' => 'mod', 'itemmodule' => $data->modulename, 'iteminstance' => $data->instance, 'courseid' => $course->id))) { // add existing outcomes foreach ($items as $item) { if (!empty($item->gradepass)) { $decimalpoints = $item->get_decimals();
/** * Checks if grading method allows quickgrade mode. At the moment it is hardcoded * that advanced grading methods do not allow quickgrade. * * Assignment type plugins are not allowed to override this method * * @param $cmid * @return boolean */ function quickgrade_mode_allowed($cmid) { global $CFG; require_once "{$CFG->dirroot}/grade/grading/lib.php"; $context = context_module::instance($cmid); if ($controller = get_grading_manager($context->id, 'mod_giportfolio', 'submission')->get_active_controller()) { return false; } return true; }
/** * Test get_definitions */ public function test_get_definitions() { global $DB, $CFG, $USER; $this->resetAfterTest(true); // Create a course and assignment. $coursedata['idnumber'] = 'idnumbercourse'; $coursedata['fullname'] = 'Lightwork Course'; $coursedata['summary'] = 'Lightwork Course description'; $coursedata['summaryformat'] = FORMAT_MOODLE; $course = self::getDataGenerator()->create_course($coursedata); $assigndata['course'] = $course->id; $assigndata['name'] = 'lightwork assignment'; $cm = self::getDataGenerator()->create_module('assign', $assigndata); // Create manual enrolment record. $manualenroldata['enrol'] = 'manual'; $manualenroldata['status'] = 0; $manualenroldata['courseid'] = $course->id; $enrolid = $DB->insert_record('enrol', $manualenroldata); // Create a teacher and give them capabilities. $coursecontext = context_course::instance($course->id); $roleid = $this->assignUserCapability('moodle/course:viewparticipants', $coursecontext->id, 3); $modulecontext = context_module::instance($cm->cmid); $this->assignUserCapability('mod/assign:grade', $modulecontext->id, $roleid); // Create the teacher's enrolment record. $userenrolmentdata['status'] = 0; $userenrolmentdata['enrolid'] = $enrolid; $userenrolmentdata['userid'] = $USER->id; $DB->insert_record('user_enrolments', $userenrolmentdata); // Create a grading area. $gradingarea = array( 'contextid' => $modulecontext->id, 'component' => 'mod_assign', 'areaname' => 'submissions', 'activemethod' => 'rubric' ); $areaid = $DB->insert_record('grading_areas', $gradingarea); // Create a rubric grading definition. $rubricdefinition = array ( 'areaid' => $areaid, 'method' => 'rubric', 'name' => 'test', 'status' => 20, 'copiedfromid' => 1, 'timecreated' => 1, 'usercreated' => $USER->id, 'timemodified' => 1, 'usermodified' => $USER->id, 'timecopied' => 0 ); $definitionid = $DB->insert_record('grading_definitions', $rubricdefinition); // Create a criterion with levels. $rubriccriteria1 = array ( 'definitionid' => $definitionid, 'sortorder' => 1, 'description' => 'Demonstrate an understanding of disease control', 'descriptionformat' => 0 ); $criterionid1 = $DB->insert_record('gradingform_rubric_criteria', $rubriccriteria1); $rubriclevel1 = array ( 'criterionid' => $criterionid1, 'score' => 5, 'definition' => 'pass', 'definitionformat' => 0 ); $DB->insert_record('gradingform_rubric_levels', $rubriclevel1); $rubriclevel2 = array ( 'criterionid' => $criterionid1, 'score' => 10, 'definition' => 'excellent', 'definitionformat' => 0 ); $DB->insert_record('gradingform_rubric_levels', $rubriclevel2); // Create a second criterion with levels. $rubriccriteria2 = array ( 'definitionid' => $definitionid, 'sortorder' => 2, 'description' => 'Demonstrate an understanding of brucellosis', 'descriptionformat' => 0 ); $criterionid2 = $DB->insert_record('gradingform_rubric_criteria', $rubriccriteria2); $rubriclevel1 = array ( 'criterionid' => $criterionid2, 'score' => 5, 'definition' => 'pass', 'definitionformat' => 0 ); $DB->insert_record('gradingform_rubric_levels', $rubriclevel1); $rubriclevel2 = array ( 'criterionid' => $criterionid2, 'score' => 10, 'definition' => 'excellent', 'definitionformat' => 0 ); $DB->insert_record('gradingform_rubric_levels', $rubriclevel2); // Call the external function. $cmids = array ($cm->cmid); $areaname = 'submissions'; $result = core_grading_external::get_definitions($cmids, $areaname); $this->assertEquals(1, count($result['areas'])); $this->assertEquals(1, count($result['areas'][0]['definitions'])); $definition = $result['areas'][0]['definitions'][0]; $this->assertEquals($rubricdefinition['method'], $definition['method']); $this->assertEquals($USER->id, $definition['usercreated']); require_once("$CFG->dirroot/grade/grading/lib.php"); require_once($CFG->dirroot.'/grade/grading/form/'.$rubricdefinition['method'].'/lib.php'); $gradingmanager = get_grading_manager($areaid); $this->assertEquals(1, count($definition[$rubricdefinition['method']])); $rubricdetails = $definition[$rubricdefinition['method']]; $details = call_user_func('gradingform_'.$rubricdefinition['method'].'_controller::get_external_definition_details'); $this->assertEquals(2, count($rubricdetails[key($details)])); $found = false; foreach ($rubricdetails[key($details)] as $criterion) { if ($criterion['id'] == $criterionid1) { $this->assertEquals($rubriccriteria1['description'], $criterion['description']); $this->assertEquals(2, count($criterion['levels'])); $found = true; break; } } $this->assertTrue($found); }
} // Page navigation and URL settings $PAGE->set_url($urlemarking); $PAGE->set_context($context); $PAGE->set_course($course); $PAGE->set_pagelayout('incourse'); $PAGE->set_cm($cm); $PAGE->set_heading($course->fullname); $PAGE->navbar->add(get_string('emarking', 'mod_emarking')); // Show header and heading echo $OUTPUT->header(); echo $OUTPUT->heading_with_help(get_string('emarking', 'mod_emarking'), 'annotatesubmission', 'mod_emarking'); // Navigation tabs echo $OUTPUT->tabtree(emarking_tabs($context, $cm, $emarking), "mark"); // Get rubric instance $gradingmanager = get_grading_manager($context, 'mod_emarking', 'attempt'); $gradingmethod = $gradingmanager->get_active_method(); // Validate that activity has a rubric ready if ($gradingmethod !== 'rubric') { $managerubricurl = new moodle_url('/grade/grading/manage.php', array('contextid' => $context->id, 'component' => 'mod_emarking', 'area' => 'attempt')); echo $OUTPUT->notification(get_string('rubricneeded', 'mod_emarking'), 'notifyproblem'); echo $OUTPUT->single_button($managerubricurl, get_string('createrubric', 'mod_emarking')); echo $OUTPUT->footer(); die; } // User filter checking capabilities. If user can not grade, then she can not // see other users $userfilter = 'WHERE 1=1 '; if (!$usercangrade) { $userfilter .= 'AND ue.userid = ' . $USER->id; }
/** * Display a single submission, ready for grading on a popup window * * This default method prints the teacher info and submissioncomment box at the top and * the student info and submission at the bottom. * This method also fetches the necessary data in order to be able to * provide a "Next submission" button. * Calls preprocess_submission() to give assignment type plug-ins a chance * to process submissions before they are graded * This method gets its arguments from the page parameters userid and offset * * @global object * @global object * @param string $extra_javascript */ function display_submission($offset = -1, $userid = -1, $display = true) { global $CFG, $DB, $PAGE, $OUTPUT, $USER; require_once $CFG->libdir . '/gradelib.php'; require_once $CFG->libdir . '/tablelib.php'; require_once "{$CFG->dirroot}/repository/lib.php"; require_once "{$CFG->dirroot}/grade/grading/lib.php"; if ($userid == -1) { $userid = required_param('userid', PARAM_INT); } if ($offset == -1) { $offset = required_param('offset', PARAM_INT); //offset for where to start looking for student. } $filter = optional_param('filter', 0, PARAM_INT); if (!($user = $DB->get_record('user', array('id' => $userid)))) { print_error('nousers'); } if (!($submission = $this->get_submission($user->id))) { $submission = $this->prepare_new_submission($userid); } if ($submission->timemodified > $submission->timemarked) { $subtype = 'assignmentnew'; } else { $subtype = 'assignmentold'; } $grading_info = grade_get_grades($this->course->id, 'mod', 'assignment', $this->assignment->id, array($user->id)); $gradingdisabled = $grading_info->items[0]->grades[$userid]->locked || $grading_info->items[0]->grades[$userid]->overridden; /// construct SQL, using current offset to find the data of the next student $course = $this->course; $assignment = $this->assignment; $cm = $this->cm; $context = get_context_instance(CONTEXT_MODULE, $cm->id); //reset filter to all for offline assignment if ($assignment->assignmenttype == 'offline' && $filter == self::FILTER_SUBMITTED) { $filter = self::FILTER_ALL; } /// Get all ppl that can submit assignments $currentgroup = groups_get_activity_group($cm); $users = get_enrolled_users($context, 'mod/assignment:submit', $currentgroup, 'u.id'); if ($users) { $users = array_keys($users); // if groupmembersonly used, remove users who are not in any group if (!empty($CFG->enablegroupmembersonly) and $cm->groupmembersonly) { if ($groupingusers = groups_get_grouping_members($cm->groupingid, 'u.id', 'u.id')) { $users = array_intersect($users, array_keys($groupingusers)); } } } $nextid = 0; $where = ''; if ($filter == self::FILTER_SUBMITTED) { $where .= 's.timemodified > 0 AND '; } else { if ($filter == self::FILTER_REQUIRE_GRADING) { $where .= 's.timemarked < s.timemodified AND '; } } if ($users) { $userfields = user_picture::fields('u', array('lastaccess')); $select = "SELECT {$userfields},\n s.id AS submissionid, s.grade, s.submissioncomment,\n s.timemodified, s.timemarked,\n CASE WHEN s.timemarked > 0 AND s.timemarked >= s.timemodified THEN 1\n ELSE 0 END AS status "; $sql = 'FROM {user} u ' . 'LEFT JOIN {assignment_submissions} s ON u.id = s.userid AND s.assignment = ' . $this->assignment->id . ' ' . 'WHERE ' . $where . 'u.id IN (' . implode(',', $users) . ') '; if ($sort = flexible_table::get_sort_for_table('mod-assignment-submissions')) { $sort = 'ORDER BY ' . $sort . ' '; } $auser = $DB->get_records_sql($select . $sql . $sort, null, $offset, 2); if (is_array($auser) && count($auser) > 1) { $nextuser = next($auser); $nextid = $nextuser->id; } } if ($submission->teacher) { $teacher = $DB->get_record('user', array('id' => $submission->teacher)); } else { global $USER; $teacher = $USER; } $this->preprocess_submission($submission); $mformdata = new stdClass(); $mformdata->context = $this->context; $mformdata->maxbytes = $this->course->maxbytes; $mformdata->courseid = $this->course->id; $mformdata->teacher = $teacher; $mformdata->assignment = $assignment; $mformdata->submission = $submission; $mformdata->lateness = $this->display_lateness($submission->timemodified); $mformdata->auser = $auser; $mformdata->user = $user; $mformdata->offset = $offset; $mformdata->userid = $userid; $mformdata->cm = $this->cm; $mformdata->grading_info = $grading_info; $mformdata->enableoutcomes = $CFG->enableoutcomes; $mformdata->grade = $this->assignment->grade; $mformdata->gradingdisabled = $gradingdisabled; $mformdata->nextid = $nextid; $mformdata->submissioncomment = $submission->submissioncomment; $mformdata->submissioncommentformat = FORMAT_HTML; $mformdata->submission_content = $this->print_user_files($user->id, true); $mformdata->filter = $filter; $mformdata->mailinfo = get_user_preferences('assignment_mailinfo', 0); if ($assignment->assignmenttype == 'upload') { $mformdata->fileui_options = array('subdirs' => 1, 'maxbytes' => $assignment->maxbytes, 'maxfiles' => $assignment->var1, 'accepted_types' => '*', 'return_types' => FILE_INTERNAL); } elseif ($assignment->assignmenttype == 'uploadsingle') { $mformdata->fileui_options = array('subdirs' => 0, 'maxbytes' => $CFG->userquota, 'maxfiles' => 1, 'accepted_types' => '*', 'return_types' => FILE_INTERNAL); } $advancedgradingwarning = false; $gradingmanager = get_grading_manager($this->context, 'mod_assignment', 'submission'); if ($gradingmethod = $gradingmanager->get_active_method()) { $controller = $gradingmanager->get_controller($gradingmethod); if ($controller->is_form_available()) { $itemid = null; if (!empty($submission->id)) { $itemid = $submission->id; } if ($gradingdisabled && $itemid) { $mformdata->advancedgradinginstance = $controller->get_current_instance($USER->id, $itemid); } else { if (!$gradingdisabled) { $instanceid = optional_param('advancedgradinginstanceid', 0, PARAM_INT); $mformdata->advancedgradinginstance = $controller->get_or_create_instance($instanceid, $USER->id, $itemid); } } } else { $advancedgradingwarning = $controller->form_unavailable_notification(); } } $submitform = new assignment_grading_form(null, $mformdata); if (!$display) { $ret_data = new stdClass(); $ret_data->mform = $submitform; if (isset($mformdata->fileui_options)) { $ret_data->fileui_options = $mformdata->fileui_options; } return $ret_data; } if ($submitform->is_cancelled()) { redirect('submissions.php?id=' . $this->cm->id); } $submitform->set_data($mformdata); $PAGE->set_title($this->course->fullname . ': ' . get_string('feedback', 'assignment') . ' - ' . fullname($user, true)); $PAGE->set_heading($this->course->fullname); $PAGE->navbar->add(get_string('submissions', 'assignment'), new moodle_url('/mod/assignment/submissions.php', array('id' => $cm->id))); $PAGE->navbar->add(fullname($user, true)); echo $OUTPUT->header(); echo $OUTPUT->heading(get_string('feedback', 'assignment') . ': ' . fullname($user, true)); // display mform here... if ($advancedgradingwarning) { echo $OUTPUT->notification($advancedgradingwarning, 'error'); } $submitform->display(); $customfeedback = $this->custom_feedbackform($submission, true); if (!empty($customfeedback)) { echo $customfeedback; } echo $OUTPUT->footer(); }
foreach ($tokens as $token) { list($methodsql, $methodparams) = $targetcontrollerclass::sql_search_where($token); $subsql = array_merge($subsql, $methodsql); $params = array_merge($params, $methodparams); } $sql .= " AND ((" . join(")\n OR (", $subsql) . "))"; } $sql .= " ORDER BY gd.name"; $rs = $DB->get_recordset_sql($sql, $params); echo $output->header(); $searchform->display(); $found = 0; foreach ($rs as $template) { $found++; $out = ''; $manager = get_grading_manager($template->areaid); $controller = $manager->get_controller($method); if ($controller->is_shared_template()) { $templatetag = html_writer::tag('span', get_string('templatetypeshared', 'core_grading'), array('class' => 'type shared')); $templatesrc = ''; } else { if ($controller->is_own_form()) { $templatetag = html_writer::tag('span', get_string('templatetypeown', 'core_grading'), array('class' => 'type ownform')); $templatesrc = get_string('templatesource', 'core_grading', array('component' => $manager->get_component_title(), 'area' => $manager->get_area_title())); } else { throw new coding_exception('Something is wrong, the displayed form must be either template or own form'); } } $out .= $output->heading(s($template->name) . ' ' . $templatetag, 2, 'template-name'); $out .= $output->container($templatesrc, 'template-source'); $out .= $output->box($controller->render_preview($PAGE), 'template-preview');
// // You should have received a copy of the GNU General Public License // along with Moodle. If not, see <http://www.gnu.org/licenses/>. /** * Rubric editor page * * @package gradingform_guide * @copyright 2012 Dan Marsden <*****@*****.**> * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later */ require_once dirname(dirname(dirname(dirname(dirname(__FILE__))))) . '/config.php'; require_once dirname(__FILE__) . '/lib.php'; require_once dirname(__FILE__) . '/edit_form.php'; require_once $CFG->dirroot . '/grade/grading/lib.php'; $areaid = required_param('areaid', PARAM_INT); $manager = get_grading_manager($areaid); list($context, $course, $cm) = get_context_info_array($manager->get_context()->id); require_login($course, true, $cm); require_capability('moodle/grade:managegradingforms', $context); $controller = $manager->get_controller('guide'); $PAGE->set_url(new moodle_url('/grade/grading/form/guide/edit.php', array('areaid' => $areaid))); $PAGE->set_title(get_string('definemarkingguide', 'gradingform_guide')); $PAGE->set_heading(get_string('definemarkingguide', 'gradingform_guide')); $mform = new gradingform_guide_editguide(null, array('areaid' => $areaid, 'context' => $context, 'allowdraft' => !$controller->has_active_instances()), 'post', '', array('class' => 'gradingform_guide_editform')); $data = $controller->get_definition_for_editing(true); $returnurl = optional_param('returnurl', $manager->get_management_url(), PARAM_LOCALURL); $data->returnurl = $returnurl; $mform->set_data($data); if ($mform->is_cancelled()) { redirect($returnurl); } else {
private function create_marker_module($markerid) { global $CFG, $DB; require_once $CFG->dirroot . '/lib/phpunit/classes/util.php'; // Start transaction. $transaction = $DB->start_delegated_transaction(); try { // Get generator. $generator = phpunit_util::get_data_generator(); /**@var mod_emarking_generator $emarking_generator*/ $emarking_generator = $generator->get_plugin_generator('mod_emarking'); $blueprint = $DB->get_record('emarking', array("id" => $this->cm->instance)); $blueprint->timecreated = time(); $originalname = $blueprint->name; $markers = get_users_by_capability($this->context, 'mod/emarking:grade', 'u.id,u.username'); $marker = $markers[$markerid]; if (!$marker) { throw new Exception("Marker not found"); } $previous = $DB->get_record('emarking_markers', array('masteractivity' => $this->parentcm->instance, 'markerid' => $markerid)); if ($previous) { throw new Exception("Delete previous marker record before assigning a new one"); } $submissions = $DB->get_records('emarking_submission', array("emarking" => $this->cm->instance)); $pages = array(); foreach ($submissions as $sub) { $pages[$sub->id] = $DB->get_records('emarking_page', array("submission" => $sub->id)); } unset($blueprint->id); $blueprint->name = $originalname . " -- " . $marker->username; $inserted = $emarking_generator->create_instance($blueprint, array("visible" => 0)); $markermap = new stdClass(); $markermap->masteractivity = $this->parentcm->instance; $markermap->markerid = $marker->id; $markermap->activityid = $inserted->id; $DB->insert_record('emarking_markers', $markermap); // se agrega el grading method correcto. require_once $CFG->dirroot . '/grade/grading/lib.php'; $gradingman = get_grading_manager(context_module::instance($inserted->cmid), 'mod_emarking'); $gradingman->set_area("attempt"); $gradingman->set_active_method("rubric"); emarking_grade_item_update($inserted); //Now replicate submissions foreach ($submissions as $sub) { $insertable = clone $sub; unset($insertable->id); $insertable->emarking = $inserted->id; $id = $DB->insert_record('emarking_submission', $insertable); foreach ($pages[$sub->id] as $subpage) { $insertablepage = clone $subpage; unset($insertablepage->id); $insertablepage->submission = $id; $DB->insert_record('emarking_page', $insertablepage); } // Update the raw grade of the user $grade_item = grade_item::fetch(array('itemtype' => 'mod', 'itemmodule' => 'emarking', 'iteminstance' => $inserted->id)); $grade = $grade_item->get_grade($insertable->student, true); $grade_item->update_final_grade($insertable->student, null, 'upload', '', FORMAT_HTML, $marker->id); // grade } $transaction->allow_commit(); } catch (Exception $e) { $transaction->rollback($e); } }
/** * Get an instance of a grading form if advanced grading is enabled. * This is specific to the assignment, marker and student. * * @param int $userid - The student userid * @param stdClass|false $grade - The grade record * @param bool $gradingdisabled * @return mixed gradingform_instance|null $gradinginstance */ protected function get_grading_instance($userid, $grade, $gradingdisabled) { global $CFG, $USER; $grademenu = make_grades_menu($this->get_instance()->grade); $allowgradedecimals = $this->get_instance()->grade > 0; $advancedgradingwarning = false; $gradingmanager = get_grading_manager($this->context, 'mod_assign', 'submissions'); $gradinginstance = null; if ($gradingmethod = $gradingmanager->get_active_method()) { $controller = $gradingmanager->get_controller($gradingmethod); if ($controller->is_form_available()) { $itemid = null; if ($grade) { $itemid = $grade->id; } if ($gradingdisabled && $itemid) { $gradinginstance = $controller->get_current_instance($USER->id, $itemid); } else { if (!$gradingdisabled) { $instanceid = optional_param('advancedgradinginstanceid', 0, PARAM_INT); $gradinginstance = $controller->get_or_create_instance($instanceid, $USER->id, $itemid); } } } else { $advancedgradingwarning = $controller->form_unavailable_notification(); } } if ($gradinginstance) { $gradinginstance->get_controller()->set_grade_range($grademenu, $allowgradedecimals); } return $gradinginstance; }
/** * Saves the areas and definitions * @param array $areas array of areas containing definitions to be saved * @return null * @throws invalid_parameter_exception * @since Moodle 2.8 */ public static function save_definitions($areas) { $params = self::validate_parameters(self::save_definitions_parameters(), array('areas' => $areas)); foreach ($params['areas'] as $area) { $context = context::instance_by_id($area['contextid']); require_capability('moodle/grade:managegradingforms', $context); $gradingmanager = get_grading_manager($context, $area['component'], $area['areaname']); $gradingmanager->set_active_method($area['activemethod']); $availablemethods = $gradingmanager->get_available_methods(); foreach ($area['definitions'] as $definition) { if (array_key_exists($definition['method'], $availablemethods)) { $controller = $gradingmanager->get_controller($definition['method']); $controller->update_definition(self::create_definition_object($definition)); } else { throw new invalid_parameter_exception('Unknown Grading method: ' . $definition['method']); } } } }
/** * This function calls the module function to inject module settings into the * settings navigation tree. * * This only gets called if there is a corrosponding function in the modules * lib file. * * For examples mod/forum/lib.php {@link forum_extend_settings_navigation()} * * @return navigation_node|false */ protected function load_module_settings() { global $CFG; if (!$this->page->cm && $this->context->contextlevel == CONTEXT_MODULE && $this->context->instanceid) { $cm = get_coursemodule_from_id(false, $this->context->instanceid, 0, false, MUST_EXIST); $this->page->set_cm($cm, $this->page->course); } $file = $CFG->dirroot . '/mod/' . $this->page->activityname . '/lib.php'; if (file_exists($file)) { require_once $file; } $modulenode = $this->add(get_string('pluginadministration', $this->page->activityname)); $modulenode->force_open(); // Settings for the module if (has_capability('moodle/course:manageactivities', $this->page->cm->context)) { $url = new moodle_url('/course/modedit.php', array('update' => $this->page->cm->id, 'return' => true, 'sesskey' => sesskey())); $modulenode->add(get_string('editsettings'), $url, navigation_node::TYPE_SETTING, null, 'modedit'); } // Assign local roles if (count(get_assignable_roles($this->page->cm->context)) > 0) { $url = new moodle_url('/' . $CFG->admin . '/roles/assign.php', array('contextid' => $this->page->cm->context->id)); $modulenode->add(get_string('localroles', 'role'), $url, self::TYPE_SETTING, null, 'roleassign'); } // Override roles if (has_capability('moodle/role:review', $this->page->cm->context) or count(get_overridable_roles($this->page->cm->context)) > 0) { $url = new moodle_url('/' . $CFG->admin . '/roles/permissions.php', array('contextid' => $this->page->cm->context->id)); $modulenode->add(get_string('permissions', 'role'), $url, self::TYPE_SETTING, null, 'roleoverride'); } // Check role permissions if (has_any_capability(array('moodle/role:assign', 'moodle/role:safeoverride', 'moodle/role:override', 'moodle/role:assign'), $this->page->cm->context)) { $url = new moodle_url('/' . $CFG->admin . '/roles/check.php', array('contextid' => $this->page->cm->context->id)); $modulenode->add(get_string('checkpermissions', 'role'), $url, self::TYPE_SETTING, null, 'rolecheck'); } // Manage filters if (has_capability('moodle/filter:manage', $this->page->cm->context) && count(filter_get_available_in_context($this->page->cm->context)) > 0) { $url = new moodle_url('/filter/manage.php', array('contextid' => $this->page->cm->context->id)); $modulenode->add(get_string('filters', 'admin'), $url, self::TYPE_SETTING, null, 'filtermanage'); } // Add reports $reports = get_plugin_list_with_function('report', 'extend_navigation_module', 'lib.php'); foreach ($reports as $reportfunction) { $reportfunction($modulenode, $this->page->cm); } // Add a backup link $featuresfunc = $this->page->activityname . '_supports'; if (function_exists($featuresfunc) && $featuresfunc(FEATURE_BACKUP_MOODLE2) && has_capability('moodle/backup:backupactivity', $this->page->cm->context)) { $url = new moodle_url('/backup/backup.php', array('id' => $this->page->cm->course, 'cm' => $this->page->cm->id)); $modulenode->add(get_string('backup'), $url, self::TYPE_SETTING, null, 'backup'); } // Restore this activity $featuresfunc = $this->page->activityname . '_supports'; if (function_exists($featuresfunc) && $featuresfunc(FEATURE_BACKUP_MOODLE2) && has_capability('moodle/restore:restoreactivity', $this->page->cm->context)) { $url = new moodle_url('/backup/restorefile.php', array('contextid' => $this->page->cm->context->id)); $modulenode->add(get_string('restore'), $url, self::TYPE_SETTING, null, 'restore'); } // Allow the active advanced grading method plugin to append its settings $featuresfunc = $this->page->activityname . '_supports'; if (function_exists($featuresfunc) && $featuresfunc(FEATURE_ADVANCED_GRADING) && has_capability('moodle/grade:managegradingforms', $this->page->cm->context)) { require_once $CFG->dirroot . '/grade/grading/lib.php'; $gradingman = get_grading_manager($this->page->cm->context, $this->page->activityname); $gradingman->extend_settings_navigation($this, $modulenode); } $function = $this->page->activityname . '_extend_settings_navigation'; if (!function_exists($function)) { return $modulenode; } $function($this, $modulenode); // Remove the module node if there are no children if (empty($modulenode->children)) { $modulenode->remove(); } return $modulenode; }
/** * * @param unknown $emarking * @param number $userid * @return void|boolean */ function emarking_calculate_grades_users($emarking, $userid = 0) { global $DB, $USER, $CFG; require_once $CFG->dirroot . '/grade/grading/lib.php'; if (!($cm = get_coursemodule_from_instance('emarking', $emarking->id))) { return; } if ($emarking->type != EMARKING_TYPE_ON_SCREEN_MARKING && $emarking->type != EMARKING_TYPE_PEER_REVIEW) { return; } $context = context_module::instance($cm->id); // Get the grading manager, then method and finally controller. $gradingmanager = get_grading_manager($context, 'mod_emarking', 'attempt'); $gradingmethod = $gradingmanager->get_active_method(); $controller = $gradingmanager->get_controller($gradingmethod); $range = $controller->get_grade_range(); $rubricscores = $controller->get_min_max_score(); $totalrubricscore = $rubricscores['maxscore']; $filter = 'WHERE 1=1'; if ($userid > 0) { $filter = 'WHERE es.student = ' . $userid; } $studentscores = $DB->get_records_sql("\n\t\t\tSELECT es.id,\n\t\t\tes.student,\n\t d.id as draftid,\n\t\t\tsum(ifnull(rl.score,0)) as score,\n\t\t\tsum(ifnull(ec.bonus,0)) as bonus,\n\t\t\tsum(ifnull(rl.score,0)) + sum(ifnull(ec.bonus,0)) as totalscore\n\t\t\tFROM {emarking_submission} es\n\t\t\tINNER JOIN {emarking_page} ep ON (es.emarking = :emarking AND ep.submission = es.id)\n\t\t\tINNER JOIN {emarking_draft} d ON (d.submissionid = es.id AND d.qualitycontrol = 0)\n\t\t\tLEFT JOIN {emarking_comment} ec ON (ec.page = ep.id AND ec.levelid > 0 AND ec.draft = d.id)\n\t\t\tLEFT JOIN {gradingform_rubric_levels} rl ON (ec.levelid = rl.id)\n\t\t\t{$filter}\n\t\t\tAND d.status >= 10\n\t AND rl.id IS NOT NULL\n\t\t\tGROUP BY es.emarking, es.id", array('emarking' => $emarking->id)); foreach ($studentscores as $studentscore) { $totalscore = min(floatval($studentscore->totalscore), $totalrubricscore); $finalgrade = emarking_calculate_grade($emarking, $totalscore, $totalrubricscore); $submission = $DB->get_record('emarking_submission', array('id' => $studentscore->id)); $submission->grade = $finalgrade; $DB->update_record('emarking_submission', $submission); $draft = $DB->get_record('emarking_draft', array('id' => $studentscore->draftid)); $draft->grade = $finalgrade; $DB->update_record('emarking_draft', $draft); } return true; }