public static function delete_favourites_for_userlist(\core_privacy\local\request\approved_userlist $userlist,
                                                          string $itemtype, int $itemid = 0) {
        global $DB;

        $userids = $userlist->get_userids();

        if (empty($userids)) {
            return;
        }

        $context = $userlist->get_context();
        list($usersql, $userparams) = $DB->get_in_or_equal($userids, SQL_PARAMS_NAMED);

        $params = [
            'component' => $userlist->get_component(),
            'itemtype' => $itemtype,
            'contextid' => $context->id
        ];

        $params += $userparams;
        $select = "component = :component AND itemtype = :itemtype AND contextid = :contextid AND userid $usersql";

        if (!empty($itemid)) {
            $select .= " AND itemid = :itemid";
            $params['itemid'] = $itemid;
        }

        $DB->delete_records_select('favourite', $select, $params);
    }