/
lib.php
156 lines (149 loc) · 6.83 KB
/
lib.php
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
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
<?php
/**
* Mahara: Electronic portfolio, weblog, resume builder and social networking
* Copyright (C) 2006-2009 Catalyst IT Ltd and others; see:
* http://wiki.mahara.org/Contributors
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*
* @package mahara
* @subpackage search
* @author Catalyst IT Ltd
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL
* @copyright (C) 2006-2009 Catalyst IT Ltd http://catalyst.net.nz
*
*/
defined('INTERNAL') || die();
/**
* Base search class. Provides a common interface with which searches can be
* carried out.
*/
abstract class PluginSearch extends Plugin {
/**
* Given a query string and limits, return an array of matching users
*
* NOTE: user with ID zero or that are NOT active should never be returned
*
* @param string The query string
* @param integer How many results to return
* @param integer What result to start at (0 == first result)
* @return array A data structure containing results looking like ...
* $results = array(
* count => integer, // total number of results
* limit => integer, // how many results are returned
* offset => integer, // starting from which result
* data => array( // the result records
* array(
* id => integer,
* username => string,
* institution => string,
* firstname => string,
* lastname => string,
* preferredname => string,
* email => string,
* ),
* array(
* id => integer,
* username => string,
* institution => string,
* firstname => string,
* lastname => string,
* preferredname => string,
* email => string,
* ),
* array(...),
* ),
* );
*/
public static abstract function search_user($query_string, $limit, $offset = 0);
/**
* Given a query string and limits, return an array of matching groups
*
* @param string The query string
* @param integer How many results to return
* @param integer What result to start at (0 == first result)
* @param string Which groups to search (all, member, notmember)
* @return array A data structure containing results looking like ...
* $results = array(
* count => integer, // total number of results
* limit => integer, // how many results are returned
* offset => integer, // starting from which result
* data => array( // the result records
* array(
* id => integer,
* name => string,
* description => string,
* jointype => string,
* owner => string,
* ctime => string,
* mtime => string,
* ),
* array(
* id => integer,
* name => string,
* description => string,
* jointype => string,
* owner => string,
* ctime => string,
* mtime => string,
* ),
* array(...),
* ),
* );
*/
public static abstract function search_group($query_string, $limit, $offset=0, $type='member');
/**
* Given a query string and limits, return an array of matching objects
* owned by the current user. Possible return types are ...
* - artefact
* - view
* - @todo potentially other types such as group could be searched by this too
*
* Implementations of this search should search across tags for artefacts
* and views at a minimum. Ideally the search would also index
* title/description and other metadata for these objects.
*
* @param string The query string
* @param integer How many results to return
* @param integer What result to start at (0 == first result)
* @param string Type to search for (either 'all' or one of the types above).
*
*/
public static abstract function self_search($query_string, $limit, $offset, $type = 'all');
protected static function self_search_make_links($data) {
$wwwroot = get_config('wwwroot');
if ($data['count']) {
foreach ($data['data'] as &$result) {
switch ($result['type']) {
case 'artefact':
safe_require('artefact', get_field('artefact_installed_type', 'plugin', 'name', $result['artefacttype']));
$result['links'] = call_static_method(generate_artefact_class_name($result['artefacttype']), 'get_links', $result['id']);
break;
case 'view':
$result['links'] = array(
'_default' => $wwwroot . 'view/view.php?id=' . $result['id'],
// TODO: these are certainly broken!
get_string('editviewinformation') => $wwwroot . 'view/editmetadata.php?viewid=' . $result['id'],
get_string('editview') => $wwwroot . 'view/edit.php?viewid=' . $result['id'],
get_string('editaccess') => $wwwroot . 'view/editaccess.php?viewid=' . $result['id'],
);
break;
default:
break;
}
}
}
}
}
?>