}
$mformclassname=$module->name.'_mod_form';
- $mform=& new $mformclassname('modedit.php', array('course' => $course));
+ $mform=& new $mformclassname($form->instance, isset($cw->section)?$cw->section:$section, ((isset($cm))?$cm:null));
if ($fromform=$mform->data_submitted()){
if (empty($fromform->coursemodule)) { //add
$icon = '<img align="middle" height="16" width="16" src="'.$CFG->modpixpath.'/'.$module->name.'/icon.gif" alt="" style="vertical-align: middle;" /> ';
print_heading_with_help($pageheading, "mods", $module->name, $icon);
- $mform->standard_coursemodule_elements_setup($course, isset($cm)?$cm:null, $form->section);
$mform->set_defaults($form);
$mform->display();
print_footer($course);
--- /dev/null
+<?php
+require_once ($CFG->libdir.'/formslib.php');
+/**
+ * This class adds extra methods to form wrapper specific to be used for module
+ * add / update forms (mod/{modname}.mod_form.php replaces deprecared mod/{modname}/mod.html
+ *
+ */
+class moodleform_mod extends moodleform {
+ /**
+ * Instance of the module that is being updated. This is the id of the {prefix}{modulename}
+ * record. Can be used in form definition. Will be "" if this is an 'add' form and not an
+ * update one.
+ *
+ * @var mixed
+ */
+ var $_instance;
+ /**
+ * Section of course that module instance will be put in or is in.
+ * This is always the section number itself.
+ *
+ * @var mixed
+ */
+ var $_section;
+ /**
+ * Coursemodle record of the module that is being updated. Will be null if this is an 'add' form and not an
+ * update one.
+ *
+ * @var mixed
+ */
+ var $_cm;
+
+ function moodleform_mod($instance, $section, $cm) {
+ $this->_instance = $instance;
+ $this->_section = $section;
+ $this->_cm = $cm;
+ parent::moodleform('modedit.php');
+ }
+ /**
+ * Only available on moodleform_mod since defaults for forms cannot
+ * be calculated externally. You can use _customdata in here if necessary.
+ *
+ *
+ * @param array $default_values passed by reference
+ */
+ function defaults_preprocessing(&$default_values){
+ }
+ /**
+ * 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
+ * already exist and data is being edited (edit entry form).
+ *
+ * @param mixed $default_values object or array of default values
+ */
+ function set_defaults($default_values) {
+ if (is_object($default_values)) {
+ $default_values = (array)$default_values;
+ }
+ $this->defaults_preprocessing($default_values);
+ parent::set_defaults($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){
+ $mform =& $this->_form;
+ $mform->addElement('header', '', get_string('modstandardels', 'form'));
+ if ($supportsgroups){
+ $mform->addElement('modgroupmode', 'groupmode', get_string('groupmode'));
+ }
+ $mform->addElement('modvisible', 'visible', get_string('visible'));
+
+ $this->standard_hidden_coursemodule_elements();
+ }
+
+ function standard_hidden_coursemodule_elements(){
+ $mform =& $this->_form;
+ $mform->addElement('hidden', 'course', 0);
+ $mform->setType('course', PARAM_INT);
+
+ $mform->addElement('hidden', 'coursemodule', 0);
+ $mform->setType('coursemodule', PARAM_INT);
+
+ $mform->addElement('hidden', 'section', 0);
+ $mform->setType('section', PARAM_INT);
+
+ $mform->addElement('hidden', 'module', 0);
+ $mform->setType('module', PARAM_INT);
+
+ $mform->addElement('hidden', 'modulename', '');
+ $mform->setType('modulename', PARAM_SAFEDIR);
+
+ $mform->addElement('hidden', 'instance', 0);
+ $mform->setType('instance', PARAM_INT);
+
+ $mform->addElement('hidden', 'add', 0);
+ $mform->setType('add', PARAM_ALPHA);
+
+ $mform->addElement('hidden', 'update', 0);
+ $mform->setType('update', PARAM_INT);
+ }
+
+ /**
+ * 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);
+ }
+
+}
+
+?>
\ No newline at end of file
function getElementTemplateType(){
return $this->_elementTemplateType;
}
-}
\ No newline at end of file
+}
+?>
\ No newline at end of file
return true;
}
}
-/**
- * This class adds extra methods to form wrapper specific to be used for module
- * add / update forms (mod/{modname}.mod_form.php replaces deprecared mod/{modname}/mod.html
- *
- */
-class moodleform_mod extends moodleform {
-
- /**
- * 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){
- $mform =& $this->_form;
- $mform->addElement('header', '', get_string('modstandardels', 'form'));
- if ($supportsgroups){
- $mform->addElement('modgroupmode', 'groupmode', get_string('groupmode'));
- }
- $mform->addElement('modvisible', 'visible', get_string('visible'));
-
- $this->standard_hidden_coursemodule_elements();
- }
-
- function standard_hidden_coursemodule_elements(){
- $mform =& $this->_form;
- $mform->addElement('hidden', 'course', 0);
- $mform->setType('course', PARAM_INT);
-
- $mform->addElement('hidden', 'coursemodule', 0);
- $mform->setType('coursemodule', PARAM_INT);
-
- $mform->addElement('hidden', 'section', 0);
- $mform->setType('section', PARAM_INT);
-
- $mform->addElement('hidden', 'module', 0);
- $mform->setType('module', PARAM_INT);
-
- $mform->addElement('hidden', 'modulename', '');
- $mform->setType('modulename', PARAM_SAFEDIR);
-
- $mform->addElement('hidden', 'instance', 0);
- $mform->setType('instance', PARAM_INT);
-
- $mform->addElement('hidden', 'add', 0);
- $mform->setType('add', PARAM_ALPHA);
-
- $mform->addElement('hidden', 'update', 0);
- $mform->setType('update', PARAM_INT);
- }
-
- /**
- * This function is called by course/modedit.php to setup defaults for standard form
- * elements.
- *
- * @param object $course
- * @param object $cm
- * @param integer $section
- */
- function standard_coursemodule_elements_setup($course, $cm, $section){
- $this->modgroupmode_setup($course, $cm);
- $this->modvisible_setup($course, $cm, $section);
- }
- /**
- * This is called from modedit.php to load the default for the groupmode element.
- *
- * @param object $course
- * @param object $cm
- */
- function modgroupmode_setup($course, $cm){
- $this->set_defaults(array('groupmode'=>groupmode($course, $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_setup($course, $cm, $section){
- if ($cm) {
- $visible = $cm->visible;
- } else {
- $visible = 1;
- }
-
- if (!$cm) { // adding activity
- //in this case $form->section is the section number, not the id
- $hiddensection = !get_field('course_sections', 'visible', 'section', $section, 'course', $course->id);
- } else { //updating activity
- $hiddensection = !get_field('course_sections', 'visible', 'id', $section);
- }
- if ($hiddensection) {
- $visible = 0;
- }
- $this->set_defaults(array('visible'=>$visible));
- }
-
-}
/**
* You never extend this class directly. The class methods of this class are available from
}
$js=rtrim($js, ', ');
$js .= "],\n";
- $js .= "condition : '{$element['condition']}'},\n";
+ $js .= "condition : '{$element['condition']}',\n";
+ $js .= "value : '{$element['value']}'},\n";
};
$js=rtrim($js, ",\n");
* condition
* @param string $condition the condition to check
*/
- function disabledIf($elementName, $dependentOn, $condition = 'notchecked'){
+ function disabledIf($elementName, $dependentOn, $condition = 'notchecked', $value=null){
$dependents = $this->_getElNamesRecursive($elementName);
foreach ($dependents as $dependent){
if ($dependent != $dependentOn) {
$this->_dependencies[$dependentOn][] = array('dependent'=>$dependent,
- 'condition'=>$condition);
+ 'condition'=>$condition, 'value'=>$value);
}
}
}
}
+
/**
* A renderer for MoodleQuickForm that only uses XHTML and CSS and no
* table tags, extends PEAR class HTML_QuickForm_Renderer_Tableless
thislock=!form.elements[master].checked;
} else if (items[master].condition=='checked'){
thislock=form.elements[master].checked;
+ } else if (items[master].condition=='eq'){
+ thislock=(form.elements[master].value==items[master].value);
} else {
- thislock=(form.elements[master].value==items[master].condition);
+ thislock=(form.elements[master].value!=items[master].value);
+
}
for (var i=0; i<subitems.length; i++) {
<?php
-require_once ($CFG->libdir.'/formslib.php');
+require_once ('moodleform_mod.php');
+
class chat_mod_form extends moodleform_mod {
function definition() {
<?php
-require_once ($CFG->libdir.'/formslib.php');
+require_once ('moodleform_mod.php');
+
class data_mod_form extends moodleform_mod {
function definition() {
<?php
-require_once ($CFG->libdir.'/formslib.php');
+require_once ('moodleform_mod.php');
+
class forum_mod_form extends moodleform_mod {
function definition() {
$mform->setDefault('blockafter', '0');
$mform->addRule('blockafter', null, 'numeric', null, 'client');
$mform->setHelpButton('blockafter', array('manageposts', get_string('blockafter', 'forum'),'forum'));
- $mform->disabledIf('blockafter', 'blockperiod', 0);
+ $mform->disabledIf('blockafter', 'blockperiod', 'eq', 0);
$mform->addElement('text', 'warnafter', get_string('warnafter', 'forum'));
$mform->setDefault('warnafter', '0');
$mform->addRule('warnafter', null, 'numeric', null, 'client');
$mform->setHelpButton('warnafter', array('manageposts', get_string('warnafter', 'forum'),'forum'));
- $mform->disabledIf('warnafter', 'blockperiod', 0);
+ $mform->disabledIf('warnafter', 'blockperiod', 'eq', 0);
//-------------------------------------------------------------------------------
$this->standard_coursemodule_elements();
}
}
- function set_defaults($default_values, $slashed=false){
- if (is_object($default_values)) {
- $default_values = (array)$default_values;
- }
+ function defaults_preprocessing($default_values){
if (isset($default_values['assessed'])){
$default_values['ratingtime']=($default_values['assessed']
&& $default_values['assesstimestart']
&& $default_values['assesstimefinish'] )?1:0;
}
- parent::set_defaults($default_values, $slashed);
}
+
}
?>
\ No newline at end of file
<?php
-require_once ($CFG->libdir.'/formslib.php');
+require_once ('moodleform_mod.php');
+
class glossary_mod_form extends moodleform_mod {
function definition() {
$choices[50] = '50';
$mform->addElement('select', 'rssarticles', get_string('rssarticles'), $choices);
$mform->setHelpButton('rssarticles', array('rssarticles', get_string('rssarticles'), 'glossary'));
- $mform->disabledIf('rssarticles', 'rsstype', 0);
+ $mform->disabledIf('rssarticles', 'rsstype', 'eq', 0);
}
//-------------------------------------------------------------------------------
}
-
- function set_defaults($default_values, $slashed=false){
- if (is_object($default_values)) {
- $default_values = (array)$default_values;
- }
+ function defaults_preprocessing($default_values){
if (isset($default_values['assessed'])){
$default_values['userating']=($default_values['assessed'])?true:false;
}
&& $default_values['assesstimestart']
&& $default_values['assesstimefinish'] )?1:0;
}
- parent::set_defaults($default_values, $slashed);
}
+
}
?>
\ No newline at end of file
<?php
-require_once ($CFG->libdir.'/formslib.php');
+require_once ('moodleform_mod.php');
+
class journal_mod_form extends moodleform_mod {
function definition() {
<?php // $Id$
-require_once ($CFG->libdir.'/formslib.php');
+require_once ('moodleform_mod.php');
+
class label_mod_form extends moodleform_mod {
function definition() {
if(!isset($lesson->completed)) {
$lesson->completed = 0;
}
- if(empty($lesson->gradebetterthan) or !is_numeric($lesson->timespent) or $lesson->gradebetterthan < 0) {
+ if(empty($lesson->gradebetterthan) or !is_numeric($lesson->gradebetterthan) or $lesson->gradebetterthan < 0) {
$lesson->gradebetterthan = 0;
} else if ($lesson->gradebetterthan > 100) {
$lesson->gradebetterthan = 100;
if(!isset($lesson->completed)) {
$lesson->completed = 0;
}
- if(empty($lesson->gradebetterthan) or !is_numeric($lesson->timespent) or $lesson->gradebetterthan < 0) {
+ if(empty($lesson->gradebetterthan) or !is_numeric($lesson->gradebetterthan) or $lesson->gradebetterthan < 0) {
$lesson->gradebetterthan = 0;
} else if ($lesson->gradebetterthan > 100) {
$lesson->gradebetterthan = 100;
* @license http://www.gnu.org/copyleft/gpl.html GNU Public License
* @package lesson
**/
-require_once ($CFG->libdir.'/formslib.php');
+require_once ('moodleform_mod.php');
+
require_once('locallib.php');
class lesson_mod_form extends moodleform_mod {
$options = array(0=>get_string('none'));
if ($lessons = get_all_instances_in_course('lesson', $COURSE)) {
foreach($lessons as $lesson) {
- $options[$lesson->id] = format_string($lesson->name, true);
+ if ($lesson->id != $this->_instance){
+ $options[$lesson->id] = format_string($lesson->name, true);
+ }
+
}
}
$mform->addElement('select', 'dependency', get_string('dependencyon', 'lesson'), $options);
//-------------------------------------------------------------------------------
$mform->addElement('header', '', get_string('mediafile', 'lesson'));
- // get the modules
- if ($mods = get_course_mods($COURSE->id)) {
- $modinstances = array();
- foreach ($mods as $mod) {
-
- // get the module name and then store it in a new array
- if ($module = get_coursemodule_from_instance($mod->modname, $mod->instance, $COURSE->id)) {
- $modinstances[$mod->id] = $mod->modname.' - '.$module->name;
- }
- }
- asort($modinstances); // sort by module name
- $modinstances=array(0=>get_string('none'))+$modinstances;
-
- $mform->addElement('select', 'activitylink', get_string('activitylink', 'lesson'), $modinstances);
- $mform->setHelpButton('activitylink', array('activitylink', get_string('activitylink', 'lesson'), 'lesson'));
- $mform->setDefault('activitylink', 0);
-
- }
-
$mform->addElement('choosecoursefile', 'mediafile', get_string('mediafile', 'lesson'), array('courseid'=>$COURSE->id));
$mform->setHelpButton('mediafile', array('mediafile', get_string('mediafile', 'lesson'), 'lesson'));
$mform->setDefault('mediafile', '');
//-------------------------------------------------------------------------------
$mform->addElement('header', '', get_string('other', 'lesson'));
+
+ // get the modules
+ if ($mods = get_course_mods($COURSE->id)) {
+ $modinstances = array();
+ foreach ($mods as $mod) {
+
+ // get the module name and then store it in a new array
+ if ($module = get_coursemodule_from_instance($mod->modname, $mod->instance, $COURSE->id)) {
+ if ($this->_cm->id != $mod->id){
+ $modinstances[$mod->id] = $mod->modname.' - '.$module->name;
+ }
+ }
+ }
+ asort($modinstances); // sort by module name
+ $modinstances=array(0=>get_string('none'))+$modinstances;
+
+ $mform->addElement('select', 'activitylink', get_string('activitylink', 'lesson'), $modinstances);
+ $mform->setHelpButton('activitylink', array('activitylink', get_string('activitylink', 'lesson'), 'lesson'));
+ $mform->setDefault('activitylink', 0);
+
+ }
+
$mform->addElement('text', 'maxhighscores', get_string('maxhighscores', 'lesson'));
$mform->setHelpButton('maxhighscores', array('maxhighscores', get_string('maxhighscores', 'lesson'), 'lesson'));
$mform->setDefault('maxhighscores', 10);
$renderer->addStopFieldsetElements('buttonar');
}
- function definition_after_data(){
- $mform =& $this->_form;
- $dependencyel =& $mform->getElement('dependency');
- //unset this option from the dependency drop down :
- $instance = $mform->getElementValue('instance');
- if ($instance){
- $dependencyel->removeOption($instance);
- }
- $update = $mform->getElementValue('update');
- if ($update){
- $activitylinkel =& $mform->getElement('activitylink');
- $activitylinkel->removeOption($update);
+
+ function defaults_preprocessing(&$default_values){
+ if (isset($default_values['conditions'])) {
+ $conditions = unserialize($default_values['conditions']);
+ $default_values['timespent'] = $conditions->timespent;
+ $default_values['completed'] = $conditions->completed;
+ $default_values['gradebetterthan'] = $conditions->gradebetterthan;
}
- }
- /**
- * 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
- * already exist and data is being edited (edit entry form).
- *
- * Overriding this to add functionality to unserialize some fields before setting deafaults for
- * this module
- *
- * @param mixed $default_values object or array of default values
- * @param bool $slased true if magic quotes applied to data values
- */
- function set_defaults($default_values, $slashed=false) {
- if (isset($default_values->conditions)) {
- $conditions = unserialize($default_values->conditions);
- $default_values->timespent = $conditions->timespent;
- $default_values->completed = $conditions->completed;
- $default_values->gradebetterthan = $conditions->gradebetterthan;
- }
- if (isset($default_values->password)) {
- unset($default_values->password);
+ if (isset($default_values['password'])) {
+ unset($default_values['password']);
}
- parent::set_defaults($default_values, $slashed=false);
- }
-
+ }
}
?>
\ No newline at end of file