mirror of
https://github.com/moodle/moodle.git
synced 2025-08-08 10:26:40 +02:00
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:
parent
e3ddf1e324
commit
9674218469
1 changed files with 26 additions and 0 deletions
|
@ -25,6 +25,7 @@
|
||||||
namespace core_rating\privacy;
|
namespace core_rating\privacy;
|
||||||
|
|
||||||
use \core_privacy\local\metadata\collection;
|
use \core_privacy\local\metadata\collection;
|
||||||
|
use \core_privacy\local\request\userlist;
|
||||||
|
|
||||||
defined('MOODLE_INTERNAL') || die();
|
defined('MOODLE_INTERNAL') || die();
|
||||||
|
|
||||||
|
@ -214,4 +215,29 @@ class provider implements
|
||||||
'contextid = :contextid AND component = :component AND ratingarea = :ratingarea AND itemid ' . $itemidstest,
|
'contextid = :contextid AND component = :component AND ratingarea = :ratingarea AND itemid ' . $itemidstest,
|
||||||
$params);
|
$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);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue