MDL-32094 some nasty quickforms hacks that should help with E_STRICT

Note: we have stopped tracking our QuickForms hacks long ago.
This commit is contained in:
Petr Skoda 2012-03-18 18:39:37 +01:00
parent f4b8586a26
commit fabbf4398b
17 changed files with 89 additions and 79 deletions

View File

@ -102,9 +102,10 @@ class MoodleQuickForm_date_selector extends MoodleQuickForm_group
for ($i=$this->_options['startyear']; $i<=$this->_options['stopyear']; $i++) {
$years[$i] = $i;
}
$this->_elements[] =& MoodleQuickForm::createElement('select', 'day', get_string('day', 'form'), $days, $this->getAttributes(), true);
$this->_elements[] =& MoodleQuickForm::createElement('select', 'month', get_string('month', 'form'), $months, $this->getAttributes(), true);
$this->_elements[] =& MoodleQuickForm::createElement('select', 'year', get_string('year', 'form'), $years, $this->getAttributes(), true);
// E_STRICT creating elements without forms is nasty because it internally uses $this
$this->_elements[] = @MoodleQuickForm::createElement('select', 'day', get_string('day', 'form'), $days, $this->getAttributes(), true);
$this->_elements[] = @MoodleQuickForm::createElement('select', 'month', get_string('month', 'form'), $months, $this->getAttributes(), true);
$this->_elements[] = @MoodleQuickForm::createElement('select', 'year', get_string('year', 'form'), $years, $this->getAttributes(), true);
// If optional we add a checkbox which the user can use to turn if on
if($this->_options['optional']) {
$this->_elements[] =& MoodleQuickForm::createElement('checkbox', 'enabled', null, get_string('enable'), $this->getAttributes(), true);

View File

@ -109,19 +109,20 @@ class MoodleQuickForm_date_time_selector extends MoodleQuickForm_group{
for ($i=0; $i<60; $i+=$this->_options['step']) {
$minutes[$i] = sprintf("%02d",$i);
}
$this->_elements[] =& MoodleQuickForm::createElement('select', 'day', get_string('day', 'form'), $days, $this->getAttributes(), true);
$this->_elements[] =& MoodleQuickForm::createElement('select', 'month', get_string('month', 'form'), $months, $this->getAttributes(), true);
$this->_elements[] =& MoodleQuickForm::createElement('select', 'year', get_string('year', 'form'), $years, $this->getAttributes(), true);
// E_STRICT creating elements without forms is nasty because it internally uses $this
$this->_elements[] = @MoodleQuickForm::createElement('select', 'day', get_string('day', 'form'), $days, $this->getAttributes(), true);
$this->_elements[] = @MoodleQuickForm::createElement('select', 'month', get_string('month', 'form'), $months, $this->getAttributes(), true);
$this->_elements[] = @MoodleQuickForm::createElement('select', 'year', get_string('year', 'form'), $years, $this->getAttributes(), true);
if (right_to_left()) { // Switch order of elements for Right-to-Left
$this->_elements[] =& MoodleQuickForm::createElement('select', 'minute', get_string('minute', 'form'), $minutes, $this->getAttributes(), true);
$this->_elements[] =& MoodleQuickForm::createElement('select', 'hour', get_string('hour', 'form'), $hours, $this->getAttributes(), true);
$this->_elements[] = @MoodleQuickForm::createElement('select', 'minute', get_string('minute', 'form'), $minutes, $this->getAttributes(), true);
$this->_elements[] = @MoodleQuickForm::createElement('select', 'hour', get_string('hour', 'form'), $hours, $this->getAttributes(), true);
} else {
$this->_elements[] =& MoodleQuickForm::createElement('select', 'hour', get_string('hour', 'form'), $hours, $this->getAttributes(), true);
$this->_elements[] =& MoodleQuickForm::createElement('select', 'minute', get_string('minute', 'form'), $minutes, $this->getAttributes(), true);
$this->_elements[] = @MoodleQuickForm::createElement('select', 'hour', get_string('hour', 'form'), $hours, $this->getAttributes(), true);
$this->_elements[] = @MoodleQuickForm::createElement('select', 'minute', get_string('minute', 'form'), $minutes, $this->getAttributes(), true);
}
// If optional we add a checkbox which the user can use to turn if on
if($this->_options['optional']) {
$this->_elements[] =& MoodleQuickForm::createElement('checkbox', 'enabled', null, get_string('enable'), $this->getAttributes(), true);
$this->_elements[] = @MoodleQuickForm::createElement('checkbox', 'enabled', null, get_string('enable'), $this->getAttributes(), true);
}
foreach ($this->_elements as $element){
if (method_exists($element, 'setHiddenLabel')){

View File

@ -131,12 +131,13 @@ class MoodleQuickForm_duration extends MoodleQuickForm_group {
$attributes['size'] = 3;
}
$this->_elements = array();
$this->_elements[] = MoodleQuickForm::createElement('text', 'number', get_string('time', 'form'), $attributes, true);
// E_STRICT creating elements without forms is nasty because it internally uses $this
$this->_elements[] = @MoodleQuickForm::createElement('text', 'number', get_string('time', 'form'), $attributes, true);
unset($attributes['size']);
$this->_elements[] = MoodleQuickForm::createElement('select', 'timeunit', get_string('timeunit', 'form'), $this->get_units(), $attributes, true);
$this->_elements[] = @MoodleQuickForm::createElement('select', 'timeunit', get_string('timeunit', 'form'), $this->get_units(), $attributes, true);
// If optional we add a checkbox which the user can use to turn if on
if($this->_options['optional']) {
$this->_elements[] = MoodleQuickForm::createElement('checkbox', 'enabled', null, get_string('enable'), $this->getAttributes(), true);
$this->_elements[] = @MoodleQuickForm::createElement('checkbox', 'enabled', null, get_string('enable'), $this->getAttributes(), true);
}
foreach ($this->_elements as $element){
if (method_exists($element, 'setHiddenLabel')){
@ -153,7 +154,7 @@ class MoodleQuickForm_duration extends MoodleQuickForm_group {
* @param object $caller calling object
* @return bool
*/
function onQuickFormEvent($event, $arg, $caller) {
function onQuickFormEvent($event, $arg, &$caller) {
switch ($event) {
case 'updateValue':
// constant values override both default and submitted ones
@ -216,7 +217,7 @@ class MoodleQuickForm_duration extends MoodleQuickForm_group {
* @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) {
function accept(&$renderer, $required = false, $error = null) {
$renderer->renderElement($this, $required, $error);
}
@ -228,7 +229,7 @@ class MoodleQuickForm_duration extends MoodleQuickForm_group {
* @param bool $notused Not used.
* @return array field name => value. The value is the time interval in seconds.
*/
function exportValue($submitValues, $notused = false) {
function exportValue(&$submitValues, $notused = false) {
// Get the values from all the child elements.
$valuearray = array();
foreach ($this->_elements as $element) {

View File

@ -361,8 +361,9 @@ class MoodleQuickForm_editor extends HTML_QuickForm_element {
if (count($formats)>1) {
$str.= html_writer::select($formats, $elname.'[format]', $format, false);
} else {
$keys = array_keys($formats);
$str.= html_writer::empty_tag('input',
array('name'=>$elname.'[format]', 'type'=> 'hidden', 'value' => array_pop(array_keys($formats))));
array('name'=>$elname.'[format]', 'type'=> 'hidden', 'value' => array_pop($keys)));
}
$str .= '</div>';

View File

@ -57,7 +57,7 @@ class MoodleQuickForm_header extends HTML_QuickForm_header
*
* @param HTML_QuickForm_Renderer $renderer a HTML_QuickForm_Renderer object
*/
function accept(&$renderer)
function accept(&$renderer, $required=false, $error=null)
{
$this->_text .= $this->getHelpButton();
$renderer->renderHeader($this);

View File

@ -150,7 +150,8 @@ class MoodleQuickForm_tags extends MoodleQuickForm_group {
// Create the element.
$size = min(5, count($officialtags));
$officialtagsselect = MoodleQuickForm::createElement('select', 'officialtags', $label, $officialtags, array('size' => $size));
// E_STRICT creating elements without forms is nasty because it internally uses $this
$officialtagsselect = @MoodleQuickForm::createElement('select', 'officialtags', $label, $officialtags, array('size' => $size));
$officialtagsselect->setMultiple(true);
if ($noofficial) {
$officialtagsselect->updateAttributes(array('disabled' => 'disabled'));
@ -165,7 +166,8 @@ class MoodleQuickForm_tags extends MoodleQuickForm_group {
} else {
$label = get_string('entertags', 'tag');
}
$othertags = MoodleQuickForm::createElement('textarea', 'othertags', $label, array('cols'=>'40', 'rows'=>'5'));
// E_STRICT creating elements without forms is nasty because it internally uses $this
$othertags = @MoodleQuickForm::createElement('textarea', 'othertags', $label, array('cols'=>'40', 'rows'=>'5'));
$this->_elements[] = $othertags;
}

View File

@ -62,7 +62,9 @@ function pear_handle_error($error){
}
if (!empty($CFG->debug) and $CFG->debug >= DEBUG_ALL){
PEAR::setErrorHandling(PEAR_ERROR_CALLBACK, 'pear_handle_error');
//TODO: this is a wrong place to init PEAR!
$GLOBALS['_PEAR_default_error_mode'] = PEAR_ERROR_CALLBACK;
$GLOBALS['_PEAR_default_error_options'] = 'pear_handle_error';
}
/**
@ -1638,7 +1640,7 @@ class MoodleQuickForm extends HTML_QuickForm_DHTMLRulesTableless {
}
foreach ($elementList as $elementName) {
$value = $this->exportValue($elementName);
if (PEAR::isError($value)) {
if (@PEAR::isError($value)) {
return $value;
}
//oh, stock QuickFOrm was returning array of arrays!

View File

@ -329,7 +329,7 @@ class HTML_QuickForm extends HTML_Common {
* @access public
* @return void
*/
function registerElementType($typeName, $include, $className)
static function registerElementType($typeName, $include, $className)
{
$GLOBALS['HTML_QUICKFORM_ELEMENT_TYPES'][strtolower($typeName)] = array($include, $className);
} // end func registerElementType
@ -348,7 +348,7 @@ class HTML_QuickForm extends HTML_Common {
* @access public
* @return void
*/
function registerRule($ruleName, $type, $data1, $data2 = null)
static function registerRule($ruleName, $type, $data1, $data2 = null)
{
include_once('HTML/QuickForm/RuleRegistry.php');
$registry =& HTML_QuickForm_RuleRegistry::singleton();
@ -600,7 +600,7 @@ class HTML_QuickForm extends HTML_Common {
} else {
$args = func_get_args();
$elementObject =& $this->_loadElement('addElement', $element, array_slice($args, 1));
if (PEAR::isError($elementObject)) {
if (@PEAR::isError($elementObject)) {
return $elementObject;
}
}
@ -1260,8 +1260,10 @@ class HTML_QuickForm extends HTML_Common {
* @param array $b array which will be merged into first one
* @return array merged array
*/
function arrayMerge($a, $b)
static function arrayMerge($a, $b)
{
if (is_null($a)) {$a = array();}
if (is_null($b)) {$b = array();}
foreach ($b as $k => $v) {
if (is_array($v)) {
if (isset($a[$k]) && !is_array($a[$k])) {

View File

@ -44,7 +44,7 @@ class HTML_QuickForm_RuleRegistry
* @static
* @return object Reference to the HTML_QuickForm_RuleRegistry singleton
*/
function &singleton()
static function &singleton()
{
static $obj;
if (!isset($obj)) {

View File

@ -27,15 +27,15 @@ require_once('HTML/QuickForm/checkbox.php');
* Basically this fixes a problem that HTML has had
* where checkboxes can only pass a single value (the
* value of the checkbox when checked). A value for when
* the checkbox is not checked cannot be passed, and
* the checkbox is not checked cannot be passed, and
* furthermore the checkbox variable doesn't even exist if
* the checkbox was submitted unchecked.
*
* It works by prepending a hidden field with the same name and
* another "unchecked" value to the checbox. If the checkbox is
* checked, PHP overwrites the value of the hidden field with
* its value.
*
* its value.
*
* @author Jason Rust <jrust@php.net>
* @since 2.0
* @access public
@ -65,13 +65,13 @@ class HTML_QuickForm_advcheckbox extends HTML_QuickForm_checkbox
/**
* Class constructor
*
*
* @param string $elementName (optional)Input field name attribute
* @param string $elementLabel (optional)Input field label
* @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
* @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
* @param mixed $values (optional)Values to pass if checked or not checked
*
* @since 1.0
* @access public
@ -82,7 +82,7 @@ class HTML_QuickForm_advcheckbox extends HTML_QuickForm_checkbox
$this->HTML_QuickForm_checkbox($elementName, $elementLabel, $text, $attributes);
$this->setValues($values);
} //end constructor
// }}}
// {{{ getPrivateName()
@ -139,7 +139,7 @@ class HTML_QuickForm_advcheckbox extends HTML_QuickForm_checkbox
// give it default checkbox behavior
$this->_values = array('', 1);
} elseif (is_scalar($values)) {
// if it's string, then assume the value to
// if it's string, then assume the value to
// be passed is for when the element is checked
$this->_values = array('', $values);
} else {
@ -154,7 +154,7 @@ class HTML_QuickForm_advcheckbox extends HTML_QuickForm_checkbox
/**
* Sets the element's value
*
*
* @param mixed Element's value
* @access public
*/
@ -188,7 +188,7 @@ class HTML_QuickForm_advcheckbox extends HTML_QuickForm_checkbox
/**
* Returns the checkbox element in HTML
* and the additional hidden element in HTML
*
*
* @access public
* @return string
*/
@ -198,14 +198,14 @@ class HTML_QuickForm_advcheckbox extends HTML_QuickForm_checkbox
return parent::toHtml();
} else {
return '<input' . $this->_getAttrString(array(
'type' => 'hidden',
'name' => $this->getName(),
'type' => 'hidden',
'name' => $this->getName(),
'value' => $this->_values[0]
)) . ' />' . parent::toHtml();
}
} //end func toHtml
// }}}
// {{{ getFrozenHtml()
@ -262,7 +262,7 @@ class HTML_QuickForm_advcheckbox extends HTML_QuickForm_checkbox
* This element has a value even if it is not checked, thus we override
* checkbox's behaviour here
*/
function exportValue(&$submitValues, $assoc)
function exportValue(&$submitValues, $assoc = false)
{
$value = $this->_findValue($submitValues);
if (null === $value) {

View File

@ -21,7 +21,7 @@
require_once 'HTML/QuickForm/static.php';
/**
* A pseudo-element used for adding headers to form
* A pseudo-element used for adding headers to form
*
* @author Alexey Borzov <borz_off@cs.msu.su>
* @access public
@ -32,7 +32,7 @@ class HTML_QuickForm_header extends HTML_QuickForm_static
/**
* Class constructor
*
*
* @param string $elementName Header name
* @param string $text Header text
* @access public
@ -52,9 +52,9 @@ class HTML_QuickForm_header extends HTML_QuickForm_static
*
* @param object An HTML_QuickForm_Renderer object
* @access public
* @return void
* @return void
*/
function accept(&$renderer)
function accept(&$renderer, $required=false, $error=null)
{
$renderer->renderHeader($this);
} // end func accept

View File

@ -23,7 +23,7 @@ require_once("HTML/QuickForm/input.php");
/**
* HTML class for a hidden type element
*
*
* @author Adam Daniel <adaniel1@eesus.jnj.com>
* @author Bertrand Mansion <bmansion@mamasam.com>
* @version 1.0
@ -36,10 +36,10 @@ class HTML_QuickForm_hidden extends HTML_QuickForm_input
/**
* Class constructor
*
*
* @param string $elementName (optional)Input field name attribute
* @param string $value (optional)Input field value
* @param mixed $attributes (optional)Either a typical HTML attribute string
* @param mixed $attributes (optional)Either a typical HTML attribute string
* or an associative array
* @since 1.0
* @access public
@ -51,13 +51,13 @@ class HTML_QuickForm_hidden extends HTML_QuickForm_input
$this->setType('hidden');
$this->setValue($value);
} //end constructor
// }}}
// {{{ freeze()
/**
* Freeze the element so that only its value is returned
*
*
* @access public
* @return void
*/
@ -74,9 +74,9 @@ class HTML_QuickForm_hidden extends HTML_QuickForm_input
*
* @param object An HTML_QuickForm_Renderer object
* @access public
* @return void
* @return void
*/
function accept(&$renderer)
function accept(&$renderer, $required=false, $error=null)
{
$renderer->renderHidden($this);
} // end func accept

View File

@ -29,7 +29,7 @@ require_once('HTML/QuickForm/select.php');
* selected values to be passed.
*
* @author Isaac Shepard <ishepard@bsiweb.com>
*
*
* @version 1.0
* @since 2.1
* @access public
@ -37,10 +37,10 @@ require_once('HTML/QuickForm/select.php');
class HTML_QuickForm_hiddenselect extends HTML_QuickForm_select
{
// {{{ constructor
/**
* Class constructor
*
*
* @param string Select name attribute
* @param mixed Label(s) for the select (not used)
* @param mixed Data to be used to populate options
@ -58,7 +58,7 @@ class HTML_QuickForm_hiddenselect extends HTML_QuickForm_select
$this->load($options);
}
} //end constructor
// }}}
// {{{ toHtml()
@ -68,7 +68,7 @@ class HTML_QuickForm_hiddenselect extends HTML_QuickForm_select
* @since 1.0
* @access public
* @return string
* @throws
* @throws
*/
function toHtml()
{
@ -90,14 +90,14 @@ class HTML_QuickForm_hiddenselect extends HTML_QuickForm_select
return $strHtml;
} //end func toHtml
// }}}
// {{{ accept()
/**
* This is essentially a hidden element and should be rendered as one
* This is essentially a hidden element and should be rendered as one
*/
function accept(&$renderer)
function accept(&$renderer, $required=false, $error=null)
{
$renderer->renderHidden($this);
}

View File

@ -22,7 +22,7 @@ require_once 'HTML/QuickForm/static.php';
/**
* A pseudo-element used for adding raw HTML to form
*
*
* Intended for use with the default renderer only, template-based
* ones may (and probably will) completely ignore this
*
@ -35,7 +35,7 @@ class HTML_QuickForm_html extends HTML_QuickForm_static
/**
* Class constructor
*
*
* @param string $text raw HTML to add
* @access public
* @return void
@ -54,9 +54,9 @@ class HTML_QuickForm_html extends HTML_QuickForm_static
*
* @param object An HTML_QuickForm_Renderer object
* @access public
* @return void
* @return void
*/
function accept(&$renderer)
function accept(&$renderer, $required=false, $error=null)
{
$renderer->renderHtml($this);
} // end func accept

View File

@ -27,10 +27,10 @@ class mod_choice_mod_form extends moodleform_mod {
//-------------------------------------------------------------------------------
$repeatarray = array();
$repeatarray[] = &MoodleQuickForm::createElement('header', '', get_string('option','choice').' {no}');
$repeatarray[] = &MoodleQuickForm::createElement('text', 'option', get_string('option','choice'));
$repeatarray[] = &MoodleQuickForm::createElement('text', 'limit', get_string('limit','choice'));
$repeatarray[] = &MoodleQuickForm::createElement('hidden', 'optionid', 0);
$repeatarray[] = $mform->createElement('header', '', get_string('option','choice').' {no}');
$repeatarray[] = $mform->createElement('text', 'option', get_string('option','choice'));
$repeatarray[] = $mform->createElement('text', 'limit', get_string('limit','choice'));
$repeatarray[] = $mform->createElement('hidden', 'optionid', 0);
$menuoptions = array();
$menuoptions[0] = get_string('disable');

View File

@ -29,11 +29,11 @@ class mod_data_export_form extends moodleform {
unset($choices[$key]);
}
$typesarray = array();
$typesarray[] = &MoodleQuickForm::createElement('radio', 'exporttype', null, get_string('csvwithselecteddelimiter', 'data') . '&nbsp;', 'csv');
$typesarray[] = &MoodleQuickForm::createElement('select', 'delimiter_name', null, $choices);
$typesarray[] = $mform->createElement('radio', 'exporttype', null, get_string('csvwithselecteddelimiter', 'data') . '&nbsp;', 'csv');
$typesarray[] = $mform->createElement('select', 'delimiter_name', null, $choices);
//temporarily commenting out Excel export option. See MDL-19864
//$typesarray[] = &MoodleQuickForm::createElement('radio', 'exporttype', null, get_string('excel', 'data'), 'xls');
$typesarray[] = &MoodleQuickForm::createElement('radio', 'exporttype', null, get_string('ods', 'data'), 'ods');
//$typesarray[] = $mform->createElement('radio', 'exporttype', null, get_string('excel', 'data'), 'xls');
$typesarray[] = $mform->createElement('radio', 'exporttype', null, get_string('ods', 'data'), 'ods');
$mform->addGroup($typesarray, 'exportar', '', array(''), false);
$mform->addRule('exportar', null, 'required');
$mform->setDefault('exporttype', 'csv');

View File

@ -310,10 +310,10 @@ class mod_quiz_mod_form extends moodleform_mod {
$repeatarray = array();
$repeatedoptions = array();
$repeatarray[] = MoodleQuickForm::createElement('editor', 'feedbacktext',
$repeatarray[] = $mform->createElement('editor', 'feedbacktext',
get_string('feedback', 'quiz'), null, array('maxfiles' => EDITOR_UNLIMITED_FILES,
'noclean' => true, 'context' => $this->context));
$repeatarray[] = MoodleQuickForm::createElement('text', 'feedbackboundaries',
$repeatarray[] = $mform->createElement('text', 'feedbackboundaries',
get_string('gradeboundary', 'quiz'), array('size' => 10));
$repeatedoptions['feedbacktext']['type'] = PARAM_RAW;
$repeatedoptions['feedbackboundaries']['type'] = PARAM_RAW;
@ -331,12 +331,12 @@ class mod_quiz_mod_form extends moodleform_mod {
get_string('addmoreoverallfeedbacks', 'quiz'), true);
// Put some extra elements in before the button
$mform->insertElementBefore(MoodleQuickForm::createElement('editor',
$mform->insertElementBefore($mform->createElement('editor',
"feedbacktext[$nextel]", get_string('feedback', 'quiz'), null,
array('maxfiles' => EDITOR_UNLIMITED_FILES, 'noclean' => true,
'context' => $this->context)),
'boundary_add_fields');
$mform->insertElementBefore(MoodleQuickForm::createElement('static',
$mform->insertElementBefore($mform->createElement('static',
'gradeboundarystatic2', get_string('gradeboundary', 'quiz'), '0%'),
'boundary_add_fields');