From 6a1adb02a873c9553b50d91fb12e046483e9819f Mon Sep 17 00:00:00 2001 From: Julio Montoya Date: Thu, 26 Feb 2015 10:48:59 +0100 Subject: [PATCH] Add new function addCheckBoxGroup(), rename add_label to addLabel --- .../lib/formvalidator/FormValidator.class.php | 162 +++++++++++------- main/inc/lib/pear/HTML/QuickForm/checkbox.php | 34 ++-- main/inc/lib/pear/HTML/QuickForm/label.php | 67 ++++---- main/inc/lib/pear/HTML/QuickForm/radio.php | 83 ++++----- main/link/link_form.class.php | 4 +- main/social/message_for_group_form.inc.php | 4 +- 6 files changed, 192 insertions(+), 162 deletions(-) diff --git a/main/inc/lib/formvalidator/FormValidator.class.php b/main/inc/lib/formvalidator/FormValidator.class.php index 5382fbb1db..5ab8e7134b 100755 --- a/main/inc/lib/formvalidator/FormValidator.class.php +++ b/main/inc/lib/formvalidator/FormValidator.class.php @@ -146,17 +146,11 @@ class FormValidator extends HTML_QuickForm // Modify the default templates $renderer = & $this->defaultRenderer(); - //Form template - $formTemplate = ' -
- {content} -
-
-{hidden} -'; + // Form template + $formTemplate = $this->getFormTemplate(); $renderer->setFormTemplate($formTemplate); - //Element template + // Element template if (isset($attributes['class']) && $attributes['class'] == 'well form-inline') { $element_template = ' {label} {element} '; $renderer->setElementTemplate($element_template); @@ -164,29 +158,7 @@ class FormValidator extends HTML_QuickForm $element_template = ' {label} {element} '; $renderer->setElementTemplate($element_template); } else { - $element_template = ' -
- -
- {element} - - - {label_3} - - - -

{label_2}

- - - - {error} - -
-
'; - $renderer->setElementTemplate($element_template); + $renderer->setElementTemplate($this->getElementTemplate()); //Display a gray div in the buttons $button_element_template_simple = '
{label} {element}
'; @@ -228,6 +200,49 @@ EOT; $renderer->setRequiredNoteTemplate($required_note_template); } + /** + * @return string + */ + public function getFormTemplate() + { + return ' +
+ {content} +
+
+ {hidden} + '; + } + + /** + * @return string + */ + public function getElementTemplate() + { + return ' +
+ +
+ {element} + + + {label_3} + + + +

{label_2}

+ + + + {error} + +
+
'; + } + /** * Adds a text field to the form. * A trim-filter is attached to the field. @@ -254,8 +269,8 @@ EOT; * * @param string $name * @param string $label - * @param bool $required - * @param array $attributes + * @param bool $required + * @param array $attributes */ public function addDateRangePicker($name, $label, $required = true, $attributes = array()) { @@ -281,49 +296,81 @@ EOT; * @param string $name * @param string $label * @param array $attributes + * + * @return HTML_QuickForm_textarea */ public function addTextarea($name, $label, $attributes = array()) { - $this->addElement('textarea', $name, $label, $attributes); + return $this->addElement('textarea', $name, $label, $attributes); } /** * @param string $name * @param string $label * @param string $icon font-awesome + * @param string $class * For example plus is transformed to icon fa fa-plus * @param array $attributes + * + * @return HTML_QuickForm_button */ - public function addButton($name, $label, $icon = 'check', $attributes = array()) + public function addButton($name, $label, $icon = 'check', $class = 'btn btn-default', $attributes = array()) { //$attributes['class'] = isset($attributes['class']) ? $attributes['class'] : 'btn btn-default'; $attributes['icon'] = $icon; - $this->addElement('button', $name, $label, $attributes); + $attributes['class'] = $class; + + return $this->addElement('button', $name, $label, $attributes); + } + + /** + * @param string $name + * @param string $label + * @param string $text + * @param array $attributes + * + * @return HTML_QuickForm_checkbox + */ + public function addCheckBox($name, $label, $text = '', $attributes = array()) + { + return $this->addElement('checkbox', $name, $label, $text, $attributes); } /** * @param string $name * @param string $label - * @param string $trailer + * @param array $options * @param array $attributes + * + * @return HTML_QuickForm_group */ - public function addCheckBox($name, $label, $trailer = '', $attributes = array()) + public function addCheckBoxGroup($name, $label, $options = array(), $attributes = array()) { - $this->addElement('checkbox', $name, $label, $trailer, $attributes); + $group = array(); + foreach ($options as $value => $text) { + $attributes['value'] = $value; + $group[] = $this->createElement('checkbox', null, null, $text, $attributes); + } + + return $this->addGroup($group, $name, $label); } /** * @param string $name * @param string $label * @param array $options + * @param array $attributes + * + * @return HTML_QuickForm_radio */ - public function addRadio($name, $label, $options = array()) + public function addRadio($name, $label, $options = array(), $attributes = array()) { $group = array(); foreach ($options as $key => $value) { - $group[] = $this->createElement('radio', null, null, $value, $key); + $group[] = $this->createElement('radio', null, null, $value, $key, $attributes); } - $this->addGroup($group, $name, $label); + + return $this->addGroup($group, $name, $label); } /** @@ -331,19 +378,23 @@ EOT; * @param string $label * @param string $options * @param array $attributes + * + * @return HTML_QuickForm_select */ public function addSelect($name, $label, $options = '', $attributes = array()) { - $this->addElement('select', $name, $label, $options, $attributes); + return $this->addElement('select', $name, $label, $options, $attributes); } /** * @param string $label * @param string $text + * + * @return HTML_QuickForm_label */ - public function add_label($label, $text) + public function addLabel($label, $text) { - $this->addElement('label', $label, $text); + return $this->addElement('label', $label, $text); } /** @@ -357,7 +408,7 @@ EOT; /** * @param string $name * @param string $label - * @param array $attributes + * @param array $attributes */ public function add_file($name, $label, $attributes = array()) { @@ -379,9 +430,9 @@ EOT; * A rule is attached to check for unwanted HTML * @param string $name * @param string $label The label for the form-element - * @param boolean $required (optional) Is the form-element required (default=true) - * @param boolean $full_page (optional) When it is true, the editor loads completed html code for a full page. - * @param array $config (optional) Configuration settings for the online editor. + * @param bool $required (optional) Is the form-element required (default=true) + * @param bool $full_page (optional) When it is true, the editor loads completed html code for a full page. + * @param array $config (optional) Configuration settings for the online editor. * */ public function addHtmlEditor($name, $label, $required = true, $fullPage = false, $config = null) @@ -447,17 +498,6 @@ EOT; $this->addRule(array($name_1, $name_2), get_lang('StartDateShouldBeBeforeEndDate'), 'date_compare', 'lte'); } - /** - * Adds a button to the form to add resources. - * @deprecated - */ - function add_resource_button() - { - $group = array(); - $group[] = $this->createElement('static', 'add_resource_img', null, '' . get_lang('Attachment') . ''); - $group[] = $this->createElement('submit', 'add_resource', get_lang('Attachment'), 'class="link_alike"'); - $this->addGroup($group); - } /** * Adds a progress bar to the form. diff --git a/main/inc/lib/pear/HTML/QuickForm/checkbox.php b/main/inc/lib/pear/HTML/QuickForm/checkbox.php index 2e8681cc64..cb517ac2c3 100755 --- a/main/inc/lib/pear/HTML/QuickForm/checkbox.php +++ b/main/inc/lib/pear/HTML/QuickForm/checkbox.php @@ -62,13 +62,23 @@ class HTML_QuickForm_checkbox extends HTML_QuickForm_input * @access public * @return void */ - function HTML_QuickForm_checkbox($elementName=null, $elementLabel=null, $text='', $attributes=null) - { + public function HTML_QuickForm_checkbox( + $elementName = null, + $elementLabel = null, + $text = '', + $attributes = null + ) { HTML_QuickForm_input::HTML_QuickForm_input($elementName, $elementLabel, $attributes); $this->_persistantFreeze = true; $this->_text = $text; $this->setType('checkbox'); - $this->updateAttributes(array('value'=>1)); + + if (!isset($attributes['value'])) { + $this->updateAttributes(array('value' => 1)); + } else { + $this->updateAttributes(array('value' => $attributes['value'])); + } + $this->_generateId(); } //end constructor @@ -117,17 +127,20 @@ class HTML_QuickForm_checkbox extends HTML_QuickForm_input * @access public * @return string */ - function toHtml() + public function toHtml() { if (0 == strlen($this->_text)) { $label = ''; } elseif ($this->_flagFrozen) { $label = $this->_text; } else { - //$label = ''; - $label = ''; + $label = ''; + return $label; } + return HTML_QuickForm_input::toHtml() . $label; } //end func toHtml @@ -144,10 +157,10 @@ class HTML_QuickForm_checkbox extends HTML_QuickForm_input function getFrozenHtml() { if ($this->getChecked()) { - return '[x]' . + return '[x]' . $this->_getPersistantData(); } else { - return '[ ]'; + return '[ ]'; } } //end func getFrozenHtml @@ -269,7 +282,4 @@ class HTML_QuickForm_checkbox extends HTML_QuickForm_input } return $this->_prepareValue($value, $assoc); } - - // }}} -} //end class HTML_QuickForm_checkbox -?> +} diff --git a/main/inc/lib/pear/HTML/QuickForm/label.php b/main/inc/lib/pear/HTML/QuickForm/label.php index e13582c59f..0f4952cb54 100755 --- a/main/inc/lib/pear/HTML/QuickForm/label.php +++ b/main/inc/lib/pear/HTML/QuickForm/label.php @@ -21,45 +21,46 @@ class HTML_QuickForm_label extends HTML_QuickForm_static { // {{{ constructor - /** - * Class constructor - * - * @param string $text raw HTML to add - * @access public - * @return void - */ - function HTML_QuickForm_label($label = null, $text = null, $attributes = null) { + /** + * Class constructor + * + * @param string $text raw HTML to add + * @access public + * @return void + */ + function HTML_QuickForm_label( + $label = null, + $text = null, + $attributes = null + ) { $this->HTML_QuickForm_static(null, $label, $text, $attributes); $this->_type = 'html'; } - // }}} - // {{{ accept() - - /** - * Accepts a renderer - * - * @param HTML_QuickForm_Renderer renderer object (only works with Default renderer!) - * @access public - * @return void - */ - function accept(&$renderer, $required=false, $error=null) { + /** + * Accepts a renderer + * + * @param HTML_QuickForm_Renderer renderer object (only works with Default renderer!) + * @access public + * @return void + */ + public function accept(&$renderer, $required = false, $error = null) + { $renderer->renderHtml($this); } - function toHtml() { - $for = $this->getLabelFor(); - return '
- + /** + * @return string + */ + public function toHtml() + { + $for = $this->getLabelFor(); + return '
+
- '.HTML_QuickForm_static::toHtml().' -
+ ' . HTML_QuickForm_static::toHtml() . ' +
- - '; - } //end func toHtml - - - - // }}} -} //end class HTML_QuickForm_html + '; + } +} diff --git a/main/inc/lib/pear/HTML/QuickForm/radio.php b/main/inc/lib/pear/HTML/QuickForm/radio.php index efcce6c87f..c3970c9c47 100755 --- a/main/inc/lib/pear/HTML/QuickForm/radio.php +++ b/main/inc/lib/pear/HTML/QuickForm/radio.php @@ -34,7 +34,6 @@ */ class HTML_QuickForm_radio extends HTML_QuickForm_input { - // {{{ properties /** * Radio display text @@ -44,9 +43,6 @@ class HTML_QuickForm_radio extends HTML_QuickForm_input */ var $_text = ''; - // }}} - // {{{ constructor - /** * Class constructor * @@ -59,8 +55,13 @@ class HTML_QuickForm_radio extends HTML_QuickForm_input * @access public * @return void */ - function HTML_QuickForm_radio($elementName=null, $elementLabel=null, $text=null, $value=null, $attributes=null) - { + public function HTML_QuickForm_radio( + $elementName = null, + $elementLabel = null, + $text = null, + $value = null, + $attributes = null + ) { $this->HTML_QuickForm_element($elementName, $elementLabel, $attributes); if (isset($value)) { $this->setValue($value); @@ -69,10 +70,7 @@ class HTML_QuickForm_radio extends HTML_QuickForm_input $this->setType('radio'); $this->_text = $text; $this->_generateId(); - } //end constructor - - // }}} - // {{{ setChecked() + } /** * Sets whether radio button is checked @@ -89,10 +87,7 @@ class HTML_QuickForm_radio extends HTML_QuickForm_input } else { $this->updateAttributes(array('checked'=>'checked')); } - } //end func setChecked - - // }}} - // {{{ getChecked() + } /** * Returns whether radio button is checked @@ -104,10 +99,7 @@ class HTML_QuickForm_radio extends HTML_QuickForm_input function getChecked() { return $this->getAttribute('checked'); - } //end func getChecked - - // }}} - // {{{ toHtml() + } /** * Returns the radio element in HTML @@ -116,22 +108,22 @@ class HTML_QuickForm_radio extends HTML_QuickForm_input * @access public * @return string */ - function toHtml() + public function toHtml() { if (0 == strlen($this->_text)) { $label = ''; } elseif ($this->_flagFrozen) { $label = $this->_text; } else { - ///$label = ''; - $label = ''; + $label = ''; + return $label; } - return HTML_QuickForm_input::toHtml() . $label; - } //end func toHtml - // }}} - // {{{ getFrozenHtml() + return HTML_QuickForm_input::toHtml() . $label; + } /** * Returns the value of field without HTML tags @@ -140,18 +132,15 @@ class HTML_QuickForm_radio extends HTML_QuickForm_input * @access public * @return string */ - function getFrozenHtml() + public function getFrozenHtml() { if ($this->getChecked()) { - return '(x)' . + return '(x)' . $this->_getPersistantData(); } else { - return '( )'; + return '( )'; } - } //end func getFrozenHtml - - // }}} - // {{{ setText() + } /** * Sets the radio text @@ -161,13 +150,10 @@ class HTML_QuickForm_radio extends HTML_QuickForm_input * @access public * @return void */ - function setText($text) + public function setText($text) { $this->_text = $text; - } //end func setText - - // }}} - // {{{ getText() + } /** * Returns the radio text @@ -176,13 +162,10 @@ class HTML_QuickForm_radio extends HTML_QuickForm_input * @access public * @return string */ - function getText() + public function getText() { return $this->_text; - } //end func getText - - // }}} - // {{{ onQuickFormEvent() + } /** * Called by HTML_QuickForm whenever form event is made on this element @@ -194,7 +177,7 @@ class HTML_QuickForm_radio extends HTML_QuickForm_input * @access public * @return void */ - function onQuickFormEvent($event, $arg, &$caller) + public function onQuickFormEvent($event, $arg, &$caller) { switch ($event) { case 'updateValue': @@ -223,16 +206,14 @@ class HTML_QuickForm_radio extends HTML_QuickForm_input default: parent::onQuickFormEvent($event, $arg, $caller); } - return true; - } // end func onQuickFormLoad - // }}} - // {{{ exportValue() + return true; + } /** * Returns the value attribute if the radio is checked, null if it is not */ - function exportValue(&$submitValues, $assoc = false) + public function exportValue(&$submitValues, $assoc = false) { $value = $this->_findValue($submitValues); if (null === $value) { @@ -240,9 +221,7 @@ class HTML_QuickForm_radio extends HTML_QuickForm_input } elseif ($value != $this->getValue()) { $value = null; } + return $this->_prepareValue($value, $assoc); } - - // }}} -} //end class HTML_QuickForm_radio -?> +} diff --git a/main/link/link_form.class.php b/main/link/link_form.class.php index 389763dfed..9762757b04 100755 --- a/main/link/link_form.class.php +++ b/main/link/link_form.class.php @@ -78,7 +78,7 @@ class LinkForm extends \FormValidator if ($id) { $url = Chamilo::url('/main/metadata/index.php', array('eid' => "Link.$id")); $metadata = '' . get_lang('AddMetadata') . ''; - $this->add_label(get_lang('Metadata'), $metadata); + $this->addLabel(get_lang('Metadata'), $metadata); } $options = array(); @@ -97,7 +97,7 @@ class LinkForm extends \FormValidator ); $this->addSelect('target', get_lang('LinkTarget'), $targets); //$help = '' . get_lang('AddTargetOfLinkOnHomepage') . ''; - //$this->add_label('', $help); + //$this->addLabel('', $help); $this->addButton('save', get_lang('Save')); diff --git a/main/social/message_for_group_form.inc.php b/main/social/message_for_group_form.inc.php index c605678718..b97b692870 100755 --- a/main/social/message_for_group_form.inc.php +++ b/main/social/message_for_group_form.inc.php @@ -109,13 +109,13 @@ if (api_get_setting('allow_message_tool') == 'true') { $form->add_file('attach_1', get_lang('AttachmentFiles')); $form->addHtml(''); - $form->add_label(null, + $form->addLabel(null, ' ' ); - $form->add_label(null, + $form->addLabel(null, api_xml_http_response_encode( sprintf( get_lang('MaximunFileSizeX'),