myviews.json.php 1.93 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
<?php
/**
 *
 * @package    mahara
 * @subpackage blocktype/groupviews
 * @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.
 *
 */

/**
 * returns shared views in a given group id
 */

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

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

safe_require('blocktype', 'myviews');
require_once(get_config('libroot') . 'view.php');
require_once(get_config('libroot') . 'pieforms/pieform.php');

$offset = param_integer('offset', 0);
$viewid = param_integer('view');
$editing = param_boolean('editing', false);

$dashboard = new View($viewid);

if (!can_view_view($dashboard)) {
    json_reply(true, get_string('accessdenied', 'error'));
}
34

35
36
37
$views = View::view_search(
        null, // $query
        null, // $ownerquery
38
        (object) array('owner' => $dashboard->get('owner')), // $ownedby
39
40
41
42
43
44
45
46
47
48
49
50
51
        null, // $copyableby
        10, // $limit
        $offset, // $offset
        true, // $extra
        null, // $sort
        array('portfolio'), // $types
        null, // $collection
        null, // $accesstypes
        null, // $tag
        null, // $viewid
        null, // $excludeowner
        true // $groupbycollection
);
52
53
54
55
56
57
58
59
60
61
62
63
64
65
$views = (array)$views;
$baseurl = $dashboard->get_url();
$baseurl .= (strpos($baseurl, '?') === false ? '?' : '&') . 'view=' . $viewid . '&editing=' . $editing;
$pagination = array(
    'baseurl'    => $baseurl,
    'id'         => 'myviews_pagination',
    'datatable'  => 'myviewlist',
    'jsonscript' => 'blocktype/myviews/myviews.json.php',
    'resultcounttextsingular' => get_string('view', 'view'),
    'resultcounttextplural'   => get_string('views', 'view'),
);
PluginBlocktypeMyViews::render_items($views, 'blocktype:myviews:myviewspaginator.tpl', array(), $pagination);

json_reply(false, array('data' => $views));