Fetching lists and their content

The OCListProvider is a class dedicated to fetching Lists and their content.

Introduction

This provider will use the Everyware "Document cache" to minimize the amount of requests against Open Content.

To request content from the List (i.g. articles) is a bit tricker though. There might be alot of reasons why a "list article" can't be fetched and the only way to find this out is to actually request them. That is why the list content is fetched through a search query and will therefore use the "Response cache" instead.

Usage

Use the OcAPI instance or a \Everyware\Contracts\OcApiProvider interface to instantiate a new provider:

use \Everyware\Helpers\OCListProvider;

$provider = new OCListProvider(new OcAPI());

Request the List using a UUID. This will result in the new improved \Everyware\Contracts\OcObject where you have acess the entire object.

try {
    
    $ocObject = $provider->getList($uuid);
    
    $listProperties = $ocObject->getProperties();
    
    $name = $listProperties['Name'];
    
} catch(ListNotFoundException $exception) {
    // Requested List could not be found in Open Content
}

You can also request certain properties from the List.

try {
    
    $listProperties = $provider->getListProperties($uuid, ['Name']);
    
    $name = $listProperties['Name'];
    
} catch(ListNotFoundException $exception) {
    // Requested List could not be found in Open Content
}

To request the accessible content from the List i.e. uuids of articles

try {
    
    // Fetch uuids throught the relational property "Articles"
    $uuids = $provider->getRelatedUuids($uuid, 'Articles');
    
} catch(ListNotFoundException $exception) {
    // Requested List could not be found in Open Content
}

You can further filter your relations with a OC query. This query will only affect the relations and not the List itself.

try {   
    
    // Fetch uuids throught the relational property "Articles" and only fetch articles from 10 days back.
    $uuids = $provider->getRelatedUuids($uuid, 'Articles', 'Pubdate: [NOW/DAY-10DAY TO NOW/DAY]');
    
} catch(ListNotFoundException $exception) {
    // Requested List could not be found in Open Content
}

Last updated