-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathlib.php
More file actions
271 lines (246 loc) · 8.47 KB
/
Copy pathlib.php
File metadata and controls
271 lines (246 loc) · 8.47 KB
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
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
<?php
// This file is part of Moodle - http://moodle.org/
//
// Moodle 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.
//
// Moodle 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 Moodle. If not, see <http://www.gnu.org/licenses/>.
/**
* Lib for editing questions filters.
*
* @package moodlecore
* @subpackage questionbank
* @copyright 1999 onwards Martin Dougiamas {@link http://moodle.com}
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
defined('MOODLE_INTERNAL') || die;
require_once($CFG->libdir . '/outputcomponents.php');
require_once($CFG->dirroot . '/question/editlib.php');
/**
* Get question bank search conditions
*
* @return array
*/
function local_question_filters_get_question_bank_search_conditions() {
return array(new local_question_filters_question_bank_search_condition());
}
/**
* Get extra fields
*
* @param integer $questionid
* @return array
*/
function local_question_filters_get_question_extra_fields($questionid) {
global $DB;
return $DB->get_record('local_question_filters', array('questionid' => $questionid));
}
/**
* Save extra fields
*
* @param object $question
* @return array
*/
function local_question_filters_save_question_extra_fields($question) {
global $DB;
$DB->delete_records('local_question_filters', array(
'questionid' => $question->questionid
));
return $DB->insert_record('local_question_filters', $question);
}
/**
* Get filters from form
*
* @return object
*/
function local_question_filters_get_filter_from_form() {
$filter = (object)array(
'filter_name' => trim(optional_param('filter_name', '', PARAM_TEXT)),
'filter_questiontext' => trim(optional_param('filter_questiontext', '', PARAM_TEXT)),
'filter_meta_field1' => trim(optional_param('filter_meta_field1', '', PARAM_TEXT)),
// Empty field -> null, anything else -> convert to integer.
'filter_defaultmark' =>
trim(optional_param('filter_defaultmark', '', PARAM_TEXT)) !== '' ?
optional_param('filter_defaultmark', 0, PARAM_INT) :
null,
'filter_defaultmark_search' => optional_param('filter_defaultmark_search', null, PARAM_RAW),
);
if (!in_array($filter->filter_defaultmark_search, array('>' => '>', '>=' => '>=', '=' => '=', '<=' => '<=', '<' => '<'))) {
$filter->filter_defaultmark_search = '=';
}
return $filter;
}
/**
* Get filter SQL
*
* @param array $params
* @param string $where
* @param boolean $filter
* @param boolean $sqlparamnames
* @param string $sqlprefix
* @return boolean
*/
function local_question_filters_get_filter_sql(&$params, &$where, $filter = null, $sqlparamnames = true, $sqlprefix = 'q.') {
global $DB;
if ($filter === null) {
$filter = local_question_filters_get_filter_from_form();
} else if (!$filter) {
return;
} else {
if (!$filter->filter_defaultmark_search || $filter->filter_defaultmark == '') {
$filter->filter_defaultmark = null;
}
}
if (!$filter->filter_name
&& !$filter->filter_questiontext
&& !$filter->filter_meta_field1
&& $filter->filter_defaultmark === null) {
// No filtering.
if (!is_array($where) && empty($where)) {
$where = '1=1';
}
return;
}
$addwhere = '(1=1';
if ($filter->filter_name) {
$params['filter_name'] = '%'.$filter->filter_name.'%';
$addwhere .= ' AND '.$DB->sql_like($sqlprefix.'name', (!$sqlparamnames ? '?' : ':filter_name'), false);
}
if ($filter->filter_questiontext) {
$params['filter_questiontext'] = '%'.$filter->filter_questiontext.'%';
$addwhere .= ' AND '.$DB->sql_like($sqlprefix.'questiontext', (!$sqlparamnames ? '?' : ':filter_questiontext'), false);
}
if ($filter->filter_meta_field1) {
$params['filter_meta_field1'] = '%'.$filter->filter_meta_field1.'%';
$addwhere .= ' AND (SELECT COUNT(*)
FROM {local_question_filters} lqf
WHERE lqf.questionid='.($sqlprefix ? $sqlprefix : '{question}.').'id'.
' AND '.$DB->sql_like('lqf.meta_field1', (!$sqlparamnames ? '?' : ':filter_meta_field1'), false).') >= 1';
}
if ($filter->filter_defaultmark !== null) {
$params['filter_defaultmark'] = $filter->filter_defaultmark;
$addwhere .= ' AND '.$sqlprefix."defaultmark ".
$filter->filter_defaultmark_search." ".(!$sqlparamnames ? '?' : ":filter_defaultmark");
}
$addwhere .= ')';
if (is_array($where)) {
$where[] = $addwhere;
} else if (is_string($where)) {
if ($where) {
$where .= ' AND ';
}
$where .= $addwhere;
} else {
die('error wrong where');
}
// Filtered.
return true;
}
/**
* Filter questions, search conditions
*
* @package mod_quiz
* @copyright 2007 Jamie Pratt me@jamiep.org
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
class local_question_filters_question_bank_search_condition extends \core_question\bank\search\condition {
/**
* @var $where for SQL
*/
protected $where = array();
/**
* @var $params array of params
*/
protected $params = array();
/**
* construct
*
* @return boolean
*/
public function __construct() {
$this->init();
}
/**
* where + 'and'
*
* @return string
*/
public function where() {
return join(' AND ', $this->where);
}
/**
* get params
*
* @return array
*/
public function params() {
return $this->params;
}
/**
* display options
*
* @return string
*/
public function display_options() {
$return = '';
$return .= html_writer::label(get_string('questionname','question'), 'filter_name');
$return .= html_writer::empty_tag('input',
array('name' => 'filter_name',
'id' => 'filter_name',
'class' => 'searchoptions',
'value' => optional_param('filter_name', null, PARAM_TEXT)));
$return .= html_writer::label(get_string('questiontext','question'), 'filter_questiontext');
$return .= html_writer::empty_tag('input',
array('name' => 'filter_questiontext',
'id' => 'filter_questiontext',
'class' => 'searchoptions',
'value' => optional_param('filter_questiontext', null, PARAM_TEXT)));
/*
$return .= html_writer::label('Metadatenfeld', 'filter_meta_field1');
$return .= html_writer::empty_tag('input',
array('name' => 'filter_meta_field1',
'id' => 'filter_meta_field1',
'class' => 'searchoptions',
'value' => optional_param('filter_meta_field1', null, PARAM_TEXT)));
*/
$return .= html_writer::label(get_string('defaultmark','question'), 'filter_defaultmark');
$return .= html_writer::select(
array('>' => '>', '>=' => '>=', '=' => '=', '<=' => '<=', '<' => '<'),
'filter_defaultmark_search',
optional_param('filter_defaultmark_search', '=', PARAM_RAW), false);
$return .= html_writer::empty_tag('input',
array('name' => 'filter_defaultmark',
'id' => 'filter_defaultmark',
'class' => 'searchoptions',
'value' => optional_param('filter_defaultmark', null, PARAM_TEXT)));
$return .= '<div>'.
html_writer::empty_tag('input',
array('type' => 'submit', 'value' => get_string('search')))
.'</div>';
return $return;
}
/**
* display advanced options
*
* @return nothing
*/
public function display_options_adv() {
// Return 'Advanced UI from search plugin here<br />';.
}
/**
* init
*
* @return nothing
*/
private function init() {
global $DB;
local_question_filters_get_filter_sql($this->params, $this->where);
}
}