MDL-19698 deprecated assign new by ref in QuickForms

This commit is contained in:
Petr Skoda
2010-07-19 08:38:28 +00:00
parent 5d8c99a3e9
commit 6d504dc07f
5 changed files with 84 additions and 80 deletions
+13 -13
View File
@@ -38,7 +38,7 @@ class HTML_QuickForm_RuleRegistry
* Returns a singleton of HTML_QuickForm_RuleRegistry
*
* Usually, only one RuleRegistry object is needed, this is the reason
* why it is recommended to use this method to get the validation object.
* why it is recommended to use this method to get the validation object.
*
* @access public
* @static
@@ -115,7 +115,7 @@ class HTML_QuickForm_RuleRegistry
if (!empty($path)) {
include_once($path);
}
$this->_rules[$class] =& new $class();
$this->_rules[$class] = new $class();
}
$this->_rules[$class]->setName($ruleName);
return $this->_rules[$class];
@@ -125,7 +125,7 @@ class HTML_QuickForm_RuleRegistry
* Performs validation on the given values
*
* @param string $ruleName Name of the rule to be used
* @param mixed $values Can be a scalar or an array of values
* @param mixed $values Can be a scalar or an array of values
* to be validated
* @param mixed $options Options used by the rule
* @param mixed $multiple Whether to validate an array of values altogether
@@ -176,21 +176,21 @@ class HTML_QuickForm_RuleRegistry
$jsField = isset($ruleData['group'])? $ruleData['group']: $elementName;
list ($jsPrefix, $jsCheck) = $rule->getValidationScript($ruleData['format']);
if (!isset($ruleData['howmany'])) {
$js = $jsValue . "\n" . $jsPrefix .
$js = $jsValue . "\n" . $jsPrefix .
" if (" . str_replace('{jsVar}', 'value', $jsCheck) . " && !errFlag['{$jsField}']) {\n" .
" errFlag['{$jsField}'] = true;\n" .
" _qfMsg = _qfMsg + '\\n - {$ruleData['message']}';\n" .
$jsReset .
" }\n";
} else {
$js = $jsValue . "\n" . $jsPrefix .
$js = $jsValue . "\n" . $jsPrefix .
" var res = 0;\n" .
" for (var i = 0; i < value.length; i++) {\n" .
" if (!(" . str_replace('{jsVar}', 'value[i]', $jsCheck) . ")) {\n" .
" res++;\n" .
" }\n" .
" }\n" .
" if (res < {$ruleData['howmany']} && !errFlag['{$jsField}']) {\n" .
" }\n" .
" if (res < {$ruleData['howmany']} && !errFlag['{$jsField}']) {\n" .
" errFlag['{$jsField}'] = true;\n" .
" _qfMsg = _qfMsg + '\\n - {$ruleData['message']}';\n" .
$jsReset .
@@ -201,8 +201,8 @@ class HTML_QuickForm_RuleRegistry
/**
* Returns JavaScript to get and to reset the element's value
*
* Returns JavaScript to get and to reset the element's value
*
* @access private
* @param object HTML_QuickForm_element element being processed
* @param string element's name
@@ -228,7 +228,7 @@ class HTML_QuickForm_RuleRegistry
" var valueIdx = 0;\n" .
" for (var i = 0; i < frm.elements.length; i++) {\n" .
" var _element = frm.elements[i];\n" .
" if (_element.name in _qfGroups['{$elementName}']) {\n" .
" if (_element.name in _qfGroups['{$elementName}']) {\n" .
" switch (_element.type) {\n" .
" case 'checkbox':\n" .
" case 'radio':\n" .
@@ -262,7 +262,7 @@ class HTML_QuickForm_RuleRegistry
$tmp_reset =
" for (var i = 0; i < frm.elements.length; i++) {\n" .
" var _element = frm.elements[i];\n" .
" if (_element.name in _qfGroups['{$elementName}']) {\n" .
" if (_element.name in _qfGroups['{$elementName}']) {\n" .
" switch (_element.type) {\n" .
" case 'checkbox':\n" .
" case 'radio':\n" .
@@ -287,7 +287,7 @@ class HTML_QuickForm_RuleRegistry
$value =
" value{$jsIndex} = new Array();\n" .
" var valueIdx = 0;\n" .
" for (var i = 0; i < frm.elements['{$elementName}'].options.length; i++) {\n" .
" for (var i = 0; i < frm.elements['{$elementName}'].options.length; i++) {\n" .
" if (frm.elements['{$elementName}'].options[i].selected) {\n" .
" value{$jsIndex}[valueIdx++] = frm.elements['{$elementName}'].options[i].value;\n" .
" }\n" .
@@ -296,7 +296,7 @@ class HTML_QuickForm_RuleRegistry
$value = " value{$jsIndex} = frm.elements['{$elementName}'].selectedIndex == -1? '': frm.elements['{$elementName}'].options[frm.elements['{$elementName}'].selectedIndex].value;\n";
}
if ($reset) {
$tmp_reset .=
$tmp_reset .=
" for (var i = 0; i < field.options.length; i++) {\n" .
" field.options[i].selected = field.options[i].defaultSelected;\n" .
" }\n";
+13 -13
View File
@@ -25,10 +25,10 @@ require_once 'HTML/QuickForm/select.php';
/**
* Class for a group of elements used to input dates (and times).
*
*
* Inspired by original 'date' element but reimplemented as a subclass
* of HTML_QuickForm_group
*
*
* @author Alexey Borzov <[email protected]>
* @access public
*/
@@ -38,7 +38,7 @@ class HTML_QuickForm_date extends HTML_QuickForm_group
/**
* Various options to control the element's display.
*
*
* Currently known options are
* 'language': date language
* 'format': Format of the date, based on PHP's date() function.
@@ -64,7 +64,7 @@ class HTML_QuickForm_date extends HTML_QuickForm_group
* 'emptyOptionValue': The value passed by the empty option.
* 'emptyOptionText': The text displayed for the empty option.
* 'optionIncrement': Step to increase the option values by (works for 'i' and 's')
*
*
* @access private
* @var array
*/
@@ -88,10 +88,10 @@ class HTML_QuickForm_date extends HTML_QuickForm_group
/**
* Options in different languages
*
*
* Note to potential translators: to avoid encoding problems please send
* your translations with "weird" letters encoded as HTML Unicode entities
*
*
* @access private
* @var array
*/
@@ -259,7 +259,7 @@ class HTML_QuickForm_date extends HTML_QuickForm_group
/**
* Class constructor
*
*
* @access public
* @param string Element's name
* @param mixed Label(s) for an element
@@ -331,7 +331,7 @@ class HTML_QuickForm_date extends HTML_QuickForm_group
case 'Y':
$options = $this->_createOptionList(
$this->_options['minYear'],
$this->_options['maxYear'],
$this->_options['maxYear'],
$this->_options['minYear'] > $this->_options['maxYear']? -1: 1
);
break;
@@ -341,7 +341,7 @@ class HTML_QuickForm_date extends HTML_QuickForm_group
$this->_options['maxYear'],
$this->_options['minYear'] > $this->_options['maxYear']? -1: 1
);
array_walk($options, create_function('&$v,$k','$v = substr($v,-2);'));
array_walk($options, create_function('&$v,$k','$v = substr($v,-2);'));
break;
case 'h':
$options = $this->_createOptionList(1, 12);
@@ -376,7 +376,7 @@ class HTML_QuickForm_date extends HTML_QuickForm_group
$separator .= (' ' == $sign? '&nbsp;': $sign);
$loadSelect = false;
}
if ($loadSelect) {
if (0 < count($this->_elements)) {
$this->_separator[] = $separator;
@@ -385,7 +385,7 @@ class HTML_QuickForm_date extends HTML_QuickForm_group
}
$separator = '';
// Should we add an empty option to the top of the select?
if (!is_array($this->_options['addEmptyOption']) && $this->_options['addEmptyOption'] ||
if (!is_array($this->_options['addEmptyOption']) && $this->_options['addEmptyOption'] ||
is_array($this->_options['addEmptyOption']) && !empty($this->_options['addEmptyOption'][$sign])) {
// Using '+' array operator to preserve the keys
@@ -395,7 +395,7 @@ class HTML_QuickForm_date extends HTML_QuickForm_group
$options = array($this->_options['emptyOptionValue'] => $this->_options['emptyOptionText']) + $options;
}
}
$this->_elements[] =& new HTML_QuickForm_select($sign, null, $options, $this->getAttributes());
$this->_elements[] = new HTML_QuickForm_select($sign, null, $options, $this->getAttributes());
}
}
}
@@ -463,7 +463,7 @@ class HTML_QuickForm_date extends HTML_QuickForm_group
function toHtml()
{
include_once('HTML/QuickForm/Renderer/Default.php');
$renderer =& new HTML_QuickForm_Renderer_Default();
$renderer = new HTML_QuickForm_Renderer_Default();
$renderer->setElementTemplate('{element}');
parent::accept($renderer);
return $this->_wrap[0] . $renderer->toHtml() . $this->_wrap[1];
+23 -23
View File
@@ -23,7 +23,7 @@ require_once("HTML/QuickForm/element.php");
/**
* HTML class for a form element group
*
*
* @author Adam Daniel <[email protected]>
* @author Bertrand Mansion <[email protected]>
* @version 1.0
@@ -33,7 +33,7 @@ require_once("HTML/QuickForm/element.php");
class HTML_QuickForm_group extends HTML_QuickForm_element
{
// {{{ properties
/**
* Name of the element
* @var string
@@ -67,7 +67,7 @@ class HTML_QuickForm_group extends HTML_QuickForm_element
var $_required = array();
/**
* Whether to change elements' names to $groupName[$elementName] or leave them as is
* Whether to change elements' names to $groupName[$elementName] or leave them as is
* @var bool
* @since 3.0
* @access private
@@ -79,14 +79,14 @@ class HTML_QuickForm_group extends HTML_QuickForm_element
/**
* Class constructor
*
*
* @param string $elementName (optional)Group name
* @param array $elementLabel (optional)Group label
* @param array $elements (optional)Group elements
* @param mixed $separator (optional)Use a string for one separator,
* use an array to alternate the separators.
* @param bool $appendName (optional)whether to change elements' names to
* the form $groupName[$elementName] or leave
* the form $groupName[$elementName] or leave
* them as is.
* @since 1.0
* @access public
@@ -106,13 +106,13 @@ class HTML_QuickForm_group extends HTML_QuickForm_element
$this->_appendName = $appendName;
}
} //end constructor
// }}}
// {{{ setName()
/**
* Sets the group name
*
*
* @param string $name Group name
* @since 1.0
* @access public
@@ -122,13 +122,13 @@ class HTML_QuickForm_group extends HTML_QuickForm_element
{
$this->_name = $name;
} //end func setName
// }}}
// {{{ getName()
/**
* Returns the group name
*
*
* @since 1.0
* @access public
* @return string
@@ -143,7 +143,7 @@ class HTML_QuickForm_group extends HTML_QuickForm_element
/**
* Sets values for group's elements
*
*
* @param mixed Values for group's elements
* @since 1.0
* @access public
@@ -172,7 +172,7 @@ class HTML_QuickForm_group extends HTML_QuickForm_element
}
}
} //end func setValue
// }}}
// {{{ getValue()
@@ -189,10 +189,10 @@ class HTML_QuickForm_group extends HTML_QuickForm_element
foreach (array_keys($this->_elements) as $key) {
$element =& $this->_elements[$key];
switch ($element->getType()) {
case 'radio':
case 'radio':
$v = $element->getChecked()? $element->getValue(): null;
break;
case 'checkbox':
case 'checkbox':
$v = $element->getChecked()? true: null;
break;
default:
@@ -282,7 +282,7 @@ class HTML_QuickForm_group extends HTML_QuickForm_element
/**
* Returns Html for the group
*
*
* @since 1.0
* @access public
* @return string
@@ -290,18 +290,18 @@ class HTML_QuickForm_group extends HTML_QuickForm_element
function toHtml()
{
include_once('HTML/QuickForm/Renderer/Default.php');
$renderer =& new HTML_QuickForm_Renderer_Default();
$renderer = new HTML_QuickForm_Renderer_Default();
$renderer->setElementTemplate('{element}');
$this->accept($renderer);
return $renderer->toHtml();
} //end func toHtml
// }}}
// {{{ getElementName()
/**
* Returns the element name inside the group such as found in the html form
*
*
* @param mixed $index Element name or element index in the group
* @since 3.0
* @access public
@@ -345,7 +345,7 @@ class HTML_QuickForm_group extends HTML_QuickForm_element
/**
* Returns the value of field without HTML tags
*
*
* @since 1.3
* @access public
* @return string
@@ -420,7 +420,7 @@ class HTML_QuickForm_group extends HTML_QuickForm_element
* @param bool Whether a group is required
* @param string An error message associated with a group
* @access public
* @return void
* @return void
*/
function accept(&$renderer, $required = false, $error = null)
{
@@ -429,7 +429,7 @@ class HTML_QuickForm_group extends HTML_QuickForm_element
$name = $this->getName();
foreach (array_keys($this->_elements) as $key) {
$element =& $this->_elements[$key];
if ($this->_appendName) {
$elementName = $element->getName();
if (isset($elementName)) {
@@ -505,12 +505,12 @@ class HTML_QuickForm_group extends HTML_QuickForm_element
/**
* Creates the group's elements.
*
* This should be overriden by child classes that need to create their
*
* This should be overriden by child classes that need to create their
* elements. The method will be called automatically when needed, calling
* it from the constructor is discouraged as the constructor is usually
* called _twice_ on element creation, first time with _no_ parameters.
*
*
* @access private
* @abstract
*/
+30 -30
View File
@@ -36,7 +36,7 @@ require_once('HTML/QuickForm/select.php');
* @access public
*/
class HTML_QuickForm_hierselect extends HTML_QuickForm_group
{
{
// {{{ properties
/**
@@ -59,7 +59,7 @@ class HTML_QuickForm_hierselect extends HTML_QuickForm_group
* $select2[2][0] = 'Pantheist';
* $select2[2][1] = 'Skepticism';
*
* // If only need two selects
* // If only need two selects
* // - and using the depracated functions
* $sel =& $form->addElement('hierselect', 'cds', 'Choose CD:');
* $sel->setMainOptions($select1);
@@ -77,12 +77,12 @@ class HTML_QuickForm_hierselect extends HTML_QuickForm_group
* // You can now use
* $sel =& $form->addElement('hierselect', 'cds', 'Choose CD:');
* $sel->setOptions(array($select1, $select2, $select3));
*
*
* @var array
* @access private
*/
var $_options = array();
/**
* Number of select elements on this group
*
@@ -104,10 +104,10 @@ class HTML_QuickForm_hierselect extends HTML_QuickForm_group
/**
* Class constructor
*
*
* @param string $elementName (optional)Input field name attribute
* @param string $elementLabel (optional)Input field label in form
* @param mixed $attributes (optional)Either a typical HTML attribute string
* @param mixed $attributes (optional)Either a typical HTML attribute string
* or an associative array. Date format is passed along the attributes.
* @param mixed $separator (optional)Use a string for one separator,
* use an array to alternate the separators.
@@ -149,17 +149,17 @@ class HTML_QuickForm_hierselect extends HTML_QuickForm_group
// check if all elements have been created
$totalNbElements = count($this->_options);
for ($i = $this->_nbElements; $i < $totalNbElements; $i ++) {
$this->_elements[] =& new HTML_QuickForm_select($i, null, array(), $this->getAttributes());
$this->_elements[] = new HTML_QuickForm_select($i, null, array(), $this->getAttributes());
$this->_nbElements++;
}
}
$this->_setOptions();
} // end func setMainOptions
// }}}
// {{{ setMainOptions()
/**
* Sets the options for the first select element. Deprecated. setOptions() should be used.
*
@@ -178,10 +178,10 @@ class HTML_QuickForm_hierselect extends HTML_QuickForm_group
$this->_createElements();
}
} // end func setMainOptions
// }}}
// {{{ setSecOptions()
/**
* Sets the options for the second select element. Deprecated. setOptions() should be used.
* The main _options array is initialized and the _setOptions function is called.
@@ -204,17 +204,17 @@ class HTML_QuickForm_hierselect extends HTML_QuickForm_group
// check if all elements have been created
$totalNbElements = 2;
for ($i = $this->_nbElements; $i < $totalNbElements; $i ++) {
$this->_elements[] =& new HTML_QuickForm_select($i, null, array(), $this->getAttributes());
$this->_elements[] = new HTML_QuickForm_select($i, null, array(), $this->getAttributes());
$this->_nbElements++;
}
}
$this->_setOptions();
} // end func setSecOptions
// }}}
// {{{ _setOptions()
/**
* Sets the options for each select element
*
@@ -236,13 +236,13 @@ class HTML_QuickForm_hierselect extends HTML_QuickForm_group
}
}
} // end func _setOptions
// }}}
// {{{ setValue()
/**
* Sets values for group's elements
*
*
* @param array $value An array of 2 or more values, for the first,
* the second, the third etc. select
*
@@ -251,27 +251,27 @@ class HTML_QuickForm_hierselect extends HTML_QuickForm_group
*/
function setValue($value)
{
// fix for bug #6766. Hope this doesn't break anything more
// fix for bug #6766. Hope this doesn't break anything more
// after bug #7961. Forgot that _nbElements was used in
// _createElements() called in several places...
// _createElements() called in several places...
$this->_nbElements = max($this->_nbElements, count($value));
parent::setValue($value);
$this->_setOptions();
} // end func setValue
// }}}
// {{{ _createElements()
/**
* Creates all the elements for the group
*
*
* @access private
* @return void
*/
function _createElements()
{
for ($i = 0; $i < $this->_nbElements; $i++) {
$this->_elements[] =& new HTML_QuickForm_select($i, null, array(), $this->getAttributes());
$this->_elements[] = new HTML_QuickForm_select($i, null, array(), $this->getAttributes());
}
} // end func _createElements
@@ -292,7 +292,7 @@ class HTML_QuickForm_hierselect extends HTML_QuickForm_group
array('onchange' => '_hs_swapOptions(this.form, \'' . $this->_escapeString($this->getName()) . '\', ' . $keys[$i] . ');' . $onChange[$i])
);
}
// create the js function to call
if (!defined('HTML_QUICKFORM_HIERSELECT_EXISTS')) {
$this->_js .= <<<JAVASCRIPT
@@ -311,9 +311,9 @@ function _hs_findOptions(ary, keys)
function _hs_findSelect(form, groupName, selectIndex)
{
if (groupName+'['+ selectIndex +']' in form) {
return form[groupName+'['+ selectIndex +']'];
return form[groupName+'['+ selectIndex +']'];
} else {
return form[groupName+'['+ selectIndex +'][]'];
return form[groupName+'['+ selectIndex +'][]'];
}
}
@@ -358,7 +358,7 @@ function _hs_swapOptions(form, groupName, selectIndex)
hsValue[i] = _hs_findSelect(form, groupName, i).value;
}
_hs_replaceOptions(_hs_findSelect(form, groupName, selectIndex + 1),
_hs_replaceOptions(_hs_findSelect(form, groupName, selectIndex + 1),
_hs_findOptions(_hs_options[groupName][selectIndex], hsValue));
if (selectIndex + 1 < _hs_options[groupName].length) {
_hs_swapOptions(form, groupName, selectIndex + 1);
@@ -372,7 +372,7 @@ function _hs_onReset(form, groupNames)
for (var j = 0; j <= _hs_options[groupNames[i]].length; j++) {
_hs_setValue(_hs_findSelect(form, groupNames[i], j), _hs_defaults[groupNames[i]][j]);
if (j < _hs_options[groupNames[i]].length) {
_hs_replaceOptions(_hs_findSelect(form, groupNames[i], j + 1),
_hs_replaceOptions(_hs_findSelect(form, groupNames[i], j + 1),
_hs_findOptions(_hs_options[groupNames[i]][j], _hs_defaults[groupNames[i]].slice(0, j + 1)));
}
}
@@ -444,7 +444,7 @@ JAVASCRIPT;
$this->_convertArrayToJavascript($values, false) . ";\n";
}
include_once('HTML/QuickForm/Renderer/Default.php');
$renderer =& new HTML_QuickForm_Renderer_Default();
$renderer = new HTML_QuickForm_Renderer_Default();
$renderer->setElementTemplate('{element}');
parent::accept($renderer);
@@ -524,7 +524,7 @@ JAVASCRIPT;
$js = implode(', ', $items);
return $assoc? '{ ' . $js . ' }': '[' . $js . ']';
}
// }}}
// {{{ _convertScalarToJavascript()
@@ -555,7 +555,7 @@ JAVASCRIPT;
// {{{ _escapeString()
/**
* Quotes the string so that it can be used in Javascript string constants
* Quotes the string so that it can be used in Javascript string constants
*
* @access private
* @param string
+5 -1
View File
@@ -18,7 +18,7 @@ and documented for Moodle at:
* http://cvs.moodle.org/moodle/lib/excel/Parser.php.diff?r1=1.1&r2=1.2
* http://cvs.moodle.org/moodle/lib/excel/Worksheet.php.diff?r1=1.1&r2=1.2
Such modifications should be carefuly each time the Excel PEAR package is updated
Such modifications should be carefully each time the Excel PEAR package is updated
to a new release within Moodle.
XML/Parser
@@ -37,3 +37,7 @@ To run the codesniffer, you can call the runsniffer script using your command-li
Example: /usr/bin/php lib/pear/PHP/runsniffer mod/forum
Quickforms
==========
Full of our custom hacks, no way to upgrade to latest upstream.
Most probably we will stop using this library in the future.