From 9ed109e7f05de76f68711bbb9137066076f63ea2 Mon Sep 17 00:00:00 2001 From: LUIZ Manoel Resplande Oliveira <06693562124@CODTI1708L.poupex.com.br> Date: Fri, 4 Oct 2019 14:24:07 -0300 Subject: [PATCH] feat(question): bring a question to 1st position Signed-off-by: LUIZ Manoel Resplande Oliveira Signed-off-by: Thierry Bugier --- front/question.form.php | 2 + inc/question.class.php | 48 +++++++++++++++++- pics/chevron-up.png | Bin 0 -> 457 bytes pics/pics_chevron-up.png | Bin 0 -> 457 bytes .../suite-unit/PluginFormcreatorQuestion.php | 25 +++++++++ 5 files changed, 74 insertions(+), 1 deletion(-) create mode 100644 pics/chevron-up.png create mode 100644 pics/pics_chevron-up.png diff --git a/front/question.form.php b/front/question.form.php index 6e686d9b9..5a475f5f5 100644 --- a/front/question.form.php +++ b/front/question.form.php @@ -90,6 +90,8 @@ if ($question->getFromDB((int) $_POST['id'])) { if ($_POST['way'] == 'up') { $question->moveUp(); + } else if($_POST['way'] == 'top') { + $question->moveTop(); } else { $question->moveDown(); } diff --git a/inc/question.class.php b/inc/question.class.php index 678563178..d6b50babf 100644 --- a/inc/question.class.php +++ b/inc/question.class.php @@ -176,7 +176,7 @@ public static function showForForm(CommonDBTM $item, $withtemplate = '') { onclick="moveSection(\'' . $token . '\', ' . $section['id'] . ', \'up\');"> '; } echo ""; - + echo ''; echo ''; @@ -226,6 +226,10 @@ public static function showForForm(CommonDBTM $item, $withtemplate = '') { title='" . __('Required', 'formcreator') . "' onclick='setRequired(\"".$token."\", ".$question['id'].", ".($question['required']?0:1).")' > "; echo ""; + } else { + echo ""; + echo '
'; + echo "
"; } echo ""; @@ -244,6 +248,14 @@ public static function showForForm(CommonDBTM $item, $withtemplate = '') { } echo ""; + echo ""; + if ($question['order'] != 1) { + echo ' '; + } + echo ""; + echo ''; echo ''; } @@ -506,6 +518,40 @@ public function moveUp() { } } + /** + * Moves the question to top + */ + public function moveTop() { + global $DB; + + $order = $this->fields['order']; + $sectionId = $this->fields['plugin_formcreator_sections_id']; + $otherItem = new static(); + + $result = $DB->request([ + 'FROM' => $otherItem->getTable(), + 'WHERE' => [ + 'plugin_formcreator_sections_id' => $sectionId, + 'order' => ['<', $order], + ], + 'ORDER' => 'order ASC', + ]); + + $this->update([ + 'id' => $this->getID(), + 'order' => '1', + '_skip_checks' => true, + ]); + + foreach ($result as $value) { + $otherItem->update([ + 'id' => $value['id'], + 'order' => $value['order'] + 1, + '_skip_checks' => true, + ]); + } + } + /** * Moves the question down in the ordered list of questions in the section */ diff --git a/pics/chevron-up.png b/pics/chevron-up.png new file mode 100644 index 0000000000000000000000000000000000000000..af4f52c56f8d3bb17a5705953723127ee85db207 GIT binary patch literal 457 zcmeAS@N?(olHy`uVBq!ia0vp^0wB!60wlNoGJgf6SkfJR9T^xl_H+M9WCijSl0AZa z85pY67#JE_7#My5g&JNkFq9fFFuY1&V6d9Oz#v{QXIG#NP=YDR+uenMVO6iP5s=4O z;1OBOz`%C|gc+x5^GO2**-JcqUD+RVF$-IZFJ)jB1qw~~ba4#PIA43gQ0Sn8NW;VP z(hasKeys($fieldsWithoutID + $extraFields + ['id']) ->hasSize(1 + count($fieldsWithoutID) + count($extraFields)); } + + public function testMoveTop() { + $section = $this->getSection(); + $question1 = $this->getQuestion([ + 'plugin_formcreator_sections_id' => $section->getID(), + ]); + $question2 = $this->getQuestion([ + 'plugin_formcreator_sections_id' => $section->getID(), + ]); + $question3 = $this->getQuestion([ + 'plugin_formcreator_sections_id' => $section->getID(), + ]); + + $this->integer((int) $question1->fields['order'])->isEqualTo(1); + $this->integer((int) $question2->fields['order'])->isEqualTo(2); + $this->integer((int) $question3->fields['order'])->isEqualTo(3); + $question3->moveTop(); + // Reload questions + $question1->getFromDB($question1->getID()); + $question2->getFromDB($question2->getID()); + $question3->getFromDB($question3->getID()); + $this->integer((int) $question3->fields['order'])->isEqualTo(1); + $this->integer((int) $question1->fields['order'])->isEqualTo(2); + $this->integer((int) $question2->fields['order'])->isEqualTo(3); + } }