MDL-59256 analytics: Respect activities specific access conditions

This commit is contained in:
David Monllao 2017-10-27 17:00:57 +02:00
parent 76f98c3bd5
commit aa30dc8860
12 changed files with 83 additions and 51 deletions

View 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';
}
}

View 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';
}
}

View 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;
}

View 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;
}
}

View 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';
}
}

View 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';
}
}

View 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;
}

View 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;
}

View 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';
}
}

View 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';
}
}

View 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';
}
}

View 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';
}
}