mirror of
https://github.com/moodle/moodle.git
synced 2025-08-04 16:36:37 +02:00
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
This commit is contained in:
parent
19384dfb70
commit
3c7656b4b0
3 changed files with 241 additions and 9 deletions
70
lib/form/button.php
Normal file
70
lib/form/button.php
Normal file
|
@ -0,0 +1,70 @@
|
||||||
|
<?php
|
||||||
|
/* vim: set expandtab tabstop=4 shiftwidth=4: */
|
||||||
|
// +----------------------------------------------------------------------+
|
||||||
|
// | PHP version 4.0 |
|
||||||
|
// +----------------------------------------------------------------------+
|
||||||
|
// | Copyright (c) 1997, 1998, 1999, 2000, 2001 The PHP Group |
|
||||||
|
// +----------------------------------------------------------------------+
|
||||||
|
// | This source file is subject to version 2.0 of the PHP license, |
|
||||||
|
// | that is bundled with this package in the file LICENSE, and is |
|
||||||
|
// | available at through the world-wide-web at |
|
||||||
|
// | http://www.php.net/license/2_02.txt. |
|
||||||
|
// | If you did not receive a copy of the PHP license and are unable to |
|
||||||
|
// | obtain it through the world-wide-web, please send a note to |
|
||||||
|
// | license@php.net so we can mail you a copy immediately. |
|
||||||
|
// +----------------------------------------------------------------------+
|
||||||
|
// | Authors: Adam Daniel <adaniel1@eesus.jnj.com> |
|
||||||
|
// | Bertrand Mansion <bmansion@mamasam.com> |
|
||||||
|
// +----------------------------------------------------------------------+
|
||||||
|
//
|
||||||
|
// $Id$
|
||||||
|
|
||||||
|
require_once("HTML/QuickForm/button.php");
|
||||||
|
|
||||||
|
/**
|
||||||
|
* HTML class for a button type element
|
||||||
|
*
|
||||||
|
* @author Adam Daniel <adaniel1@eesus.jnj.com>
|
||||||
|
* @author Bertrand Mansion <bmansion@mamasam.com>
|
||||||
|
* @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
|
||||||
|
?>
|
143
lib/form/choosecoursefile.php
Normal file
143
lib/form/choosecoursefile.php
Normal file
|
@ -0,0 +1,143 @@
|
||||||
|
<?php //$Id$
|
||||||
|
global $CFG;
|
||||||
|
require_once "$CFG->libdir/form/group.php";
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Class for an element used to choose a file from the course files folder.
|
||||||
|
*
|
||||||
|
*
|
||||||
|
* @author Jamie Pratt <me@jamiep.org>
|
||||||
|
* @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
|
||||||
|
}
|
||||||
|
?>
|
|
@ -44,9 +44,24 @@ if ($CFG->debug >= DEBUG_ALL){
|
||||||
*/
|
*/
|
||||||
class moodleform {
|
class moodleform {
|
||||||
var $_formname; // form name
|
var $_formname; // form name
|
||||||
var $_form; // quickform object definition
|
/**
|
||||||
var $_customdata; // globals workaround
|
* quickform object definition
|
||||||
var $_upload_manager; // file upload manager
|
*
|
||||||
|
* @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
|
* The constructor function calls the abstract function definition() and it will then
|
||||||
|
@ -329,16 +344,18 @@ class moodleform {
|
||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
class moodleform_mod extends moodleform {
|
class moodleform_mod extends moodleform {
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Adds all the standard elements to a form to edit the settings for an activity module.
|
* 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 =& $this->_form;
|
||||||
$mform->addElement('header', '', get_string('modstandardels', 'form'));
|
$mform->addElement('header', '', get_string('modstandardels', 'form'));
|
||||||
|
if ($supportsgroups){
|
||||||
$mform->addElement('modgroupmode', 'groupmode', get_string('groupmode'));
|
$mform->addElement('modgroupmode', 'groupmode', get_string('groupmode'));
|
||||||
|
}
|
||||||
$mform->addElement('modvisible', 'visible', get_string('visible'));
|
$mform->addElement('modvisible', 'visible', get_string('visible'));
|
||||||
|
|
||||||
$this->standard_hidden_coursemodule_elements();
|
$this->standard_hidden_coursemodule_elements();
|
||||||
|
@ -384,7 +401,7 @@ class moodleform_mod extends moodleform {
|
||||||
$this->modvisible_setup($course, $cm, $section);
|
$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 $course
|
||||||
* @param object $cm
|
* @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 $course
|
||||||
* @param object $cm
|
* @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('selectyesno', "$CFG->libdir/form/selectyesno.php", 'MoodleQuickForm_selectyesno');
|
||||||
MoodleQuickForm::registerElementType('modgrade', "$CFG->libdir/form/modgrade.php", 'MoodleQuickForm_modgrade');
|
MoodleQuickForm::registerElementType('modgrade', "$CFG->libdir/form/modgrade.php", 'MoodleQuickForm_modgrade');
|
||||||
MoodleQuickForm::registerElementType('submit', "$CFG->libdir/form/submit.php", 'MoodleQuickForm_submit');
|
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');
|
||||||
|
|
||||||
?>
|
?>
|
Loading…
Add table
Add a link
Reference in a new issue