From 3824d220f12106adaed4eec1743c83938df13bf5 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Andr=C3=A9=20Noack?= <noack@data-quest.de>
Date: Fri, 19 Jan 2024 10:20:55 +0000
Subject: [PATCH] =?UTF-8?q?Resolve=20#3646=20"Frageb=C3=B6gen:=20Standards?=
 =?UTF-8?q?ortierung=20nach=20Titel=20ist=20nicht=20hilfreich"?=
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit

Closes #3646

Merge request studip/studip!2529
---
 app/controllers/questionnaire.php                   |  4 ++--
 app/views/questionnaire/_overview_questionnaire.php |  3 +++
 app/views/questionnaire/overview.php                | 11 ++++++-----
 3 files changed, 11 insertions(+), 7 deletions(-)

diff --git a/app/controllers/questionnaire.php b/app/controllers/questionnaire.php
index 3f1be16b2f6..66a4e0b6ad5 100644
--- a/app/controllers/questionnaire.php
+++ b/app/controllers/questionnaire.php
@@ -34,7 +34,7 @@ class QuestionnaireController extends AuthenticatedController
         if (!$GLOBALS['perm']->have_perm('autor')) {
             throw new AccessDeniedException('Only for logged in users.');
         }
-        $this->questionnaires = Questionnaire::findBySQL("user_id = ? ORDER BY title ASC", [$GLOBALS['user']->id]);
+        $this->questionnaires = Questionnaire::findBySQL("user_id = ? ORDER BY chdate DESC", [$GLOBALS['user']->id]);
         foreach ($this->questionnaires as $questionnaire) {
             if (!$questionnaire['visible'] && $questionnaire->isRunning()) {
                 $questionnaire->start();
@@ -55,7 +55,7 @@ class QuestionnaireController extends AuthenticatedController
         Navigation::activateItem("/course/admin/questionnaires");
         $this->statusgruppen = Statusgruppen::findByRange_id($this->range_id);
         $this->questionnaires = Questionnaire::findBySQL(
-            "INNER JOIN questionnaire_assignments USING (questionnaire_id) WHERE (questionnaire_assignments.range_id = ? AND questionnaire_assignments.range_type = ?) OR (questionnaire_assignments.range_id IN (?) AND questionnaire_assignments.range_type = 'statusgruppe') ORDER BY questionnaires.title ASC",
+            "INNER JOIN questionnaire_assignments USING (questionnaire_id) WHERE (questionnaire_assignments.range_id = ? AND questionnaire_assignments.range_type = ?) OR (questionnaire_assignments.range_id IN (?) AND questionnaire_assignments.range_type = 'statusgruppe') ORDER BY questionnaires.chdate DESC",
             [$this->range_id, $this->range_type, array_map(function ($g) { return $g->getId(); }, $this->statusgruppen)]
         );
         foreach ($this->questionnaires as $questionnaire) {
diff --git a/app/views/questionnaire/_overview_questionnaire.php b/app/views/questionnaire/_overview_questionnaire.php
index d1d9066da25..bb7586ef853 100644
--- a/app/views/questionnaire/_overview_questionnaire.php
+++ b/app/views/questionnaire/_overview_questionnaire.php
@@ -69,6 +69,9 @@
     <td>
         <?= htmlReady($countedAnswers ?: '0') ?>
     </td>
+    <td data-text="<?= (int) $questionnaire['chdate'] ?>">
+        <?= date('d.m.Y H:i', $questionnaire['chdate']) ?>
+    </td>
     <td class="actions">
     <? if ($questionnaire->isRunning() && $countedAnswers) : ?>
         <?= Icon::create('edit', Icon::ROLE_INACTIVE)->asImg(['title' => _('Der Fragebogen wurde gestartet und kann nicht mehr bearbeitet werden.')]) ?>
diff --git a/app/views/questionnaire/overview.php b/app/views/questionnaire/overview.php
index 9062e1cc7a2..c7e14fad5b9 100644
--- a/app/views/questionnaire/overview.php
+++ b/app/views/questionnaire/overview.php
@@ -1,15 +1,16 @@
 <form action="<?= $controller->link_for("questionnaire/bulkdelete", compact('range_type', 'range_id')) ?>"
       method="post">
     <?= CSRFProtection::tokenTag() ?>
-    <table class="default sortable-table" data-sortlist="[[1, 0]]" id="questionnaire_overview">
+    <table class="default sortable-table" data-sortlist="[[6, 1]]" id="questionnaire_overview">
         <thead>
             <tr>
                 <th width="20"><input type="checkbox" data-proxyfor="#questionnaire_overview > tbody input[type=checkbox]"></th>
                 <th data-sort="text"><?= _('Fragebogen') ?></th>
-                <th data-sort="digit"><?= _('Startet') ?></th>
-                <th data-sort="digit"><?= _('Endet') ?></th>
+                <th data-sort="digit"><?= _('Start') ?></th>
+                <th data-sort="digit"><?= _('Ende') ?></th>
                 <th data-sort="text"><?= _('Eingebunden') ?></th>
                 <th data-sort="digit"><?= _('Teilnehmende') ?></th>
+                <th data-sort="digit"><?= _('Datum') ?></th>
                 <th class="actions"><?= _('Aktionen') ?></th>
             </tr>
         </thead>
@@ -20,7 +21,7 @@
             <? endforeach ?>
             <? else : ?>
                 <tr class="noquestionnaires">
-                    <td colspan="7" style="text-align: center">
+                    <td colspan="8" style="text-align: center">
                         <?= _('Sie haben noch keine Fragebögen erstellt.') ?>
                     </td>
                 </tr>
@@ -28,7 +29,7 @@
         </tbody>
         <tfoot>
             <tr>
-                <td colspan="7">
+                <td colspan="8">
                     <?= \Studip\Button::create(_("Löschen"), "bulkdelete", ['data-confirm' => _("Wirklich löschen?")]) ?>
                 </td>
             </tr>
-- 
GitLab