From 413c5b998bf8884bb658e7311e772945fd1edb2d Mon Sep 17 00:00:00 2001
From: Rasmus Fuhse <fuhse@data-quest.de>
Date: Wed, 19 Jul 2023 14:23:04 +0000
Subject: [PATCH] =?UTF-8?q?Resolve=20"Eventuell=20falsche=20Anzahl=20an=20?=
 =?UTF-8?q?abgegebenen=20Antworten=20in=20Frageb=C3=B6gen=20angezeigt"?=
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit

Closes #2942

Merge request studip/studip!1982
---
 lib/models/Questionnaire.php | 7 +++++--
 1 file changed, 5 insertions(+), 2 deletions(-)

diff --git a/lib/models/Questionnaire.php b/lib/models/Questionnaire.php
index f221ca116ce..d69068de89f 100644
--- a/lib/models/Questionnaire.php
+++ b/lib/models/Questionnaire.php
@@ -31,17 +31,20 @@ class Questionnaire extends SimpleORMap implements PrivacyObject
     public function countAnswers()
     {
         $statement = DBManager::get()->prepare("
-            SELECT COUNT(*)
+            SELECT COUNT(*) as `count_answers`
             FROM questionnaire_answers
                 INNER JOIN questionnaire_questions ON (questionnaire_answers.question_id = questionnaire_questions.question_id)
             WHERE questionnaire_id = :questionnaire_id
+            GROUP BY questionnaire_answers.question_id
+            ORDER BY `count_answers` DESC
+            LIMIT 1
         ");
         $statement->execute([
             'questionnaire_id' => $this->getId()
         ]);
         $answers_total = $statement->fetch(PDO::FETCH_COLUMN, 0);
 
-        return count($this->questions) ? $answers_total / count($this->questions) : 0;
+        return $answers_total;
     }
 
     public function isAnswered($user_id = null)
-- 
GitLab