Example #1
0
 /**
  * Renders the active method selector at the grading method management screen
  *
  * @param grading_manager $gradingman
  * @param moodle_url $targeturl
  * @return string
  */
 public function management_method_selector(grading_manager $manager, moodle_url $targeturl)
 {
     $method = $manager->get_active_method();
     $methods = $manager->get_available_methods(false);
     $methods['none'] = get_string('gradingmethodnone', 'core_grading');
     $selector = new single_select(new moodle_url($targeturl, array('sesskey' => sesskey())), 'setmethod', $methods, empty($method) ? 'none' : $method, null, 'activemethodselector');
     $selector->set_label(get_string('changeactivemethod', 'core_grading'));
     $selector->set_help_icon('gradingmethod', 'core_grading');
     return $this->output->render($selector);
 }
Example #2
0
/**
 * Factory method returning an instance of the grading manager
 *
 * There are basically ways how to use this factory method. If the area record
 * id is known to the caller, get the manager for that area by providing just
 * the id. If the area record id is not know, the context, component and area name
 * can be provided. Note that null values are allowed in the second case as the context,
 * component and the area name can be set explicitly later.
 *
 * @category grading
 * @example $manager = get_grading_manager($areaid);
 * @example $manager = get_grading_manager(context_system::instance());
 * @example $manager = get_grading_manager($context, 'mod_assignment', 'submission');
 * @param stdClass|int|null $context_or_areaid if $areaid is passed, no other parameter is needed
 * @param string|null $component the frankenstyle name of the component
 * @param string|null $area the name of the gradable area
 * @return grading_manager
 */
function get_grading_manager($context_or_areaid = null, $component = null, $area = null)
{
    global $DB;
    $manager = new grading_manager();
    if (is_object($context_or_areaid)) {
        $context = $context_or_areaid;
    } else {
        $context = null;
        if (is_numeric($context_or_areaid)) {
            $manager->load($context_or_areaid);
            return $manager;
        }
    }
    if (!is_null($context)) {
        $manager->set_context($context);
    }
    if (!is_null($component)) {
        $manager->set_component($component);
    }
    if (!is_null($area)) {
        $manager->set_area($area);
    }
    return $manager;
}
Example #3
0
 /**
  * Delete all data linked to content, do not delete the context record itself
  */
 public function delete_content()
 {
     global $CFG, $DB;
     blocks_delete_all_for_context($this->_id);
     filter_delete_all_for_context($this->_id);
     require_once $CFG->dirroot . '/comment/lib.php';
     comment::delete_comments(array('contextid' => $this->_id));
     require_once $CFG->dirroot . '/rating/lib.php';
     $delopt = new stdclass();
     $delopt->contextid = $this->_id;
     $rm = new rating_manager();
     $rm->delete_ratings($delopt);
     // delete all files attached to this context
     $fs = get_file_storage();
     $fs->delete_area_files($this->_id);
     // delete all advanced grading data attached to this context
     require_once $CFG->dirroot . '/grade/grading/lib.php';
     grading_manager::delete_all_for_context($this->_id);
     // now delete stuff from role related tables, role_unassign_all
     // and unenrol should be called earlier to do proper cleanup
     $DB->delete_records('role_assignments', array('contextid' => $this->_id));
     $DB->delete_records('role_capabilities', array('contextid' => $this->_id));
     $DB->delete_records('role_names', array('contextid' => $this->_id));
 }
Example #4
0
 /**
  * Set assign module specific test values for calling create_module().
  *
  * @param object $moduleinfo - the moduleinfo to add some specific values - passed in reference.
  */
 private function assign_create_set_values(&$moduleinfo)
 {
     // Specific values to the Assign module.
     $moduleinfo->alwaysshowdescription = true;
     $moduleinfo->submissiondrafts = true;
     $moduleinfo->requiresubmissionstatement = true;
     $moduleinfo->sendnotifications = true;
     $moduleinfo->sendlatenotifications = true;
     $moduleinfo->duedate = time() + 7 * 24 * 3600;
     $moduleinfo->cutoffdate = time() + 7 * 24 * 3600;
     $moduleinfo->allowsubmissionsfromdate = time();
     $moduleinfo->teamsubmission = true;
     $moduleinfo->requireallteammemberssubmit = true;
     $moduleinfo->teamsubmissiongroupingid = true;
     $moduleinfo->blindmarking = true;
     $moduleinfo->markingworkflow = true;
     $moduleinfo->markingallocation = true;
     $moduleinfo->assignsubmission_onlinetext_enabled = true;
     $moduleinfo->assignsubmission_file_enabled = true;
     $moduleinfo->assignsubmission_file_maxfiles = 1;
     $moduleinfo->assignsubmission_file_maxsizebytes = 1000000;
     $moduleinfo->assignsubmission_comments_enabled = true;
     $moduleinfo->assignfeedback_comments_enabled = true;
     $moduleinfo->assignfeedback_offline_enabled = true;
     $moduleinfo->assignfeedback_file_enabled = true;
     // Advanced grading.
     $gradingmethods = grading_manager::available_methods();
     $moduleinfo->advancedgradingmethod_submissions = current(array_keys($gradingmethods));
 }
 /**
  * Describes the parameters for save_grades
  * @return external_external_function_parameters
  * @since  Moodle 2.7
  */
 public static function save_grades_parameters()
 {
     global $CFG;
     require_once "{$CFG->dirroot}/mod/sepl/locallib.php";
     require_once "{$CFG->dirroot}/grade/grading/lib.php";
     $instance = new sepl(null, null, null);
     $pluginfeedbackparams = array();
     foreach ($instance->get_feedback_plugins() as $plugin) {
         $pluginparams = $plugin->get_external_parameters();
         if (!empty($pluginparams)) {
             $pluginfeedbackparams = array_merge($pluginfeedbackparams, $pluginparams);
         }
     }
     $advancedgradingdata = array();
     $methods = array_keys(grading_manager::available_methods(false));
     foreach ($methods as $method) {
         require_once $CFG->dirroot . '/grade/grading/form/' . $method . '/lib.php';
         $details = call_user_func('gradingform_' . $method . '_controller::get_external_instance_filling_details');
         if (!empty($details)) {
             $items = array();
             foreach ($details as $key => $value) {
                 $value->required = VALUE_OPTIONAL;
                 unset($value->content->keys['id']);
                 $items[$key] = new external_multiple_structure(new external_single_structure(array('criterionid' => new external_value(PARAM_INT, 'criterion id'), 'fillings' => $value)));
             }
             $advancedgradingdata[$method] = new external_single_structure($items, 'items', VALUE_OPTIONAL);
         }
     }
     return new external_function_parameters(array('seplmentid' => new external_value(PARAM_INT, 'The seplment id to operate on'), 'applytoall' => new external_value(PARAM_BOOL, 'If true, this grade will be applied ' . 'to all members ' . 'of the group (for group seplments).'), 'grades' => new external_multiple_structure(new external_single_structure(array('userid' => new external_value(PARAM_INT, 'The student id to operate on'), 'grade' => new external_value(PARAM_FLOAT, 'The new grade for this user. ' . 'Ignored if advanced grading used'), 'attemptnumber' => new external_value(PARAM_INT, 'The attempt number (-1 means latest attempt)'), 'addattempt' => new external_value(PARAM_BOOL, 'Allow another attempt if manual attempt reopen method'), 'workflowstate' => new external_value(PARAM_ALPHA, 'The next marking workflow state'), 'plugindata' => new external_single_structure($pluginfeedbackparams, 'plugin data', VALUE_DEFAULT, array()), 'advancedgradingdata' => new external_single_structure($advancedgradingdata, 'advanced grading data', VALUE_DEFAULT, array()))))));
 }
Example #6
0
 $data->instance = '';
 $data->coursemodule = '';
 $data->add = $add;
 $data->return = 0;
 //must be false if this is an add, go back to course view on cancel
 $data->sr = $sectionreturn;
 if (plugin_supports('mod', $data->modulename, FEATURE_MOD_INTRO, true)) {
     $draftid_editor = file_get_submitted_draft_itemid('introeditor');
     file_prepare_draft_area($draftid_editor, null, null, null, null, array('subdirs' => true));
     $data->introeditor = array('text' => '', 'format' => FORMAT_HTML, 'itemid' => $draftid_editor);
     // TODO: add better default
 }
 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';
     $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;
 }
 $sectionname = get_section_name($course, $cw);
 $fullmodulename = get_string('modulename', $module->name);
 if ($data->section && $course->format != 'site') {
     $heading = new stdClass();
     $heading->what = $fullmodulename;
Example #7
0
 /**
  * @return array of available grading methods
  * @since Moodle 2.5
  */
 private static function get_grading_methods()
 {
     $methods = array_keys(grading_manager::available_methods(false));
     return $methods;
 }
Example #8
0
    }
    if (!$confirmed) {
        echo $output->header();
        echo $output->confirm(get_string('templatedeleteconfirm', 'core_grading', s($definition->name)), new moodle_url($PAGE->url, array('remove' => $remove, 'confirmed' => 1)), $PAGE->url);
        echo $output->box($sourcecontroller->render_preview($PAGE), 'template-preview-confirm');
        echo $output->footer();
        die;
    } else {
        require_sesskey();
        $sourcecontroller->delete_definition();
        redirect($PAGE->url);
    }
}
$searchform = new grading_search_template_form($PAGE->url, null, 'GET', '', array('class' => 'templatesearchform'));
if ($searchdata = $searchform->get_data()) {
    $tokens = grading_manager::tokenize($searchdata->needle);
    $includeownforms = !empty($searchdata->mode);
} else {
    $tokens = array();
    $includeownforms = false;
}
// construct the SQL to find all matching templates
$sql = "SELECT DISTINCT gd.id, gd.areaid, gd.name, gd.usercreated\n          FROM {grading_definitions} gd\n          JOIN {grading_areas} ga ON (gd.areaid = ga.id)\n          JOIN {context} cx ON (ga.contextid = cx.id)";
// join method-specific tables from the plugin scope
$sql .= $targetcontrollerclass::sql_search_from_tables('gd.id');
$sql .= " WHERE gd.method = ?";
$params = array($method);
if (!$includeownforms) {
    // search for public templates only
    $sql .= " AND ga.contextid = ? AND ga.component = 'core_grading'";
    $params[] = context_system::instance()->id;
Example #9
0
/**
 * Prepare the standard module information for a new module instance.
 *
 * @param  stdClass $course  course object
 * @param  string $modulename  module name
 * @param  int $section section number
 * @return array module information about other required data
 * @since  Moodle 3.2
 */
function prepare_new_moduleinfo_data($course, $modulename, $section)
{
    global $CFG;
    list($module, $context, $cw) = can_add_moduleinfo($course, $modulename, $section);
    $cm = null;
    $data = new stdClass();
    $data->section = $section;
    // The section number itself - relative!!! (section column in course_sections)
    $data->visible = $cw->visible;
    $data->course = $course->id;
    $data->module = $module->id;
    $data->modulename = $module->name;
    $data->groupmode = $course->groupmode;
    $data->groupingid = $course->defaultgroupingid;
    $data->id = '';
    $data->instance = '';
    $data->coursemodule = '';
    if (plugin_supports('mod', $data->modulename, FEATURE_MOD_INTRO, true)) {
        $draftid_editor = file_get_submitted_draft_itemid('introeditor');
        file_prepare_draft_area($draftid_editor, null, null, null, null, array('subdirs' => true));
        $data->introeditor = array('text' => '', 'format' => FORMAT_HTML, 'itemid' => $draftid_editor);
        // TODO: add better default
    }
    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';
        $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} = '';
        }
    }
    return array($module, $context, $cw, $cm, $data);
}