require_once("../config.php");
require_once("lib.php");
+ require_once($CFG->libdir.'/gradelib.php');
require_login();
$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);
} 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");
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");
$this->_cm = $cm;
parent::moodleform('modedit.php');
}
+
/**
* Only available on moodleform_mod.
*
*/
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
$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){
}
$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();
}