Filters for listCollections?

Hi,
The documentation doesn’t talk about filters on collections (or in general for that matter)?
https://getcockpit.com/documentation/api/collections

I am trying to build a wiki using Cockpit (thanks @artur for sharing this project). I want to listCollections but only those matching Group: wiki (or any other alternative).

Possible or not?
Thanks!

It’s not possible by default, but you can write your own api endpoint and return the filterered collections. Create a file in /cockpit/config/api/collections/myOwnEndpoint.php

$collections = $this->module('collections')->getCollectionsInGroup();
// check the array
return $collections;

That’s the original function:

@raffaelj Thank you so much for replying so fast! I was looking at this method too (in RestApi.php) and I was wondering if it was possible to use the getCollectionsInGroup (as user)?

I’m not quite sure, what you mean. The function getCollectionsInGroup() returns only collections with the user group permissions. But if you don’t care about user groups, than do

<?php
$collections = $this->module('collections')->collections();
$filtered = [];
foreach($collections as $collection) {
    if (isset($collection['group'] && $collection['group'] == 'wiki') {
        $filtered[] = $collection;
    }
}

or something similar.

1 Like