Merge branch 'MDL-59670-master' of git://github.com/andrewnicols/moodle
authorEloy Lafuente (stronk7) <stronk7@moodle.org>
Mon, 28 Aug 2017 22:41:57 +0000 (00:41 +0200)
committerEloy Lafuente (stronk7) <stronk7@moodle.org>
Mon, 28 Aug 2017 22:41:57 +0000 (00:41 +0200)
lib/db/install.xml
lib/db/upgrade.php
question/engine/questionusage.php
user/classes/participants_table.php
user/tests/behat/view_participants.feature
version.php

index 399b613..da15f9e 100644 (file)
       </FIELDS>
       <KEYS>
         <KEY NAME="primary" TYPE="primary" FIELDS="id"/>
+        <KEY NAME="modelid" TYPE="foreign" FIELDS="modelid" REFTABLE="analytics_models" REFFIELDS="id"/>
       </KEYS>
-      <INDEXES>
-        <INDEX NAME="modelid" UNIQUE="false" FIELDS="modelid" COMMENT="Index on modelid"/>
-      </INDEXES>
     </TABLE>
     <TABLE NAME="analytics_predictions" COMMENT="Predictions">
       <FIELDS>
       </FIELDS>
       <KEYS>
         <KEY NAME="primary" TYPE="primary" FIELDS="id"/>
+        <KEY NAME="modelid" TYPE="foreign" FIELDS="modelid" REFTABLE="analytics_models" REFFIELDS="id"/>
+        <KEY NAME="contextid" TYPE="foreign" FIELDS="contextid" REFTABLE="context" REFFIELDS="id"/>
       </KEYS>
       <INDEXES>
         <INDEX NAME="modelidandcontextid" UNIQUE="false" FIELDS="modelid, contextid" COMMENT="Index on modelid and contextid"/>
       </FIELDS>
       <KEYS>
         <KEY NAME="primary" TYPE="primary" FIELDS="id"/>
+        <KEY NAME="modelid" TYPE="foreign" FIELDS="modelid" REFTABLE="analytics_models" REFFIELDS="id"/>
+        <KEY NAME="fileid" TYPE="foreign" FIELDS="fileid" REFTABLE="files" REFFIELDS="id"/>
       </KEYS>
       <INDEXES>
         <INDEX NAME="modelidandanalysableidandtimesplitting" UNIQUE="false" FIELDS="modelid, analysableid, timesplitting" COMMENT="Index on modelid and analysableid and timesplitting"/>
       </FIELDS>
       <KEYS>
         <KEY NAME="primary" TYPE="primary" FIELDS="id"/>
+        <KEY NAME="modelid" TYPE="foreign" FIELDS="modelid" REFTABLE="analytics_models" REFFIELDS="id"/>
       </KEYS>
       <INDEXES>
         <INDEX NAME="modelidandanalysableidandtimesplittingandrangeindex" UNIQUE="false" FIELDS="modelid, analysableid, timesplitting, rangeindex" COMMENT="Index on modelid and analysableid and timesplitting"/>
       </FIELDS>
       <KEYS>
         <KEY NAME="primary" TYPE="primary" FIELDS="id"/>
+        <KEY NAME="modelid" TYPE="foreign" FIELDS="modelid" REFTABLE="analytics_models" REFFIELDS="id"/>
+        <KEY NAME="fileid" TYPE="foreign" FIELDS="fileid" REFTABLE="files" REFFIELDS="id"/>
       </KEYS>
       <INDEXES>
         <INDEX NAME="modelidandfileidandaction" UNIQUE="false" FIELDS="modelid, fileid, action" COMMENT="Index on modelid and fileid and action"/>
       </FIELDS>
       <KEYS>
         <KEY NAME="primary" TYPE="primary" FIELDS="id"/>
+        <KEY NAME="contextid" TYPE="foreign" FIELDS="contextid" REFTABLE="context" REFFIELDS="id"/>
       </KEYS>
       <INDEXES>
         <INDEX NAME="starttime-endtime-contextid" UNIQUE="false" FIELDS="starttime, endtime, contextid"/>
index fcc7154..5a5b4a5 100644 (file)
@@ -2369,5 +2369,59 @@ function xmldb_main_upgrade($oldversion) {
         upgrade_main_savepoint(true, 2017082300.01);
     }
 
+    if ($oldversion < 2017082500.00) {
+        // Handle FKs for the table 'analytics_models_log'.
+        $table = new xmldb_table('analytics_models_log');
+
+        // Remove the existing index before adding FK (which creates an index).
+        $index = new xmldb_index('modelid', XMLDB_INDEX_NOTUNIQUE, array('modelid'));
+
+        // Conditionally launch drop index.
+        if ($dbman->index_exists($table, $index)) {
+            $dbman->drop_index($table, $index);
+        }
+
+        // Now, add the FK.
+        $key = new xmldb_key('modelid', XMLDB_KEY_FOREIGN, array('modelid'), 'analytics_models', array('id'));
+        $dbman->add_key($table, $key);
+
+        // Handle FKs for the table 'analytics_predictions'.
+        $table = new xmldb_table('analytics_predictions');
+        $key = new xmldb_key('modelid', XMLDB_KEY_FOREIGN, array('modelid'), 'analytics_models', array('id'));
+        $dbman->add_key($table, $key);
+
+        $key = new xmldb_key('contextid', XMLDB_KEY_FOREIGN, array('contextid'), 'context', array('id'));
+        $dbman->add_key($table, $key);
+
+        // Handle FKs for the table 'analytics_train_samples'.
+        $table = new xmldb_table('analytics_train_samples');
+        $key = new xmldb_key('modelid', XMLDB_KEY_FOREIGN, array('modelid'), 'analytics_models', array('id'));
+        $dbman->add_key($table, $key);
+
+        $key = new xmldb_key('fileid', XMLDB_KEY_FOREIGN, array('fileid'), 'files', array('id'));
+        $dbman->add_key($table, $key);
+
+        // Handle FKs for the table 'analytics_predict_samples'.
+        $table = new xmldb_table('analytics_predict_samples');
+        $key = new xmldb_key('modelid', XMLDB_KEY_FOREIGN, array('modelid'), 'analytics_models', array('id'));
+        $dbman->add_key($table, $key);
+
+        // Handle FKs for the table 'analytics_used_files'.
+        $table = new xmldb_table('analytics_used_files');
+        $key = new xmldb_key('modelid', XMLDB_KEY_FOREIGN, array('modelid'), 'analytics_models', array('id'));
+        $dbman->add_key($table, $key);
+
+        $key = new xmldb_key('fileid', XMLDB_KEY_FOREIGN, array('fileid'), 'files', array('id'));
+        $dbman->add_key($table, $key);
+
+        // Handle FKs for the table 'analytics_indicator_calc'.
+        $table = new xmldb_table('analytics_indicator_calc');
+        $key = new xmldb_key('contextid', XMLDB_KEY_FOREIGN, array('contextid'), 'context', array('id'));
+        $dbman->add_key($table, $key);
+
+        // Main savepoint reached.
+        upgrade_main_savepoint(true, 2017082500.00);
+    }
+
     return true;
 }
index 49c0ef5..453fcd2 100644 (file)
@@ -568,7 +568,8 @@ class question_usage_by_activity {
         }
 
         foreach ($this->questionattempts as $qa) {
-            $qa->start($this->preferredbehaviour, $qa->select_variant($variantstrategy));
+            $qa->start($this->preferredbehaviour, $qa->select_variant($variantstrategy), array(),
+                    $timestamp, $userid);
             $this->observer->notify_attempt_modified($qa);
         }
     }
index aa8e2f9..54d73da 100644 (file)
@@ -169,17 +169,19 @@ class participants_table extends \table_sql {
         $headers[] = get_string('roles');
         $columns[] = 'roles';
 
-        // Load and cache the course groupinfo.
-        // Add column for groups.
-        $headers[] = get_string('groups');
-        $columns[] = 'groups';
-
         // Get the list of fields we have to hide.
         $hiddenfields = array();
         if (!has_capability('moodle/course:viewhiddenuserfields', $context)) {
             $hiddenfields = array_flip(explode(',', $CFG->hiddenuserfields));
         }
 
+        // Add column for groups if the user can view them.
+        $canseegroups = !isset($hiddenfields['groups']);
+        if ($canseegroups) {
+            $headers[] = get_string('groups');
+            $columns[] = 'groups';
+        }
+
         // Do not show the columns if it exists in the hiddenfields array.
         if (!isset($hiddenfields['lastaccess'])) {
             if ($courseid == SITEID) {
@@ -205,7 +207,9 @@ class participants_table extends \table_sql {
 
         $this->no_sorting('select');
         $this->no_sorting('roles');
-        $this->no_sorting('groups');
+        if ($canseegroups) {
+            $this->no_sorting('groups');
+        }
 
         $this->set_attribute('id', 'participants');
 
@@ -220,7 +224,9 @@ class participants_table extends \table_sql {
         $this->countries = get_string_manager()->get_list_of_countries();
         $this->extrafields = $extrafields;
         $this->context = $context;
-        $this->groups = groups_get_all_groups($courseid, 0, 0, 'g.*', true);
+        if ($canseegroups) {
+            $this->groups = groups_get_all_groups($courseid, 0, 0, 'g.*', true);
+        }
         $this->allroles = role_fix_names(get_all_roles($this->context), $this->context);
         $this->allroleassignments = get_users_roles($this->context, [], true, 'c.contextlevel DESC, r.sortorder ASC');
         $this->assignableroles = get_assignable_roles($this->context, ROLENAME_ALIAS, false);
index 532d7c9..6d93553 100644 (file)
@@ -8,6 +8,7 @@ Feature: View course participants
     Given the following "users" exist:
       | username  | firstname | lastname | email                 |
       | teacher1  | Teacher   | 1        | teacher1@example.com  |
+      | student0  | Student   | 0        | student0@example.com  |
       | student1  | Student   | 1        | student1@example.com  |
       | student2  | Student   | 2        | student2@example.com  |
       | student3  | Student   | 3        | student3@example.com  |
@@ -27,13 +28,13 @@ Feature: View course participants
       | student17 | Student   | 17       | student17@example.com |
       | student18 | Student   | 18       | student18@example.com |
       | student19 | Student   | 19       | student19@example.com |
-      | student20 | Student   | 20       | student20@example.com |
     And the following "courses" exist:
       | fullname | shortname | format |
       | Course 1 | C1        | topics |
     And the following "course enrolments" exist:
       | user      | course | role           | status | timeend |
       | teacher1  | C1     | editingteacher |    0   |    0    |
+      | student0  | C1     | student        |    0   |    0    |
       | student1  | C1     | student        |    0   |    0    |
       | student2  | C1     | student        |    0   |    0    |
       | student3  | C1     | student        |    0   |    0    |
@@ -52,7 +53,6 @@ Feature: View course participants
       | student16 | C1     | student        |    0   |    0    |
       | student17 | C1     | student        |    0   |    0    |
       | student18 | C1     | student        |    0   |    0    |
-      | student19 | C1     | student        |    0   |    0    |
 
   @javascript
   Scenario: Use select and deselect all buttons
@@ -107,26 +107,26 @@ Feature: View course participants
     Given I log in as "teacher1"
     And the following "course enrolments" exist:
       | user      | course | role           |
-      | student20 | C1     | student |
+      | student19 | C1     | student |
     And I am on "Course 1" course homepage
     And I navigate to course participants
     And I follow "Email address"
     When I follow "2"
-    Then I should not see "student1@example.com"
-    And I should not see "student20@example.com"
+    Then I should not see "student0@example.com"
+    And I should not see "student19@example.com"
     And I should see "teacher1@example.com"
     And I follow "Email address"
     And I follow "2"
     And I should not see "teacher1@example.com"
-    And I should not see "student20@example.com"
+    And I should not see "student19@example.com"
     And I should not see "student1@example.com"
-    And I should see "student10@example.com"
+    And I should see "student0@example.com"
 
   @javascript
   Scenario: Use select all users on this page, select all n users and deselect all
     Given the following "course enrolments" exist:
       | user      | course | role    |
-      | student20 | C1     | student |
+      | student19 | C1     | student |
     When I log in as "teacher1"
     And I am on "Course 1" course homepage
     And I navigate to course participants
@@ -227,7 +227,8 @@ Feature: View course participants
     Given I log in as "teacher1"
     And I am on "Course 1" course homepage
     When I navigate to course participants
-    Then I should see "Active" in the "student1" "table_row"
+    Then I should see "Active" in the "student0" "table_row"
+    And I should see "Active" in the "student1" "table_row"
     And I should see "Active" in the "student2" "table_row"
     And I should see "Active" in the "student3" "table_row"
     And I should see "Active" in the "student4" "table_row"
@@ -245,7 +246,6 @@ Feature: View course participants
     And I should see "Active" in the "student16" "table_row"
     And I should see "Active" in the "student17" "table_row"
     And I should see "Active" in the "student18" "table_row"
-    And I should see "Active" in the "student19" "table_row"
 
   Scenario: View the participants page as a student
     Given I log in as "student1"
index fa89905..767b38c 100644 (file)
@@ -29,7 +29,7 @@
 
 defined('MOODLE_INTERNAL') || die();
 
-$version  = 2017082400.00;              // YYYYMMDD      = weekly release date of this DEV branch.
+$version  = 2017082500.00;              // YYYYMMDD      = weekly release date of this DEV branch.
                                         //         RR    = release increments - 00 in DEV branches.
                                         //           .XX = incremental changes.