MDL-63495 core_rating: Add helper to fetch users in context

This issue is a part of the MDL-62560 Epic.
This commit is contained in:
Andrew Nicols 2018-09-03 08:57:45 +08:00
parent bf347c4d2b
commit e2ca4224f2

View File

@ -25,6 +25,7 @@
namespace core_rating\privacy;
use \core_privacy\local\metadata\collection;
use \core_privacy\local\request\userlist;
defined('MOODLE_INTERNAL') || die();
@ -214,4 +215,29 @@ class provider implements
'contextid = :contextid AND component = :component AND ratingarea = :ratingarea AND itemid ' . $itemidstest,
$params);
}
/**
* Add the list of users who have rated in the specified constraints.
*
* @param userlist $userlist The userlist to add the users to.
* @param string $alias An alias prefix to use for rating selects to avoid interference with your own sql.
* @param string $component The component to check.
* @param string $area The rating 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) {
// Discussion authors.
$sql = "SELECT {$alias}.userid
FROM {rating} {$alias}
WHERE {$alias}.component = :{$alias}component
AND {$alias}.ratingarea = :{$alias}ratingarea
AND {$alias}.itemid IN ({$insql})";
$params["{$alias}component"] = $component;
$params["{$alias}ratingarea"] = $area;
$userlist->add_from_sql('userid', $sql, $params);
}
}