viewtasks.json.php 2.27 KB
Newer Older
1
2
3
4
5
6
<?php
/**
 *
 * @package    mahara
 * @subpackage artefact-plans
 * @author     Catalyst IT Ltd
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
13
14
 *
 */

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

15
require(dirname(dirname(dirname(__FILE__))) . '/init.php');
16
17
18
19
20
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);
21
22
23
24
$limit = param_integer('limit', 10);

if ($blockid = param_integer('block', null)) {
    $bi = new BlockInstance($blockid);
25
26
27
    if (!can_view_view($bi->get('view'))) {
        json_reply(true, get_string('accessdenied', 'error'));
    }
28
    $options = $configdata = $bi->get('configdata');
29
30
    // If block sets limit use that instead
    $limit = !empty($configdata['count']) ? $configdata['count'] : $limit;
31
    $tasks = ArtefactTypeTask::get_tasks($configdata['artefactid'], $offset, $limit);
32
33

    $template = 'artefact:plans:taskrows.tpl';
34
35
    $baseurl = $bi->get_view()->get_url();
    $baseurl .= ((false === strpos($baseurl, '?')) ? '?' : '&') . 'block=' . $blockid;
36
    $pagination = array(
37
        'baseurl'   => $baseurl,
38
        'id'        => 'block' . $blockid . '_pagination',
39
        'datatable' => 'tasklist_' . $blockid,
40
41
        'jsonscript' => 'artefact/plans/viewtasks.json.php',
    );
42
43
44
45
}
else {
    $planid = param_integer('artefact');
    $viewid = param_integer('view');
46
47
48
    if (!can_view_view($viewid)) {
        json_reply(true, get_string('accessdenied', 'error'));
    }
49
50
51
52
    $options = array('viewid' => $viewid);
    $tasks = ArtefactTypeTask::get_tasks($planid, $offset, $limit);

    $template = 'artefact:plans:taskrows.tpl';
53
    $baseurl = get_config('wwwroot') . 'artefact/artefact.php?artefact=' . $planid . '&view=' . $options['viewid'];
54
55
56
    $pagination = array(
        'baseurl' => $baseurl,
        'id' => 'task_pagination',
57
        'datatable' => 'tasktable',
58
59
        'jsonscript' => 'artefact/plans/viewtasks.json.php',
    );
60

61
}
62
ArtefactTypeTask::render_tasks($tasks, $template, $options, $pagination);
63

64
json_reply(false, (object) array('message' => false, 'data' => $tasks));