Skip to content

Commit

Permalink
Bug #8, Fix user/ajax PHP; add base::config() method [iet:1031422…
Browse files Browse the repository at this point in the history
…2][ci skip]
  • Loading branch information
nfreear committed Mar 9, 2018
1 parent 1836c50 commit dc370fa
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 2 deletions.
14 changes: 14 additions & 0 deletions classes/local/base.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,21 @@ class base {

const BASE_KEY = 'auth_ouopenid';

/**
* @param string $key Get plugin configuration for given key.
* @param mixed $default
* @return mixed Configuration item (object, array, string...)
*/
public static function config($key, $default = null) {
if (isset($CFG->{ 'auth_ouopenid_' . $key })) {
return $CFG->{ 'auth_ouopenid_' . $key };
}
self::debug([ __FUNCTION__, 'Missing or null value. Key / default: ', $key, $default ]);
return $default;
}

/** Output arbitrary data, eg. to HTTP header.
* @param mixed $obj Array or object.
*/
public static function debug($obj) {
static $count = 0;
Expand Down
6 changes: 4 additions & 2 deletions db/User.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,12 +14,13 @@
* @link http://csv.thephpleague.com/8.0/examples/#importing-a-csv-into-a-database-table
*/

use auth_ouopenid\local\base;
use Goodby\CSV\Import\Standard\Lexer;
use Goodby\CSV\Import\Standard\Interpreter;
use Goodby\CSV\Import\Standard\LexerConfig;
use Exception;

class User
class User extends base
{
const USER_TABLE = 'auth_ouopenid_users';

Expand Down Expand Up @@ -307,12 +308,13 @@ public static function getRedirectUrl($profile, $action = null)
{
global $CFG; // Moodle global.

$redirects = $CFG->auth_ouopenid_redirects;
$redirects = self::config('redirects');
$instrument = isset($profile->teslainstrument) ? $profile->teslainstrument : self::UNDEF_INSTRUMENT;

if (! isset($profile->teslainstrument)) {
self::debug([ __FUNCTION__, 'Undefined instrument', $profile ]);
}
if (! $redirects) { return null; }

$url = $redirects[ $instrument ]->url;

Expand Down
1 change: 1 addition & 0 deletions user/ajax.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@

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

define('DEBUG', filter_input(INPUT_GET, 'debug', FILTER_VALIDATE_BOOLEAN));
define('LONG_TXT', filter_input(INPUT_GET, 'longtexts', FILTER_VALIDATE_BOOLEAN));
Expand Down

0 comments on commit dc370fa

Please sign in to comment.