diff --git a/mod/assign/classes/analytics/indicator/activity_base.php b/mod/assign/classes/analytics/indicator/activity_base.php index f5a5203f984..aea9067d6f1 100644 --- a/mod/assign/classes/analytics/indicator/activity_base.php +++ b/mod/assign/classes/analytics/indicator/activity_base.php @@ -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'; + } + } diff --git a/mod/choice/classes/analytics/indicator/activity_base.php b/mod/choice/classes/analytics/indicator/activity_base.php index 4395c6fa930..d28fedc12e5 100644 --- a/mod/choice/classes/analytics/indicator/activity_base.php +++ b/mod/choice/classes/analytics/indicator/activity_base.php @@ -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'; + } } diff --git a/mod/choice/classes/analytics/indicator/cognitive_depth.php b/mod/choice/classes/analytics/indicator/cognitive_depth.php index 48cec079cfa..5dcbeb844a1 100644 --- a/mod/choice/classes/analytics/indicator/cognitive_depth.php +++ b/mod/choice/classes/analytics/indicator/cognitive_depth.php @@ -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; } diff --git a/mod/choice/classes/analytics/indicator/social_breadth.php b/mod/choice/classes/analytics/indicator/social_breadth.php index 26c0a7dd4bb..2ae86497b49 100644 --- a/mod/choice/classes/analytics/indicator/social_breadth.php +++ b/mod/choice/classes/analytics/indicator/social_breadth.php @@ -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; } } diff --git a/mod/data/classes/analytics/indicator/activity_base.php b/mod/data/classes/analytics/indicator/activity_base.php index 7d2a160fe84..6dd5c6f07d5 100644 --- a/mod/data/classes/analytics/indicator/activity_base.php +++ b/mod/data/classes/analytics/indicator/activity_base.php @@ -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'; + } } diff --git a/mod/feedback/classes/analytics/indicator/activity_base.php b/mod/feedback/classes/analytics/indicator/activity_base.php index 72f31c1d0e1..706f9d7c9a8 100644 --- a/mod/feedback/classes/analytics/indicator/activity_base.php +++ b/mod/feedback/classes/analytics/indicator/activity_base.php @@ -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'; + } } diff --git a/mod/feedback/classes/analytics/indicator/cognitive_depth.php b/mod/feedback/classes/analytics/indicator/cognitive_depth.php index 0890982e329..5641005b2c3 100644 --- a/mod/feedback/classes/analytics/indicator/cognitive_depth.php +++ b/mod/feedback/classes/analytics/indicator/cognitive_depth.php @@ -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; } diff --git a/mod/feedback/classes/analytics/indicator/social_breadth.php b/mod/feedback/classes/analytics/indicator/social_breadth.php index d1c7e276f73..8d972ea0008 100644 --- a/mod/feedback/classes/analytics/indicator/social_breadth.php +++ b/mod/feedback/classes/analytics/indicator/social_breadth.php @@ -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; } diff --git a/mod/lesson/classes/analytics/indicator/activity_base.php b/mod/lesson/classes/analytics/indicator/activity_base.php index f87612672c7..4758344f3e6 100644 --- a/mod/lesson/classes/analytics/indicator/activity_base.php +++ b/mod/lesson/classes/analytics/indicator/activity_base.php @@ -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'; + } } diff --git a/mod/quiz/classes/analytics/indicator/activity_base.php b/mod/quiz/classes/analytics/indicator/activity_base.php index 4f3804cbeba..03f12e0d523 100644 --- a/mod/quiz/classes/analytics/indicator/activity_base.php +++ b/mod/quiz/classes/analytics/indicator/activity_base.php @@ -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'; + } } diff --git a/mod/scorm/classes/analytics/indicator/activity_base.php b/mod/scorm/classes/analytics/indicator/activity_base.php index 75a6ace56c2..c11cdbcf4bf 100644 --- a/mod/scorm/classes/analytics/indicator/activity_base.php +++ b/mod/scorm/classes/analytics/indicator/activity_base.php @@ -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'; + } } diff --git a/mod/workshop/classes/analytics/indicator/activity_base.php b/mod/workshop/classes/analytics/indicator/activity_base.php index 1774d6357ed..9c5489d204f 100644 --- a/mod/workshop/classes/analytics/indicator/activity_base.php +++ b/mod/workshop/classes/analytics/indicator/activity_base.php @@ -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'; + } }