Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

MDL-30974 form: Checked and updated docblock for form library

  • Loading branch information...
commit 6c1fd304841c633a1a2b2feb09596787b80ffe0b 1 parent 5fc420e
Rajesh Taneja authored rajeshtaneja committed
Showing with 2,551 additions and 1,140 deletions.
  1. +58 −34 lib/form/advcheckbox.php
  2. +48 −30 lib/form/button.php
  3. +60 −13 lib/form/cancel.php
  4. +64 −18 lib/form/checkbox.php
  5. +70 −70 lib/form/dateselector.php
  6. +72 −73 lib/form/datetimeselector.php
  7. +72 −40 lib/form/duration.php
  8. +129 −8 lib/form/editor.php
  9. +55 −13 lib/form/file.php
  10. +113 −10 lib/form/filemanager.php
  11. +74 −4 lib/form/filepicker.php
  12. +40 −10 lib/form/format.php
  13. +31 −30 lib/form/grading.php
  14. +60 −15 lib/form/group.php
  15. +46 −16 lib/form/header.php
  16. +46 −10 lib/form/hidden.php
  17. +60 −8 lib/form/htmleditor.php
  18. +43 −15 lib/form/modgrade.php
  19. +41 −14 lib/form/modvisible.php
  20. +47 −9 lib/form/password.php
  21. +46 −4 lib/form/passwordunmask.php
  22. +33 −10 lib/form/questioncategory.php
  23. +57 −9 lib/form/radio.php
  24. +50 −24 lib/form/recaptcha.php
  25. +25 −6 lib/form/searchableselector.php
  26. +73 −22 lib/form/select.php
  27. +113 −185 lib/form/selectgroups.php
  28. +80 −24 lib/form/selectwithlink.php
  29. +41 −17 lib/form/selectyesno.php
  30. +54 −26 lib/form/simpletest/testduration.php
  31. +53 −9 lib/form/static.php
  32. +48 −12 lib/form/submit.php
  33. +52 −0 lib/form/submitlink.php
  34. +81 −36 lib/form/tags.php
  35. +60 −11 lib/form/text.php
  36. +65 −23 lib/form/textarea.php
  37. +61 −12 lib/form/url.php
  38. +59 −12 lib/form/warning.php
  39. +271 −258 lib/formslib.php
View
92 lib/form/advcheckbox.php
@@ -1,42 +1,59 @@
<?php
+// This file is part of Moodle - http://moodle.org/
+//
+// Moodle is free software: you can redistribute it and/or modify
+// it under the terms of the GNU General Public License as published by
+// the Free Software Foundation, either version 3 of the License, or
+// (at your option) any later version.
+//
+// Moodle is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+// GNU General Public License for more details.
+//
+// You should have received a copy of the GNU General Public License
+// along with Moodle. If not, see <http://www.gnu.org/licenses/>.
+
+
+/**
+ * Advanced checkbox type form element
+ *
+ * Contains HTML class for an advcheckbox type form element
+ *
+ * @package core_form
+ * @copyright 2007 Jamie Pratt <me@jamiep.org>
+ * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
+ */
+
require_once('HTML/QuickForm/advcheckbox.php');
/**
- * HTML class for a advcheckbox type element
+ * HTML class for an advcheckbox type element
*
- * default behavior special for Moodle is to return '0' if not checked
- * '1' for checked.
+ * Overloaded {@see HTML_QuickForm_advcheckbox} with default behavior modified for Moodle.
+ * This will return '0' if not checked and '1' if checked.
*
- * * @author Jamie Pratt
- * @access public
+ * @package core_form
+ * @category form
+ * @copyright 2007 Jamie Pratt <me@jamiep.org>
+ * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
class MoodleQuickForm_advcheckbox extends HTML_QuickForm_advcheckbox{
- /**
- * html for help button, if empty then no help
- *
- * @var string
- */
+ /** @var string html for help button, if empty then no help will icon will be dispalyed. */
var $_helpbutton='';
- /**
- * Group to which this checkbox belongs (for select all/select none button)
- * @var string $_group
- */
+ /** @var string Group to which this checkbox belongs (for select all/select none button) */
var $_group;
/**
- * Class constructor
- *
- * @param string $elementName (optional)Input field name attribute
- * @param string $elementLabel (optional)Input field label
- * @param string $text (optional)Text to put after the checkbox
- * @param mixed $attributes (optional)Either a typical HTML attribute string
- * or an associative array
- * @param mixed $values (optional)Values to pass if checked or not checked
+ * constructor
*
- * @since 1.0
- * @access public
- * @return void
+ * @param string $elementName (optional) name of the checkbox
+ * @param string $elementLabel (optional) checkbox label
+ * @param string $text (optional) Text to put after the checkbox
+ * @param mixed $attributes (optional) Either a typical HTML attribute string
+ * or an associative array
+ * @param mixed $values (optional) Values to pass if checked or not checked
*/
function MoodleQuickForm_advcheckbox($elementName=null, $elementLabel=null, $text=null, $attributes=null, $values=null)
{
@@ -65,29 +82,35 @@ function MoodleQuickForm_advcheckbox($elementName=null, $elementLabel=null, $tex
}
parent::HTML_QuickForm_advcheckbox($elementName, $elementLabel, $text, $attributes, $values);
- } //end constructor
-
+ }
/**
* 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
+ * @param array $helpbuttonargs array of arguments to make a help button
+ * @param string $function (optional)function name get help html
+ * @deprecated since Moodle 2.0. Please do not call this function any more.
+ * @todo MDL-31047 this api will be removed.
+ * @see MoodleQuickForm::setHelpButton()
*/
function setHelpButton($helpbuttonargs, $function='helpbutton'){
debugging('component setHelpButton() is not used any more, please use $mform->setHelpButton() instead');
}
+
/**
* get html for help button
*
- * @access public
- * @return string html for help button
+ * @return string html for help button
*/
function getHelpButton(){
return $this->_helpbutton;
}
+ /**
+ * Returns HTML for advchecbox form element.
+ *
+ * @return string
+ */
function toHtml()
{
return '<span>' . parent::toHtml() . '</span>';
@@ -96,7 +119,8 @@ function toHtml()
/**
* Returns the disabled field. Accessibility: the return "[ ]" from parent
* class is not acceptable for screenreader users, and we DO want a label.
- * @return string
+ *
+ * @return string
*/
function getFrozenHtml()
{
@@ -108,6 +132,6 @@ function getFrozenHtml()
$output .= '/>';
}
return $output;
- } //end func getFrozenHtml
+ }
}
View
78 lib/form/button.php
@@ -1,63 +1,81 @@
<?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> |
-// +----------------------------------------------------------------------+
+// This file is part of Moodle - http://moodle.org/
+//
+// Moodle is free software: you can redistribute it and/or modify
+// it under the terms of the GNU General Public License as published by
+// the Free Software Foundation, either version 3 of the License, or
+// (at your option) any later version.
+//
+// Moodle is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+// GNU General Public License for more details.
+//
+// You should have received a copy of the GNU General Public License
+// along with Moodle. If not, see <http://www.gnu.org/licenses/>.
+
+
+/**
+ * Button form element
+ *
+ * Contains HTML class for a button type element
+ *
+ * @package core_form
+ * @copyright 2007 Jamie Pratt <me@jamiep.org>
+ * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
+ */
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
+ * Overloaded {@see HTML_QuickForm_button} to add help button
+ *
+ * @package core_form
+ * @category form
+ * @copyright 2007 Jamie Pratt <me@jamiep.org>
+ * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
class MoodleQuickForm_button extends HTML_QuickForm_button
{
+ /** @var string html for help button, if empty then no help */
+ var $_helpbutton='';
+
/**
- * html for help button, if empty then no help
+ * constructor
*
- * @var string
+ * @param string $elementName (optional) name for the button
+ * @param string $value (optional) value for the button
+ * @param mixed $attributes (optional) Either a typical HTML attribute string
+ * or an associative array
*/
- var $_helpbutton='';
function MoodleQuickForm_button($elementName=null, $value=null, $attributes=null) {
parent::HTML_QuickForm_button($elementName, $value, $attributes);
}
+
/**
* set html for help button
*
- * @access public
- * @param array $help array of arguments to make a help button
+ * @param array $helpbuttonargs array of arguments to make a help button
* @param string $function function name to call to get html
+ * @deprecated since Moodle 2.0. Please do not call this function any more.
+ * @todo MDL-31047 this api will be removed.
+ * @see MoodleQuickForm::setHelpButton()
*/
function setHelpButton($helpbuttonargs, $function='helpbutton'){
debugging('component setHelpButton() is not used any more, please use $mform->setHelpButton() instead');
}
+
/**
* get html for help button
*
- * @access public
- * @return string html for help button
+ * @return string html for help button
*/
function getHelpButton(){
return $this->_helpbutton;
}
+
/**
* Slightly different container template when frozen.
*
@@ -70,4 +88,4 @@ function getElementTemplateType(){
return 'default';
}
}
-} //end class MoodleQuickForm_button
+}
View
73 lib/form/cancel.php
@@ -1,4 +1,30 @@
<?php
+// This file is part of Moodle - http://moodle.org/
+//
+// Moodle is free software: you can redistribute it and/or modify
+// it under the terms of the GNU General Public License as published by
+// the Free Software Foundation, either version 3 of the License, or
+// (at your option) any later version.
+//
+// Moodle is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+// GNU General Public License for more details.
+//
+// You should have received a copy of the GNU General Public License
+// along with Moodle. If not, see <http://www.gnu.org/licenses/>.
+
+
+/**
+ * Button form element
+ *
+ * Contains HTML class for a button type element
+ *
+ * @package core_form
+ * @copyright 2007 Jamie Pratt <me@jamiep.org>
+ * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
+ */
+
if (!defined('MOODLE_INTERNAL')) {
die('Direct access to this script is forbidden.'); /// It must be included from a Moodle page
}
@@ -7,21 +33,24 @@
require_once($CFG->libdir.'/form/submit.php');
/**
- * HTML class for a submit type element
+ * HTML class for a submit cancel type element
+ *
+ * Overloaded {@see MoodleQuickForm_submit} with default behavior modified to cancel a form.
*
- * @author Jamie Pratt
- * @access public
+ * @package core_form
+ * @category form
+ * @copyright 2007 Jamie Pratt <me@jamiep.org>
+ * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
class MoodleQuickForm_cancel extends MoodleQuickForm_submit
{
- // {{{ constructor
-
/**
- * Class constructor
+ * constructor
*
- * @since 1.0
- * @access public
- * @return void
+ * @param string $elementName (optional) name of the checkbox
+ * @param string $value (optional) value for the button
+ * @param mixed $attributes (optional) Either a typical HTML attribute string
+ * or an associative array
*/
function MoodleQuickForm_cancel($elementName=null, $value=null, $attributes=null)
{
@@ -33,7 +62,16 @@ function MoodleQuickForm_cancel($elementName=null, $value=null, $attributes=null
}
MoodleQuickForm_submit::MoodleQuickForm_submit($elementName, $value, $attributes);
$this->updateAttributes(array('onclick'=>'skipClientValidation = true; return true;'));
- } //end constructor
+ }
+
+ /**
+ * 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
+ * @return bool
+ */
function onQuickFormEvent($event, $arg, &$caller)
{
switch ($event) {
@@ -45,14 +83,23 @@ function onQuickFormEvent($event, $arg, &$caller)
break;
}
return parent::onQuickFormEvent($event, $arg, $caller);
- } // end func onQuickFormEvent
+ }
+ /**
+ * Returns the value of field without HTML tags
+ *
+ * @return string
+ */
function getFrozenHtml(){
return HTML_QuickForm_submit::getFrozenHtml();
}
+ /**
+ * Freeze the element so that only its value is returned
+ *
+ * @return bool
+ */
function freeze(){
return HTML_QuickForm_submit::freeze();
}
- // }}}
-} //end class MoodleQuickForm_cancel
+}
View
82 lib/form/checkbox.php
@@ -1,37 +1,78 @@
<?php
+// This file is part of Moodle - http://moodle.org/
+//
+// Moodle is free software: you can redistribute it and/or modify
+// it under the terms of the GNU General Public License as published by
+// the Free Software Foundation, either version 3 of the License, or
+// (at your option) any later version.
+//
+// Moodle is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+// GNU General Public License for more details.
+//
+// You should have received a copy of the GNU General Public License
+// along with Moodle. If not, see <http://www.gnu.org/licenses/>.
+
+
+/**
+ * checkbox form element
+ *
+ * Contains HTML class for a checkbox type element
+ *
+ * @package core_form
+ * @copyright 2007 Jamie Pratt <me@jamiep.org>
+ * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
+ */
+
require_once('HTML/QuickForm/checkbox.php');
/**
* HTML class for a checkbox type element
*
- * @author Jamie Pratt
- * @access public
+ * Overloaded {@see HTML_QuickForm_checkbox} to add help button. Also, fixes bug in quickforms
+ * checkbox, which lets previous set value override submitted value if checkbox is not checked
+ * and no value is submitted
+ *
+ * @package core_form
+ * @category form
+ * @copyright 2007 Jamie Pratt <me@jamiep.org>
+ * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
class MoodleQuickForm_checkbox extends HTML_QuickForm_checkbox{
+ /** @var string html for help button, if empty then no help */
+ var $_helpbutton='';
+
/**
- * html for help button, if empty then no help
+ * Constructor
*
- * @var string
+ * @param string $elementName (optional) name of the checkbox
+ * @param string $elementLabel (optional) checkbox label
+ * @param string $text (optional) Text to put after the checkbox
+ * @param mixed $attributes (optional) Either a typical HTML attribute string
+ * or an associative array
*/
- var $_helpbutton='';
function MoodleQuickForm_checkbox($elementName=null, $elementLabel=null, $text='', $attributes=null) {
parent::HTML_QuickForm_checkbox($elementName, $elementLabel, $text, $attributes);
}
+
/**
* set html for help button
*
- * @access public
- * @param array $help array of arguments to make a help button
+ * @param array $helpbuttonargs array of arguments to make a help button
* @param string $function function name to call to get html
+ * @deprecated since Moodle 2.0. Please do not call this function any more.
+ * @todo MDL-31047 this api will be removed.
+ * @see MoodleQuickForm::setHelpButton()
*/
function setHelpButton($helpbuttonargs, $function='helpbutton'){
debugging('component setHelpButton() is not used any more, please use $mform->setHelpButton() instead');
}
+
/**
* get html for help button
*
- * @access public
- * @return string html for help button
+ * @return string html for help button
*/
function getHelpButton(){
return $this->_helpbutton;
@@ -40,12 +81,10 @@ function getHelpButton(){
/**
* 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
+ * @param string $event Name of event
+ * @param mixed $arg event arguments
+ * @param object $caller calling object
+ * @return bool
*/
function onQuickFormEvent($event, $arg, &$caller)
{
@@ -73,7 +112,13 @@ function onQuickFormEvent($event, $arg, &$caller)
parent::onQuickFormEvent($event, $arg, $caller);
}
return true;
- } // end func onQuickFormEvent
+ }
+
+ /**
+ * Returns HTML for checbox form element.
+ *
+ * @return string
+ */
function toHtml()
{
return '<span>' . parent::toHtml() . '</span>';
@@ -82,7 +127,8 @@ function toHtml()
/**
* Returns the disabled field. Accessibility: the return "[ ]" from parent
* class is not acceptable for screenreader users, and we DO want a label.
- * @return string
+ *
+ * @return string
*/
function getFrozenHtml()
{
@@ -94,5 +140,5 @@ function getFrozenHtml()
$output .= '/>';
}
return $output;
- } //end func getFrozenHtml
+ }
}
View
140 lib/form/dateselector.php
@@ -1,27 +1,29 @@
<?php
+// This file is part of Moodle - http://moodle.org/
+//
+// Moodle is free software: you can redistribute it and/or modify
+// it under the terms of the GNU General Public License as published by
+// the Free Software Foundation, either version 3 of the License, or
+// (at your option) any later version.
+//
+// Moodle is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+// GNU General Public License for more details.
+//
+// You should have received a copy of the GNU General Public License
+// along with Moodle. If not, see <http://www.gnu.org/licenses/>.
-///////////////////////////////////////////////////////////////////////////
-// //
-// NOTICE OF COPYRIGHT //
-// //
-// Moodle - Modular Object-Oriented Dynamic Learning Environment //
-// http://moodle.org //
-// //
-// Copyright (C) 1999 onwards Martin Dougiamas http://dougiamas.com //
-// //
-// This program is free software; you can redistribute it and/or modify //
-// it under the terms of the GNU General Public License as published by //
-// the Free Software Foundation; either version 2 of the License, or //
-// (at your option) any later version. //
-// //
-// This program is distributed in the hope that it will be useful, //
-// but WITHOUT ANY WARRANTY; without even the implied warranty of //
-// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the //
-// GNU General Public License for more details: //
-// //
-// http://www.gnu.org/copyleft/gpl.html //
-// //
-///////////////////////////////////////////////////////////////////////////
+
+/**
+ * Group of date input element
+ *
+ * Contains class for a group of elements used to input a date.
+ *
+ * @package core_form
+ * @copyright 2007 Jamie Pratt <me@jamiep.org>
+ * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
+ */
global $CFG;
require_once($CFG->libdir . '/form/group.php');
@@ -32,38 +34,36 @@
*
* Emulates moodle print_date_selector function
*
- * @package formslib
+ * @package core_form
+ * @category form
+ * @copyright 2007 Jamie Pratt <me@jamiep.org>
+ * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
class MoodleQuickForm_date_selector extends MoodleQuickForm_group
{
/**
- * Control the fieldnames for form elements
- *
- * startyear => integer start of range of years that can be selected
- * stopyear => integer last year that can be selected
- * timezone => float/string timezone
- * applydst => apply users daylight savings adjustment?
- * optional => if true, show a checkbox beside the date to turn it on (or off)
- */
+ * Control the fieldnames for form elements
+ * startyear => int start of range of years that can be selected
+ * stopyear => int last year that can be selected
+ * timezone => float/string timezone
+ * applydst => apply users daylight savings adjustment?
+ * optional => if true, show a checkbox beside the date to turn it on (or off)
+ * @var array
+ */
protected $_options = array('startyear' => 1970, 'stopyear' => 2020,
'timezone' => 99, 'applydst' => true, 'optional' => false);
- /**
- * These complement separators, they are appended to the resultant HTML
- * @access private
- * @var array
- */
+ /** @var array These complement separators, they are appended to the resultant HTML */
protected $_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
- */
+ /**
+ * constructor
+ *
+ * @param string $elementName Element's name
+ * @param mixed $elementLabel Label(s) for an element
+ * @param array $options Options to control the element's display
+ * @param mixed $attributes Either a typical HTML attribute string or an associative array
+ */
function MoodleQuickForm_date_selector($elementName = null, $elementLabel = null, $options = array(), $attributes = null)
{
$this->HTML_QuickForm_element($elementName, $elementLabel, $attributes);
@@ -85,9 +85,11 @@ function MoodleQuickForm_date_selector($elementName = null, $elementLabel = null
form_init_date_js();
}
- // }}}
- // {{{ _createElements()
-
+ /**
+ * This will create date group element constisting of day, month and year.
+ *
+ * @access private
+ */
function _createElements()
{
$this->_elements = array();
@@ -115,18 +117,13 @@ function _createElements()
}
- // }}}
- // {{{ onQuickFormEvent()
-
/**
* 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
+ *
+ * @param string $event Name of event
+ * @param mixed $arg event arguments
+ * @param object $caller calling object
+ * @return bool
*/
function onQuickFormEvent($event, $arg, &$caller)
{
@@ -176,10 +173,13 @@ function onQuickFormEvent($event, $arg, &$caller)
default:
return parent::onQuickFormEvent($event, $arg, $caller);
}
- } // end func onQuickFormEvent
-
- // {{{ toHtml()
+ }
+ /**
+ * Returns HTML for advchecbox form element.
+ *
+ * @return string
+ */
function toHtml()
{
include_once('HTML/QuickForm/Renderer/Default.php');
@@ -189,21 +189,23 @@ function toHtml()
return $this->_wrap[0] . $renderer->toHtml() . $this->_wrap[1];
}
- // }}}
- // {{{ accept()
-
+ /**
+ * Accepts a renderer
+ *
+ * @param HTML_QuickForm_Renderer $renderer An HTML_QuickForm_Renderer object
+ * @param bool $required Whether a group is required
+ * @param string $error An error message associated with a group
+ */
function accept(&$renderer, $required = false, $error = null)
{
$renderer->renderElement($this, $required, $error);
}
- // }}}
-
/**
* Output a timestamp. Give it the name of the group.
*
- * @param array $submitValues
- * @param bool $assoc
+ * @param array $submitValues values submitted.
+ * @param bool $assoc specifies if returned array is associative
* @return array
*/
function exportValue(&$submitValues, $assoc = false)
@@ -237,6 +239,4 @@ function exportValue(&$submitValues, $assoc = false)
return null;
}
}
-
- // }}}
}
View
145 lib/form/datetimeselector.php
@@ -1,70 +1,70 @@
<?php
+// This file is part of Moodle - http://moodle.org/
+//
+// Moodle is free software: you can redistribute it and/or modify
+// it under the terms of the GNU General Public License as published by
+// the Free Software Foundation, either version 3 of the License, or
+// (at your option) any later version.
+//
+// Moodle is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+// GNU General Public License for more details.
+//
+// You should have received a copy of the GNU General Public License
+// along with Moodle. If not, see <http://www.gnu.org/licenses/>.
-///////////////////////////////////////////////////////////////////////////
-// //
-// NOTICE OF COPYRIGHT //
-// //
-// Moodle - Modular Object-Oriented Dynamic Learning Environment //
-// http://moodle.org //
-// //
-// Copyright (C) 1999 onwards Martin Dougiamas http://dougiamas.com //
-// //
-// This program is free software; you can redistribute it and/or modify //
-// it under the terms of the GNU General Public License as published by //
-// the Free Software Foundation; either version 2 of the License, or //
-// (at your option) any later version. //
-// //
-// This program is distributed in the hope that it will be useful, //
-// but WITHOUT ANY WARRANTY; without even the implied warranty of //
-// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the //
-// GNU General Public License for more details: //
-// //
-// http://www.gnu.org/copyleft/gpl.html //
-// //
-///////////////////////////////////////////////////////////////////////////
+
+/**
+ * Group of date and time input element
+ *
+ * Contains class for a group of elements used to input a date and time.
+ *
+ * @package core_form
+ * @copyright 2006 Jamie Pratt <me@jamiep.org>
+ * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
+ */
global $CFG;
require_once($CFG->libdir . '/form/group.php');
require_once($CFG->libdir . '/formslib.php');
/**
- * Class for a group of elements used to input a date and time.
+ * Element used to input a date and time.
*
- * Emulates moodle print_date_selector function and also allows you to select a time.
+ * Class for a group of elements used to input a date and time.
*
- * @package formslib
+ * @package core_form
+ * @category form
+ * @copyright 2006 Jamie Pratt <me@jamiep.org>
+ * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
class MoodleQuickForm_date_time_selector extends MoodleQuickForm_group{
/**
- * Options for the element
- *
- * startyear => integer start of range of years that can be selected
- * stopyear => integer last year that can be selected
- * defaulttime => default time value if the field is currently not set
- * timezone => float/string timezone
- * applydst => apply users daylight savings adjustment?
- * step => step to increment minutes by
- * optional => if true, show a checkbox beside the date to turn it on (or off)
- */
+ * Options for the element
+ * startyear => int start of range of years that can be selected
+ * stopyear => int last year that can be selected
+ * defaulttime => default time value if the field is currently not set
+ * timezone => float/string timezone
+ * applydst => apply users daylight savings adjustment?
+ * step => step to increment minutes by
+ * optional => if true, show a checkbox beside the date to turn it on (or off)
+ * @var array
+ */
var $_options = array('startyear' => 1970, 'stopyear' => 2020, 'defaulttime' => 0,
'timezone' => 99, 'applydst' => true, 'step' => 5, 'optional' => false);
- /**
- * These complement separators, they are appended to the resultant HTML
- * @access private
- * @var array
- */
+ /** @var array These complement separators, they are appended to the resultant HTML */
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
- */
+ /**
+ * Class constructor
+ *
+ * @param string $elementName Element's name
+ * @param mixed $elementLabel Label(s) for an element
+ * @param array $options Options to control the element's display
+ * @param mixed $attributes Either a typical HTML attribute string or an associative array
+ */
function MoodleQuickForm_date_time_selector($elementName = null, $elementLabel = null, $options = array(), $attributes = null)
{
$this->HTML_QuickForm_element($elementName, $elementLabel, $attributes);
@@ -86,9 +86,11 @@ function MoodleQuickForm_date_time_selector($elementName = null, $elementLabel =
form_init_date_js();
}
- // }}}
- // {{{ _createElements()
-
+ /**
+ * This will create date group element constisting of day, month and year.
+ *
+ * @access private
+ */
function _createElements()
{
$this->_elements = array();
@@ -129,18 +131,13 @@ function _createElements()
}
- // }}}
- // {{{ onQuickFormEvent()
-
/**
* 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
+ * @param string $event Name of event
+ * @param mixed $arg event arguments
+ * @param object $caller calling object
+ * @return bool
*/
function onQuickFormEvent($event, $arg, &$caller)
{
@@ -197,9 +194,11 @@ function onQuickFormEvent($event, $arg, &$caller)
}
}
- // }}}
- // {{{ toHtml()
-
+ /**
+ * Returns HTML for advchecbox form element.
+ *
+ * @return string
+ */
function toHtml()
{
include_once('HTML/QuickForm/Renderer/Default.php');
@@ -209,21 +208,23 @@ function toHtml()
return $this->_wrap[0] . $renderer->toHtml() . $this->_wrap[1];
}
- // }}}
- // {{{ accept()
-
+ /**
+ * Accepts a renderer
+ *
+ * @param HTML_QuickForm_Renderer $renderer An HTML_QuickForm_Renderer object
+ * @param bool $required Whether a group is required
+ * @param string $error An error message associated with a group
+ */
function accept(&$renderer, $required = false, $error = null)
{
$renderer->renderElement($this, $required, $error);
}
- // }}}
-
/**
* Output a timestamp. Give it the name of the group.
*
- * @param array $submitValues
- * @param bool $assoc
+ * @param array $submitValues values submitted.
+ * @param bool $assoc specifies if returned array is associative
* @return array
*/
function exportValue(&$submitValues, $assoc = false)
@@ -261,6 +262,4 @@ function exportValue(&$submitValues, $assoc = false)
return null;
}
}
-
- // }}}
}
View
112 lib/form/duration.php
@@ -1,27 +1,29 @@
<?php
+// This file is part of Moodle - http://moodle.org/
+//
+// Moodle is free software: you can redistribute it and/or modify
+// it under the terms of the GNU General Public License as published by
+// the Free Software Foundation, either version 3 of the License, or
+// (at your option) any later version.
+//
+// Moodle is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+// GNU General Public License for more details.
+//
+// You should have received a copy of the GNU General Public License
+// along with Moodle. If not, see <http://www.gnu.org/licenses/>.
-///////////////////////////////////////////////////////////////////////////
-// //
-// NOTICE OF COPYRIGHT //
-// //
-// Moodle - Modular Object-Oriented Dynamic Learning Environment //
-// http://moodle.org //
-// //
-// Copyright (C) 1999 onwards Martin Dougiamas http://dougiamas.com //
-// //
-// This program is free software; you can redistribute it and/or modify //
-// it under the terms of the GNU General Public License as published by //
-// the Free Software Foundation; either version 2 of the License, or //
-// (at your option) any later version. //
-// //
-// This program is distributed in the hope that it will be useful, //
-// but WITHOUT ANY WARRANTY; without even the implied warranty of //
-// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the //
-// GNU General Public License for more details: //
-// //
-// http://www.gnu.org/copyleft/gpl.html //
-// //
-///////////////////////////////////////////////////////////////////////////
+
+/**
+ * Duration form element
+ *
+ * Contains class to create length of time for element.
+ *
+ * @package core_form
+ * @copyright 2009 Tim Hunt
+ * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
+ */
global $CFG;
require_once($CFG->libdir . '/form/group.php');
@@ -29,30 +31,37 @@
require_once($CFG->libdir . '/form/text.php');
/**
+ * Duration element
+ *
* HTML class for a length of time. For example, 30 minutes of 4 days. The
* values returned to PHP is the duration in seconds.
*
- * @package formslib
+ * @package core_form
+ * @category form
+ * @copyright 2009 Tim Hunt
+ * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
class MoodleQuickForm_duration extends MoodleQuickForm_group {
/**
* Control the fieldnames for form elements
* optional => if true, show a checkbox beside the element to turn it on (or off)
+ * @var array
*/
protected $_options = array('optional' => false, 'defaultunit' => 60);
+ /** @var array associative array of time units (days, hours, minutes, seconds) */
private $_units = null;
/**
- * Class constructor
+ * constructor
*
- * @access public
- * @param string $elementName Element's name
- * @param mixed $elementLabel Label(s) for an element
- * @param array $options Options to control the element's display. Recognised values are
- * 'optional' => true/false - whether to display an 'enabled' checkbox next to the element.
- * 'defaultunit' => 1|60|3600|86400 - the default unit to display when the time is blank. If not specified, minutes is used.
- * @param mixed $attributes Either a typical HTML attribute string or an associative array
+ * @param string $elementName Element's name
+ * @param mixed $elementLabel Label(s) for an element
+ * @param array $options Options to control the element's display. Recognised values are
+ 'optional' => true/false - whether to display an 'enabled' checkbox next to the element.
+ 'defaultunit' => 1|60|3600|86400 - the default unit to display when the time is blank.
+ * If not specified, minutes is used.
+ * @param mixed $attributes Either a typical HTML attribute string or an associative array
*/
function MoodleQuickForm_duration($elementName = null, $elementLabel = null, $options = array(), $attributes = null) {
$this->HTML_QuickForm_element($elementName, $elementLabel, $attributes);
@@ -75,6 +84,8 @@ function MoodleQuickForm_duration($elementName = null, $elementLabel = null, $op
}
/**
+ * Returns time associative array of unit length.
+ *
* @return array unit length in seconds => string unit name.
*/
public function get_units() {
@@ -90,9 +101,11 @@ public function get_units() {
}
/**
- * @param $seconds an amout of time in seconds.
- * @return array($number, $unit) Conver an interval to the best possible unit.
- * for example 1800 -> array(30, 60) = 30 minutes.
+ * Converts seconds to the best possible time unit. for example
+ * 1800 -> array(30, 60) = 30 minutes.
+ *
+ * @param int $seconds an amout of time in seconds.
+ * @return array associative array ($number => $unit)
*/
public function seconds_to_unit($seconds) {
if ($seconds == 0) {
@@ -106,7 +119,9 @@ public function seconds_to_unit($seconds) {
return array($seconds, 1);
}
- // Override of standard quickforms method.
+ /**
+ * Override of standard quickforms method to create this element.
+ */
function _createElements() {
$attributes = $this->getAttributes();
if (is_null($attributes)) {
@@ -130,7 +145,14 @@ function _createElements() {
}
}
- // Override of standard quickforms method.
+ /**
+ * 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
+ * @return bool
+ */
function onQuickFormEvent($event, $arg, $caller) {
switch ($event) {
case 'updateValue':
@@ -174,7 +196,11 @@ function onQuickFormEvent($event, $arg, $caller) {
}
}
- // Override of standard quickforms method.
+ /**
+ * Returns HTML for advchecbox form element.
+ *
+ * @return string
+ */
function toHtml() {
include_once('HTML/QuickForm/Renderer/Default.php');
$renderer = new HTML_QuickForm_Renderer_Default();
@@ -183,7 +209,13 @@ function toHtml() {
return $renderer->toHtml();
}
- // Override of standard quickforms method.
+ /**
+ * Accepts a renderer
+ *
+ * @param HTML_QuickForm_Renderer $renderer An HTML_QuickForm_Renderer object
+ * @param bool $required Whether a group is required
+ * @param string $error An error message associated with a group
+ */
function accept($renderer, $required = false, $error = null) {
$renderer->renderElement($this, $required, $error);
}
@@ -192,8 +224,8 @@ function accept($renderer, $required = false, $error = null) {
* Output a timestamp. Give it the name of the group.
* Override of standard quickforms method.
*
- * @param array $submitValues
- * @param bool $notused Not used.
+ * @param array $submitValues
+ * @param bool $notused Not used.
* @return array field name => value. The value is the time interval in seconds.
*/
function exportValue($submitValues, $notused = false) {
View
137 lib/form/editor.php
@@ -1,4 +1,29 @@
<?php
+// This file is part of Moodle - http://moodle.org/
+//
+// Moodle is free software: you can redistribute it and/or modify
+// it under the terms of the GNU General Public License as published by
+// the Free Software Foundation, either version 3 of the License, or
+// (at your option) any later version.
+//
+// Moodle is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+// GNU General Public License for more details.
+//
+// You should have received a copy of the GNU General Public License
+// along with Moodle. If not, see <http://www.gnu.org/licenses/>.
+
+
+/**
+ * Editor input element
+ *
+ * Contains class to create preffered editor form element
+ *
+ * @package core_form
+ * @copyright 2009 Petr Skoda {@link http://skodak.org}
+ * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
+ */
global $CFG;
@@ -6,19 +31,41 @@
require_once($CFG->dirroot.'/lib/filelib.php');
require_once($CFG->dirroot.'/repository/lib.php');
-//TODO:
-// * locking
-// * freezing
-// * ajax format conversion
-
+/**
+ * Editor element
+ *
+ * It creates preffered editor (textbox/TinyMce) form element for the format (Text/HTML) selected.
+ *
+ * @package core_form
+ * @category form
+ * @copyright 2009 Petr Skoda {@link http://skodak.org}
+ * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
+ * @todo MDL-29421 element Freezing
+ * @todo MDL-29426 ajax format conversion
+ */
class MoodleQuickForm_editor extends HTML_QuickForm_element {
+ /** @var string html for help button, if empty then no help will icon will be dispalyed. */
public $_helpbutton = '';
+ /** @var string defines the type of editor */
public $_type = 'editor';
+
+ /** @var array options provided to initalize filepicker */
protected $_options = array('subdirs'=>0, 'maxbytes'=>0, 'maxfiles'=>0, 'changeformat'=>0,
'context'=>null, 'noclean'=>0, 'trusttext'=>0);
+
+ /** @var array values for editor */
protected $_values = array('text'=>null, 'format'=>null, 'itemid'=>null);
+ /**
+ * Constructor
+ *
+ * @param string $elementName (optional) name of the editor
+ * @param string $elementLabel (optional) editor label
+ * @param array $attributes (optional) Either a typical HTML attribute string
+ * or an associative array
+ * @param array $options set of options to initalize filepicker
+ */
function MoodleQuickForm_editor($elementName=null, $elementLabel=null, $attributes=null, $options=null) {
global $CFG, $PAGE;
@@ -40,14 +87,29 @@ function MoodleQuickForm_editor($elementName=null, $elementLabel=null, $attribut
editors_head_setup();
}
+ /**
+ * Sets name of editor
+ *
+ * @param string $name name of the editor
+ */
function setName($name) {
$this->updateAttributes(array('name'=>$name));
}
+ /**
+ * Returns name of element
+ *
+ * @return string
+ */
function getName() {
return $this->getAttribute('name');
}
+ /**
+ * Updates editor values, if part of $_values
+ *
+ * @param array $values associative array of values to set
+ */
function setValue($values) {
$values = (array)$values;
foreach ($values as $name=>$value) {
@@ -57,31 +119,66 @@ function setValue($values) {
}
}
+ /**
+ * Returns editor values
+ *
+ * @return array
+ */
function getValue() {
return $this->_values;
}
+ /**
+ * Returns maximum file size which can be uploaded
+ *
+ * @return int
+ */
function getMaxbytes() {
return $this->_options['maxbytes'];
}
+ /**
+ * Sets maximum file size which can be uploaded
+ *
+ * @param int $maxbytes file size
+ */
function setMaxbytes($maxbytes) {
global $CFG;
$this->_options['maxbytes'] = get_max_upload_file_size($CFG->maxbytes, $maxbytes);
}
+ /**
+ * Returns maximum number of files which can be uploaded
+ *
+ * @return int
+ */
function getMaxfiles() {
return $this->_options['maxfiles'];
}
+ /**
+ * Sets maximum number of files which can be uploaded.
+ *
+ * @param int $num number of files
+ */
function setMaxfiles($num) {
$this->_options['maxfiles'] = $num;
}
+ /**
+ * Returns true if subdirectoy can be created, else false
+ *
+ * @return bool
+ */
function getSubdirs() {
return $this->_options['subdirs'];
}
+ /**
+ * Set option to create sub directory, while uploading file
+ *
+ * @param bool $allow true if sub directory can be created.
+ */
function setSubdirs($allow) {
$this->_options['subdirs'] = $allow;
}
@@ -96,14 +193,23 @@ function getFormat() {
}
/**
- * Checks if editor used is tinymce and is required field
+ * Checks if editor used is a required field
*
- * @return true if required field.
+ * @return bool true if required field.
*/
function isRequired() {
return (isset($this->_options['required']) && $this->_options['required']);
}
+ /**
+ * Sets help button for editor
+ *
+ * @param mixed $_helpbuttonargs arguments to create help button
+ * @param string $function name of the callback function
+ * @deprecated since Moodle 2.0. Please do not call this function any more.
+ * @todo MDL-31047 this api will be removed.
+ * @see MoodleQuickForm::setHelpButton()
+ */
function setHelpButton($_helpbuttonargs, $function='_helpbutton') {
if (!is_array($_helpbuttonargs)) {
$_helpbuttonargs = array($_helpbuttonargs);
@@ -119,10 +225,20 @@ function setHelpButton($_helpbuttonargs, $function='_helpbutton') {
$this->_helpbutton=call_user_func_array($function, $_helpbuttonargs);
}
+ /**
+ * Returns html for help button.
+ *
+ * @return string html for help button
+ */
function getHelpButton() {
return $this->_helpbutton;
}
+ /**
+ * Returns type of editor element
+ *
+ * @return string
+ */
function getElementTemplateType() {
if ($this->_flagFrozen){
return 'nodisplay';
@@ -131,6 +247,11 @@ function getElementTemplateType() {
}
}
+ /**
+ * Returns HTML for editor form element.
+ *
+ * @return string
+ */
function toHtml() {
global $CFG, $PAGE;
require_once($CFG->dirroot.'/repository/lib.php');
@@ -285,4 +406,4 @@ function getFrozenHtml() {
return '';
}
-}
+}
View
68 lib/form/file.php
@@ -1,19 +1,57 @@
<?php
+// This file is part of Moodle - http://moodle.org/
+//
+// Moodle is free software: you can redistribute it and/or modify
+// it under the terms of the GNU General Public License as published by
+// the Free Software Foundation, either version 3 of the License, or
+// (at your option) any later version.
+//
+// Moodle is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+// GNU General Public License for more details.
+//
+// You should have received a copy of the GNU General Public License
+// along with Moodle. If not, see <http://www.gnu.org/licenses/>.
+
+
+/**
+ * File type form element
+ *
+ * Contains HTML class for a file type form element
+ *
+ * @package core_form
+ * @copyright 2007 Jamie Pratt <me@jamiep.org>
+ * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
+ */
+
require_once('HTML/QuickForm/file.php');
/**
+ * file element
+ *
* HTML class for a form element to upload a file
*
- * @author Jamie Pratt
- * @access public
+ * @package core_form
+ * @deprecated since Moodle 2.0 Please do not use this form element.
+ * @todo MDL-31294 remove this element
+ * @see MoodleQuickForm_filepicker
+ * @see MoodleQuickForm_filemanager
+ * @copyright 2007 Jamie Pratt <me@jamiep.org>
+ * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
class MoodleQuickForm_file extends HTML_QuickForm_file{
+ /** @var string html for help button, if empty then no help */
+ var $_helpbutton='';
+
/**
- * html for help button, if empty then no help
+ * Constructor
*
- * @var string
+ * @param string $elementName (optional) name of the editor
+ * @param string $elementLabel (optional) editor label
+ * @param array $attributes (optional) Either a typical HTML attribute string
+ * or an associative array
*/
- var $_helpbutton='';
function MoodleQuickForm_file($elementName=null, $elementLabel=null, $attributes=null) {
debugging('file forms element is deprecated, please use new filepicker instead');
parent::HTML_QuickForm_file($elementName, $elementLabel, $attributes);
@@ -21,19 +59,17 @@ function MoodleQuickForm_file($elementName=null, $elementLabel=null, $attributes
/**
* set html for help button
*
- * @access public
- * @param array $help array of arguments to make a help button
+ * @param array $helpbuttonargs array of arguments to make a help button
* @param string $function function name to call to get html
+ * @deprecated since Moodle 2.0. Please do not call this function any more.
+ * @todo MDL-31047 this api will be removed.
+ * @see MoodleQuickForm::setHelpButton()
*/
function setHelpButton($helpbuttonargs, $function='helpbutton'){
debugging('component setHelpButton() is not used any more, please use $mform->setHelpButton() instead');
}
/**
* 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 getHelpButton(){
return $this->_helpbutton;
@@ -41,6 +77,11 @@ function getHelpButton(){
/**
* Override createElement event to add max files
+ *
+ * @param string $event Name of event
+ * @param mixed $arg event arguments
+ * @param object $caller calling object
+ * @return bool
*/
function onQuickFormEvent($event, $arg, &$caller)
{
@@ -50,7 +91,8 @@ function onQuickFormEvent($event, $arg, &$caller)
return true;
}
return parent::onQuickFormEvent($event, $arg, $caller);
- } // end func onQuickFormEvent
+ }
+
/**
* Slightly different container template when frozen.
*
@@ -64,4 +106,4 @@ function getElementTemplateType(){
}
}
-}
+}
View
123 lib/form/filemanager.php
@@ -14,13 +14,15 @@
// You should have received a copy of the GNU General Public License
// along with Moodle. If not, see <http://www.gnu.org/licenses/>.
+
/**
- * File manager
+ * FileManager form element
+ *
+ * Contains HTML class for a filemanager form element
*
- * @package moodlecore
- * @subpackage file
- * @copyright 1999 onwards Dongsheng Cai <dongsheng@moodle.com>
- * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
+ * @package core_form
+ * @copyright 2009 Dongsheng Cai <dongsheng@moodle.com>
+ * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
global $CFG;
@@ -29,10 +31,31 @@
require_once($CFG->dirroot.'/lib/filelib.php');
require_once($CFG->dirroot.'/repository/lib.php');
+/**
+ * Filemanager form element
+ *
+ * FilemaneManager lets user to upload/manage multiple files
+ * @package core_form
+ * @category form
+ * @copyright 2009 Dongsheng Cai <dongsheng@moodle.com>
+ * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
+ */
class MoodleQuickForm_filemanager extends HTML_QuickForm_element {
+ /** @var string html for help button, if empty then no help will icon will be dispalyed. */
public $_helpbutton = '';
+
+ /** @var array options provided to initalize filemanager */
protected $_options = array('mainfile'=>'', 'subdirs'=>1, 'maxbytes'=>-1, 'maxfiles'=>-1, 'accepted_types'=>'*', 'return_types'=>FILE_INTERNAL);
+ /**
+ * Constructor
+ *
+ * @param string $elementName (optional) name of the filemanager
+ * @param string $elementLabel (optional) filemanager label
+ * @param array $attributes (optional) Either a typical HTML attribute string
+ * or an associative array
+ * @param array $options set of options to initalize filemanager
+ */
function MoodleQuickForm_filemanager($elementName=null, $elementLabel=null, $attributes=null, $options=null) {
global $CFG, $PAGE;
@@ -49,55 +72,124 @@ function MoodleQuickForm_filemanager($elementName=null, $elementLabel=null, $att
parent::HTML_QuickForm_element($elementName, $elementLabel, $attributes);
}
+ /**
+ * Sets name of filemanager
+ *
+ * @param string $name name of the filemanager
+ */
function setName($name) {
$this->updateAttributes(array('name'=>$name));
}
+ /**
+ * Returns name of filemanager
+ *
+ * @return string
+ */
function getName() {
return $this->getAttribute('name');
}
+ /**
+ * Updates filemanager attribute value
+ *
+ * @param string $value value to set
+ */
function setValue($value) {
$this->updateAttributes(array('value'=>$value));
}
+ /**
+ * Returns filemanager attribute value
+ *
+ * @return string
+ */
function getValue() {
return $this->getAttribute('value');
}
+ /**
+ * Returns maximum file size which can be uploaded
+ *
+ * @return int
+ */
function getMaxbytes() {
return $this->_options['maxbytes'];
}
+ /**
+ * Sets maximum file size which can be uploaded
+ *
+ * @param int $maxbytes file size
+ */
function setMaxbytes($maxbytes) {
global $CFG;
$this->_options['maxbytes'] = get_max_upload_file_size($CFG->maxbytes, $maxbytes);
}
+ /**
+ * Returns true if subdirectoy can be created, else false
+ *
+ * @return bool
+ */
function getSubdirs() {
return $this->_options['subdirs'];
}
+ /**
+ * Set option to create sub directory, while uploading file
+ *
+ * @param bool $allow true if sub directory can be created.
+ */
function setSubdirs($allow) {
$this->_options['subdirs'] = $allow;
}
+ /**
+ * Returns maximum number of files which can be uploaded
+ *
+ * @return int
+ */
function getMaxfiles() {
return $this->_options['maxfiles'];
}
+ /**
+ * Sets maximum number of files which can be uploaded.
+ *
+ * @param int $num number of files
+ */
function setMaxfiles($num) {
$this->_options['maxfiles'] = $num;
}
+ /**
+ * Sets help button for filemanager
+ *
+ * @param mixed $helpbuttonargs arguments to create help button
+ * @param string $function name of the callback function
+ * @deprecated since Moodle 2.0. Please do not call this function any more.
+ * @todo MDL-31047 this api will be removed.
+ * @see MoodleQuickForm::setHelpButton()
+ */
function setHelpButton($helpbuttonargs, $function='helpbutton'){
debugging('component setHelpButton() is not used any more, please use $mform->setHelpButton() instead');
}
+ /**
+ * Returns html for help button.
+ *
+ * @return string html for help button
+ */
function getHelpButton() {
return $this->_helpbutton;
}
+ /**
+ * Returns type of filemanager element
+ *
+ * @return string
+ */
function getElementTemplateType() {
if ($this->_flagFrozen){
return 'nodisplay';
@@ -106,6 +198,11 @@ function getElementTemplateType() {
}
}
+ /**
+ * Returns HTML for filemanager form element.
+ *
+ * @return string
+ */
function toHtml() {
global $CFG, $USER, $COURSE, $PAGE, $OUTPUT;
require_once("$CFG->dirroot/repository/lib.php");
@@ -159,19 +256,25 @@ function toHtml() {
}
}
-
-
/**
* Data structure representing a file manager.
*
+ * This class defines the data structure for file mnager
+ *
+ * @package core_form
* @copyright 2010 Dongsheng Cai
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
- * @since Moodle 2.0
+ * @todo do not use this abstraction (skodak)
*/
class form_filemanaer_x {
- //TODO: do not use this abstraction (skodak)
-
+ /** @var stdClass $options options for filemanager */
public $options;
+
+ /**
+ * Constructor
+ *
+ * @param stdClass $options options for filemanager
+ */
public function __construct(stdClass $options) {
global $CFG, $USER, $PAGE;
require_once($CFG->dirroot. '/repository/lib.php');
View
78 lib/form/filepicker.php
@@ -1,4 +1,29 @@
<?php
+// This file is part of Moodle - http://moodle.org/
+//
+// Moodle is free software: you can redistribute it and/or modify
+// it under the terms of the GNU General Public License as published by
+// the Free Software Foundation, either version 3 of the License, or
+// (at your option) any later version.
+//
+// Moodle is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+// GNU General Public License for more details.
+//
+// You should have received a copy of the GNU General Public License
+// along with Moodle. If not, see <http://www.gnu.org/licenses/>.
+
+
+/**
+ * Filepicker form element
+ *
+ * Contains HTML class for a single filepicker form element
+ *
+ * @package core_form
+ * @copyright 2009 Dongsheng Cai <dongsheng@moodle.com>
+ * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
+ */
global $CFG;
@@ -6,17 +31,31 @@
require_once($CFG->dirroot.'/repository/lib.php');
/**
+ * Filepicker form element
+ *
* HTML class for a single filepicker element (based on button)
*
- * @author Moodle.com
- * @version 1.0
- * @since Moodle 2.0
- * @access public
+ * @package core_form
+ * @category form
+ * @copyright 2009 Dongsheng Cai <dongsheng@moodle.com>
+ * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
class MoodleQuickForm_filepicker extends HTML_QuickForm_input {
+ /** @var string html for help button, if empty then no help will icon will be dispalyed. */
public $_helpbutton = '';
+
+ /** @var array options provided to initalize filemanager */
protected $_options = array('maxbytes'=>0, 'accepted_types'=>'*', 'return_types'=>FILE_INTERNAL);
+ /**
+ * Constructor
+ *
+ * @param string $elementName (optional) name of the filepicker
+ * @param string $elementLabel (optional) filepicker label
+ * @param array $attributes (optional) Either a typical HTML attribute string
+ * or an associative array
+ * @param array $options set of options to initalize filepicker
+ */
function MoodleQuickForm_filepicker($elementName=null, $elementLabel=null, $attributes=null, $options=null) {
global $CFG;
@@ -33,14 +72,33 @@ function MoodleQuickForm_filepicker($elementName=null, $elementLabel=null, $attr
parent::HTML_QuickForm_input($elementName, $elementLabel, $attributes);
}
+ /**
+ * Sets help button for filepicker
+ *
+ * @param mixed $helpbuttonargs arguments to create help button
+ * @param string $function name of the callback function
+ * @deprecated since Moodle 2.0. Please do not call this function any more.
+ * @todo MDL-31047 this api will be removed.
+ * @see MoodleQuickForm::setHelpButton()
+ */
function setHelpButton($helpbuttonargs, $function='helpbutton') {
debugging('component setHelpButton() is not used any more, please use $mform->setHelpButton() instead');
}
+ /**
+ * Returns html for help button.
+ *
+ * @return string html for help button
+ */
function getHelpButton() {
return $this->_helpbutton;
}
+ /**
+ * Returns type of filepicker element
+ *
+ * @return string
+ */
function getElementTemplateType() {
if ($this->_flagFrozen){
return 'nodisplay';
@@ -49,6 +107,11 @@ function getElementTemplateType() {
}
}
+ /**
+ * Returns HTML for filepicker form element.
+ *
+ * @return string
+ */
function toHtml() {
global $CFG, $COURSE, $USER, $PAGE, $OUTPUT;
$id = $this->_attributes['id'];
@@ -111,6 +174,13 @@ function toHtml() {
return $html;
}
+ /**
+ * export uploaded file
+ *
+ * @param array $submitValues values submitted.
+ * @param bool $assoc specifies if returned array is associative
+ * @return array
+ */
function exportValue(&$submitValues, $assoc = false) {
global $USER;
View
50 lib/form/format.php
@@ -1,25 +1,55 @@
<?php
+// This file is part of Moodle - http://moodle.org/
+//
+// Moodle is free software: you can redistribute it and/or modify
+// it under the terms of the GNU General Public License as published by
+// the Free Software Foundation, either version 3 of the License, or
+// (at your option) any later version.
+//
+// Moodle is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+// GNU General Public License for more details.
+//
+// You should have received a copy of the GNU General Public License
+// along with Moodle. If not, see <http://www.gnu.org/licenses/>.
+
+
+/**
+ * editor format form element
+ *
+ * Contains HTML class for a editor format drop down element
+ *
+ * @package core_form
+ * @copyright 2007 Jamie Pratt <me@jamiep.org>
+ * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
+ */
+
global $CFG;
require_once "$CFG->libdir/form/select.php";
/**
- * HTML class for a editor format drop down element
+ * editor format form element
*
- * @author Jamie Pratt
- * @access public
+ * HTML class for a editor format drop down element
+ *
+ * @package core_form
+ * @copyright 2007 Jamie Pratt <me@jamiep.org>
+ * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
+ * @deprecated since Moodle 2.0 Please do not use this form element.
+ * @todo MDL-31294, remove this element
+ * @see MoodleQuickForm_editor
*/
class MoodleQuickForm_format extends MoodleQuickForm_select{
/**
* Class constructor
*
- * @param string Select name attribute
- * @param mixed Label(s) for the select
- * @param mixed Either a typical HTML attribute string or an associative array
- * @param mixed Either a string returned from can_use_html_editor() or false for no html editor
- * default 'detect' tells element to use html editor if it is available.
- * @access public
- * @return void
+ * @param string $elementName Select name attribute
+ * @param mixed $elementLabel Label(s) for the select
+ * @param mixed $attributes Either a typical HTML attribute string or an associative array
+ * @param mixed $useHtmlEditor Either a string returned from can_use_html_editor() or false for no html editor
+ * default 'detect' tells element to use html editor if it is available.
*/
function MoodleQuickForm_format($elementName=null, $elementLabel=null, $attributes=null, $useHtmlEditor=null)
{
View
61 lib/form/grading.php
@@ -1,5 +1,4 @@
<?php
-
// This file is part of Moodle - http://moodle.org/
//
// Moodle is free software: you can redistribute it and/or modify
@@ -15,11 +14,15 @@
// You should have received a copy of the GNU General Public License
// along with Moodle. If not, see <http://www.gnu.org/licenses/>.
+
/**
+ * Advance grading form element
+ *
* Element-container for advanced grading custom input
*
- * @copyright 2011 Marina Glancy
- * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
+ * @package core_form
+ * @copyright 2011 Marina Glancy
+ * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
global $CFG;
@@ -31,36 +34,32 @@
}
/**
+ * Advance grading form element
+ *
* HTML class for a grading element. This is a wrapper for advanced grading plugins.
* When adding the 'grading' element to the form, developer must pass an object of
* class gradingform_instance as $attributes['gradinginstance']. Otherwise an exception will be
* thrown.
* This object is responsible for implementing functions to render element html and validate it
*
- * @author Marina Glancy
- * @access public
+ * @package core_form
+ * @category form
+ * @copyright 2011 Marina Glancy
+ * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
class MoodleQuickForm_grading extends HTML_QuickForm_input{
- /**
- * html for help button, if empty then no help
- *
- * @var string
- */
+ /** @var string html for help button, if empty then no help */
var $_helpbutton='';
- /**
- * Stores attributes passed to the element
- * @var array
- */
+ /** @var array Stores attributes passed to the element */
private $gradingattributes;
/**
* Class constructor
*
- * @param string $elementName Input field name attribute
- * @param mixed $elementLabel Label(s) for the input field
- * @param mixed $attributes Either a typical HTML attribute string or an associative array
- * @return void
+ * @param string $elementName Input field name attribute
+ * @param mixed $elementLabel Label(s) for the input field
+ * @param mixed $attributes Either a typical HTML attribute string or an associative array
*/
public function MoodleQuickForm_grading($elementName=null, $elementLabel=null, $attributes=null) {
parent::HTML_QuickForm_input($elementName, $elementLabel, $attributes);
@@ -83,7 +82,7 @@ public function get_gradinginstance() {
/**
* Returns the input field in HTML
*
- * @return string
+ * @return string
*/
public function toHtml(){
global $PAGE;
@@ -93,9 +92,11 @@ public function toHtml(){
/**
* set html for help button
*
- * @access public
- * @param array $help array of arguments to make a help button
+ * @param array $helpbuttonargs array of arguments to make a help button
* @param string $function function name to call to get html
+ * @deprecated since Moodle 2.0. Please do not call this function any more.
+ * @todo MDL-31047 this api will be removed.
+ * @see MoodleQuickForm::setHelpButton()
*/
public function setHelpButton($helpbuttonargs, $function='helpbutton'){
debugging('component setHelpButton() is not used any more, please use $mform->setHelpButton() instead');
@@ -104,8 +105,7 @@ public function setHelpButton($helpbuttonargs, $function='helpbutton'){
/**
* get html for help button
*
- * @access public
- * @return string html for help button
+ * @return string html for help button
*/
public function getHelpButton(){
return $this->_helpbutton;
@@ -126,11 +126,11 @@ public function getElementTemplateType(){
* Adds necessary rules to the element and checks that coorenct instance of gradingform_instance
* is passed in attributes
*
- * @param string $event Name of event
- * @param mixed $arg event arguments
- * @param object $caller calling object
- * @return void
- * @throws moodle_exception
+ * @param string $event Name of event
+ * @param mixed $arg event arguments
+ * @param object $caller calling object
+ * @return bool
+ * @throws moodle_exception
*/
public function onQuickFormEvent($event, $arg, &$caller) {
if ($event == 'createElement') {
@@ -151,8 +151,9 @@ public function onQuickFormEvent($event, $arg, &$caller) {
* Function registered as rule for this element and is called when this element is being validated.
* This is a wrapper to pass the validation to the method gradingform_instance::validate_grading_element
*
- * @param mixed $elementValue
- * @param array $attributes
+ * @param mixed $elementValue value of element to be validated
+ * @param array $attributes element attributes
+ * @return MoodleQuickForm_grading
*/
static function _validate($elementValue, $attributes = null) {
return $attributes['gradinginstance']->validate_grading_element($elementValue);
View
75 lib/form/group.php
@@ -1,47 +1,87 @@
<?php
+// This file is part of Moodle - http://moodle.org/
+//
+// Moodle is free software: you can redistribute it and/or modify
+// it under the terms of the GNU General Public License as published by
+// the Free Software Foundation, either version 3 of the License, or
+// (at your option) any later version.
+//
+// Moodle is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+// GNU General Public License for more details.
+//
+// You should have received a copy of the GNU General Public License
+// along with Moodle. If not, see <http://www.gnu.org/licenses/>.
+
+