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 000000000..af4f52c56
Binary files /dev/null and b/pics/chevron-up.png differ
diff --git a/pics/pics_chevron-up.png b/pics/pics_chevron-up.png
new file mode 100644
index 000000000..af4f52c56
Binary files /dev/null and b/pics/pics_chevron-up.png differ
diff --git a/tests/suite-unit/PluginFormcreatorQuestion.php b/tests/suite-unit/PluginFormcreatorQuestion.php
index 257de7bac..6f82e3fa1 100644
--- a/tests/suite-unit/PluginFormcreatorQuestion.php
+++ b/tests/suite-unit/PluginFormcreatorQuestion.php
@@ -428,4 +428,29 @@ public function testExport() {
->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);
+ }
}