tasks.json.php 1.98 KB
Newer Older
1 2 3 4 5
<?php
/**
 *
 * @package    mahara
 * @subpackage artefact-plans
6
 * @author     Catalyst IT Ltd, Alexander Del Ponte
7 8
 * @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.
9 10 11 12
 *
 */

define('INTERNAL', 1);
13
define('PUBLIC', 1);
14 15
define('JSON', 1);

16
require(dirname(dirname(dirname(__FILE__))) . '/init.php');
17 18 19 20 21
safe_require('artefact', 'plans');
require_once(get_config('docroot') . 'blocktype/lib.php');
require_once(get_config('docroot') . 'artefact/plans/blocktype/plans/lib.php');

$offset = param_integer('offset', 0);
22
$limit = param_integer('limit', 10);
23
$editing = param_variable('editing', false);
24 25
$artefactid = param_integer('artefact', null);
$blockid = param_integer('block', null);
26

27
if ($blockid && !$artefactid) {
28
    $bi = new BlockInstance($blockid);
29 30 31
    if (!can_view_view($bi->get('view'))) {
        json_reply(true, get_string('accessdenied', 'error'));
    }
32
    $options = $configdata = $bi->get('configdata');
33
    $options['view'] = $bi->get('view');
34

35 36
    // If block sets limit use that instead
    $limit = !empty($configdata['count']) ? $configdata['count'] : $limit;
37 38 39
    $planId = param_integer('planid');
    $plan = new ArtefactTypePlan($planId);
    $tasks = ArtefactTypeTask::get_tasks($plan, $offset, $limit);
40

41
    $template = 'artefact:plans:view/plantasks.tpl';
42
    $baseurl = $bi->get_view()->get_url();
43 44 45 46 47 48 49
    $baseurl .= ((false === strpos($baseurl, '?')) ? '?' : '&') . 'block=' . $blockid . '&planid=' . $planId . '&editing=' . $editing;
    $pagination = [
        'baseurl'   => $baseurl,
        'id'        => 'block' . $blockid . '_plan' . $planId . '_pagination',
        'datatable' => 'tasklist_' . $blockid . '_plan' . $planId,
        'jsonscript' => 'artefact/plans/block/tasks.json.php',
    ];
50 51
}

52
ArtefactTypeTask::render_tasks($tasks, $template, $options, $pagination, $editing);
53

54
json_reply(false, (object) ['message' => false, 'data' => $tasks]);