/**
  * Populate a digital object from a resource pointed to by a URI
  * This is for, eg. importing encoded digital objects from XML
  *
  * @param string  $uri  URI pointing to the resource
  * @return boolean  success or failure
  */
 public function importFromURI($uri, $options = array())
 {
     // Parse URL into components and get file/base name
     $uriComponents = parse_url($uri);
     // Initialize web browser
     $browser = new sfWebBrowser(array(), null, array('Timeout' => 10));
     // Add asset to digital object assets array
     if (true !== $browser->get($uri)->responseIsError() && 0 < strlen($filename = basename($uriComponents['path']))) {
         $asset = new QubitAsset($uri, $browser->getResponseText());
         $this->assets[] = $asset;
     } else {
         throw new sfException('Encountered error fetching external resource.');
     }
     // Set digital object as external URI
     $this->usageId = QubitTerm::EXTERNAL_URI_ID;
     // Save filestream temporary, because sfImageMagickAdapter does not support load data from streams
     $this->localPath = Qubit::saveTemporaryFile($filename, $asset->getContents());
     $this->name = $filename;
     $this->path = $uri;
     $this->checksum = $asset->getChecksum();
     $this->checksumType = $asset->getChecksumAlgorithm();
     $this->byteSize = strlen($browser->getResponseText());
     $this->setMimeAndMediaType();
 }
 /**
  * Update digital object properties, or upload new digital object derivatives.
  *
  * @return DigitalObjectEditAction this action
  */
 public function processForm()
 {
     // Set property 'displayAsCompound'
     $this->resource->setDisplayAsCompoundObject($this->form->getValue('displayAsCompound'));
     // Update media type
     $this->resource->mediaTypeId = $this->form->getValue('mediaType');
     // Process master rights component
     $this->rightEditComponent->processForm();
     // Process reference/thumbnail rights components
     foreach ($this->representations as $usageId => $representation) {
         $this["rightEditComponent_{$usageId}"]->processForm();
         $representation->save();
     }
     // Upload new representations
     $uploadedFiles = array();
     foreach ($this->representations as $usageId => $representation) {
         if (null !== ($uf = $this->form->getValue("repFile_{$usageId}"))) {
             $uploadedFiles[$usageId] = $uf;
         }
     }
     foreach ($uploadedFiles as $usageId => $uploadFile) {
         $content = file_get_contents($uploadFile->getTempName());
         if (QubitDigitalObject::isImageFile($uploadFile->getOriginalName())) {
             $tmpFile = Qubit::saveTemporaryFile($uploadFile->getOriginalName(), $content);
             if (QubitTerm::REFERENCE_ID == $usageId) {
                 $maxwidth = sfConfig::get('app_reference_image_maxwidth') ? sfConfig::get('app_reference_image_maxwidth') : 480;
                 $maxheight = null;
             } else {
                 if (QubitTerm::THUMBNAIL_ID == $usageId) {
                     $maxwidth = 100;
                     $maxheight = 100;
                 }
             }
             $content = QubitDigitalObject::resizeImage($tmpFile, $maxwidth, $maxheight);
             @unlink($tmpFile);
         }
         $representation = new QubitDigitalObject();
         $representation->usageId = $usageId;
         $representation->assets[] = new QubitAsset($uploadFile->getOriginalName(), $content);
         $representation->parentId = $this->resource->id;
         $representation->createDerivatives = false;
         $representation->save();
     }
     // Generate new reference
     if (null != $this->form->getValue('generateDerivative_' . QubitTerm::REFERENCE_ID)) {
         $this->resource->createReferenceImage();
     }
     // Generate new thumb
     if (null != $this->form->getValue('generateDerivative_' . QubitTerm::THUMBNAIL_ID)) {
         $this->resource->createThumbnail();
     }
 }