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 $component The component 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 array $params The params required for the insql.
|
||||
*/
|
||||
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.
|
||||
$sql = "SELECT {$alias}.userid
|
||||
FROM {comments} {$alias}
|
||||
WHERE {$alias}.component = :{$alias}component
|
||||
AND {$alias}.commentarea = :{$alias}commentarea
|
||||
AND {$alias}.itemid IN ({$insql})";
|
||||
$contextsql $insql";
|
||||
|
||||
$params["{$alias}component"] = $component;
|
||||
$params["{$alias}commentarea"] = $area;
|
||||
|
@ -102,15 +102,8 @@ class provider implements metadataprovider,
|
||||
if ($context->contextlevel != CONTEXT_MODULE) {
|
||||
return;
|
||||
}
|
||||
$sql = "SELECT userid
|
||||
FROM {comments}
|
||||
WHERE contextid = :contextid
|
||||
AND component = :component
|
||||
AND commentarea = :commentarea";
|
||||
$userlist->add_from_sql('userid', $sql, [
|
||||
'contextid' => $context->id,
|
||||
'component' => 'assignsubmission_comments',
|
||||
'commentarea' => 'submission_comments']);
|
||||
comments_provider::get_users_in_context_from_sql($userlist, 'c', 'assignsubmission_comments', 'submission_comments',
|
||||
$context->id);
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -162,22 +162,7 @@ class provider implements
|
||||
$userlist->add_from_sql('userid', $sql, $params);
|
||||
|
||||
// Find users with comments.
|
||||
$sql = "SELECT dr.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);
|
||||
\core_comment\privacy\provider::get_users_in_context_from_sql($userlist, 'com', 'mod_data', 'database_entry', $context->id);
|
||||
|
||||
// Find users with ratings.
|
||||
$sql = "SELECT dr.id
|
||||
|
@ -136,22 +136,8 @@ class provider implements
|
||||
$userlist->add_from_sql('userid', $sql, $params);
|
||||
|
||||
// Find users with glossary comments.
|
||||
$sql = "SELECT ge.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 {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);
|
||||
\core_comment\privacy\provider::get_users_in_context_from_sql($userlist, 'com', 'mod_glossary', 'glossary_entry',
|
||||
$context->id);
|
||||
|
||||
// Find users with glossary ratings.
|
||||
$sql = "SELECT ge.id
|
||||
|
@ -184,17 +184,7 @@ class provider implements
|
||||
WHERE ctx.id = :contextid";
|
||||
|
||||
$userlist->add_from_sql('userid', $sql, $params);
|
||||
|
||||
$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);
|
||||
\core_comment\privacy\provider::get_users_in_context_from_sql($userlist, 'com', 'mod_wiki', 'wiki_page', $context->id);
|
||||
}
|
||||
|
||||
/**
|
||||
|
Loading…
x
Reference in New Issue
Block a user