MDL-30162 The grading method can be selected when creating new instance of the activity module

This commit is contained in:
David Mudrak 2011-11-08 01:54:36 +01:00
parent b2c16c6e51
commit bb50c37651
2 changed files with 63 additions and 17 deletions

View File

@ -86,6 +86,22 @@ if (!empty($add)) {
$data->introeditor = array('text'=>'', 'format'=>FORMAT_HTML, 'itemid'=>$draftid_editor); // TODO: add better default
}
if (plugin_supports('mod', $data->modulename, FEATURE_ADVANCED_GRADING, false)) {
require_once($CFG->dirroot.'/grade/grading/lib.php');
$data->_advancedgradingdata['methods'] = grading_manager::available_methods();
$areas = grading_manager::available_areas('mod_'.$module->name);
foreach ($areas as $areaname => $areatitle) {
$data->_advancedgradingdata['areas'][$areaname] = array(
'title' => $areatitle,
'method' => '',
);
$formfield = 'advancedgradingmethod_'.$areaname;
$data->{$formfield} = '';
}
}
if (!empty($type)) { //TODO: hopefully will be removed in 2.0
$data->type = $type;
}

View File

@ -220,20 +220,13 @@ class grading_manager {
}
/**
* Returns the list of available grading methods in the given context
*
* Basically this returns the list of installed grading plugins with an empty value
* for simple direct grading. In the future, the list of available methods may be
* controlled per-context.
*
* Requires the context property to be set in advance.
* Returns the list of installed grading plugins together, optionally extended
* with a simple direct grading.
*
* @param bool $includenone should the 'Simple direct grading' be included
* @return array of the (string)name => (string)localized title of the method
*/
public function get_available_methods($includenone = true) {
$this->ensure_isset(array('context'));
public static function available_methods($includenone = true) {
if ($includenone) {
$list = array('' => get_string('gradingmethodnone', 'core_grading'));
@ -248,6 +241,48 @@ class grading_manager {
return $list;
}
/**
* Returns the list of available grading methods in the given context
*
* Currently this is just a static list obtained from {@link self::available_methods()}.
* In the future, the list of available methods may be controlled per-context.
*
* Requires the context property to be set in advance.
*
* @param bool $includenone should the 'Simple direct grading' be included
* @return array of the (string)name => (string)localized title of the method
*/
public function get_available_methods($includenone = true) {
$this->ensure_isset(array('context'));
return self::available_methods($includenone);
}
/**
* Returns the list of gradable areas provided by the given component
*
* This performs a callback to the library of the relevant plugin to obtain
* the list of supported areas.
*
* @param string $component normalized component name
* @return array of (string)areacode => (string)localized title of the area
*/
public static function available_areas($component) {
global $CFG;
list($plugintype, $pluginname) = normalize_component($component);
if ($component === 'core_grading') {
return array();
} else if ($plugintype === 'mod') {
return plugin_callback('mod', $pluginname, 'grading', 'areas_list', null, array());
} else {
throw new coding_exception('Unsupported area location');
}
}
/**
* Returns the list of gradable areas in the given context and component
*
@ -267,14 +302,9 @@ class grading_manager {
return array();
}
} else if ($this->get_context()->contextlevel >= CONTEXT_COURSE) {
} else if ($this->get_context()->contextlevel == CONTEXT_MODULE) {
list($context, $course, $cm) = get_context_info_array($this->get_context()->id);
if (empty($cm->modname)) {
throw new coding_exception('Unsupported area location');
} else {
return plugin_callback('mod', $cm->modname, 'grading', 'areas_list', null, array());
}
return self::available_areas('mod_'.$cm->modname);
} else {
throw new coding_exception('Unsupported gradable area context level');