07: COMPOUND OBJECTS — I

The dreaded Bandersnatch of CONTENTdm API coding is compound objects, because of the complexity of the data types that can be compound objects.

API: dmGetCompoundObjectInfo

INVOKED: <server address>/dmwebservices/index.php?q=dmGetCompoundObjectInfo/<collection>/<pointer>/xml

EXAMPLE: https://server16614.contentdm.oclc.org/dmwebservices/index.php?q=dmGetCompoundObjectInfo/p16614coll12/2/xml

The first difficulty in working with compound objects is the different encoding schema. Consider a simple postcard:

https://server16614.contentdm.oclc.org/dmwebservices/index.php?q=dmGetCompoundObjectInfo/p16614coll12/2/xml

<cpd>
   <type>Postcard</type>
      <page>
         <pagetitle>LL1</pagetitle>
         <pagefile>1.jp2</pagefile>
         <pageptr>0</pageptr>
      </page>
      <page>
         <pagetitle>LL1b</pagetitle>
         <pagefile>2.jp2</pagefile>
         <pageptr>1</pageptr>
      </page>
</cpd>

sharing the same structure as a Document type:

https://server16614.contentdm.oclc.org/dmwebservices/index.php?q=dmGetCompoundObjectInfo/p16614coll23/232/xml

<cpd>
   <type>Document</type>
   <page>
      <pagetitle>Front Cover</pagetitle>
      <pagefile>228.jp2</pagefile>
      <pageptr>227</pageptr>
   </page>
   <page>
      <pagetitle>AIFF File</pagetitle>
      <pagefile>229.aif</pagefile>
      <pageptr>228</pageptr>
   </page>
   <page>
      <pagetitle>MIDI File</pagetitle>
      <pagefile>230.mid</pagefile>
      <pageptr>229</pageptr>
   </page>
   <page>
      <pagetitle>MP3 File</pagetitle>
      <pagefile>231.mp3</pagefile>
      <pageptr>230</pageptr>
   </page>
   <page>
      <pagetitle>Whole Score</pagetitle>
      <pagefile>232.pdf</pagefile>
      <pageptr>231</pageptr>
  </page>
</cpd>

https://server16614.contentdm.oclc.org/dmwebservices/index.php?q=dmGetCompoundObjectInfo/isl/40168/xml

By contrast, the Monograph type adds <node> and <nodetitle> elements, which allow chapters, etc.

<cpd>
   <type>Monograph</type>
   <node>
      <nodetitle>
         A map for a maze: Illinois' system of funding residential schools: a report to the General Assembly
      </nodetitle>
      <page>
         <pagetitle>Font Cover</pagetitle>
         <pagefile>49815.jp2</pagefile>
         <pageptr>39878</pageptr>
      </page>
      <page>
         <pagetitle>Title Page</pagetitle>
         <pagefile>49816.jp2</pagefile>
         <pageptr>39879</pageptr>
      </page>

<em>Etc.</em> 

getCompoundObjects.php

This program will get the various and sundry bits of the XML record, no matter its structure. The important bit that we’re grabbing is the page pointer, which will allow us to get the thumbnail or full sized image (or digital object) pointed to by the record.

<?php

$xmlData = file_get_contents('https://server16614.contentdm.oclc.org/dmwebservices/index.php?q=dmGetCompoundObjectInfo/isl/40168/xml');

// Create the document object

$xml = simplexml_load_string($xmlData);

$cpd = $xml->{"type"};
$title = $xml->{"node"}->{"nodetitle"};
$pointer = $xml->{"node"}->{"page"}[0]->{"pageptr"};

$result = array();

// Get the <page> nodes and loop them

if ($cpd == "Monograph") {
        foreach ($xml->xpath('//node') as $record) {
                foreach ($record->xpath('//page') as $page) {
                        $result[] = array(
                                'nodeTitle' => (string) $record->nodetitle,
                                'pageTitle' => (string) $page->pagetitle,
                                'pageFile' => (string) $page->pagefile,
                                'pagePtr' => (string) $page->pageptr
                        );
                }
        }
}
else {
foreach ($xml->xpath('//page') as $record) {
                $result[] = array(
                        'nodeTitle' => "NONE",
                        'pageTitle' => (string) $record->pagetitle,
                        'pageFile' => (string) $record->pagefile,
                        'pagePtr' => (string) $record->pageptr
                );
        }
}

// $resultCount is the number of elements in the $result array; the first element is result[0]

$resultCount = count($result) - 1;

$oldNodeTitle = "";

for ($i=0;$i<=$resultCount;$i++) {
        $nodeTitleStr = $result[$i]["nodeTitle"];
        $pageTitleStr = $result[$i]["pageTitle"];
        $jpegStr = $result[$i]["pageFile"];
        $pointer = $result[$i]["pagePtr"];
        if ($oldNodeTitle != $nodeTitleStr) { echo "NODE TITLE: $nodeTitleStr\n"; }
        $oldNodeTitle = $nodeTitleStr;
        echo "$pageTitleStr $jpegStr $pointer\n";
}

?>