require_login();
- $add = optional_param('add', '', PARAM_ALPHA);
- $update = optional_param('update', 0, PARAM_INT);
- //return to course/view.php if false or mod/modname/view.php if true
- $return = optional_param('return', 0, PARAM_BOOL);
- $type = optional_param('type', '', PARAM_ALPHANUM);
+ $add = optional_param('add', 0, PARAM_ALPHA);
+ $update = optional_param('update', 0, PARAM_INT);
+ $return = optional_param('return', 0, PARAM_BOOL); //return to course/view.php if false or mod/modname/view.php if true
+ $type = optional_param('type', '', PARAM_ALPHANUM);
if (!empty($add)) {
$section = required_param('section', PARAM_INT);
error("This course doesn't exist");
}
+ require_login($course);
+ $context = get_context_instance(CONTEXT_COURSE, $course->id);
+ require_capability('moodle/course:manageactivities', $context);
+
if (! $module = get_record("modules", "name", $add)) {
error("This module type doesn't exist");
}
- $context = get_context_instance(CONTEXT_COURSE, $course->id);
- require_capability('moodle/course:manageactivities', $context);
+ if (! $cw = get_record("course_sections", "section", $section, "course", $course->id)) {
+ error("This course section doesn't exist");
+ }
if (!course_allowed_module($course, $module->id)) {
error("This module has been disabled for this particular course");
}
- require_login($course->id); // needed to setup proper $COURSE
+ $cm = null;
+
+ $form->section = $section; // The section number itself - relative!!! (section column in course_sections)
+ $form->visible = $cw->visible;
+ $form->course = $course->id;
+ $form->module = $module->id;
+ $form->modulename = $module->name;
+ $form->groupmode = $course->groupmode;
+ $form->groupingid = $course->defaultgroupingid;
+ $form->groupmembersonly = 0;
+ $form->instance = '';
+ $form->coursemodule = '';
+ $form->add = $add;
+ $form->return = 0; //must be false if this is an add, go back to course view on cancel
- $form->section = $section; // The section number itself
- $form->course = $course->id;
- $form->module = $module->id;
- $form->modulename = $module->name;
- $form->instance = "";
- $form->coursemodule = "";
- $form->add=$add;
- $form->return=0;//must be false if this is an add, go back to course view on cancel
if (!empty($type)) {
$form->type = $type;
}
$CFG->pagepath .= '/mod';
}
+ $navlinksinstancename = '';
+
} else if (!empty($update)) {
if (! $cm = get_record("course_modules", "id", $update)) {
error("This course module doesn't exist");
error("This course doesn't exist");
}
- require_login($course->id); // needed to setup proper $COURSE
+ require_login($course); // needed to setup proper $COURSE
$context = get_context_instance(CONTEXT_MODULE, $cm->id);
require_capability('moodle/course:manageactivities', $context);
error("This course section doesn't exist");
}
-
- $form->coursemodule = $cm->id;
- $form->section = $cm->section; // The section ID
- $form->cmidnumber = $cm->idnumber; // The cm IDnumber
- $form->course = $course->id;
- $form->module = $module->id;
- $form->modulename = $module->name;
- $form->instance = $cm->instance;
- $form->return = $return;
- $form->update = $update;
+ $form->coursemodule = $cm->id;
+ $form->section = $cw->section; // The section number itself - relative!!! (section column in course_sections)
+ $form->visible = $cm->visible; //?? $cw->visible ? $cm->visible : 0; // section hiding overrides
+ $form->cmidnumber = $cm->idnumber; // The cm IDnumber
+ $form->groupmode = groupmode($COURSE,$cm); // locked later if forced
+ $form->groupingid = $cm->groupingid;
+ $form->groupmembersonly = $cm->groupmembersonly;
+ $form->course = $course->id;
+ $form->module = $module->id;
+ $form->modulename = $module->name;
+ $form->instance = $cm->instance;
+ $form->return = $return;
+ $form->update = $update;
// add existing outcomes
if ($items = grade_item::fetch_all(array('itemtype'=>'mod', 'itemmodule'=>$form->modulename,
}
$mformclassname = 'mod_'.$module->name.'_mod_form';
- $cousesection=isset($cw->section)?$cw->section:$section;
- $mform=& new $mformclassname($form->instance, $cousesection, ((isset($cm))?$cm:null));
+ $mform =& new $mformclassname($form->instance, $cw->section, $cm);
$mform->set_data($form);
if ($mform->is_cancelled()) {
- if ($return && isset($cm)){
+ if ($return && !empty($cm->id)){
redirect("$CFG->wwwroot/mod/$module->name/view.php?id=$cm->id");
} else {
- redirect("view.php?id=$course->id#section-".$cousesection);
+ redirect("view.php?id=$course->id#section-".$cw->section);
}
} else if ($fromform = $mform->get_data()) {
if (empty($fromform->coursemodule)) { //add
error($returnfromfunc, "view.php?id=$course->id");
}
- if (isset($fromform->visible)) {
- set_coursemodule_visible($fromform->coursemodule, $fromform->visible);
- }
+ set_coursemodule_visible($fromform->coursemodule, $fromform->visible);
if (isset($fromform->groupmode)) {
set_coursemodule_groupmode($fromform->coursemodule, $fromform->groupmode);
}
- // set cm id number
- if (isset($fromform->cmidnumber)) {
- set_coursemodule_idnumber($fromform->coursemodule, $fromform->cmidnumber);
+ if (isset($fromform->groupingid)) {
+ set_coursemodule_groupingid($fromform->coursemodule, $fromform->groupingid);
}
+ if (isset($fromform->groupmembersonly)) {
+ set_coursemodule_groupmembersonly($fromform->coursemodule, $fromform->groupmembersonly);
+ }
+
+ // set cm id number
+ set_coursemodule_idnumber($fromform->coursemodule, $fromform->cmidnumber);
+
add_to_log($course->id, "course", "update mod",
"../mod/$fromform->modulename/view.php?id=$fromform->coursemodule",
"$fromform->modulename $fromform->instance");
$returnfromfunc = $addinstancefunction($fromform);
if (!$returnfromfunc) {
- /*if (file_exists($moderr)) {
- $form = $fromform;
- include_once($moderr);
- die;
- }*/
error("Could not add a new instance of $fromform->modulename", "view.php?id=$course->id");
}
if (is_string($returnfromfunc)) {
error($returnfromfunc, "view.php?id=$course->id");
}
- if (!isset($fromform->groupmode)) { // to deal with pre-1.5 modules
- $fromform->groupmode = $course->groupmode; /// Default groupmode the same as course
- }
-
$fromform->instance = $returnfromfunc;
// course_modules and course_sections each contain a reference
error("Could not update the course module with the correct section");
}
- if (!isset($fromform->visible)) { // We get the section's visible field status
- $fromform->visible = get_field("course_sections","visible","id",$sectionid);
- }
// make sure visibility is set correctly (in particular in calendar)
set_coursemodule_visible($fromform->coursemodule, $fromform->visible);
// set cm idnumber
- if (isset($fromform->cmidnumber)) {
- set_coursemodule_idnumber($fromform->coursemodule, $fromform->cmidnumber);
- }
+ set_coursemodule_idnumber($fromform->coursemodule, $fromform->cmidnumber);
add_to_log($course->id, "course", "add mod",
"../mod/$fromform->modulename/view.php?id=$fromform->coursemodule",
$navlinks = array();
$navlinks[] = array('name' => $strmodulenameplural, 'link' => "$CFG->wwwroot/mod/$module->name/index.php?id=$course->id", 'type' => 'activity');
- if (isset($navlinksinstancename)) {
+ if ($navlinksinstancename) {
$navlinks[] = $navlinksinstancename;
}
$navlinks[] = array('name' => $streditinga, 'link' => '', 'type' => 'title');
var $_instance;
/**
* Section of course that module instance will be put in or is in.
- * This is always the section number itself.
+ * This is always the section number itself (column 'section' from 'course_sections' table).
*
* @var mixed
*/
}
}
}
+
+ if ($mform->elementExists('groupmode')) {
+ if ($COURSE->groupmodeforce) {
+ $mform->hardFreeze('groupmode'); // groupmode can not be changed if forced from course settings
+ }
+ }
}
// form verification
$default_values = (array)$default_values;
}
$this->data_preprocessing($default_values);
- parent::set_data($default_values + $this->standard_coursemodule_elements_settings());//never slashed for moodleform_mod
+ parent::set_data($default_values); //never slashed for moodleform_mod
}
/**
$mform->addElement('header', 'modstandardelshdr', get_string('modstandardels', 'form'));
if ($supportsgroups){
- // TODO: we must define this as mod property!
$mform->addElement('modgroupmode', 'groupmode', get_string('groupmode'));
}
+
+ if (!empty($CFG->enablegroupings)) {
+ //groupings selector
+ $options = array();
+ $options[0] = get_string('none');
+ if ($groupings = get_records('groupings', 'courseid', $COURSE->id)) {
+ foreach ($groupings as $grouping) {
+ $options[$grouping->id] = format_string($grouping->name);
+ }
+ }
+ $mform->addElement('select', 'groupingid', get_string('grouping', 'group'), $options);
+ $mform->addElement('advcheckbox', 'groupmembersonly', get_string('groupmembersonly', 'group'));
+ }
+
$mform->addElement('modvisible', 'visible', get_string('visible'));
$mform->addElement('text', 'cmidnumber', get_string('idnumber'));
$mform->setType('return', PARAM_BOOL);
}
- /**
- * This function is called by course/modedit.php to setup defaults for standard form
- * elements.
- *
- * @param object $course
- * @param object $cm
- * @param integer $section
- * @return unknown
- */
- function standard_coursemodule_elements_settings(){
- return ($this->modgroupmode_settings() + $this->modvisible_settings());
- }
- /**
- * This is called from modedit.php to load the default for the groupmode element.
- *
- * @param object $course
- * @param object $cm
- */
- function modgroupmode_settings(){
- global $COURSE;
- return array('groupmode'=>groupmode($COURSE, $this->_cm));
- }
- /**
- * This is called from modedit.php to set the default for modvisible form element.
- *
- * @param object $course
- * @param object $cm
- * @param integer $section section is a db id when updating a activity config
- * or the section no when adding a new activity
- */
- function modvisible_settings(){
- global $COURSE;
- $cm=$this->_cm;
- $section=$this->_section;
- if ($cm) {
- $visible = $cm->visible;
- } else {
- $visible = 1;
- }
-
- $hiddensection = !get_field('course_sections', 'visible', 'section', $section, 'course', $COURSE->id);
- if ($hiddensection) {
- $visible = 0;
- }
- return array('visible'=>$visible);
- }
-
}
?>