Permalink
Browse files

MDL-30162 The grading method can be selected when creating new instan…

…ce of the activity module
  • Loading branch information...
1 parent b2c16c6 commit bb50c376512161cd277c3584651250612e3b9e75 @mudrd8mz mudrd8mz committed Nov 8, 2011
Showing with 63 additions and 17 deletions.
  1. +16 −0 course/modedit.php
  2. +47 −17 grade/grading/lib.php
View
@@ -86,6 +86,22 @@
$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
@@ -220,20 +220,13 @@ public function load($areaid) {
}
/**
- * 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'));
@@ -249,6 +242,48 @@ public function get_available_methods($includenone = true) {
}
/**
+ * 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
*
* This performs a callback to the library of the relevant plugin to obtain
@@ -267,14 +302,9 @@ public function get_available_areas() {
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');

0 comments on commit bb50c37

Please sign in to comment.