public static function delete_favourites_for_user(approved_contextlist $contextlist, string $component, string $itemtype,
                                                      int $itemid = 0) {
        global $DB;

        $userid = $contextlist->get_user()->id;

        list($insql, $inparams) = $DB->get_in_or_equal($contextlist->get_contextids(), SQL_PARAMS_NAMED);

        $params = [
            'userid' => $userid,
            'component' => $component,
            'itemtype' => $itemtype,
        ];
        $params += $inparams;

        $select = "userid = :userid AND component = :component AND itemtype =:itemtype AND contextid $insql";

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

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