MDL-66696 forum: Add forum_grades table
authorAndrew Nicols <andrew@nicols.co.uk>
Wed, 18 Sep 2019 02:54:26 +0000 (10:54 +0800)
committerMathew May <mathewm@hotmail.co.nz>
Wed, 30 Oct 2019 02:23:40 +0000 (10:23 +0800)
Part of MDL-66074

mod/forum/classes/privacy/provider.php
mod/forum/db/install.xml
mod/forum/db/upgrade.php
mod/forum/lang/en/forum.php
mod/forum/version.php

index 7572044..367c253 100644 (file)
@@ -131,6 +131,13 @@ class provider implements
             'timemodified' => 'privacy:metadata:forum_queue:timemodified'
         ], 'privacy:metadata:forum_queue');
 
+        //The 'forum_grades' table stores grade data.
+        $items->add_database_table('forum_grades', [
+            'userid' => 'privacy:metadata:forum_grades:userid',
+            'forum' => 'privacy:metadata:forum_grades:forum',
+            'grade' => 'privacy:metadata:forum_grades:grade',
+        ], 'privacy:metadata:forum_grades');
+
         // Forum posts can be tagged and rated.
         $items->link_subsystem('core_tag', 'privacy:metadata:core_tag');
         $items->link_subsystem('core_rating', 'privacy:metadata:core_rating');
@@ -256,6 +263,8 @@ class provider implements
         $params += $ratingsql->params;
         $contextlist->add_from_sql($sql, $params);
 
+        // TODO MDL-66358 forum_grades
+
         return $contextlist;
     }
 
index 643ef77..f335ad3 100644 (file)
         <KEY NAME="user_discussions" TYPE="unique" FIELDS="userid, discussion" COMMENT="Users may only have one discussion preferences per discussion"/>
       </KEYS>
     </TABLE>
+    <TABLE NAME="forum_grades" COMMENT="Grading data for forum instances">
+      <FIELDS>
+        <FIELD NAME="id" TYPE="int" LENGTH="10" NOTNULL="true" SEQUENCE="true"/>
+        <FIELD NAME="forum" TYPE="int" LENGTH="10" NOTNULL="true" SEQUENCE="false" COMMENT="The ID of the forum that this grade relates to"/>
+        <FIELD NAME="itemnumber" TYPE="int" LENGTH="10" NOTNULL="true" SEQUENCE="false" COMMENT="The grade itemnumber"/>
+        <FIELD NAME="userid" TYPE="int" LENGTH="10" NOTNULL="true" SEQUENCE="false" COMMENT="The user who was graded"/>
+        <FIELD NAME="grade" TYPE="number" LENGTH="10" NOTNULL="false" SEQUENCE="false" DECIMALS="5" COMMENT="The numerical grade for this user's forum assessment.
+Can be determined by scales/advancedgradingforms etc but will always be converted back to a floating point number."/>
+        <FIELD NAME="timecreated" TYPE="int" LENGTH="10" NOTNULL="true" SEQUENCE="false"/>
+        <FIELD NAME="timemodified" TYPE="int" LENGTH="10" NOTNULL="true" SEQUENCE="false"/>
+      </FIELDS>
+      <KEYS>
+        <KEY NAME="primary" TYPE="primary" FIELDS="id"/>
+        <KEY NAME="forum" TYPE="foreign" FIELDS="forum" REFTABLE="forum" REFFIELDS="id"/>
+      </KEYS>
+      <INDEXES>
+        <INDEX NAME="userid" UNIQUE="false" FIELDS="userid"/>
+        <INDEX NAME="forumusergrade" UNIQUE="true" FIELDS="forum, itemnumber, userid"/>
+      </INDEXES>
+    </TABLE>
   </TABLES>
 </XMLDB>
index 5e5ccec..e4cdeef 100644 (file)
@@ -209,5 +209,35 @@ function xmldb_forum_upgrade($oldversion) {
         // Forum savepoint reached.
         upgrade_mod_savepoint(true, 2019081100, 'forum');
 
+    if ($oldversion < 2019100100) {
+        // Define table forum_grades to be created.
+        $table = new xmldb_table('forum_grades');
+
+        // Adding fields to table forum_grades.
+        $table->add_field('id', XMLDB_TYPE_INTEGER, '10', null, XMLDB_NOTNULL, XMLDB_SEQUENCE, null);
+        $table->add_field('forum', XMLDB_TYPE_INTEGER, '10', null, XMLDB_NOTNULL, null, null);
+        $table->add_field('itemnumber', XMLDB_TYPE_INTEGER, '10', null, XMLDB_NOTNULL, null, null);
+        $table->add_field('userid', XMLDB_TYPE_INTEGER, '10', null, XMLDB_NOTNULL, null, null);
+        $table->add_field('grade', XMLDB_TYPE_NUMBER, '10, 5', null, null, null, null);
+        $table->add_field('timecreated', XMLDB_TYPE_INTEGER, '10', null, XMLDB_NOTNULL, null, null);
+        $table->add_field('timemodified', XMLDB_TYPE_INTEGER, '10', null, XMLDB_NOTNULL, null, null);
+
+        // Adding keys to table forum_grades.
+        $table->add_key('primary', XMLDB_KEY_PRIMARY, ['id']);
+        $table->add_key('forum', XMLDB_KEY_FOREIGN, ['forum'], 'forum', ['id']);
+
+        // Adding indexes to table forum_grades.
+        $table->add_index('userid', XMLDB_INDEX_NOTUNIQUE, ['userid']);
+        $table->add_index('forumusergrade', XMLDB_INDEX_UNIQUE, ['forum', 'itemnumber', 'userid']);
+
+        // Conditionally launch create table for forum_grades.
+        if (!$dbman->table_exists($table)) {
+            $dbman->create_table($table);
+        }
+
+        // Forum savepoint reached.
+        upgrade_mod_savepoint(true, 2019100100, 'forum');
+    }
+
     return true;
 }
index 1121409..29789c6 100644 (file)
@@ -527,6 +527,10 @@ $string['privacy:metadata:forum_discussions:name'] = 'The name of the discussion
 $string['privacy:metadata:forum_discussions:timemodified'] = 'The time that the discussion was last modified.';
 $string['privacy:metadata:forum_discussions:userid'] = 'The ID of the user who created the discussion';
 $string['privacy:metadata:forum_discussions:usermodified'] = 'The ID of the user who last modified the discussion in some way.';
+$string['privacy:metadata:forum_grades'] = 'Grade data for the forum';
+$string['privacy:metadata:forum_grades:forum'] = 'The forum that was graded';
+$string['privacy:metadata:forum_grades:grade'] = 'The grade awarded';
+$string['privacy:metadata:forum_grades:userid'] = 'The user who was graded';
 $string['privacy:metadata:forum_posts'] = 'Information about the digest preferences for each forum.';
 $string['privacy:metadata:forum_posts:created'] = 'The time that the post was created.';
 $string['privacy:metadata:forum_posts:discussion'] = 'The discussion that the post is in.';
index fad9d80..ed070d4 100644 (file)
@@ -24,6 +24,6 @@
 
 defined('MOODLE_INTERNAL') || die();
 
-$plugin->version   = 2019100103;       // The current module version (Date: YYYYMMDDXX)
+$plugin->version   = 2019100104;       // The current module version (Date: YYYYMMDDXX)
 $plugin->requires  = 2019051100;       // Requires this Moodle version
 $plugin->component = 'mod_forum';      // Full name of the plugin (used for diagnostics)