From 60458aa876d7e4395fb42f6e394e56b250e5f02c Mon Sep 17 00:00:00 2001
From: Hendrik Donath <hendrik.donath@gmx.de>
Date: Fri, 23 Oct 2020 10:47:35 +0200
Subject: [PATCH] Changed SQL-Statements so that they work under Standard SQL
 not only MySQL

---
 locallib.php            | 5 ++---
 model/comment.class.php | 4 +++-
 version.php             | 2 +-
 3 files changed, 6 insertions(+), 5 deletions(-)

diff --git a/locallib.php b/locallib.php
index d3acd71..36446a4 100644
--- a/locallib.php
+++ b/locallib.php
@@ -736,8 +736,7 @@ function pdfannotator_get_questions($courseid, $context, $questionfilter) {
     if ($questionfilter == 1) {
         $sql = $sql . ' AND NOT c.solved = 0 ';
     }
-    $sql = $sql . "GROUP BY a.id, p.name, p.usevotes, cm.id, c.id";
-    $params = array_merge([$courseid], $inparams);
+    $sql = $sql . "GROUP BY a.id, p.name, p.usevotes, cm.id, c.id, a.page, a.pdfannotatorid, c.content, c.userid, c.visibility, c.timecreated, c.isdeleted, c.ishidden";    $params = array_merge([$courseid], $inparams);
     $questions = $DB->get_records_sql($sql, $params);
 
     $seehidden = has_capability('mod/pdfannotator:seehiddencomments', $context);
@@ -827,7 +826,7 @@ function pdfannotator_get_posts_by_this_user($courseid, $context) {
             . "JOIN {course_modules} cm ON p.id = cm.instance "
             . "LEFT JOIN {pdfannotator_votes} v ON c.id = v.commentid "
             . "WHERE c.userid = ? AND p.course = ? AND cm.id $insql "
-            . "GROUP BY a.id, p.name, p.usevotes, cm.id, c.id";
+            . "GROUP BY a.id, p.name, p.usevotes, cm.id, c.id, c.annotationid, c.content, c.timemodified, c.ishidden, a.page, a.pdfannotatorid";
 
     $params = array_merge([$USER->id, $courseid], $inparams);
 
diff --git a/model/comment.class.php b/model/comment.class.php
index 428d751..e844901 100644
--- a/model/comment.class.php
+++ b/model/comment.class.php
@@ -145,7 +145,9 @@ class pdfannotator_comment {
         // Get the ids and text content of all comments attached to this annotation/highlight.
         $sql = "SELECT c.id, c.content, c.userid, c.visibility, c.isquestion, c.isdeleted, c.ishidden, c.timecreated, c.timemodified, c.modifiedby, c.solved, SUM(vote) AS votes "
                 . "FROM {pdfannotator_comments} c LEFT JOIN {pdfannotator_votes} v"
-                . " ON c.id=v.commentid WHERE annotationid = ? GROUP BY c.id ORDER BY c.timecreated";
+                . " ON c.id=v.commentid WHERE annotationid = ?"
+                . " GROUP BY c.id, c.content, c.userid, c.visibility, c.isquestion, c.isdeleted, c.ishidden, c.timecreated, c.timemodified, c.modifiedby, c.solved"
+                . " ORDER BY c.timecreated";
         $a = array();
         $a[] = $annotationid;
         $comments = $DB->get_records_sql($sql, $a); // Records taken from table 'comments' as an array of objects.
diff --git a/version.php b/version.php
index 6375f6a..be37fbc 100644
--- a/version.php
+++ b/version.php
@@ -25,6 +25,6 @@
 defined('MOODLE_INTERNAL') || die();
 
 $plugin->component = 'mod_pdfannotator'; // Full name of the plugin (used for diagnostics).
-$plugin->version   = 2020100800; // The current module version (Date: YYYYMMDDXX).
+$plugin->version   = 2020102300; // The current module version (Date: YYYYMMDDXX).
 $plugin->release  = 'PDF Annotator v1.4 release 4';
 $plugin->requires  = 2016112900; // Requires this Moodle version.
-- 
GitLab