public static function from_xml($alias, $itnum, $xmlbuffer)
 {
     $xml = new SimpleXMLElement($xmlbuffer);
     $doc = ItemFactory::node($xml, '//xml');
     $compound_object = new CompoundObject($alias, $itnum);
     $compound_object->title = (string) $doc->title;
     $compound_object->file = (string) $doc->find;
     dmGetCompoundObjectInfo($alias, $itnum, $compound_xml_buffer);
     $compound_xml = new SimpleXMLElement($compound_xml_buffer);
     $type = $compound_xml->xpath('//cpd/type');
     if ((string) $type[0] == 'Monograph') {
         $pages = $compound_xml->xpath('//cpd/node/page');
     } else {
         $pages = $compound_xml->xpath('//cpd/page');
     }
     $num = 1;
     foreach ($pages as $page) {
         $subitnum = (string) $page->pageptr;
         $item = ItemFactory::create($alias, $subitnum, NULL);
         $compound_object->add_item($item, $num++);
     }
     return $compound_object;
 }
    public function testFromXml()
    {
        $buf = <<<XML
    <xml>
      <title>Adrian (Mich.)</title>
      <subjec>Adrian High School (Adrian, Mich.); schools</subjec>
      <descri>High School Building in Adrian (Mich.); c. 1920.</descri>
      <format>Document</format>
      <fullrs></fullrs>
      <find>9876.cpd</find>
      <dmaccess></dmaccess>
      <dmimage></dmimage>
      <dmcreated>2009-08-28</dmcreated>
      <dmmodified>2009-08-28</dmmodified>
      <dmoclcno></dmoclcno>
      <dmrecord>9876</dmrecord>
    </xml>
XML;
        $co = CompoundObject::from_xml('aaa111', '9876', $buf);
        $this->assertEquals('aaa111', $co->alias);
        $this->assertEquals('9876', $co->itnum);
        $this->assertEquals(2, $co->num_items());
    }
 public static function create_from_xml($alias, $itnum, $subitnum, $xmlbuffer)
 {
     $xml = new SimpleXMLElement($xmlbuffer);
     $xmlnode = ItemFactory::node($xml, '//xml');
     $format = (string) $xmlnode->format;
     $extension = Item::extension((string) $xmlnode->find);
     #some items have no format
     $is_image = array_search($extension, Item::image_extensions());
     if ($extension == 'cpd') {
         // $format == 'Document' ||  -- inconsistent
         $compound_object = CompoundObject::from_xml($alias, $itnum, $xmlbuffer);
         if ($subitnum != NULL) {
             return $compound_object->item_by_itnum($subitnum);
         } else {
             return $compound_object->first_item();
         }
     } else {
         if ($format == 'Image' || $is_image) {
             return Image::from_xml($alias, $itnum, $xmlbuffer);
         } else {
             return Item::from_xml($alias, $itnum, $xmlbuffer);
         }
     }
 }
 public function testShouldReturnNonuple()
 {
     $obj = new CompoundObject('/p12233', '1245');
     $level = $obj->monograph_level(array(1, 2, 3, 4, 5, 6, 7, 8, 9, 0));
     $this->assertEquals('1.2.3.4.5.6.7.8.9', $level);
 }
 public function testShouldGetListOfItems()
 {
     $obj = new CompoundObject('/p12233', '1245');
     $items = $obj->items();
     assertEquals(5, count($items));
 }