Commit af64abec authored by Robert Lyon's avatar Robert Lyon

Bug 1565546: Allowing $cfg setting to be json

1) Allowing $CFG to accept json encoded strings and to be decoded back to php
2) Making the $cfg->openbadgedisplayer_source a json encoded string
3) Allowing the openbadges have the defaults only on one place and warn when they are missing

behatnotneeded

Change-Id: Ica0349d6343d9f608b2272117d7412b288799278
Signed-off-by: Robert Lyon's avatarRobert Lyon <robertl@catalyst.net.nz>
parent c4c4a46b
......@@ -69,3 +69,5 @@ $string['title_backpack'] = 'Mozilla Backpack';
$string['title_passport'] = 'Open Badge Passport';
$string['fetchingbadges'] = 'Fetching entries. This may take a while.';
$string['missingbadgesources'] = 'Missing sources setting. Please add to your config.php file, eg:<br><br>$cfg->openbadgedisplayer_source = \'{"backpack":"https://backpack.openbadges.org/"}\'';
\ No newline at end of file
......@@ -61,12 +61,11 @@ class PluginBlocktypeOpenbadgedisplayer extends SystemBlocktype {
if (is_null(self::$source)) {
$source = get_config('openbadgedisplayer_source');
if (empty($source)) {
// default values
$source = array(
'backpack' => 'https://backpack.openbadges.org/',
'passport' => null
);
if (!empty($source)) {
$source = (array) $source;
}
else {
return false;
}
self::$source = $source;
......@@ -77,7 +76,7 @@ class PluginBlocktypeOpenbadgedisplayer extends SystemBlocktype {
public static function render_instance(BlockInstance $instance, $editing=false) {
$configdata = $instance->get('configdata');
if (empty($configdata) || !isset($configdata['badgegroup'])) {
if (empty($configdata) || !isset($configdata['badgegroup']) || !get_config('openbadgedisplayer_source')) {
return;
}
......@@ -252,6 +251,17 @@ class PluginBlocktypeOpenbadgedisplayer extends SystemBlocktype {
global $USER;
$sources = self::get_backpack_source();
if ($sources === false) {
$fields = array(
'message' => array(
'type' => 'html',
'class' => '',
'value' => '<div class="alert alert-warning" role="alert"><span class="icon icon-lg icon-exclamation-triangle left" aria-hidden="true" role="presentation"></span>' . get_string('missingbadgesources', 'blocktype.openbadgedisplayer') . '</div>'
),
);
return $fields;
}
$configdata = $instance->get('configdata');
$addresses = get_column('artefact_internal_profile_email', 'email', 'owner', $USER->id, 'verified', 1);
$current_values = array();
......
......@@ -94,6 +94,17 @@ set_error_handler('error', $errorlevel);
// core libraries
require('mahara.php');
ensure_sanity();
// Now that we know json_decode exists we check if any config vars are
// encoded json strings and we convert them to be used in php
foreach ($CFG as $key => $option) {
if (is_string($option)) {
$decode = json_decode($option, true);
if ($decode !== null && is_array($decode) && json_last_error() === JSON_ERROR_NONE) {
$CFG->$key = $decode;
}
}
}
require('dml.php');
require('web.php');
require('user.php');
......
......@@ -700,7 +700,4 @@ $cfg->passwordsaltalt1 = 'old salt value';
* @global array $cfg->openbadgedisplayer_source The open badge sources
* The default sources are Mozilla Backpack and openbadgepassport.com
*/
$cfg->openbadgedisplayer_source = array(
'backpack' => 'https://backpack.openbadges.org/',
'passport' => 'https://openbadgepassport.com/'
);
$cfg->openbadgedisplayer_source = '{"backpack":"https://backpack.openbadges.org/","passport":"https://openbadgepassport.com/"}';
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment