Skip to content

Commit

Permalink
MDL-63495 comment: Added provider::get_users_in_context_from_sql
Browse files Browse the repository at this point in the history
This issue is part of the MDL-62560 Epic.
  • Loading branch information
mickhawkins authored and David Monllao committed Oct 22, 2018
1 parent d744b15 commit cea5338
Showing 1 changed file with 26 additions and 0 deletions.
26 changes: 26 additions & 0 deletions comment/classes/privacy/provider.php
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@

use \core_privacy\local\metadata\collection;
use \core_privacy\local\request\transform;
use \core_privacy\local\request\userlist;

/**
* Privacy class for requesting user data.
Expand Down Expand Up @@ -226,4 +227,29 @@ public static function delete_comments_for_users(\core_privacy\local\request\app
$select = "contextid = :contextid AND component = :component {$areasql} {$itemsql} AND userid {$insql}";
$DB->delete_records_select('comments', $select, $params);
}

/**
* Add the list of users who have commented in the specified constraints.
*
* @param userlist $userlist The userlist to add the users to.
* @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 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) {
// Comment authors.
$sql = "SELECT {$alias}.userid
FROM {comments} {$alias}
WHERE {$alias}.component = :{$alias}component
AND {$alias}.commentarea = :{$alias}commentarea
AND {$alias}.itemid IN ({$insql})";

$params["{$alias}component"] = $component;
$params["{$alias}commentarea"] = $area;

$userlist->add_from_sql('userid', $sql, $params);
}
}

0 comments on commit cea5338

Please sign in to comment.