From 6adf1811d6a0c6995b635eb43aeb9912d5196781 Mon Sep 17 00:00:00 2001 From: Julio Montoya Date: Thu, 26 Feb 2015 14:25:48 +0100 Subject: [PATCH] Using FormValidator in survey (up/down button missing) BT#8968 --- .../lib/formvalidator/Element/HtmlEditor.php | 10 +- .../lib/formvalidator/FormValidator.class.php | 4 +- main/inc/lib/pear/HTML/QuickForm/element.php | 2 + main/survey/ch_comment.php | 11 + main/survey/ch_dropdown.php | 68 ++ main/survey/ch_multiplechoice.php | 61 + main/survey/ch_multipleresponse.php | 103 ++ main/survey/ch_open.php | 21 + main/survey/ch_pagebreak.php | 12 + main/survey/ch_percentage.php | 30 + main/survey/ch_personality.php | 100 ++ main/survey/ch_score.php | 74 ++ main/survey/ch_yesno.php | 96 ++ main/survey/create_new_survey.php | 16 +- main/survey/fillsurvey.php | 139 ++- main/survey/preview.php | 60 +- main/survey/question.php | 156 ++- main/survey/survey.lib.php | 1019 +---------------- main/survey/survey.php | 8 +- main/survey/survey_invite.php | 17 +- main/survey/survey_question.php | 299 +++++ .../Editor/CkEditor/Toolbar/Survey.php | 14 + .../CkEditor/Toolbar/SurveyQuestion.php | 14 + 23 files changed, 1163 insertions(+), 1171 deletions(-) create mode 100644 main/survey/ch_comment.php create mode 100644 main/survey/ch_dropdown.php create mode 100644 main/survey/ch_multiplechoice.php create mode 100644 main/survey/ch_multipleresponse.php create mode 100644 main/survey/ch_open.php create mode 100644 main/survey/ch_pagebreak.php create mode 100644 main/survey/ch_percentage.php create mode 100644 main/survey/ch_personality.php create mode 100644 main/survey/ch_score.php create mode 100644 main/survey/ch_yesno.php create mode 100644 main/survey/survey_question.php create mode 100644 src/Chamilo/CoreBundle/Component/Editor/CkEditor/Toolbar/Survey.php create mode 100644 src/Chamilo/CoreBundle/Component/Editor/CkEditor/Toolbar/SurveyQuestion.php diff --git a/main/inc/lib/formvalidator/Element/HtmlEditor.php b/main/inc/lib/formvalidator/Element/HtmlEditor.php index f69d86a1e5..a27d94b859 100644 --- a/main/inc/lib/formvalidator/Element/HtmlEditor.php +++ b/main/inc/lib/formvalidator/Element/HtmlEditor.php @@ -14,9 +14,7 @@ class HtmlEditor extends HTML_QuickForm_textarea /** * Full page */ - var $fullPage; - var $fck_editor; - var $content; + public $fullPage; /** * Class Constructor @@ -40,14 +38,11 @@ class HtmlEditor extends HTML_QuickForm_textarea $this->_persistantFreeze = true; $this->_type = 'html_editor'; - global $fck_attribute; - //$editor = Container::getHtmlEditor(); $editor = new CkEditor(); if ($editor) { $this->editor = $editor; $this->editor->setName($name); - $this->editor->processConfig($fck_attribute); $this->editor->processConfig($config); } } @@ -59,6 +54,7 @@ class HtmlEditor extends HTML_QuickForm_textarea public function toHtml() { $value = $this->getValue(); + if ($this->editor) { if ($this->editor->getConfigAttribute('fullPage')) { if (strlen(trim($value)) == 0) { @@ -69,6 +65,7 @@ class HtmlEditor extends HTML_QuickForm_textarea } } + if ($this->isFrozen()) { return $this->getFrozenHtml(); } else { @@ -93,6 +90,7 @@ class HtmlEditor extends HTML_QuickForm_textarea $result = ''; if ($this->editor) { $this->editor->value = $this->getValue(); + //echo '----->'; var_dump($this->getValue(),$this->getName()); $this->editor->setName($this->getName()); $result = $this->editor->createHtml(); } diff --git a/main/inc/lib/formvalidator/FormValidator.class.php b/main/inc/lib/formvalidator/FormValidator.class.php index 5ab8e7134b..a6f390f4f3 100755 --- a/main/inc/lib/formvalidator/FormValidator.class.php +++ b/main/inc/lib/formvalidator/FormValidator.class.php @@ -431,11 +431,11 @@ EOT; * @param string $name * @param string $label The label for the form-element * @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 bool $fullPage (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) + public function addHtmlEditor($name, $label, $required = true, $fullPage = false, $config = array()) { $this->addElement('html_editor', $name, $label, 'rows="15" cols="80"', $config); $this->applyFilter($name, 'trim'); diff --git a/main/inc/lib/pear/HTML/QuickForm/element.php b/main/inc/lib/pear/HTML/QuickForm/element.php index 590ab24479..39aca8af8e 100755 --- a/main/inc/lib/pear/HTML/QuickForm/element.php +++ b/main/inc/lib/pear/HTML/QuickForm/element.php @@ -410,6 +410,7 @@ class HTML_QuickForm_element extends HTML_Common // constant values override both default and submitted ones // default values are overriden by submitted $value = $this->_findValue($caller->_constantValues); + if (null === $value) { $value = $this->_findValue($caller->_submitValues); if (null === $value) { @@ -423,6 +424,7 @@ class HTML_QuickForm_element extends HTML_Common case 'setGroupValue': $this->setValue($arg); } + return true; } diff --git a/main/survey/ch_comment.php b/main/survey/ch_comment.php new file mode 100644 index 0000000000..87c3b61f58 --- /dev/null +++ b/main/survey/ch_comment.php @@ -0,0 +1,11 @@ +html .= '
'; + $this->html .= ' '; + $this->html .= '
'; + $total_number_of_answers = count($form_content['answers']); + $this->html .= ' '; + foreach ($form_content['answers'] as $key => & $value) { + $this->html .= ' '; + $this->html .= ' '; + $this->html .= ' '; + $this->html .= ' '; + $this->html .= ' '; + } + // The buttons for adding or removing + $this->html .= '
'; + if ($key < $total_number_of_answers - 1) { + $this->html .= ' '; + } + if ($key > 0) { + $this->html .= ' '; + } + if ($total_number_of_answers> 2) { + $this->html .= ' '; + } + $this->html .= '
'; + $this->html .= '
'; + $this->html .= '
';*/ + + if (is_array($formData['answers'])) { + foreach ($formData['answers'] as $key => $value) { + $this->getForm()->addText('answers['.$key.']', $key + 1); + } + } + + return parent :: add_remove_buttons($formData); + } + + /** + * @param FormValidator $form + * @param array $questionData + * @param array $answers + */ + public function render(FormValidator $form, $questionData = array(), $answers = array()) + { + $form->addSelect("question".$questionData['question_id'], null, $questionData['options']); + } +} + + diff --git a/main/survey/ch_multiplechoice.php b/main/survey/ch_multiplechoice.php new file mode 100644 index 0000000000..f7af16402f --- /dev/null +++ b/main/survey/ch_multiplechoice.php @@ -0,0 +1,61 @@ + get_lang('Horizontal'), + 'vertical' => get_lang('Vertical') + ); + $this->getForm()->addRadio('horizontalvertical', get_lang('DisplayAnswersHorVert'), $options); + + $formData['horizontalvertical'] = isset($formData['horizontalvertical']) ? $formData['horizontalvertical'] : 'horizontal'; + + $config = array('ToolbarSet' => 'Survey', 'Width' => '100%', 'Height' => '120'); + $total = count($formData['answers']); + if (is_array($formData['answers'])) { + foreach ($formData['answers'] as $key => $value) { + + $this->getForm()->addHtmlEditor('answers['.$key.']', null, false, false, $config); + + if ($key < $total-1) { + //$this->getForm()->addButton("move_down[$key]", get_lang('Down')); + } + + if ($key > 0) { + //$this->getForm()->addButton("move_up[$key]", get_lang('Up')); + } + + if ($total> 2) { + $this->getForm()->addButton("delete_answer[$key]", get_lang('Delete')); + } + } + } + $this->getForm()->setDefaults($formData); + + return parent :: add_remove_buttons($formData); + } + + /** + * @param FormValidator $form + * @param array $questionData + * @param array $answers + */ + public function render(FormValidator $form, $questionData = array(), $answers = array()) + { + $question = new ch_yesno(); + $question->render($form, $questionData, $answers); + } +} diff --git a/main/survey/ch_multipleresponse.php b/main/survey/ch_multipleresponse.php new file mode 100644 index 0000000000..9dbff1a82f --- /dev/null +++ b/main/survey/ch_multipleresponse.php @@ -0,0 +1,103 @@ + get_lang('Horizontal'), + 'vertical' => get_lang('Vertical') + ); + $this->getForm()->addRadio('horizontalvertical', get_lang('DisplayAnswersHorVert'), $options); + + $formData['horizontalvertical'] = isset($formData['horizontalvertical']) ? $formData['horizontalvertical'] : 'horizontal'; + + $config = array('ToolbarSet' => 'Survey', 'Width' => '100%', 'Height' => '120'); + if (is_array($formData['answers'])) { + foreach ($formData['answers'] as $key => $value) { + $this->getForm()->addHtmlEditor('answers['.$key.']', null, false, false, $config); + /* + $this->html .= ' '; + $this->html .= ' '; + //$this->html .= ' '; + //$this->html .= ' '.api_return_html_area('answers['.$key.']', api_html_entity_decode(stripslashes($form_content['answers'][$key]), ENT_QUOTES), '', '', null, ).''; + $this->html .= ' '; + if ($key<$total_number_of_answers-1) { + $this->html .= ' '; + } + if ($key>0) { + $this->html .= ' '; + } + if ($total_number_of_answers> 2) { + $this->html .= ' '; + } + $this->html .= ' '; + $this->html .= ' ';*/ + } + } + + $this->getForm()->setDefaults($formData); + + return parent :: add_remove_buttons($formData); + } + + /** + * @param FormValidator $form + * @param array $questionData + * @param array $answers + */ + public function render(FormValidator $form, $questionData = array(), $answers = array()) + { + if ($questionData['display'] == 'vertical') { + $class = ''; + } else { + $class = 'inline'; + } + + foreach ($questionData['options'] as $key => & $value) { + /*if ($questionData['display'] == 'vertical') { + $this->html .= '