sharedcollections.json.php 3 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
<?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 collections in a given group id
 */

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

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

safe_require('blocktype', 'groupviews');
require_once(get_config('libroot') . 'view.php');
require_once(get_config('libroot') . 'group.php');

$offset = param_integer('offset', 0);
$groupid = param_integer('group');
27
$editing = param_boolean('editing', false);
28
29
30
31
32
33
34
35
36

$group_homepage_view = group_get_homepage_view($groupid);
$bi = group_get_homepage_view_groupview_block($groupid);

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

$configdata = $bi->get('configdata');
37
38
39
if (!isset($configdata['showsharedcollections'])) {
    $configdata['showsharedcollections'] = 1;
}
40
41
42
$limit = isset($configdata['count']) ? intval($configdata['count']) : 5;
$limit = ($limit > 0) ? $limit : 5;

43
44
// Find out what order to sort them by (default is titles)
if (!isset($configdata['sortsharedviewsby']) || $configdata['sortsharedviewsby'] == PluginBlocktypeGroupViews::SORTBY_TITLE) {
45
    $sortsharedcollectionsby = array(array('type' => 'name'));
46
47
48
49
}
else {
    $sortsharedcollectionsby = array(
            array(
50
                    'type' => 'lastchanged',
51
52
53
54
55
56
57
                    'desc' => true
            )
    );
}

// For group members, display a list of collections that others have
// shared to the group
58
$hidesubmitted = group_user_can_assess_submitted_views($groupid, $USER->get('id'));
59
60
61
62
63
64
65
66
67
68
69
70
71
72
if (empty($configdata['showsharedcollections'])) {
    $sharedcollections = array(
        'data'   => array(),
        'count'  => 0,
        'limit'  => $limit,
        'offset' => 0
    );
}
else {
    $sharedcollections = (array) View::get_sharedcollections_data(
            $limit,
            $offset,
            $groupid,
            ($configdata['showsharedcollections'] == 2 ? false : true),
73
74
            $sortsharedcollectionsby,
            $hidesubmitted
75
76
77
    );
}

78
if (!empty($configdata['showsharedcollections'])) {
79
    $baseurl = $group_homepage_view->get_url();
80
    $baseurl .= (strpos($baseurl, '?') === false ? '?' : '&') . 'group=' . $groupid . '&editing=' . $editing;
81
82
83
84
85
86
87
88
    $pagination = array(
        'baseurl'    => $baseurl,
        'id'         => 'sharedcollections_pagination',
        'datatable'  => 'sharedcollectionlist',
        'jsonscript' => 'blocktype/groupviews/sharedcollections.json.php',
        'resultcounttextsingular' => get_string('collection', 'collection'),
        'resultcounttextplural'   => get_string('collections', 'collection'),
    );
89
    PluginBlocktypeGroupViews::render_items($sharedcollections, 'blocktype:groupviews:sharedviews.tpl', $configdata, $pagination);
90
91
92
}

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