From 3c7656b4b02e35de0bfdc9a9668c4e64e0f54e23 Mon Sep 17 00:00:00 2001 From: jamiesensei Date: Wed, 15 Nov 2006 07:40:49 +0000 Subject: [PATCH] added two new elements button and choosecoursefile which inherits from button added $supportsgroups bool parameter with default true to give method standard_coursemodule_elements($supportsgroups=true) on moodleform_mod --- lib/form/button.php | 70 +++++++++++++++++ lib/form/choosecoursefile.php | 143 ++++++++++++++++++++++++++++++++++ lib/formslib.php | 37 ++++++--- 3 files changed, 241 insertions(+), 9 deletions(-) create mode 100644 lib/form/button.php create mode 100644 lib/form/choosecoursefile.php diff --git a/lib/form/button.php b/lib/form/button.php new file mode 100644 index 0000000000..514c687116 --- /dev/null +++ b/lib/form/button.php @@ -0,0 +1,70 @@ + | +// | Bertrand Mansion | +// +----------------------------------------------------------------------+ +// +// $Id$ + +require_once("HTML/QuickForm/button.php"); + +/** + * HTML class for a button type element + * + * @author Adam Daniel + * @author Bertrand Mansion + * @version 1.1 + * @since PHP4.04pl1 + * @access public + */ +class MoodleQuickForm_button extends HTML_QuickForm_button +{ + /** + * html for help button, if empty then no help + * + * @var string + */ + var $_helpbutton=''; + /** + * set html for help button + * + * @access public + * @param array $help array of arguments to make a help button + * @param string $function function name to call to get html + */ + function setHelpButton($helpbuttonargs, $function='helpbutton'){ + if (!is_array($helpbuttonargs)){ + $helpbuttonargs=array($helpbuttonargs); + }else{ + $helpbuttonargs=$helpbuttonargs; + } + //we do this to to return html instead of printing it + //without having to specify it in every call to make a button. + $defaultargs=array('', '', 'moodle', true, false, '', true); + $helpbuttonargs=$helpbuttonargs + $defaultargs ; + $this->_helpbutton=call_user_func_array($function, $helpbuttonargs); + } + /** + * get html for help button + * + * @access public + * @return string html for help button + */ + function getHelpButton(){ + return $this->_helpbutton; + } +} //end class MoodleQuickForm_button +?> diff --git a/lib/form/choosecoursefile.php b/lib/form/choosecoursefile.php new file mode 100644 index 0000000000..7315c04536 --- /dev/null +++ b/lib/form/choosecoursefile.php @@ -0,0 +1,143 @@ +libdir/form/group.php"; + +/** + * Class for an element used to choose a file from the course files folder. + * + * + * @author Jamie Pratt + * @access public + */ +class MoodleQuickForm_choosecoursefile extends MoodleQuickForm_group +{ + /** + * Options for element : + * + * $url must be relative to home page eg /mod/survey/stuff.php + * courseid => int course id if null then uses $COURSE global + * width => int Height to assign to popup window + * title => string Text to be displayed as popup page title + * options => string List of additional options for popup window + */ + var $_options = array('courseid'=>null, + 'height'=>500, 'width'=>750, 'options'=>'none'); + + /** + * These complement separators, they are appended to the resultant HTML + * @access private + * @var array + */ + var $_wrap = array('', ''); + + /** + * Class constructor + * + * @access public + * @param string Element's name + * @param mixed Label(s) for an element + * @param array Options to control the element's display + * @param mixed Either a typical HTML attribute string or an associative array + */ + function MoodleQuickForm_choosecoursefile($elementName = null, $elementLabel = null, $options = array(), $attributes = null) + { + $this->HTML_QuickForm_element($elementName, $elementLabel, $attributes); + $this->_appendName = true; + $this->_type = 'choosecoursefile'; + // set the options, do not bother setting bogus ones + if (is_array($options)) { + foreach ($options as $name => $value) { + if (isset($this->_options[$name])) { + if (is_array($value) && is_array($this->_options[$name])) { + $this->_options[$name] = @array_merge($this->_options[$name], $value); + } else { + $this->_options[$name] = $value; + } + } + } + } + } + + // }}} + // {{{ _createElements() + + function _createElements() { + global $COURSE; + $this->_elements = array(); + + $this->_elements[0] =& MoodleQuickForm::createElement('text', 'value', ''); + $this->_elements[1] =& MoodleQuickForm::createElement('button', 'popup', get_string('chooseafile', 'resource') .' ...'); + + $button=$this->_elements[1]; + + if ($this->_options['courseid']!==null){ + $courseid=$this->_options['courseid']; + } else { + $courseid=$COURSE->id; + } + $url="/files/index.php?id=$courseid&choose=id_".$this->getElementName(0); + + if ($this->_options['options'] == 'none') { + $options = 'menubar=0,location=0,scrollbars,resizable,width='. $this->_options['width'] .',height='. $this->_options['height']; + }else{ + $options = $this->_options['options']; + } + $fullscreen = 0; + + $buttonattributes = array('title'=>get_string("chooseafile", "resource"), + 'onclick'=>"return openpopup('$url', '".$button->getName()."', '$options', $fullscreen);"); + $button->updateAttributes($buttonattributes); + } + /** + * Output a timestamp. Give it the name of the group. + * + * @param array $submitValues + * @param bool $assoc + * @return array + */ + function exportValue(&$submitValues, $assoc = false) + { + $value = null; + $valuearray = $this->_elements[0]->exportValue($submitValues[$this->getName()], true); + $value[$this->getName()]=$valuearray['value']; + return $value; + } + // }}} + + /** + * Called by HTML_QuickForm whenever form event is made on this element + * + * @param string $event Name of event + * @param mixed $arg event arguments + * @param object $caller calling object + * @since 1.0 + * @access public + * @return void + */ + function onQuickFormEvent($event, $arg, &$caller) + { + switch ($event) { + case 'updateValue': + // constant values override both default and submitted ones + // default values are overriden by submitted + $value = $this->_findValue($caller->_constantValues); + if (null === $value) { + $value = $this->_findValue($caller->_submitValues); + if (null === $value) { + $value = $this->_findValue($caller->_defaultValues); + } + } + if (!is_array($value)) { + $value = array('value' => $value); + } + if (null !== $value) { + $this->setValue($value); + } + return true; + break; + } + return parent::onQuickFormEvent($event, $arg, $caller); + + } // end func onQuickFormEvent +} +?> \ No newline at end of file diff --git a/lib/formslib.php b/lib/formslib.php index 3ab200b158..4f6306fa3c 100644 --- a/lib/formslib.php +++ b/lib/formslib.php @@ -44,9 +44,24 @@ if ($CFG->debug >= DEBUG_ALL){ */ class moodleform { var $_formname; // form name - var $_form; // quickform object definition - var $_customdata; // globals workaround - var $_upload_manager; // file upload manager + /** + * quickform object definition + * + * @var MoodleQuickForm + */ + var $_form; + /** + * globals workaround + * + * @var array + */ + var $_customdata; + /** + * file upload manager + * + * @var upload_manager + */ + var $_upload_manager; // /** * The constructor function calls the abstract function definition() and it will then @@ -329,16 +344,18 @@ class moodleform { * */ 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(){ + function standard_coursemodule_elements($supportsgroups=true){ $mform =& $this->_form; $mform->addElement('header', '', get_string('modstandardels', 'form')); - - $mform->addElement('modgroupmode', 'groupmode', get_string('groupmode')); - + if ($supportsgroups){ + $mform->addElement('modgroupmode', 'groupmode', get_string('groupmode')); + } $mform->addElement('modvisible', 'visible', get_string('visible')); $this->standard_hidden_coursemodule_elements(); @@ -384,7 +401,7 @@ class moodleform_mod extends moodleform { $this->modvisible_setup($course, $cm, $section); } /** - * You can call this to load the default for the groupmode element. + * This is called from modedit.php to load the default for the groupmode element. * * @param object $course * @param object $cm @@ -394,7 +411,7 @@ class moodleform_mod extends moodleform { } /** - * Sets the default for modvisible form element. + * This is called from modedit.php to set the default for modvisible form element. * * @param object $course * @param object $cm @@ -941,5 +958,7 @@ MoodleQuickForm::registerElementType('modgroupmode', "$CFG->libdir/form/modgroup MoodleQuickForm::registerElementType('selectyesno', "$CFG->libdir/form/selectyesno.php", 'MoodleQuickForm_selectyesno'); MoodleQuickForm::registerElementType('modgrade', "$CFG->libdir/form/modgrade.php", 'MoodleQuickForm_modgrade'); MoodleQuickForm::registerElementType('submit', "$CFG->libdir/form/submit.php", 'MoodleQuickForm_submit'); +MoodleQuickForm::registerElementType('button', "$CFG->libdir/form/button.php", 'MoodleQuickForm_button'); +MoodleQuickForm::registerElementType('choosecoursefile', "$CFG->libdir/form/choosecoursefile.php", 'MoodleQuickForm_choosecoursefile'); ?> \ No newline at end of file -- 2.39.5