access.json.php 2.02 KB
Newer Older
1
2
3
4
5
<?php
/**
 *
 * @package    mahara
 * @subpackage core
6
 * @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
15
16
17
18
 *
 */

// NOTE: this JSON script is used by the 'viewacl' element. It could probably
// be moved elsewhere without harm if necessary (e.g. if the 'viewacl' element
// was used in more places
define('INTERNAL', 1);
define('JSON', 1);

require(dirname(dirname(__FILE__)) . '/init.php');
19
require_once('searchlib.php');
20
21
22

$type   = param_variable('type');
$query  = param_variable('query', '');
23
24
25
26
27
28
$page = param_integer('page');
$limit  = 10;
if ($page < 1) {
    $page = 1;
}
$offset = ($page - 1) * $limit;
29
switch ($type) {
30
31
32
    case 'friend':
        $data = search_user($query, $limit, $offset,  array('exclude' => $USER->get('id'), 'friends' => true));
        break;
33
    case 'user':
34
        $data = search_user($query, $limit, $offset, array('exclude' => $USER->get('id')));
35
        $roles = get_records_array('usr_access_roles');
36
37
38
39
        $data['roles'] =  array();
        foreach ($roles as $r) {
            $data['roles'][] = array('name' => $r->role, 'display' => get_string($r->role, 'view'));
        }
40
41
        break;
    case 'group':
42
        require_once('group.php');
43
        $data = search_group($query, $limit, $offset, '');
44
45
46
        $roles = get_records_array('grouptype_roles');
        $data['roles'] = array();
        foreach ($roles as $r) {
47
            $data['roles'][$r->grouptype][] = array('name' => $r->role, 'display' => get_string($r->role, 'grouptype.'.$r->grouptype));
48
        }
49
50
51
        foreach ($data['data'] as &$r) {
            $r->url = group_homepage_url($r);
        }
52
        break;
Robert Lyon's avatar
Robert Lyon committed
53
54
55
    default:
        $data = search_user($query, $limit, $offset,  array('exclude' => $USER->get('id'), 'friends' => true));
        break;
56
}
57
$more = $data['count'] > $limit * $page;
58
59
60

$data['error'] = false;
$data['message'] = '';
61
$data['more'] = $more;
62
json_reply(false, $data);