public static function delete_favourites_for_all_users(\context $context, string $component, string $itemtype,
                                                           int $itemid = 0) {
        global $DB;

        $params = [
            'component' => $component,
            'itemtype' => $itemtype,
            'contextid' => $context->id
        ];

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

        if (!empty($itemid)) {
            $select .= " AND itemid = :itemid";
            $params['itemid'] = $itemid;
        }
        $DB->delete_records_select('favourite', $select, $params);
    }
public static function delete_favourites_for_all_users(\context $context, string $component, string $itemtype,
                                                           int $itemid = 0) {
        global $DB;

        $params = [
            'component' => $component,
            'itemtype' => $itemtype,
            'contextid' => $context->id
        ];

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

        if (!empty($itemid)) {
            $select .= " AND itemid = :itemid";
            $params['itemid'] = $itemid;
        }
        $DB->delete_records_select('favourite', $select, $params);
    }
public static function delete_favourites_for_all_users ( \ context $ context , string $ component , string $ itemtype , int $ itemid = 0 ) { global $ DB ; $ params = [ 'component' => $ component , 'itemtype' => $ itemtype , 'contextid' => $ context -> id ] ; $ select = "component = :component AND itemtype =:itemtype AND contextid = :contextid" ; if ( ! empty ( $ itemid ) ) { $ select .= " AND itemid = :itemid" ; $ params [ 'itemid' ] = $ itemid ; } $ DB -> delete_records_select ( 'favourite' , $ select , $ params ) ; }
Delete all favourites for all users in the specified contexts, and component area.

@param \context $context The context to which deletion is scoped.
@param string $component The favourite's component name.
@param string $itemtype The favourite's itemtype.
@param int $itemid Optional itemid associated with component.
@throws \dml_exception if any errors are encountered during deletion.
Delete all favourites for all users in the specified contexts and component area .