MDL-59256 analytics: Respect activities specific access conditions
authorDavid Monllao <davidm@moodle.com>
Fri, 27 Oct 2017 15:00:57 +0000 (17:00 +0200)
committerDavid Monllao <davidm@moodle.com>
Tue, 7 Nov 2017 07:14:53 +0000 (08:14 +0100)
12 files changed:
mod/assign/classes/analytics/indicator/activity_base.php
mod/choice/classes/analytics/indicator/activity_base.php
mod/choice/classes/analytics/indicator/cognitive_depth.php
mod/choice/classes/analytics/indicator/social_breadth.php
mod/data/classes/analytics/indicator/activity_base.php
mod/feedback/classes/analytics/indicator/activity_base.php
mod/feedback/classes/analytics/indicator/cognitive_depth.php
mod/feedback/classes/analytics/indicator/social_breadth.php
mod/lesson/classes/analytics/indicator/activity_base.php
mod/quiz/classes/analytics/indicator/activity_base.php
mod/scorm/classes/analytics/indicator/activity_base.php
mod/workshop/classes/analytics/indicator/activity_base.php

index f5a5203..aea9067 100644 (file)
@@ -53,4 +53,14 @@ abstract class activity_base extends \core_analytics\local\indicator\community_o
         // We need the grade to be released to the student to consider that feedback has been provided.
         return true;
     }
+
+    /**
+     * Returns the name of the field that controls activity availability.
+     *
+     * @return null|string
+     */
+    protected function get_timeclose_field() {
+        return 'duedate';
+    }
+
 }
index 4395c6f..d28fedc 100644 (file)
@@ -35,13 +35,6 @@ defined('MOODLE_INTERNAL') || die();
  */
 abstract class activity_base extends \core_analytics\local\indicator\community_of_inquiry_activity {
 
-    /**
-     * choicedata
-     *
-     * @var array
-     */
-    protected $choicedata = array();
-
     /**
      * feedback_viewed_events
      *
@@ -51,21 +44,6 @@ abstract class activity_base extends \core_analytics\local\indicator\community_o
         return array('\mod_choice\event\course_module_viewed', '\mod_choice\event\answer_updated');
     }
 
-    /**
-     * Fills choice activities data.
-     *
-     * @param \cm_info $cm
-     * @return void
-     */
-    protected function fill_choice_data(\cm_info $cm) {
-        global $DB;
-
-        if (!isset($this->choicedata[$cm->instance])) {
-            $this->choicedata[$cm->instance] = $DB->get_record('choice', array('id' => $cm->instance),
-                'id, showresults, timeclose', MUST_EXIST);
-        }
-    }
-
     /**
      * feedback_viewed
      *
@@ -78,17 +56,26 @@ abstract class activity_base extends \core_analytics\local\indicator\community_o
     protected function feedback_viewed(\cm_info $cm, $contextid, $userid, $after = null) {
 
         // If results are shown after they answer a write action counts as feedback viewed.
-        if ($this->choicedata[$cm->instance]->showresults == 1) {
+        if ($this->instancedata[$cm->instance]->showresults == 1) {
             // The user id will be enough for any_write_log.
             $user = (object)['id' => $userid];
             return $this->any_write_log($contextid, $user);
         }
 
         $after = null;
-        if ($this->choicedata[$cm->instance]->timeclose) {
-            $after = $this->choicedata[$cm->instance]->timeclose;
+        if ($this->instancedata[$cm->instance]->timeclose) {
+            $after = $this->instancedata[$cm->instance]->timeclose;
         }
 
         return $this->feedback_post_action($cm, $contextid, $userid, $this->feedback_viewed_events(), $after);
     }
+
+    /**
+     * Returns the name of the field that controls activity availability.
+     *
+     * @return null|string
+     */
+    protected function get_timeclose_field() {
+        return 'timeclose';
+    }
 }
index 48cec07..5dcbeb8 100644 (file)
@@ -51,9 +51,9 @@ class cognitive_depth extends activity_base {
     }
 
     public function get_cognitive_depth_level(\cm_info $cm) {
-        $this->fill_choice_data($cm);
+        $this->fill_instance_data($cm);
 
-        if ($this->choicedata[$cm->instance]->showresults == 0 || $this->choicedata[$cm->instance]->showresults == 4) {
+        if ($this->instancedata[$cm->instance]->showresults == 0 || $this->instancedata[$cm->instance]->showresults == 4) {
             // Results are not shown to students or are always shown.
             return self::COGNITIVE_LEVEL_2;
         }
index 26c0a7d..2ae8649 100644 (file)
@@ -51,7 +51,7 @@ class social_breadth extends activity_base {
     }
 
     public function get_social_breadth_level(\cm_info $cm) {
-        $this->fill_choice_data($cm);
+        $this->fill_instance_data($cm);
         return self::SOCIAL_LEVEL_2;
     }
 }
index 7d2a160..6dd5c6f 100644 (file)
@@ -34,4 +34,13 @@ defined('MOODLE_INTERNAL') || die();
  * @license   http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
  */
 abstract class activity_base extends \core_analytics\local\indicator\community_of_inquiry_activity {
+
+    /**
+     * Returns the name of the field that controls activity availability.
+     *
+     * @return null|string
+     */
+    protected function get_timeclose_field() {
+        return 'timeavailableto';
+    }
 }
index 72f31c1..706f9d7 100644 (file)
@@ -35,25 +35,6 @@ defined('MOODLE_INTERNAL') || die();
  */
 abstract class activity_base extends \core_analytics\local\indicator\community_of_inquiry_activity {
 
-    /**
-     * @var int[] Tiny cache to hold feedback instance - publish_stats field relation.
-     */
-    protected $publishstats = array();
-
-    /**
-     * fill_publishstats
-     *
-     * @param \cm_info $cm
-     * @return void
-     */
-    protected function fill_publishstats(\cm_info $cm) {
-        global $DB;
-
-        if (!isset($this->publishstats[$cm->instance])) {
-            $this->publishstats[$cm->instance] = $DB->get_field('feedback', 'publish_stats', array('id' => $cm->instance));
-        }
-    }
-
     /**
      * Overwritten to mark as viewed if stats are published.
      *
@@ -65,11 +46,20 @@ abstract class activity_base extends \core_analytics\local\indicator\community_o
      */
     protected function feedback_viewed(\cm_info $cm, $contextid, $userid, $after = null) {
         // If stats are published any write action counts as viewed feedback.
-        if (!empty($this->publishstats[$cm->instance])) {
+        if (!empty($this->instancedata[$cm->instance]->publish_stats)) {
             $user = (object)['id' => $userid];
             return $this->any_write_log($contextid, $user);
         }
 
         return parent::feedback_viewed($cm, $contextid, $userid, $after);
     }
+
+    /**
+     * Returns the name of the field that controls activity availability.
+     *
+     * @return null|string
+     */
+    protected function get_timeclose_field() {
+        return 'timeclose';
+    }
 }
index 0890982..5641005 100644 (file)
@@ -51,9 +51,9 @@ class cognitive_depth extends activity_base {
     }
 
     public function get_cognitive_depth_level(\cm_info $cm) {
-        $this->fill_publishstats($cm);
+        $this->fill_instance_data($cm);
 
-        if (!empty($this->publishstats[$cm->instance])) {
+        if (!empty($this->instancedata[$cm->instance]->publish_stats)) {
             // If stats are published we count that the user viewed feedback.
             return self::COGNITIVE_LEVEL_3;
         }
index d1c7e27..8d972ea 100644 (file)
@@ -51,7 +51,7 @@ class social_breadth extends activity_base {
     }
 
     public function get_social_breadth_level(\cm_info $cm) {
-        $this->fill_publishstats($cm);
+        $this->fill_instance_data($cm);
 
         return self::SOCIAL_LEVEL_2;
     }
index f876126..4758344 100644 (file)
@@ -53,4 +53,13 @@ abstract class activity_base extends \core_analytics\local\indicator\community_o
         // We don't need to check grades as we get the feedback while completing the activity.
         return false;
     }
+
+    /**
+     * Returns the name of the field that controls activity availability.
+     *
+     * @return null|string
+     */
+    protected function get_timeclose_field() {
+        return 'deadline';
+    }
 }
index 4f3804c..03f12e0 100644 (file)
@@ -53,4 +53,13 @@ abstract class activity_base extends \core_analytics\local\indicator\community_o
     protected function feedback_viewed_events() {
         return array('\mod_quiz\event\course_module_viewed');
     }
+
+    /**
+     * Returns the name of the field that controls activity availability.
+     *
+     * @return null|string
+     */
+    protected function get_timeclose_field() {
+        return 'timeclose';
+    }
 }
index 75a6ace..c11cdbc 100644 (file)
@@ -44,4 +44,13 @@ abstract class activity_base extends \core_analytics\local\indicator\community_o
         // Any view after the data graded counts as feedback viewed.
         return array('\mod_scorm\event\course_module_viewed');
     }
+
+    /**
+     * Returns the name of the field that controls activity availability.
+     *
+     * @return null|string
+     */
+    protected function get_timeclose_field() {
+        return 'timeclose';
+    }
 }
index 1774d63..9c5489d 100644 (file)
@@ -52,4 +52,13 @@ abstract class activity_base extends \core_analytics\local\indicator\community_o
     protected function feedback_viewed_events() {
         return array('\mod_workshop\event\course_module_viewed', '\mod_workshop\event\submission_viewed');
     }
+
+    /**
+     * Returns the name of the field that controls activity availability.
+     *
+     * @return null|string
+     */
+    protected function get_timeclose_field() {
+        return 'submissionend';
+    }
 }