MDL-66079 mod_forum: Add field to support whole forum grading
authorAndrew Nicols <andrew@nicols.co.uk>
Sun, 11 Aug 2019 08:10:13 +0000 (16:10 +0800)
committerMathew May <mathewm@hotmail.co.nz>
Wed, 30 Oct 2019 02:23:40 +0000 (10:23 +0800)
Part of MDL-66074

course/tests/courselib_test.php
mod/forum/classes/local/data_mappers/legacy/forum.php
mod/forum/classes/local/entities/forum.php
mod/forum/classes/local/factories/entity.php
mod/forum/db/install.xml
mod/forum/db/upgrade.php
mod/forum/tests/entities_forum_test.php
mod/forum/tests/generator/lib.php
mod/forum/version.php

index c5b37fc..3a39c14 100644 (file)
@@ -54,6 +54,9 @@ class core_course_courselib_testcase extends advanced_testcase {
         $moduleinfo->blockperiod = 60*60*24;
         $moduleinfo->blockafter = 10;
         $moduleinfo->warnafter = 5;
+
+        // Grading of whole forum settings.
+        $moduleinfo->grade_forum = 0;
     }
 
     /**
@@ -395,6 +398,9 @@ class core_course_courselib_testcase extends advanced_testcase {
         $moduleinfo->blockperiod = 60*60*24;
         $moduleinfo->blockafter = 10;
         $moduleinfo->warnafter = 5;
+
+        // Grading of whole forum settings.
+        $moduleinfo->grade_forum = 0;
     }
 
     /**
index 97aa7a9..9258074 100644 (file)
@@ -55,6 +55,7 @@ class forum {
                 'assesstimestart' => $forum->get_assess_time_start(),
                 'assesstimefinish' => $forum->get_assess_time_finish(),
                 'scale' => $forum->get_scale(),
+                'grade_forum' => $forum->get_grade_for_forum(),
                 'maxbytes' => $forum->get_max_bytes(),
                 'maxattachments' => $forum->get_max_attachments(),
                 'forcesubscribe' => $forum->get_subscription_mode(),
index 66d6364..16b851d 100644 (file)
@@ -69,6 +69,8 @@ class forum {
     private $assesstimefinish;
     /** @var int $scale The rating scale */
     private $scale;
+    /** @var int $gradeforum The grade for the forum when grading holistcally */
+    private $gradeforum;
     /** @var int $maxbytes Maximum attachment size */
     private $maxbytes;
     /** @var int $maxattachments Maximum number of attachments */
@@ -121,6 +123,7 @@ class forum {
      * @param int $assesstimestart Timestamp to begin assessment
      * @param int $assesstimefinish Timestamp to end assessment
      * @param int $scale The rating scale
+     * @param int $forum_grade The holistic grade
      * @param int $maxbytes Maximum attachment size
      * @param int $maxattachments Maximum number of attachments
      * @param int $forcesubscribe Does the forum force users to subscribe?
@@ -154,6 +157,7 @@ class forum {
         int $assesstimestart,
         int $assesstimefinish,
         int $scale,
+        int $gradeforum,
         int $maxbytes,
         int $maxattachments,
         int $forcesubscribe,
@@ -186,6 +190,7 @@ class forum {
         $this->assesstimestart = $assesstimestart;
         $this->assesstimefinish = $assesstimefinish;
         $this->scale = $scale;
+        $this->gradeforum = $gradeforum;
         $this->maxbytes = $maxbytes;
         $this->maxattachments = $maxattachments;
         $this->forcesubscribe = $forcesubscribe;
@@ -349,6 +354,15 @@ class forum {
         return $this->scale;
     }
 
+    /**
+     * Get the grade for the forum when grading holistically.
+     *
+     * @return int
+     */
+    public function get_grade_for_forum() : int {
+        return $this->gradeforum;
+    }
+
     /**
      * Get the maximum bytes.
      *
index 8406b99..0b252a6 100644 (file)
@@ -86,6 +86,7 @@ class entity {
             $record->assesstimestart,
             $record->assesstimefinish,
             $record->scale,
+            $record->grade_forum,
             $record->maxbytes,
             $record->maxattachments,
             $record->forcesubscribe,
index ac12f9b..643ef77 100644 (file)
@@ -18,6 +18,7 @@
         <FIELD NAME="assesstimestart" TYPE="int" LENGTH="10" NOTNULL="true" DEFAULT="0" SEQUENCE="false"/>
         <FIELD NAME="assesstimefinish" TYPE="int" LENGTH="10" NOTNULL="true" DEFAULT="0" SEQUENCE="false"/>
         <FIELD NAME="scale" TYPE="int" LENGTH="10" NOTNULL="true" DEFAULT="0" SEQUENCE="false"/>
+        <FIELD NAME="grade_forum" TYPE="int" LENGTH="10" NOTNULL="true" DEFAULT="0" SEQUENCE="false"/>
         <FIELD NAME="maxbytes" TYPE="int" LENGTH="10" NOTNULL="true" DEFAULT="0" SEQUENCE="false"/>
         <FIELD NAME="maxattachments" TYPE="int" LENGTH="10" NOTNULL="true" DEFAULT="1" SEQUENCE="false" COMMENT="Number of attachments allowed per post"/>
         <FIELD NAME="forcesubscribe" TYPE="int" LENGTH="1" NOTNULL="true" DEFAULT="0" SEQUENCE="false"/>
       </KEYS>
     </TABLE>
   </TABLES>
-</XMLDB>
\ No newline at end of file
+</XMLDB>
index 9c6d83e..5e5ccec 100644 (file)
@@ -195,6 +195,19 @@ function xmldb_forum_upgrade($oldversion) {
         // Main savepoint reached.
         upgrade_mod_savepoint(true, 2019071902, 'forum');
     }
+    if ($oldversion < 2019071902) {
+
+        // Define field grade_forum to be added to forum.
+        $table = new xmldb_table('forum');
+        $field = new xmldb_field('grade_forum', XMLDB_TYPE_INTEGER, '10', null, XMLDB_NOTNULL, null, '0', 'scale');
+
+        // Conditionally launch add field grade_forum.
+        if (!$dbman->field_exists($table, $field)) {
+            $dbman->add_field($table, $field);
+        }
+
+        // Forum savepoint reached.
+        upgrade_mod_savepoint(true, 2019081100, 'forum');
 
     return true;
 }
index 829d29f..40487cf 100644 (file)
@@ -78,6 +78,7 @@ class mod_forum_entities_forum_testcase extends advanced_testcase {
         $assesstimestart = 0;
         $assesstimefinish = 0;
         $scale = 0;
+        $gradeforum = 0;
         $maxbytes = 200;
         $maxattachments = 5;
         $forcesubscribe = 0;
@@ -111,6 +112,7 @@ class mod_forum_entities_forum_testcase extends advanced_testcase {
             $assesstimestart,
             $assesstimefinish,
             $scale,
+            $gradeforum,
             $maxbytes,
             $maxattachments,
             $forcesubscribe,
@@ -147,6 +149,7 @@ class mod_forum_entities_forum_testcase extends advanced_testcase {
         $this->assertEquals($assesstimestart, $forum->get_assess_time_start());
         $this->assertEquals($assesstimefinish, $forum->get_assess_time_finish());
         $this->assertEquals($scale, $forum->get_scale());
+        $this->assertEquals($gradeforum, $forum->get_grade_for_forum());
         $this->assertEquals($maxbytes, $forum->get_max_bytes());
         $this->assertEquals($maxattachments, $forum->get_max_attachments());
         $this->assertEquals($forcesubscribe, $forum->get_subscription_mode());
index dad429e..303c195 100644 (file)
@@ -81,6 +81,9 @@ class mod_forum_generator extends testing_module_generator {
         if (!isset($record->forcesubscribe)) {
             $record->forcesubscribe = FORUM_CHOOSESUBSCRIBE;
         }
+        if (!isset($record->grade_forum)) {
+            $record->grade_forum = 0;
+        }
 
         return parent::create_instance($record, (array)$options);
     }
index fd2008c..fad9d80 100644 (file)
@@ -24,6 +24,6 @@
 
 defined('MOODLE_INTERNAL') || die();
 
-$plugin->version   = 2019100101;       // The current module version (Date: YYYYMMDDXX)
+$plugin->version   = 2019100103;       // 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)