mirror of
https://github.com/moodle/moodle.git
synced 2025-04-14 13:02:07 +02:00
MDL-10544 outcome adding from modedit
This commit is contained in:
parent
e36fe14acc
commit
71ee4471ac
@ -4,6 +4,7 @@
|
||||
|
||||
require_once("../config.php");
|
||||
require_once("lib.php");
|
||||
require_once($CFG->libdir.'/gradelib.php');
|
||||
|
||||
require_login();
|
||||
|
||||
@ -100,6 +101,16 @@
|
||||
$form->return = $return;
|
||||
$form->update = $update;
|
||||
|
||||
// add existing outcomes
|
||||
if ($items = grade_item::fetch_all(array('itemtype'=>'mod', 'itemmodule'=>$form->modulename,
|
||||
'iteminstance'=>$form->instance, 'courseid'=>$COURSE->id))) {
|
||||
foreach ($items as $item) {
|
||||
if (!empty($item->outcomeid)) {
|
||||
$form->{'outcome_'.$item->outcomeid} = 1;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
$sectionname = get_section_name($course->format);
|
||||
$fullmodulename = get_string("modulename", $module->name);
|
||||
|
||||
@ -149,7 +160,7 @@
|
||||
} else {
|
||||
redirect("view.php?id=$course->id#section-".$cousesection);
|
||||
}
|
||||
} else if ($fromform=$mform->get_data()){
|
||||
} else if ($fromform = $mform->get_data()) {
|
||||
if (empty($fromform->coursemodule)) { //add
|
||||
if (! $course = get_record("course", "id", $fromform->course)) {
|
||||
error("This course doesn't exist");
|
||||
@ -283,6 +294,54 @@
|
||||
error("Data submitted is invalid.");
|
||||
}
|
||||
|
||||
// add outcomes if requested
|
||||
if ($outcomes = grade_outcome::fetch_all_available($COURSE->id)) {
|
||||
foreach($outcomes as $outcome) {
|
||||
$elname = 'outcome_'.$outcome->id;
|
||||
if (array_key_exists($elname, $fromform) and $fromform->$elname) {
|
||||
// we have a request for new outcome grade item
|
||||
$grade_item = new grade_item();
|
||||
$max = 999;
|
||||
if ($items = grade_item::fetch_all(array('itemtype'=>'mod', 'itemmodule'=>$fromform->modulename,
|
||||
'iteminstance'=>$fromform->instance, 'courseid'=>$COURSE->id))) {
|
||||
$exists = false;
|
||||
foreach($items as $item) {
|
||||
if ($item->outcomeid == $outcome->id) {
|
||||
$exists = true;
|
||||
break;
|
||||
}
|
||||
if (empty($item->outcomeid)) {
|
||||
continue;
|
||||
}
|
||||
if ($item->itemnumber > $max) {
|
||||
$max = $item->itemnumber;
|
||||
}
|
||||
}
|
||||
}
|
||||
if ($exists) {
|
||||
continue;
|
||||
}
|
||||
$grade_item->courseid = $COURSE->id;
|
||||
$grade_item->itemtype = 'mod';
|
||||
$grade_item->itemmodule = $fromform->modulename;
|
||||
$grade_item->iteminstance = $fromform->instance;
|
||||
$grade_item->itemnumber = $max + 1;
|
||||
$grade_item->itemname = $fromform->name.' - '.$outcome->fullname;
|
||||
$grade_item->outcomeid = $outcome->id;
|
||||
$grade_item->gradetype = GRADE_TYPE_SCALE;
|
||||
$grade_item->scaleid = $outcome->scaleid;
|
||||
|
||||
$grade_item->insert();
|
||||
|
||||
if ($item = grade_item::fetch(array('itemtype'=>'mod', 'itemmodule'=>$grade_item->itemmodule,
|
||||
'iteminstance'=>$grade_item->iteminstance, 'itemnumber'=>0, 'courseid'=>$COURSE->id))) {
|
||||
$grade_item->set_parent($item->categoryid);
|
||||
$grade_item->move_after_sortorder($item->sortorder);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
rebuild_course_cache($course->id);
|
||||
|
||||
redirect("$CFG->wwwroot/mod/$module->name/view.php?id=$fromform->coursemodule");
|
||||
|
@ -35,6 +35,7 @@ class moodleform_mod extends moodleform {
|
||||
$this->_cm = $cm;
|
||||
parent::moodleform('modedit.php');
|
||||
}
|
||||
|
||||
/**
|
||||
* Only available on moodleform_mod.
|
||||
*
|
||||
@ -42,6 +43,29 @@ class moodleform_mod extends moodleform {
|
||||
*/
|
||||
function data_preprocessing(&$default_values){
|
||||
}
|
||||
|
||||
function definition_after_data() {
|
||||
global $COURSE;
|
||||
$mform =& $this->_form;
|
||||
|
||||
if ($id = $mform->getElementValue('update')) {
|
||||
$modulename = $mform->getElementValue('modulename');
|
||||
$instance = $mform->getElementValue('instance');
|
||||
|
||||
if ($items = grade_item::fetch_all(array('itemtype'=>'mod', 'itemmodule'=>$modulename,
|
||||
'iteminstance'=>$instance, 'courseid'=>$COURSE->id))) {
|
||||
foreach ($items as $item) {
|
||||
if (!empty($item->outcomeid)) {
|
||||
$elname = 'outcome_'.$item->outcomeid;
|
||||
if ($mform->elementExists($elname)) {
|
||||
$mform->hardFreeze($elname); // prevent removing of existing outcomes
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Load in existing data as form defaults. Usually new entry defaults are stored directly in
|
||||
* form definition (new entry form); this function is used to load in data where values
|
||||
@ -56,12 +80,14 @@ class moodleform_mod extends moodleform {
|
||||
$this->data_preprocessing($default_values);
|
||||
parent::set_data($default_values + $this->standard_coursemodule_elements_settings());//never slashed for moodleform_mod
|
||||
}
|
||||
|
||||
/**
|
||||
* Adds all the standard elements to a form to edit the settings for an activity module.
|
||||
*
|
||||
* @param bool $supportsgroups does this module support groups?
|
||||
*/
|
||||
function standard_coursemodule_elements($supportsgroups=true){
|
||||
global $COURSE;
|
||||
$mform =& $this->_form;
|
||||
$mform->addElement('header', 'modstandardelshdr', get_string('modstandardels', 'form'));
|
||||
if ($supportsgroups){
|
||||
@ -70,6 +96,14 @@ class moodleform_mod extends moodleform {
|
||||
}
|
||||
$mform->addElement('modvisible', 'visible', get_string('visible'));
|
||||
$mform->addElement('text', 'cmidnumber', get_string('idnumber'));
|
||||
|
||||
if ($outcomes = grade_outcome::fetch_all_available($COURSE->id)) {
|
||||
$mform->addElement('header', 'modoutcomes', get_string('outcomes', 'grades'));
|
||||
foreach($outcomes as $outcome) {
|
||||
$mform->addElement('advcheckbox', 'outcome_'.$outcome->id, $outcome->get_name());
|
||||
}
|
||||
|
||||
}
|
||||
$this->standard_hidden_coursemodule_elements();
|
||||
}
|
||||
|
||||
|
@ -150,7 +150,8 @@ class mod_glossary_mod_form extends moodleform_mod {
|
||||
$this->add_action_buttons();
|
||||
}
|
||||
|
||||
function definition_after_data(){
|
||||
function definition_after_data() {
|
||||
parent::definition_after_data();
|
||||
global $COURSE;
|
||||
$mform =& $this->_form;
|
||||
$mainglossaryel =& $mform->getElement('mainglossary');
|
||||
|
Loading…
x
Reference in New Issue
Block a user