Commit fb44c5ab authored by Robert Lyon's avatar Robert Lyon
Browse files

Bug 1863511: Course completion (courseinfo) block



This block allows one to import information from an external source
It requires the connection via webservices to
1) find out the external user id value based on the page owner's email address
2) fetch the course completion data for that external user id

Change-Id: I6c67feb470bbcb35b0c549a8467c9204a00c9389
Signed-off-by: default avatarRobert Lyon <robertl@catalyst.net.nz>
parent efee320b
Loading
Loading
Loading
Loading
+41 −0
Original line number Diff line number Diff line
<?php
/**
 *
 * @package    mahara
 * @subpackage admin
 * @author     Catalyst IT Ltd
 * @license    http://www.gnu.org/copyleft/gpl.html GNU GPL version 3 or later
 * @copyright  For copyright information on Mahara, please see the README file distributed with this software.
 *
 */

define('INTERNAL', 1);
define('ADMIN', 1);
define('JSON', 1);

require(dirname(dirname(dirname(__FILE__))) . '/init.php');

$plugintype = param_alpha('plugintype');
$pluginname = param_alpha('pluginname');
$type       = param_alpha('type', null);

$result = array();

safe_require($plugintype, $pluginname);

if ($type) {
    $classname = generate_artefact_class_name($type);
}
else {
    $classname = generate_class_name($plugintype, $pluginname);
}

if (call_static_method($classname, 'has_config_info')) {
    $info = call_static_method($classname, 'get_config_info');
    $result['info_header'] = $info['header'];
    $result['info_body'] = $info['body'];
    json_reply(null, array('data' => $result));
}
else {
    json_reply(true, array('message' => get_string('noinformation')));
}
+12 −2
Original line number Diff line number Diff line
@@ -65,12 +65,19 @@ foreach (array_keys($plugins) as $plugin) {
                        foreach ($types as $t) {
                            $classname = generate_artefact_class_name($t);
                            if ($collapseto = call_static_method($classname, 'collapse_config')) {
                                $plugins[$plugin]['installed'][$key]['types'][$collapseto] = true;
                                $plugins[$plugin]['installed'][$key]['types'][$collapseto]['config'] = true;
                            }
                            else {
                                $plugins[$plugin]['installed'][$key]['types'][$t] =
                                $plugins[$plugin]['installed'][$key]['types'][$t]['config'] =
                                    call_static_method($classname, 'has_config');
                            }
                            if ($collapseto = call_static_method($classname, 'collapse_config_info')) {
                                $plugins[$plugin]['installed'][$key]['types'][$collapseto]['info'] = true;
                            }
                            else {
                                $plugins[$plugin]['installed'][$key]['types'][$t]['info'] =
                                    call_static_method($classname, 'has_config_info');
                            }
                        }
                    }
                }
@@ -80,6 +87,9 @@ foreach (array_keys($plugins) as $plugin) {
                    if (call_static_method($classname, 'has_config')) {
                        $plugins[$plugin]['installed'][$key]['config'] = true;
                    }
                    if (call_static_method($classname, 'has_config_info')) {
                        $plugins[$plugin]['installed'][$key]['info'] = true;
                    }
                }
            }
        }
+8 −0
Original line number Diff line number Diff line
@@ -988,6 +988,10 @@ abstract class ArtefactType implements IArtefactType {
        return false;
    }

    public static function has_config_info() {
        return false;
    }

    public static function get_config_options() {
        return array();
    }
@@ -996,6 +1000,10 @@ abstract class ArtefactType implements IArtefactType {
        return false;
    }

    public static function collapse_config_info() {
        return false;
    }

    private function save_rolepermissions() {
        if (!$this->group) {
            return;
+5 −0
Original line number Diff line number Diff line
@@ -432,3 +432,8 @@ $string['institutionunknown'] = '- unknown -';
$string['unabletodeleteadmin'] = 'Unable to delete user with ID "%s" as they are an admin';
$string['notuserblog'] = 'The journal is not owned by "%s"';
$string['oneof'] = 'One of';

$string['servicetype'] = 'Service type';
$string['authtype'] = 'Auth type';
$string['jsonenabled'] = 'JSON response';
$string['customfields'] = 'Custom fields';
+49 −0
Original line number Diff line number Diff line
<?php
/**
 *
 * @package    mahara
 * @subpackage blocktype-groupviews
 * @author     Catalyst IT
 * @license    http://www.gnu.org/copyleft/gpl.html GNU GPL version 3 or later
 * @copyright  For copyright information on Mahara, please see the README file distributed with this software.
 *
 */

define('INTERNAL', 1);
define('JSON', 1);

require(dirname(dirname(dirname(__FILE__))) . '/init.php');
require_once(get_config('docroot') . 'blocktype/lib.php');
require_once(get_config('docroot') . 'blocktype/courseinfo/lib.php');

$offset = param_integer('offset', 0);
$limit = param_integer('limit', 10);

if ($blockid = param_integer('block', null)) {
    $bi = new BlockInstance($blockid);
    $owner = $bi->get_view()->get('owner');
    if ($owner) {
        $options = $configdata = $bi->get('configdata');
        $configdata['ownerid'] = $owner;

        $courses = PluginBlocktypeCourseinfo::get_data($configdata, $offset, $limit);
        $template = 'blocktype:courseinfo:courserows.tpl';
        $baseurl = $bi->get_view()->get_url();
        $baseurl .= ((false === strpos($baseurl, '?')) ? '?' : '&') . 'block=' . $blockid;
        $pagination = array(
            'baseurl'    => $baseurl,
            'id'         => 'block' . $blockid . '_pagination',
            'datatable'  => 'coursedata_' . $blockid,
            'jsonscript' => 'blocktype/courseinfo/courses.json.php',
        );

        PluginBlocktypeCourseinfo::render_courses($courses, $template, $options, $pagination);
        json_reply(false, (object) array('message' => false, 'data' => $courses));
    }
    else {
        json_reply(true, get_string('accessdenied', 'error'));
    }
}
else {
    json_reply(true, get_string('accessdenied', 'error'));
}
Loading