The Basics

The PHP client has been tested with PHP 5.3 and 5.4.

Setting up

The first thing to do is to load the PHP Portal Client into your webpage. The client is a directory-tree of .php-files which can be found in the src folder of the project’s Github repository.

<?php
set_include_path(get_include_path() . PATH_SEPARATOR . __DIR__ .
                 "/../src"); // <-- Relative path to Portal Client

require_once("CaseSensitiveAutoload.php");

spl_autoload_extensions(".php");
spl_autoload_register("CaseSensitiveAutoload");

use CHAOS\Portal\Client\PortalClient;
?>

The above code sets up the include path so that the client will be automatically loaded. Just copy and paste the code into the script where you will be using the client. All you need to worry about is the "/../src" which should be the path from your current PHP file to the src directory of the client.

Having loaded the client, we can now instantiate it:

<?php
$servicePath = "http://api.chaos-systems.com/";
$clientGUID = "B9CBFFDD-3F73-48FC-9D5D-3802FBAD4CBD";
$accessPointGUID = "7A06C4FF-D15A-48D9-A908-088F9796AF28";

$client = new PortalClient($servicePath, $clientGUID);

echo "SessionGUID: " . $client->SessionGUID() . "<br>";
?>
  • servicePath is the URL at which your CHAOS.Portal is set up.
  • clientGUID should be unique for each application, any GUID can be used.
  • accessPointGUID is an ID that authenticates us to use the CHAOS.Portal. This should be given to you by your friendly neighbourhood CHAOS.Portal administrator.

Instantiating the PortalClient this way automatically sets up a session. When the session has been set up we are ready to use the CHAOS.Portal.

Searching

The easiest way to retrieve some objects from a CHAOS database is to search. This is done with the method PortalClient::Object()::GetBySearch()

<?php
$fields = array(
  "5906a41b-feae-48db-bfb7-714b3e105396",
  "00000000-0000-0000-0000-000063c30000",
  "00000000-0000-0000-0000-000065c30000"
);

$serviceResult = $client->Object()->GetSearchSchemas(
  "test",       // search string
  $fields,      // fields to search
  "da",         // language code
  $accessPointGUID,
  0,            // pageIndex
  10,           // pageSize
  true,         // includeMetadata
  true,         // includeFiles
  true          // includeObjectRelations
);
$objects = $serviceResult->MCM()->Results();

echo "Got " . $serviceResult->MCM()->Count() . "/" . $serviceResult->MCM()->TotalCount() . " objects";
?>
fields
are search fields to use in the Solr index. The long GUIDs refers to metadata schemas. So what we’re doing here is searching the object metadata for the word ‘mut’.
pageIndex
is the starting page of the search results, where the page size is determined by pageSize
pageSize
is the number of results you want retrieve
includeFiles
include files attached to objects in the results.
includeMetadata
include metadata attached to objects in the results.
includeObjectRelations
include object relations for an object in the results.

When the search results has been recieved from the CHAOS.Portal, the callback is invoked with serviceResult as its argument. The serviceResult has a number of fields, of which MCM() is the most important and the one we are going to be using.

PortalClient::Object()::GetBySearch() returns a serviceResult. The serviceResult has a number of fields, of which MCM() is the most important and the one we are going to be using.

serviceResult->MCM()->Results() The result of the CHAOS query: A list of objects (URL, metadata etc.). An explaination of these objects is found in the next section. serviceResult->MCM()->Count() The number of objects on this page, i.e. the number of objects available to you in the serviceResult->MCM()->Results(). If you want all the objects from a query at once you will have to increase the pageSize or go through all pages via pageIndex. serviceResult->MCM()->TotalCount() The number of objects that matched the query

Now the resulting objects are quite big, so let’s only grab one, by setting pageSize to 1:

<?php
// Retrieve objects
$serviceResult = $client->Object()->GetSearchSchemas(
  "test",       // search string
  array("5906a41b-feae-48db-bfb7-714b3e105396"),      // fields to search
  "da",         // language code
  $accessPointGUID,
  0,            // pageIndex
  1,           // pageSize
  true,         // includeMetadata
  true,         // includeFiles
  true          // includeObjectRelations
);
$objects = $serviceResult->MCM()->Results();

var_dump($objects[0]);
?>

The results you get should look something like this: (I have Xdebug installed so it might look a little different on your setup)

object(stdClass)[47]
  public 'GUID' => string '00000000-0000-0000-0000-000064faff15' (length=36)
  public 'ObjectTypeID' => int 36
  public 'DateCreated' => int -2147483648
  public 'Metadatas' =>
    array (size=2)
      0 =>
        object(stdClass)[48]
          public 'GUID' => string '72164e6d-c9ec-f145-8907-b187ec108fe0' (length=36)
          public 'EditingUserGUID' => string '80d15fb4-c1fb-9445-89c6-1a398cbd85e5' (length=36)
          public 'LanguageCode' => string 'da' (length=2)
          public 'MetadataSchemaGUID' => string '5906a41b-feae-48db-bfb7-714b3e105396' (length=36)
          public 'RevisionID' => int 1
          public 'MetadataXML' => string '<DKA xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://www.danskkulturarv.dk/DKA2.xsd" xmlns:oa="http://www.openarchives.org/OAI/2.0/" xmlns:ese="http://www.europeana.eu/schemas/ese/" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:dcterms="http://purl.org/dc/terms/" xsi:schemaLocation="http://www.danskkulturarv.dk/DKA2.xsd ../../Base/schemas/DKA2.xsd"><Title>Livets gang i Lidenlund</Title><Abstract /><Description><div xmlns="http://www.w3.org/1999/xhtml"><p>Politibetjent Strøhmer på p'... (length=1592)
          public 'DateCreated' => int -2147483648
          public 'FullName' => string 'CHAOS.MCM.Data.DTO.Metadata' (length=27)
      1 =>
        object(stdClass)[49]
          public 'GUID' => string 'c7d38f18-39cb-9a49-b3be-46c1be735f1c' (length=36)
          public 'EditingUserGUID' => string '80d15fb4-c1fb-9445-89c6-1a398cbd85e5' (length=36)
          public 'LanguageCode' => string 'da' (length=2)
          public 'MetadataSchemaGUID' => string '00000000-0000-0000-0000-000063c30000' (length=36)
          public 'RevisionID' => int 1
          public 'MetadataXML' => string '<DKA><Title>Livets gang i Lidenlund</Title><Abstract>Politibetjent Strøhmer på politigården.</Abstract><Description /><Organization>Det Kongelige Bibliotek</Organization><Type /><CreatedDate>2009-12-17T00:00:00</CreatedDate><FirstPublishedDate>2009-12-17T00:00:00</FirstPublishedDate><Identifier>102188</Identifier><Contributor /><Creator><Person Name="Gantriis, Henning (1918-1989) bladtegner" Role="Creator" /></Creator><TechnicalComment /><Location /><RightsDescription>Billedet er beskyttet af loven om op'... (length=559)
          public 'DateCreated' => int -2147483648
          public 'FullName' => string 'CHAOS.MCM.Data.DTO.Metadata' (length=27)
  public 'Files' =>
    array (size=2)
      0 =>
        object(stdClass)[50]
          public 'ID' => int 501377
          public 'ParentID' => null
          public 'Filename' => string 'db_henning_gantriis_01384.jpg' (length=29)
          public 'OriginalFilename' => string 'db_henning_gantriis_01384.jpg' (length=29)
          public 'Token' => string 'HTTP Download' (length=13)
          public 'URL' => string 'http://www.kb.dk/imageService//online_master_arkiv_2/non-archival/Images/BLADTE_VANDMAERKER//db_henning_gantriis_01384.jpg' (length=122)
          public 'FormatID' => int 42
          public 'Format' => string 'KB Source JPEG ' (length=15)
          public 'FormatCategory' => string 'Image Source' (length=12)
          public 'FormatType' => string 'Image' (length=5)
          public 'FullName' => string 'CHAOS.MCM.Data.DTO.FileInfo' (length=27)
      1 =>
        object(stdClass)[51]
          public 'ID' => int 3550788
          public 'ParentID' => null
          public 'Filename' => string 'db_henning_gantriis_01384.jpg' (length=29)
          public 'OriginalFilename' => string 'db_henning_gantriis_01384.jpg' (length=29)
          public 'Token' => string 'HTTP Download' (length=13)
          public 'URL' => string 'http://www.kb.dk/imageService/w150/online_master_arkiv_2/non-archival/Images/BLADTE_VANDMAERKER/db_henning_gantriis_01384.jpg' (length=125)
          public 'FormatID' => int 10
          public 'Format' => string 'SMK asset thumbnail' (length=19)
          public 'FormatCategory' => string 'SMK asset thumbnail' (length=19)
          public 'FormatType' => string 'Image' (length=5)
          public 'FullName' => string 'CHAOS.MCM.Data.DTO.FileInfo' (length=27)
  public 'ObjectRelations' =>
    array (size=0)
      empty
  public 'FullName' => string 'CHAOS.MCM.Data.DTO.Object' (length=25)

What you get from a CHAOS query is an array of objects like the one above. Each object has a GUID and an ObjectTypeID. Furthermore we can see that each object has a list of files and a list of metadata.

Try turning off and on includeFiles and includeMetadata and changing pageSize and pageIndex in order to familiarize yourself with the interface. Unfortunately this object has no relations.

You are now ready to head on to the next section, which will teach you how to use files and metadata.