/**
  * Create an info and digital object tree for multi-page assets
  *
  * For digital objects that describe a multi-page digital asset (e.g. a
  * multi-page tif image), create a derived asset for each page, create a child
  * information object and linked child digital object and move the derived
  * asset to the appropriate directory for the new (child) info object
  *
  * NOTE: Requires the Imagemagick library for creating derivative assets
  *
  * @return QubitDigitalObject this object
  */
 public function createCompoundChildren()
 {
     // Bail out if the imagemagick library is not installed
     if (false === self::hasImageMagick()) {
         return $this;
     }
     $pages = $this->explodeMultiPageAsset();
     foreach ($pages as $i => $filepath) {
         // Create a new information object
         $newInfoObject = new QubitInformationObject();
         $newInfoObject->parentId = $this->getInformationObject()->id;
         $newInfoObject->setTitle($this->getInformationObject()->getTitle() . ' (' . ($i + 1) . ')');
         $newInfoObject->save();
         // Create and link a new digital object
         $newDigiObject = new QubitDigitalObject();
         $newDigiObject->parentId = $this->id;
         $newDigiObject->setInformationObjectId($newInfoObject->id);
         $newDigiObject->save();
         // Derive new file path based on newInfoObject
         $assetPath = $newDigiObject->getAssetPath();
         $createPath = '';
         foreach (explode('/', $assetPath) as $d) {
             $createPath .= '/' . $d;
             if (!is_dir(sfConfig::get('sf_web_dir') . $createPath)) {
                 mkdir(sfConfig::get('sf_web_dir') . $createPath, 0755);
             }
             chmod(sfConfig::get('sf_web_dir') . $createPath, 0755);
         }
         // Derive new name for file based on original file name + newDigitalObject
         // id
         $filename = basename($filepath);
         $newFilepath = sfConfig::get('sf_web_dir') . $assetPath . '/' . $filename;
         // Move asset to new name and path
         rename($filepath, $newFilepath);
         chmod($newFilepath, 0644);
         // Save new file information
         $newDigiObject->setPath("{$assetPath}/");
         $newDigiObject->setName($filename);
         $newDigiObject->setByteSize(filesize($newFilepath));
         $newDigiObject->usageId = QubitTerm::MASTER_ID;
         $newDigiObject->setMimeType(QubitDigitalObject::deriveMimeType($filename));
         $newDigiObject->mediaTypeId = $this->mediaTypeId;
         $newDigiObject->setPageCount();
         $newDigiObject->setSequence($i + 1);
         $newDigiObject->save();
         // And finally create reference and thumb images for child asssets
         $newDigiObject->createRepresentations($newDigiObject->getUsageId(), $connection);
     }
     return $this;
 }