Skip to content

Commit

Permalink
Bug #8, add tesla_consent::agree() PHP class & method [iet:10310858]
Browse files Browse the repository at this point in the history
 * [iet:10310859]
  • Loading branch information
nfreear committed Mar 4, 2018
1 parent 4d500d1 commit 30daf68
Show file tree
Hide file tree
Showing 4 changed files with 71 additions and 4 deletions.
8 changes: 5 additions & 3 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,11 @@

* _Date: ~ 19 February ~ March 2018_
* _Tag: v1.5.0-beta_
* Add functionality to reveal a TeSLA activity after the pre-activity survey is completed — `conditional_embedded_survey` PHP class.
* Add functionality to reveal a TeSLA activity after the pre-activity
survey is completed — `conditional_embedded_survey` PHP class (Bug #8)
(That is, to "Complete" a survey embedded via `<IFRAME>` in a Moodle `mod/assign` conditional activity.)
* Add functionality to "consent" to the TeSLA student-agreement in a survey embedded in an `<IFRAME>`. `tesla_consent` PHP class;
* Add functionality to "consent" to the TeSLA student-agreement in a
survey embedded in an `<IFRAME>`. `tesla_consent` PHP class (Bug #8)
* Automated accessibility testing — [pa11y-ci][];

## Version 1.4.2 (Beta) - Pilot 3-A
Expand All @@ -26,7 +28,7 @@
* _Date: ~ 22 August - 6 December 2017_ (Deployed at start of TeSLA pilot 3-A)
* _Tag: v1.4.0-beta_
* _Build: "2017-12-05T13:25:56Z (MCD267768)"_
* Javascript now built using Browserify,
* Javascript now built using Browserify (Bug #7)
* Add 'poem server' — convert long texts (poems), into images of text, (Bug #6)
* Add `fix_enrollment_callibrate_page()` Javascript,
* Add long texts, with Chris E.
Expand Down
61 changes: 61 additions & 0 deletions classes/local/tesla_consent.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
<?php
/**
* Allow a student to "consent" to the TeSLA pilot study, via an embedded survey.
*
* @package auth_ouopenid
* @author Nick Freear, 02-March-2018.
* @copyright © 2018 The Open University.
*
* @link https://docs.moodle.org/dev/Data_manipulation_API#Inserting_Records
*/

namespace auth_ouopenid\local;

class tesla_consent {

const DB_TABLE = 'local_tesla_agreement';
const AGREE_VERSION = '2.0';

// const CONFIG_KEY = 'auth_ouopenid_tesla_consent';

/** Has the user already consented?
* @param int $userid
*/
public static function has_agreed( $userid = null ) {
global $DB, $USER; // Moodle global.

$userid = $userid ? $userid : $USER->id;

return $DB->count_records( self::DB_TABLE, [ 'userid' => $userid ]);
}

/** The user consents to the agreement.
* @param int $userid
* @param string $version Agreement version.
* @return int The inserted agreement ID.
*/
public static function agree( $userid = null, $version = self::AGREE_VERSION ) {
global $DB, $USER; // Moodle global.

$userid = $userid ? $userid : $USER->id;

$lastinsertid = $DB->insert_record(self::DB_TABLE, (object) [
'userid' => $userid,
'timesubmitted' => time(), // UNIX_TIMESTAMP()
'version' => $version,
'accepted' => true,
], false);

// self::_debug([ __METHOD__, $lastinsertid ]);
return $lastinsertid;
}

/* [1241] => stdClass Object (
[id] => 1241
[userid] => 5
[timesubmitted] => 1519734197
[version] => 2.0
[accepted] => 1
[timesubmitted_iso] => 2018-02-27T12:23:17+00:00
) */
}
1 change: 1 addition & 0 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
"require": {
"php": ">=5.5.9",
"dariuszp/cli-progress-bar": "^1.0.2",
"goodby/csv": "^1.3",
"vlucas/phpdotenv": "^2.4",
"composer/installers": "^1.2"
},
Expand Down
5 changes: 4 additions & 1 deletion survey-end/index.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,9 @@
// For 'print_string()' language support!
require_once __DIR__ . '/../../../config.php';
require_once __DIR__ . '/../classes/local/conditional_embedded_survey.php';
require_once __DIR__ . '/../classes/local/tesla_consent.php';

use auth_ouopenid\local\conditional_embedded_survey;
use auth_ouopenid\local\tesla_consent;

define( 'OUOP_STRING', 'auth_ouopenid' );

Expand Down Expand Up @@ -54,6 +55,7 @@ public static function complete_conditional() {
Ou_Open_Id_Survey_End::checkMaintenanceMode();

$conditional_completed = Ou_Open_Id_Survey_End::complete_conditional();
$agreement_id = tesla_consent::agree();

header('Content-Language: en');
header('X-Frame-Options: sameorigin');
Expand Down Expand Up @@ -122,6 +124,7 @@ public static function complete_conditional() {
echo json_encode([
'course_code' => Ou_Open_Id_Survey_End::getReturnCode(),
'cond_completed' => $conditional_completed,
'agreement_id' => $agreement_id,
'redirects' => $CFG->auth_ouopenid_redirects,
'hash' => '#section-3',
'timeout' => 3000,
Expand Down

0 comments on commit 30daf68

Please sign in to comment.