Skip to content

Commit

Permalink
Add support for attempt tracking.
Browse files Browse the repository at this point in the history
  • Loading branch information
csev committed Sep 17, 2024
1 parent 4c3816d commit 696f1f1
Show file tree
Hide file tree
Showing 6 changed files with 56 additions and 13 deletions.
6 changes: 6 additions & 0 deletions admin/lti/database.php
Original file line number Diff line number Diff line change
Expand Up @@ -468,6 +468,7 @@
grade FLOAT NULL,
note MEDIUMTEXT NULL,
attempts INTEGER NULL,
server_grade FLOAT NULL,
grading_progress TINYINT(1) NOT NULL DEFAULT 0,
activity_progress TINYINT(1) NOT NULL DEFAULT 0,
Expand All @@ -477,6 +478,7 @@
created_at TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP,
updated_at TIMESTAMP NULL,
deleted_at TIMESTAMP NULL,
attempted_at TIMESTAMP NULL,
retrieved_at TIMESTAMP NULL,
CONSTRAINT `{$CFG->dbprefix}lti_result_ibfk_1`
Expand Down Expand Up @@ -794,6 +796,10 @@

// 2023-07-29 Adding Context Groups Service
array('lti_context', 'lti13_context_groups_url', 'TEXT NULL'),

// 2024-09-17
array('lti_result', 'attempts', 'INTEGER NULL'),
array('lti_result', 'attempted_at', 'TIMESTAMP NULL'),
);

foreach ( $add_some_fields as $add_field ) {
Expand Down
2 changes: 1 addition & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@
"react/dns" : ">=1.12.0",
"react/socket" : ">=1.15.0",

"tsugi/lib": "dev-master#5457d480421839a53f5823dd653becd613407346",
"tsugi/lib": "dev-master#8f7fa3b0171b90c1c328523f14329f74dd4aefa7",
"koseu/lib": "dev-master#b9a31b7875108196dbdf284e685b813d424f2def"
},
"config": {
Expand Down
10 changes: 5 additions & 5 deletions composer.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

8 changes: 4 additions & 4 deletions vendor/composer/installed.json
Original file line number Diff line number Diff line change
Expand Up @@ -7708,12 +7708,12 @@
"source": {
"type": "git",
"url": "https://github.com/tsugiproject/tsugi-php.git",
"reference": "5457d480421839a53f5823dd653becd613407346"
"reference": "8f7fa3b0171b90c1c328523f14329f74dd4aefa7"
},
"dist": {
"type": "zip",
"url": "https://api.github.com/repos/tsugiproject/tsugi-php/zipball/5457d480421839a53f5823dd653becd613407346",
"reference": "5457d480421839a53f5823dd653becd613407346",
"url": "https://api.github.com/repos/tsugiproject/tsugi-php/zipball/8f7fa3b0171b90c1c328523f14329f74dd4aefa7",
"reference": "8f7fa3b0171b90c1c328523f14329f74dd4aefa7",
"shasum": ""
},
"require": {
Expand All @@ -7727,7 +7727,7 @@
"phpunit/php-timer": "v5.0.3",
"phpunit/phpunit": "9.*"
},
"time": "2024-08-03T03:52:28+00:00",
"time": "2024-09-17T17:49:17+00:00",
"default-branch": true,
"type": "library",
"installation-source": "dist",
Expand Down
6 changes: 3 additions & 3 deletions vendor/composer/installed.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
'name' => '__root__',
'pretty_version' => 'dev-master',
'version' => 'dev-master',
'reference' => '8b3a0a88baf7c40138314ac7513dfd96d3d49704',
'reference' => '4c3816d04aedb00a1d0dc0223d85cd8ef24224b9',
'type' => 'library',
'install_path' => __DIR__ . '/../../',
'aliases' => array(),
Expand All @@ -13,7 +13,7 @@
'__root__' => array(
'pretty_version' => 'dev-master',
'version' => 'dev-master',
'reference' => '8b3a0a88baf7c40138314ac7513dfd96d3d49704',
'reference' => '4c3816d04aedb00a1d0dc0223d85cd8ef24224b9',
'type' => 'library',
'install_path' => __DIR__ . '/../../',
'aliases' => array(),
Expand Down Expand Up @@ -1078,7 +1078,7 @@
'tsugi/lib' => array(
'pretty_version' => 'dev-master',
'version' => 'dev-master',
'reference' => '5457d480421839a53f5823dd653becd613407346',
'reference' => '8f7fa3b0171b90c1c328523f14329f74dd4aefa7',
'type' => 'library',
'install_path' => __DIR__ . '/../tsugi/lib',
'aliases' => array(
Expand Down
37 changes: 37 additions & 0 deletions vendor/tsugi/lib/src/Core/Result.php
Original file line number Diff line number Diff line change
Expand Up @@ -659,4 +659,41 @@ public function setNote($note_str, $user_id=false) {
die();
}
}

/**
* Retrieve the number of attempts and latest attempt
*
* @return object with attempted_at and attempts
*/
public function getAttempts() {
global $CFG;
$PDOX = $this->launch->pdox;

$retval = new \stdClass();
$retval->attempts = 0;
$retval->attempted_at = 0;

if ( ($this->id ?? null) == null ) return $retval;
$p = $CFG->dbprefix;
$sql = "SELECT COALESCE(attempts, 0) AS attempts, COALESCE(attempted_at, 0) AS attempted_at FROM {$p}lti_result WHERE result_id = :RID";
$stmt = $PDOX->queryReturnError($sql, array( ":RID" => $this->id));
if ( $stmt->success ) {
$row = $stmt->fetch(\PDO::FETCH_OBJ);
if ( is_object($row) ) return $row;
}
return $retval;
}

/**
* Record an attempt on this result - different than submitting a grade
*/
public function recordAttempt() {
global $CFG;
$PDOX = $this->launch->pdox;

if ( ($this->id ?? null) == null ) return;
$p = $CFG->dbprefix;
$sql = "UPDATE {$p}lti_result SET attempts = COALESCE(attempts, 0) + 1, attempted_at = NOW() WHERE result_id = :RID";
$stmt = $PDOX->queryReturnError($sql, array( ":RID" => $this->id));
}
}

0 comments on commit 696f1f1

Please sign in to comment.