Skip to content

Commit

Permalink
Bug #8, fix survey-end PHP; Add base class [iet:10314222]
Browse files Browse the repository at this point in the history
* [iet:10314221][iet:10314088]
  • Loading branch information
nfreear committed Mar 7, 2018
1 parent 5b809d9 commit 1e0d559
Show file tree
Hide file tree
Showing 5 changed files with 41 additions and 18 deletions.
23 changes: 23 additions & 0 deletions classes/local/base.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
<?php
/**
* Base class.
*
* @package auth_ouopenid
* @author Nick Freear, 07-March-2018.
* @copyright © 2018 The Open University.
*
* @link https://docs.moodle.org/dev/Data_manipulation_API#Inserting_Records
*/

namespace auth_ouopenid\local;

class base {

/** Output arbitrary data, eg. to HTTP header.
*/
public static function debug($obj) {
static $count = 0;
header(sprintf('Xx-auth-ou-openid-%02d: %s', $count, json_encode($obj)));
$count++;
}
}
13 changes: 3 additions & 10 deletions classes/local/conditional_embedded_survey.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,9 @@

namespace auth_ouopenid\local;

class conditional_embedded_survey {
use auth_ouopenid\local\base;

class conditional_embedded_survey extends base {

const CONFIG_KEY = 'auth_ouopenid_conditional_survey_activity';
const MOD_TYPE_NAME = 'assign'; // 'mod/assign'
Expand Down Expand Up @@ -130,13 +132,4 @@ protected function course_module_completion() {

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

/** Output arbitrary data, eg. to HTTP header.
*/
protected static function _debug($obj)
{
static $count = 0;
header(sprintf('X-auth-ou-cond-%02d: %s', $count, json_encode($obj)));
$count++;
}
}
7 changes: 5 additions & 2 deletions classes/local/tesla_consent.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,9 @@

namespace auth_ouopenid\local;

class tesla_consent {
use auth_ouopenid\local\base;

class tesla_consent extends base {

const DB_TABLE = 'local_tesla_agreement';
const AGREE_VERSION = '2.0';
Expand Down Expand Up @@ -46,7 +48,8 @@ public static function agree( $userid = null, $version = self::AGREE_VERSION ) {
'accepted' => true,
], false);

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

return $lastinsertid;
}

Expand Down
14 changes: 8 additions & 6 deletions classes/user_event_observer.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,10 +10,12 @@
namespace auth_ouopenid;

require_once __DIR__ . '/../../../vendor/autoload.php';
require_once __DIR__ . '/local/base.php';

use IET_OU\Moodle\Auth\Ouopenid\Db\User as OuUser;
use auth_ouopenid\local\base;

class user_event_observer {
class user_event_observer extends base {

public static function core_user_created($event) {

Expand All @@ -22,7 +24,7 @@ public static function core_user_created($event) {

// Was: self::redirect($user_created = true, __FUNCTION__);

OuUser::debug(__FUNCTION__);
self::debug(__FUNCTION__);
}

public static function core_user_loggedin($event) {
Expand All @@ -35,7 +37,7 @@ public static function embed_event_data(\core\event\base $event) {
json_encode( $event->get_data() ) .
"</script>\n";
} else {
OuUser::debug([ __FUNCTION__, $event->get_data() ]);
self::debug([ __FUNCTION__, $event->get_data() ]);
}
}

Expand All @@ -46,15 +48,15 @@ protected static function redirect($user_created, $fn) {
$redirects = isset($CFG->auth_ouopenid_redirects) ? $CFG->auth_ouopenid_redirects : null;

if (! isset($USER->username)) {
return OuUser::debug([ __FUNCTION__, 'Warning, no username.', $USER ]);
return self::debug([ __FUNCTION__, 'Warning, no username.', $USER ]);
}

$ou_profile = OuUser::getUser($USER->username);

OuUser::debug([ __FUNCTION__, $fn, $redirects, $ou_profile ]);
self::debug([ __FUNCTION__, $fn, $redirects, $ou_profile ]);

if (! $redirects || ! $enabled) {
return OuUser::debug([ __FUNCTION__, 'Warning, redirect is disabled (or missing).', $redirects ]);
return self::debug([ __FUNCTION__, 'Warning, redirect is disabled (or missing).' ]);
}

$url = OuUser::getRedirectUrl($ou_profile, $user_created ? 'newenrol' : 'return');
Expand Down
2 changes: 2 additions & 0 deletions survey-end/index.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,11 @@

// For 'print_string()' language support!
require_once __DIR__ . '/../../../config.php';
require_once __DIR__ . '/../classes/local/base.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

0 comments on commit 1e0d559

Please sign in to comment.