public static function get_user_contexts_with_script(userlist $userlist, \context $context, string $script,
                                                         int $instance = null) {
        if (!$context instanceof \context_user) {
            return;
        }

        $params = [
            'userid' => $context->instanceid,
            'script' => $script
        ];

        $whereinstance = '';

        if (!empty($instance)) {
            $params['instance'] = $instance;
            $whereinstance = ' AND k.instance = :instance';
        }

        $sql = "SELECT k.userid
                  FROM {user_private_key} k
                 WHERE k.script = :script
                       AND k.userid = :userid
                       {$whereinstance}";

        $userlist->add_from_sql('userid', $sql, $params);
    }
public static function get_user_contexts_with_script(userlist $userlist, \context $context, string $script,
                                                         int $instance = null) {
        if (!$context instanceof \context_user) {
            return;
        }

        $params = [
            'userid' => $context->instanceid,
            'script' => $script
        ];

        $whereinstance = '';

        if (!empty($instance)) {
            $params['instance'] = $instance;
            $whereinstance = ' AND k.instance = :instance';
        }

        $sql = "SELECT k.userid
                  FROM {user_private_key} k
                 WHERE k.script = :script
                       AND k.userid = :userid
                       {$whereinstance}";

        $userlist->add_from_sql('userid', $sql, $params);
    }
public static function get_user_contexts_with_script ( userlist $ userlist , \ context $ context , string $ script , int $ instance = null ) { if ( ! $ context instanceof \ context_user ) { return ; } $ params = [ 'userid' => $ context -> instanceid , 'script' => $ script ] ; $ whereinstance = '' ; if ( ! empty ( $ instance ) ) { $ params [ 'instance' ] = $ instance ; $ whereinstance = ' AND k.instance = :instance' ; } $ sql = "SELECT k.userid
                  FROM {user_private_key} k
                 WHERE k.script = :script
                       AND k.userid = :userid
                       {$whereinstance}" ; $ userlist -> add_from_sql ( 'userid' , $ sql , $ params ) ; }
Get the list of users within a specific context for this system.

@param userlist $userlist The userlist containing the list of users who have data in this context/plugin combination.
@param context $context The context.
@param string $script The unique target identifier.
@param int $instance The instance ID.
Get the list of users within a specific context for this system .