Skip to content

Commit

Permalink
fix: Corrects attempts to close #317. (#319 - Thanks @caperneoignis)
Browse files Browse the repository at this point in the history
  • Loading branch information
caperneoignis authored and ryasmi committed Nov 27, 2018
1 parent 1816098 commit 19ee47e
Show file tree
Hide file tree
Showing 23 changed files with 106 additions and 14 deletions.
6 changes: 3 additions & 3 deletions src/transformer/events/mod_quiz/attempt_submitted/handler.php
Original file line number Diff line number Diff line change
Expand Up @@ -23,9 +23,9 @@

function handler(array $config, \stdClass $event) {
$repo = $config['repo'];
$questionattempts = $repo->read_records('question_attempts', [
'questionusageid' => $event->objectid
]);
$quizattempt = $repo->read_record_by_id('quiz_attempts', $event->objectid);
// Other two look ups should be returning one record, This one should return all questions attempted.
$questionattempts = $repo->read_records('question_attempts', ['questionusageid' => $quizattempt->uniqueid]);

return array_merge(
attempt_submitted($config, $event),
Expand Down
4 changes: 2 additions & 2 deletions src/transformer/events/mod_quiz/question_answered/essay.php
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ function essay(array $config, \stdClass $event, \stdClass $questionattempt, \std
$repo = $config['repo'];
$user = $repo->read_record_by_id('user', $event->relateduserid);
$course = $repo->read_record_by_id('course', $event->courseid);
$attempt = $repo->read_record_by_id('quiz_attempts', $questionattempt->questionusageid);
$attempt = $repo->read_record('quiz_attempts', ['uniqueid' => $questionattempt->questionusageid]);
$quiz = $repo->read_record_by_id('quiz', $attempt->quiz);
$coursemodule = $repo->read_record_by_id('course_modules', $event->contextinstanceid);
$lang = utils\get_course_lang($course);
Expand Down Expand Up @@ -71,4 +71,4 @@ function essay(array $config, \stdClass $event, \stdClass $questionattempt, \std
],
]
]];
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ function gapselect(array $config, \stdClass $event, \stdClass $questionattempt,
$repo = $config['repo'];
$user = $repo->read_record_by_id('user', $event->relateduserid);
$course = $repo->read_record_by_id('course', $event->courseid);
$attempt = $repo->read_record_by_id('quiz_attempts', $questionattempt->questionusageid);
$attempt = $repo->read_record('quiz_attempts', ['uniqueid' => $questionattempt->questionusageid]);
$quiz = $repo->read_record_by_id('quiz', $attempt->quiz);
$coursemodule = $repo->read_record_by_id('course_modules', $event->contextinstanceid);
$lang = utils\get_course_lang($course);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ function match(array $config, \stdClass $event, \stdClass $questionattempt, \std
$repo = $config['repo'];
$user = $repo->read_record_by_id('user', $event->relateduserid);
$course = $repo->read_record_by_id('course', $event->courseid);
$attempt = $repo->read_record_by_id('quiz_attempts', $questionattempt->questionusageid);
$attempt = $repo->read_record('quiz_attempts', ['uniqueid' => $questionattempt->questionusageid]);
$quiz = $repo->read_record_by_id('quiz', $attempt->quiz);
$coursemodule = $repo->read_record_by_id('course_modules', $event->contextinstanceid);
$lang = utils\get_course_lang($course);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ function multichoice(array $config, \stdClass $event, \stdClass $questionattempt
$repo = $config['repo'];
$user = $repo->read_record_by_id('user', $event->relateduserid);
$course = $repo->read_record_by_id('course', $event->courseid);
$attempt = $repo->read_record_by_id('quiz_attempts', $questionattempt->questionusageid);
$attempt = $repo->read_record('quiz_attempts', ['uniqueid' => $questionattempt->questionusageid]);
$quiz = $repo->read_record_by_id('quiz', $attempt->quiz);
$coursemodule = $repo->read_record_by_id('course_modules', $event->contextinstanceid);
$lang = utils\get_course_lang($course);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ function numerical(array $config, \stdClass $event, \stdClass $questionattempt,
$repo = $config['repo'];
$user = $repo->read_record_by_id('user', $event->relateduserid);
$course = $repo->read_record_by_id('course', $event->courseid);
$attempt = $repo->read_record_by_id('quiz_attempts', $questionattempt->questionusageid);
$attempt = $repo->read_record('quiz_attempts', ['uniqueid' => $questionattempt->questionusageid]);
$quiz = $repo->read_record_by_id('quiz', $attempt->quiz);
$coursemodule = $repo->read_record_by_id('course_modules', $event->contextinstanceid);
$lang = utils\get_course_lang($course);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ function randomsamatch(array $config, \stdClass $event, \stdClass $questionattem
$repo = $config['repo'];
$user = $repo->read_record_by_id('user', $event->relateduserid);
$course = $repo->read_record_by_id('course', $event->courseid);
$attempt = $repo->read_record_by_id('quiz_attempts', $questionattempt->questionusageid);
$attempt = $repo->read_record('quiz_attempts', ['uniqueid' => $questionattempt->questionusageid]);
$quiz = $repo->read_record_by_id('quiz', $attempt->quiz);
$coursemodule = $repo->read_record_by_id('course_modules', $event->contextinstanceid);
$lang = utils\get_course_lang($course);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ function shortanswer(array $config, \stdClass $event, \stdClass $questionattempt
$repo = $config['repo'];
$user = $repo->read_record_by_id('user', $event->relateduserid);
$course = $repo->read_record_by_id('course', $event->courseid);
$attempt = $repo->read_record_by_id('quiz_attempts', $questionattempt->questionusageid);
$attempt = $repo->read_record('quiz_attempts', ['uniqueid' => $questionattempt->questionusageid]);
$quiz = $repo->read_record_by_id('quiz', $attempt->quiz);
$coursemodule = $repo->read_record_by_id('course_modules', $event->contextinstanceid);
$lang = utils\get_course_lang($course);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ function truefalse(array $config, \stdClass $event, \stdClass $questionattempt,
$repo = $config['repo'];
$user = $repo->read_record_by_id('user', $event->relateduserid);
$course = $repo->read_record_by_id('course', $event->courseid);
$attempt = $repo->read_record_by_id('quiz_attempts', $questionattempt->questionusageid);
$attempt = $repo->read_record('quiz_attempts', ['uniqueid' => $questionattempt->questionusageid]);
$quiz = $repo->read_record_by_id('quiz', $attempt->quiz);
$coursemodule = $repo->read_record_by_id('course_modules', $event->contextinstanceid);
$lang = utils\get_course_lang($course);
Expand Down Expand Up @@ -52,7 +52,8 @@ function truefalse(array $config, \stdClass $event, \stdClass $questionattempt,
'completion' => $questionattempt->responsesummary !== null,
'success' => $questionattempt->rightanswer === $questionattempt->responsesummary,
'extensions' => [
'http://learninglocker.net/xapi/cmi/true-false/response' => $questionattempt->responsesummary === 'True',
'http://learninglocker.net/xapi/cmi/true-false/response' => $questionattempt->responsesummary ===
'True',
],
],
'context' => [
Expand Down
2 changes: 1 addition & 1 deletion src/transformer/repos/Repository.php
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,6 @@ abstract class Repository extends PhpObj {
* @return PhpArr
*/
public abstract function read_records($type, array $query);

/**
* Reads an object from the store with the given type and query.
* @param String $type
Expand All @@ -50,6 +49,7 @@ public function read_record($type, array $query) {
* @param String $id
* @param String $type
* @return PhpObj
* @throws \Exception
*/
public function read_record_by_id($type, $id) {
return $this->read_record($type, ['id' => $id]);
Expand Down
7 changes: 7 additions & 0 deletions tests/mod_quiz/attempt_submitted/essay/data.json
Original file line number Diff line number Diff line change
Expand Up @@ -31,12 +31,19 @@
{
"id": 1,
"quiz": 1,
"uniqueid": 1,
"sumgrades": 50,
"state": "finished",
"timefinish": 1,
"timestart": 0
}
],
"question_usages": [
{
"id": 1

}
],
"quiz": [
{
"id": 1,
Expand Down
7 changes: 7 additions & 0 deletions tests/mod_quiz/attempt_submitted/gapselect/data.json
Original file line number Diff line number Diff line change
Expand Up @@ -31,12 +31,19 @@
{
"id": 1,
"quiz": 1,
"uniqueid": 1,
"sumgrades": 50,
"state": "finished",
"timefinish": 1,
"timestart": 0
}
],
"question_usages": [
{
"id": 1

}
],
"quiz": [
{
"id": 1,
Expand Down
7 changes: 7 additions & 0 deletions tests/mod_quiz/attempt_submitted/match/data.json
Original file line number Diff line number Diff line change
Expand Up @@ -31,12 +31,19 @@
{
"id": 1,
"quiz": 1,
"uniqueid": 1,
"sumgrades": 50,
"state": "finished",
"timefinish": 1,
"timestart": 0
}
],
"question_usages": [
{
"id": 1

}
],
"quiz": [
{
"id": 1,
Expand Down
7 changes: 7 additions & 0 deletions tests/mod_quiz/attempt_submitted/multichoice/data.json
Original file line number Diff line number Diff line change
Expand Up @@ -31,12 +31,19 @@
{
"id": 1,
"quiz": 1,
"uniqueid": 1,
"sumgrades": 50,
"state": "finished",
"timefinish": 1,
"timestart": 0
}
],
"question_usages": [
{
"id": 1

}
],
"quiz": [
{
"id": 1,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,12 +31,19 @@
{
"id": 1,
"quiz": 1,
"uniqueid": 1,
"sumgrades": 50,
"state": "finished",
"timefinish": 1,
"timestart": 0
}
],
"question_usages": [
{
"id": 1

}
],
"quiz": [
{
"id": 1,
Expand Down
7 changes: 7 additions & 0 deletions tests/mod_quiz/attempt_submitted/multichoiceset/data.json
Original file line number Diff line number Diff line change
Expand Up @@ -31,12 +31,19 @@
{
"id": 1,
"quiz": 1,
"uniqueid": 1,
"sumgrades": 50,
"state": "finished",
"timefinish": 1,
"timestart": 0
}
],
"question_usages": [
{
"id": 1

}
],
"quiz": [
{
"id": 1,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,12 +31,19 @@
{
"id": 1,
"quiz": 1,
"uniqueid": 1,
"sumgrades": 50,
"state": "finished",
"timefinish": 1,
"timestart": 0
}
],
"question_usages": [
{
"id": 1

}
],
"quiz": [
{
"id": 1,
Expand Down
7 changes: 7 additions & 0 deletions tests/mod_quiz/attempt_submitted/no_questions/data.json
Original file line number Diff line number Diff line change
Expand Up @@ -31,12 +31,19 @@
{
"id": 1,
"quiz": 1,
"uniqueid": 1,
"sumgrades": 50,
"state": "finished",
"timefinish": 1,
"timestart": 0
}
],
"question_usages": [
{
"id": 1

}
],
"quiz": [
{
"id": 1,
Expand Down
7 changes: 7 additions & 0 deletions tests/mod_quiz/attempt_submitted/numerical/data.json
Original file line number Diff line number Diff line change
Expand Up @@ -31,12 +31,19 @@
{
"id": 1,
"quiz": 1,
"uniqueid": 1,
"sumgrades": 50,
"state": "finished",
"timefinish": 1,
"timestart": 0
}
],
"question_usages": [
{
"id": 1

}
],
"quiz": [
{
"id": 1,
Expand Down
7 changes: 7 additions & 0 deletions tests/mod_quiz/attempt_submitted/randomsamatch/data.json
Original file line number Diff line number Diff line change
Expand Up @@ -31,12 +31,19 @@
{
"id": 1,
"quiz": 1,
"uniqueid": 1,
"sumgrades": 50,
"state": "finished",
"timefinish": 1,
"timestart": 0
}
],
"question_usages": [
{
"id": 1

}
],
"quiz": [
{
"id": 1,
Expand Down
7 changes: 7 additions & 0 deletions tests/mod_quiz/attempt_submitted/shortanswer/data.json
Original file line number Diff line number Diff line change
Expand Up @@ -31,12 +31,19 @@
{
"id": 1,
"quiz": 1,
"uniqueid": 1,
"sumgrades": 50,
"state": "finished",
"timefinish": 1,
"timestart": 0
}
],
"question_usages": [
{
"id": 1

}
],
"quiz": [
{
"id": 1,
Expand Down
7 changes: 7 additions & 0 deletions tests/mod_quiz/attempt_submitted/truefalse/data.json
Original file line number Diff line number Diff line change
Expand Up @@ -31,12 +31,19 @@
{
"id": 1,
"quiz": 1,
"uniqueid": 1,
"sumgrades": 50,
"state": "finished",
"timefinish": 1,
"timestart": 0
}
],
"question_usages": [
{
"id": 1

}
],
"quiz": [
{
"id": 1,
Expand Down
7 changes: 7 additions & 0 deletions tests/mod_quiz/attempt_submitted/unknown_qtype/data.json
Original file line number Diff line number Diff line change
Expand Up @@ -31,12 +31,19 @@
{
"id": 1,
"quiz": 1,
"uniqueid": 1,
"sumgrades": 50,
"state": "finished",
"timefinish": 1,
"timestart": 0
}
],
"question_usages": [
{
"id": 1

}
],
"quiz": [
{
"id": 1,
Expand Down

0 comments on commit 19ee47e

Please sign in to comment.