mirror of
https://github.com/moodle/moodle.git
synced 2025-08-05 00:46:50 +02:00
MDL-13766, fixed the hard coded double code in sql, use get_in_or_equal to generate NOT IN subquery
This commit is contained in:
parent
f574799836
commit
227dfa4332
1 changed files with 8 additions and 3 deletions
|
@ -633,13 +633,17 @@ abstract class repository {
|
||||||
$sql = 'SELECT i.*, r.type AS repositorytype, r.sortorder, r.visible FROM {repository} r, {repository_instances} i WHERE ';
|
$sql = 'SELECT i.*, r.type AS repositorytype, r.sortorder, r.visible FROM {repository} r, {repository_instances} i WHERE ';
|
||||||
$sql .= 'i.typeid = r.id ';
|
$sql .= 'i.typeid = r.id ';
|
||||||
|
|
||||||
|
if (!empty($args['disable_types']) && is_array($args['disable_types'])) {
|
||||||
|
list($types, $p) = $DB->get_in_or_equal($args['disable_types'], SQL_PARAMS_QM, 'param0000', false);
|
||||||
|
$sql .= ' AND r.type '.$types;
|
||||||
|
$params = array_merge($params, $p);
|
||||||
|
}
|
||||||
|
|
||||||
if (!empty($args['userid']) && is_numeric($args['userid'])) {
|
if (!empty($args['userid']) && is_numeric($args['userid'])) {
|
||||||
$sql .= ' AND (i.userid = 0 or i.userid = ?)';
|
$sql .= ' AND (i.userid = 0 or i.userid = ?)';
|
||||||
$params[] = $args['userid'];
|
$params[] = $args['userid'];
|
||||||
}
|
}
|
||||||
if (!empty($args['disable_types']) && is_array($args['disable_types'])) {
|
|
||||||
$sql .= ' AND r.type NOT IN ("'.implode('","', $args['disable_types']).'")';
|
|
||||||
}
|
|
||||||
foreach ($contexts as $context) {
|
foreach ($contexts as $context) {
|
||||||
if (empty($firstcontext)) {
|
if (empty($firstcontext)) {
|
||||||
$firstcontext = true;
|
$firstcontext = true;
|
||||||
|
@ -664,6 +668,7 @@ abstract class repository {
|
||||||
}
|
}
|
||||||
$sql .= ' order by r.sortorder, i.name';
|
$sql .= ' order by r.sortorder, i.name';
|
||||||
|
|
||||||
|
var_dump($sql);
|
||||||
if (!$records = $DB->get_records_sql($sql, $params)) {
|
if (!$records = $DB->get_records_sql($sql, $params)) {
|
||||||
$records = array();
|
$records = array();
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue