diff options
author | mattab <matthieu.aubry@gmail.com> | 2013-03-28 03:42:39 +0400 |
---|---|---|
committer | mattab <matthieu.aubry@gmail.com> | 2013-03-28 03:42:40 +0400 |
commit | ae4b03163792f0b6e933933e5d37df87dc3fd566 (patch) | |
tree | d1d7510a9728f587d3d63ebd03e4ecf3d904838b /core/QuickForm2.php | |
parent | 158c2150f5f2e13ece459b8d131244c11b763997 (diff) |
Mass conversion of all files to the newly agreed coding standard: PSR 1/2
Converting Piwik core source files, PHP, JS, TPL, CSS
More info: http://piwik.org/participate/coding-standards/
Diffstat (limited to 'core/QuickForm2.php')
-rw-r--r-- | core/QuickForm2.php | 209 |
1 files changed, 101 insertions, 108 deletions
diff --git a/core/QuickForm2.php b/core/QuickForm2.php index 63793c235e..a41f2e5eb9 100644 --- a/core/QuickForm2.php +++ b/core/QuickForm2.php @@ -1,135 +1,128 @@ <?php /** * Piwik - Open source web analytics - * + * * @link http://piwik.org * @license http://www.gnu.org/licenses/gpl-3.0.html GPL v3 or later - * + * * @category Piwik * @package Piwik */ /** * Parent class for forms to be included in Smarty - * + * * For an example, @see Piwik_Login_FormLogin - * + * * @package Piwik - * @see HTML_QuickForm2, libs/HTML/QuickForm2.php + * @see HTML_QuickForm2, libs/HTML/QuickForm2.php * @link http://pear.php.net/package/HTML_QuickForm2/ */ abstract class Piwik_QuickForm2 extends HTML_QuickForm2 { - protected $a_formElements = array(); - - function __construct( $id, $method = 'post', $attributes = null, $trackSubmit = false) - { - if(!isset($attributes['action'])) - { - $attributes['action'] = Piwik_Url::getCurrentQueryString(); - } - if(!isset($attributes['name'])) - { - $attributes['name'] = $id; - } - parent::__construct($id, $method, $attributes, $trackSubmit); + protected $a_formElements = array(); - $this->init(); - } + function __construct($id, $method = 'post', $attributes = null, $trackSubmit = false) + { + if (!isset($attributes['action'])) { + $attributes['action'] = Piwik_Url::getCurrentQueryString(); + } + if (!isset($attributes['name'])) { + $attributes['name'] = $id; + } + parent::__construct($id, $method, $attributes, $trackSubmit); - /** - * Class specific initialization - */ - abstract function init(); + $this->init(); + } - /** - * The elements in this form - * - * @return array Element names - */ - public function getElementList() - { - return $this->a_formElements; - } + /** + * Class specific initialization + */ + abstract function init(); - /** - * Wrapper around HTML_QuickForm2_Container's addElement() - * - * @param string|HTML_QuickForm2_Node Either type name (treated - * case-insensitively) or an element instance - * @param mixed Element name - * @param mixed Element attributes - * @param array Element-specific data - * @return HTML_QuickForm2_Node Added element - * @throws HTML_QuickForm2_InvalidArgumentException - * @throws HTML_QuickForm2_NotFoundException - */ + /** + * The elements in this form + * + * @return array Element names + */ + public function getElementList() + { + return $this->a_formElements; + } + + /** + * Wrapper around HTML_QuickForm2_Container's addElement() + * + * @param string|HTML_QuickForm2_Node Either type name (treated + * case-insensitively) or an element instance + * @param mixed Element name + * @param mixed Element attributes + * @param array Element-specific data + * @return HTML_QuickForm2_Node Added element + * @throws HTML_QuickForm2_InvalidArgumentException + * @throws HTML_QuickForm2_NotFoundException + */ public function addElement($elementOrType, $name = null, $attributes = null, array $data = array()) - { - if($name != 'submit') - { - $this->a_formElements[] = $name; - } + { + if ($name != 'submit') { + $this->a_formElements[] = $name; + } + + return parent::addElement($elementOrType, $name, $attributes, $data); + } + + function setChecked($nameElement) + { + foreach ($this->_elements as $key => $value) { + if ($value->_attributes['name'] == $nameElement) { + $this->_elements[$key]->_attributes['checked'] = 'checked'; + } + } + } + + function setSelected($nameElement, $value) + { + foreach ($this->_elements as $key => $value) { + if ($value->_attributes['name'] == $nameElement) { + $this->_elements[$key]->_attributes['selected'] = 'selected'; + } + } + } + + /** + * Ported from HTML_QuickForm to minimize changes to Controllers + * + * @param string $elementName + * @return mixed + */ + function getSubmitValue($elementName) + { + $value = $this->getValue(); + return isset($value[$elementName]) ? $value[$elementName] : null; + } + + /** + * Returns the rendered form as an array. + * + * @param bool $groupErrors Whether to group errors together or not. + * @return array + */ + public function getFormData($groupErrors = true) + { + static $registered = false; + if (!$registered) { + HTML_QuickForm2_Renderer::register('smarty', 'HTML_QuickForm2_Renderer_Smarty'); + $registered = true; + } - return parent::addElement($elementOrType, $name, $attributes, $data); - } - - function setChecked( $nameElement ) - { - foreach( $this->_elements as $key => $value) - { - if($value->_attributes['name'] == $nameElement) - { - $this->_elements[$key]->_attributes['checked'] = 'checked'; - } - } - } - function setSelected( $nameElement, $value ) - { - foreach( $this->_elements as $key => $value) - { - if($value->_attributes['name'] == $nameElement) - { - $this->_elements[$key]->_attributes['selected'] = 'selected'; - } - } - } + // Create the renderer object + $renderer = HTML_QuickForm2_Renderer::factory('smarty'); + $renderer->setOption('group_errors', $groupErrors); - /** - * Ported from HTML_QuickForm to minimize changes to Controllers - * - * @param string $elementName - * @return mixed - */ - function getSubmitValue($elementName) - { - $value = $this->getValue(); - return isset($value[$elementName]) ? $value[$elementName] : null; - } - - /** - * Returns the rendered form as an array. - * - * @param bool $groupErrors Whether to group errors together or not. - * @return array - */ - public function getFormData( $groupErrors = true ) - { - static $registered = false; - if(!$registered) - { - HTML_QuickForm2_Renderer::register('smarty', 'HTML_QuickForm2_Renderer_Smarty'); - $registered = true; - } - - // Create the renderer object - $renderer = HTML_QuickForm2_Renderer::factory('smarty'); - $renderer->setOption('group_errors', $groupErrors); + // build the HTML for the form + $this->render($renderer); - // build the HTML for the form - $this->render($renderer); - - return $renderer->toArray(); - } + return $renderer->toArray(); + } } |