Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse code

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

…ce of the activity module
  • Loading branch information...
commit bb50c376512161cd277c3584651250612e3b9e75 1 parent b2c16c6
David Mudrák mudrd8mz authored

Showing 2 changed files with 63 additions and 17 deletions. Show diff stats Hide diff stats

  1. +16 0 course/modedit.php
  2. +47 17 grade/grading/lib.php
16 course/modedit.php
@@ -86,6 +86,22 @@
86 86 $data->introeditor = array('text'=>'', 'format'=>FORMAT_HTML, 'itemid'=>$draftid_editor); // TODO: add better default
87 87 }
88 88
  89 + if (plugin_supports('mod', $data->modulename, FEATURE_ADVANCED_GRADING, false)) {
  90 + require_once($CFG->dirroot.'/grade/grading/lib.php');
  91 +
  92 + $data->_advancedgradingdata['methods'] = grading_manager::available_methods();
  93 + $areas = grading_manager::available_areas('mod_'.$module->name);
  94 +
  95 + foreach ($areas as $areaname => $areatitle) {
  96 + $data->_advancedgradingdata['areas'][$areaname] = array(
  97 + 'title' => $areatitle,
  98 + 'method' => '',
  99 + );
  100 + $formfield = 'advancedgradingmethod_'.$areaname;
  101 + $data->{$formfield} = '';
  102 + }
  103 + }
  104 +
89 105 if (!empty($type)) { //TODO: hopefully will be removed in 2.0
90 106 $data->type = $type;
91 107 }
64 grade/grading/lib.php
@@ -220,20 +220,13 @@ public function load($areaid) {
220 220 }
221 221
222 222 /**
223   - * Returns the list of available grading methods in the given context
224   - *
225   - * Basically this returns the list of installed grading plugins with an empty value
226   - * for simple direct grading. In the future, the list of available methods may be
227   - * controlled per-context.
228   - *
229   - * Requires the context property to be set in advance.
  223 + * Returns the list of installed grading plugins together, optionally extended
  224 + * with a simple direct grading.
230 225 *
231 226 * @param bool $includenone should the 'Simple direct grading' be included
232 227 * @return array of the (string)name => (string)localized title of the method
233 228 */
234   - public function get_available_methods($includenone = true) {
235   -
236   - $this->ensure_isset(array('context'));
  229 + public static function available_methods($includenone = true) {
237 230
238 231 if ($includenone) {
239 232 $list = array('' => get_string('gradingmethodnone', 'core_grading'));
@@ -249,6 +242,48 @@ public function get_available_methods($includenone = true) {
249 242 }
250 243
251 244 /**
  245 + * Returns the list of available grading methods in the given context
  246 + *
  247 + * Currently this is just a static list obtained from {@link self::available_methods()}.
  248 + * In the future, the list of available methods may be controlled per-context.
  249 + *
  250 + * Requires the context property to be set in advance.
  251 + *
  252 + * @param bool $includenone should the 'Simple direct grading' be included
  253 + * @return array of the (string)name => (string)localized title of the method
  254 + */
  255 + public function get_available_methods($includenone = true) {
  256 + $this->ensure_isset(array('context'));
  257 + return self::available_methods($includenone);
  258 + }
  259 +
  260 + /**
  261 + * Returns the list of gradable areas provided by the given component
  262 + *
  263 + * This performs a callback to the library of the relevant plugin to obtain
  264 + * the list of supported areas.
  265 + *
  266 + * @param string $component normalized component name
  267 + * @return array of (string)areacode => (string)localized title of the area
  268 + */
  269 + public static function available_areas($component) {
  270 + global $CFG;
  271 +
  272 + list($plugintype, $pluginname) = normalize_component($component);
  273 +
  274 + if ($component === 'core_grading') {
  275 + return array();
  276 +
  277 + } else if ($plugintype === 'mod') {
  278 + return plugin_callback('mod', $pluginname, 'grading', 'areas_list', null, array());
  279 +
  280 + } else {
  281 + throw new coding_exception('Unsupported area location');
  282 + }
  283 + }
  284 +
  285 +
  286 + /**
252 287 * Returns the list of gradable areas in the given context and component
253 288 *
254 289 * This performs a callback to the library of the relevant plugin to obtain
@@ -267,14 +302,9 @@ public function get_available_areas() {
267 302 return array();
268 303 }
269 304
270   - } else if ($this->get_context()->contextlevel >= CONTEXT_COURSE) {
  305 + } else if ($this->get_context()->contextlevel == CONTEXT_MODULE) {
271 306 list($context, $course, $cm) = get_context_info_array($this->get_context()->id);
272   -
273   - if (empty($cm->modname)) {
274   - throw new coding_exception('Unsupported area location');
275   - } else {
276   - return plugin_callback('mod', $cm->modname, 'grading', 'areas_list', null, array());
277   - }
  307 + return self::available_areas('mod_'.$cm->modname);
278 308
279 309 } else {
280 310 throw new coding_exception('Unsupported gradable area context level');

0 comments on commit bb50c37

Please sign in to comment.
Something went wrong with that request. Please try again.