courses.json.php 1.69 KB
Newer Older
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
<?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'));
}