Skip to content
Snippets Groups Projects
Commit d66c6d53 authored by David Pesce's avatar David Pesce
Browse files

fixes for attempt_submitted and attempt_reviewed events

parent e2677a45
No related branches found
No related tags found
No related merge requests found
......@@ -29,7 +29,8 @@ class Controller extends PhpObj {
'module_viewed' => 'ModuleViewed',
'attempt_started' => 'AttemptStarted',
'attempt_abandoned' => 'AttemptCompleted',
'attempt_completed' => 'AttemptCompleted',
'attempt_submitted' => 'AttemptCompleted',
'attempt_reviewed' => 'AttemptReviewed',
'attempt_question_completed' => 'QuestionAnswered',
'user_loggedin' => 'UserLoggedin',
'user_loggedout' => 'UserLoggedout',
......
<?php
// This file is part of Moodle - http://moodle.org/
//
// Moodle is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// Moodle is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with Moodle. If not, see <http://www.gnu.org/licenses/>.
namespace XREmitter\Events;
defined('MOODLE_INTERNAL') || die();
class AttemptReviewed extends Event {
protected static $verbdisplay = [
'en' => 'reviewed'
];
/**
* Reads data for an event.
* @param [String => Mixed] $opts
* @return [String => Mixed]
* @override Event
*/
public function read(array $opts) {
return array_merge_recursive(parent::read($opts), [
'verb' => [
'id' => 'http://activitystrea.ms/schema/1.0/review',
'display' => $this->read_verb_display($opts),
],
'object' => [
'id' => $opts['attempt_url'],
'definition' => [
'type' => $opts['attempt_type'],
'name' => [
$opts['context_lang'] => $opts['attempt_name'],
],
'extensions' => [
$opts['attempt_ext_key'] => $opts['attempt_ext']
],
],
],
'context' => [
'contextActivities' => [
'grouping' => [
$this->read_course($opts),
$this->read_module($opts),
],
],
],
]);
}
}
......@@ -50,6 +50,7 @@ class Controller extends PhpObj {
'\mod_quiz\event\attempt_preview_started' => 'AttemptEvent',
'\mod_quiz\event\attempt_reviewed' => 'AttemptEvent',
'\mod_quiz\event\attempt_viewed' => 'AttemptEvent',
'\mod_quiz\event\attempt_submitted' => 'AttemptEvent',
'\core\event\user_loggedin' => 'Event',
'\core\event\user_loggedout' => 'Event',
'\mod_assign\event\submission_graded' => 'AssignmentGraded',
......
......@@ -51,6 +51,7 @@ class Controller extends PhpObj {
'\mod_quiz\event\attempt_preview_started' => 'AttemptStarted',
'\mod_quiz\event\attempt_reviewed' => ['AttemptReviewed', 'QuestionSubmitted'],
'\mod_quiz\event\attempt_viewed' => 'ModuleViewed',
'\mod_quiz\event\attempt_submitted' => ['AttemptSubmitted', 'QuestionSubmitted'],
'\core\event\user_loggedin' => 'UserLoggedin',
'\core\event\user_loggedout' => 'UserLoggedout',
'\mod_assign\event\submission_graded' => 'AssignmentGraded',
......
<?php
// This file is part of Moodle - http://moodle.org/
//
// Moodle is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// Moodle is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with Moodle. If not, see <http://www.gnu.org/licenses/>.
namespace MXTranslator\Events;
defined('MOODLE_INTERNAL') || die();
class AttemptSubmitted extends AttemptStarted {
/**
* Reads data for an event.
* @param [String => Mixed] $opts
* @return [String => Mixed]
* @override AttemtStarted
*/
public function read(array $opts) {
if (isset($opts['attempt']->timefinish)) {
$seconds = $opts['attempt']->timefinish - $opts['attempt']->timestart;
$duration = "PT".(string) $seconds."S";
} else {
$duration = "PT0S";
}
$scoreraw = isset($opts['attempt']->sumgrades) ? $opts['attempt']->sumgrades : 0;
$scoremin = (float) ($opts['grade_items']->grademin ?: 0);
$scoremax = (float) ($opts['grade_items']->grademax ?: 0);
$scorepass = (float) ($opts['grade_items']->gradepass ?: null);
$success = false;
// If there is no passing score then success is unknown.
if ($scorepass == null) {
$success = null;
} else if ($scoreraw >= $scorepass) {
$success = true;
}
// It's possible to configure Moodle quizzes such that you can score higher than the maximum grade.
// This is not allowed by xAPI, so cap the raw at the min/max.
if ($scoreraw > $scoremax) {
$scoreraw = $scoremax;
}
if ($scoreraw < $scoremin) {
$scoreraw = $scoremin;
}
// Calculate scaled score as the distance from zero towards the max (or min for negative scores).
if ($scoreraw >= 0) {
$scorescaled = $scoreraw / $scoremax;
} else {
$scorescaled = $scoreraw / $scoremin;
}
// Determine if the attempt was marked finished.
if (isset($opts['attempt']->state)) {
$completedstate = $opts['attempt']->state === 'finished';
} else {
$completedstate = false;
}
return [array_merge(parent::read($opts)[0], [
'recipe' => 'attempt_completed',
'attempt_score_raw' => $scoreraw,
'attempt_score_min' => $scoremin,
'attempt_score_max' => $scoremax,
'attempt_score_scaled' => $scorescaled,
'attempt_success' => $success,
'attempt_completed' => $completedstate,
'attempt_duration' => $duration,
])];
}
}
<?php
// This file is part of Moodle - http://moodle.org/
//
// Moodle is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// Moodle is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with Moodle. If not, see <http://www.gnu.org/licenses/>.
namespace Tests;
defined('MOODLE_INTERNAL') || die();
require_once(__DIR__ . '/quiz_attempt_testcase.php');
class attempt_submitted_test extends quiz_attempt_testcase {
protected function construct_input() {
return array_merge(parent::construct_input(), [
'eventname' => '\mod_quiz\event\attempt_submitted',
]);
}
}
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment