mirror of
https://github.com/moodle/moodle.git
synced 2025-01-17 21:49:15 +01:00
MDL-63531 privacy: Update to comments provider to simplfy sql.
This updates the get_users_in_context_from_sql query to include the context id to simplify the calls made from other components.
This commit is contained in:
parent
6592598f71
commit
d2148f32ca
@ -235,17 +235,29 @@ class provider implements \core_privacy\local\metadata\provider, \core_privacy\l
|
|||||||
* @param string $alias An alias prefix to use for comment selects to avoid interference with your own sql.
|
* @param string $alias An alias prefix to use for comment selects to avoid interference with your own sql.
|
||||||
* @param string $component The component to check.
|
* @param string $component The component to check.
|
||||||
* @param string $area The comment area to check.
|
* @param string $area The comment area to check.
|
||||||
|
* @param int $contextid The context id.
|
||||||
* @param string $insql The SQL to use in a sub-select for the itemid query.
|
* @param string $insql The SQL to use in a sub-select for the itemid query.
|
||||||
* @param array $params The params required for the insql.
|
* @param array $params The params required for the insql.
|
||||||
*/
|
*/
|
||||||
public static function get_users_in_context_from_sql(
|
public static function get_users_in_context_from_sql(
|
||||||
userlist $userlist, string $alias, string $component, string $area, string $insql, $params) {
|
userlist $userlist, string $alias, string $component, string $area, int $contextid = null, string $insql = '',
|
||||||
|
array $params = []) {
|
||||||
|
|
||||||
|
if ($insql != '') {
|
||||||
|
$insql = "AND {$alias}.itemid {$insql}";
|
||||||
|
}
|
||||||
|
$contextsql = '';
|
||||||
|
if (isset($contextid)) {
|
||||||
|
$contextsql = "AND {$alias}.contextid = :{$alias}contextid";
|
||||||
|
$params["{$alias}contextid"] = $contextid;
|
||||||
|
}
|
||||||
|
|
||||||
// Comment authors.
|
// Comment authors.
|
||||||
$sql = "SELECT {$alias}.userid
|
$sql = "SELECT {$alias}.userid
|
||||||
FROM {comments} {$alias}
|
FROM {comments} {$alias}
|
||||||
WHERE {$alias}.component = :{$alias}component
|
WHERE {$alias}.component = :{$alias}component
|
||||||
AND {$alias}.commentarea = :{$alias}commentarea
|
AND {$alias}.commentarea = :{$alias}commentarea
|
||||||
AND {$alias}.itemid IN ({$insql})";
|
$contextsql $insql";
|
||||||
|
|
||||||
$params["{$alias}component"] = $component;
|
$params["{$alias}component"] = $component;
|
||||||
$params["{$alias}commentarea"] = $area;
|
$params["{$alias}commentarea"] = $area;
|
||||||
|
@ -102,15 +102,8 @@ class provider implements metadataprovider,
|
|||||||
if ($context->contextlevel != CONTEXT_MODULE) {
|
if ($context->contextlevel != CONTEXT_MODULE) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
$sql = "SELECT userid
|
comments_provider::get_users_in_context_from_sql($userlist, 'c', 'assignsubmission_comments', 'submission_comments',
|
||||||
FROM {comments}
|
$context->id);
|
||||||
WHERE contextid = :contextid
|
|
||||||
AND component = :component
|
|
||||||
AND commentarea = :commentarea";
|
|
||||||
$userlist->add_from_sql('userid', $sql, [
|
|
||||||
'contextid' => $context->id,
|
|
||||||
'component' => 'assignsubmission_comments',
|
|
||||||
'commentarea' => 'submission_comments']);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -162,22 +162,7 @@ class provider implements
|
|||||||
$userlist->add_from_sql('userid', $sql, $params);
|
$userlist->add_from_sql('userid', $sql, $params);
|
||||||
|
|
||||||
// Find users with comments.
|
// Find users with comments.
|
||||||
$sql = "SELECT dr.id
|
\core_comment\privacy\provider::get_users_in_context_from_sql($userlist, 'com', 'mod_data', 'database_entry', $context->id);
|
||||||
FROM {context} c
|
|
||||||
JOIN {course_modules} cm ON cm.id = c.instanceid AND c.contextlevel = :contextlevel
|
|
||||||
JOIN {modules} m ON m.id = cm.module AND m.name = :modname
|
|
||||||
JOIN {data} d ON d.id = cm.instance
|
|
||||||
JOIN {data_records} dr ON dr.dataid = d.id
|
|
||||||
WHERE c.id = :contextid";
|
|
||||||
|
|
||||||
$params = [
|
|
||||||
'modname' => 'data',
|
|
||||||
'contextid' => $context->id,
|
|
||||||
'contextlevel' => CONTEXT_MODULE,
|
|
||||||
];
|
|
||||||
|
|
||||||
\core_comment\privacy\provider::get_users_in_context_from_sql(
|
|
||||||
$userlist, 'com', 'mod_data', 'database_entry', $sql, $params);
|
|
||||||
|
|
||||||
// Find users with ratings.
|
// Find users with ratings.
|
||||||
$sql = "SELECT dr.id
|
$sql = "SELECT dr.id
|
||||||
|
@ -136,22 +136,8 @@ class provider implements
|
|||||||
$userlist->add_from_sql('userid', $sql, $params);
|
$userlist->add_from_sql('userid', $sql, $params);
|
||||||
|
|
||||||
// Find users with glossary comments.
|
// Find users with glossary comments.
|
||||||
$sql = "SELECT ge.id
|
\core_comment\privacy\provider::get_users_in_context_from_sql($userlist, 'com', 'mod_glossary', 'glossary_entry',
|
||||||
FROM {context} c
|
$context->id);
|
||||||
JOIN {course_modules} cm ON cm.id = c.instanceid AND c.contextlevel = :contextlevel
|
|
||||||
JOIN {modules} m ON m.id = cm.module AND m.name = :modname
|
|
||||||
JOIN {glossary} g ON g.id = cm.instance
|
|
||||||
JOIN {glossary_entries} ge ON ge.glossaryid = g.id
|
|
||||||
WHERE c.id = :contextid";
|
|
||||||
|
|
||||||
$params = [
|
|
||||||
'contextid' => $context->id,
|
|
||||||
'contextlevel' => CONTEXT_MODULE,
|
|
||||||
'modname' => 'glossary',
|
|
||||||
];
|
|
||||||
|
|
||||||
\core_comment\privacy\provider::get_users_in_context_from_sql(
|
|
||||||
$userlist, 'com', 'mod_glossary', 'glossary_entry', $sql, $params);
|
|
||||||
|
|
||||||
// Find users with glossary ratings.
|
// Find users with glossary ratings.
|
||||||
$sql = "SELECT ge.id
|
$sql = "SELECT ge.id
|
||||||
|
@ -184,17 +184,7 @@ class provider implements
|
|||||||
WHERE ctx.id = :contextid";
|
WHERE ctx.id = :contextid";
|
||||||
|
|
||||||
$userlist->add_from_sql('userid', $sql, $params);
|
$userlist->add_from_sql('userid', $sql, $params);
|
||||||
|
\core_comment\privacy\provider::get_users_in_context_from_sql($userlist, 'com', 'mod_wiki', 'wiki_page', $context->id);
|
||||||
$sql = "
|
|
||||||
SELECT p.id
|
|
||||||
FROM {modules} m
|
|
||||||
JOIN {course_modules} cm ON cm.module = m.id AND m.name = :modname
|
|
||||||
JOIN {context} ctx ON ctx.instanceid = cm.id AND ctx.contextlevel = :contextlevel
|
|
||||||
JOIN {wiki_subwikis} s ON cm.instance = s.wikiid
|
|
||||||
JOIN {wiki_pages} p ON p.subwikiid = s.id
|
|
||||||
WHERE ctx.id = :contextid";
|
|
||||||
|
|
||||||
\core_comment\privacy\provider::get_users_in_context_from_sql($userlist, 'com', 'mod_wiki', 'wiki_page', $sql, $params);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
Loading…
x
Reference in New Issue
Block a user