protected function addDigitalObject($informationObject, $filepath, $conn)
 {
     // read file contents
     if (false === ($content = file_get_contents($filepath))) {
         $this->log("Couldn't read file '{$filepath}'");
         return;
     }
     $filename = basename($filepath);
     $this->log("Loading '{$filename}'");
     // Create digital object
     $do = new QubitDigitalObject();
     $do->informationObject = $informationObject;
     $do->usageId = QubitTerm::MASTER_ID;
     $do->assets[] = new QubitAsset($filename, $content);
     $do->save($conn);
     self::$count++;
 }
 public function processForm()
 {
     $tmpPath = sfConfig::get('sf_upload_dir') . '/tmp';
     // Upload files
     $i = 0;
     foreach ($this->form->getValue('files') as $file) {
         if (0 == strlen($file['infoObjectTitle'] || 0 == strlen($file['tmpName']))) {
             continue;
         }
         $i++;
         // Create an information object for this digital object
         $informationObject = new QubitInformationObject();
         $informationObject->parentId = $this->resource->id;
         if (0 < strlen($title = $file['infoObjectTitle'])) {
             $informationObject->title = $title;
         }
         if (0 != intval($levelOfDescriptionId = $this->form->getValue('level_of_description_id'))) {
             $informationObject->levelOfDescriptionId = $levelOfDescriptionId;
         }
         $informationObject->setStatus(array('typeId' => QubitTerm::STATUS_TYPE_PUBLICATION_ID, 'statusId' => sfConfig::get('app_defaultPubStatus')));
         // Save description
         $informationObject->save();
         if (file_exists("{$tmpPath}/{$file['tmpName']}")) {
             // Upload asset and create digital object
             $digitalObject = new QubitDigitalObject();
             $digitalObject->informationObject = $informationObject;
             $digitalObject->usageId = QubitTerm::MASTER_ID;
             $digitalObject->assets[] = new QubitAsset($file['name'], file_get_contents("{$tmpPath}/{$file['tmpName']}"));
             $digitalObject->save();
         }
         $thumbnailIsGeneric = (bool) strstr($file['thumb'], 'generic-icons');
         // Clean up temp files
         if (file_exists("{$tmpPath}/{$file['tmpName']}")) {
             unlink("{$tmpPath}/{$file['tmpName']}");
         }
         if (!$thumbnailIsGeneric && file_exists("{$tmpPath}/{$file['thumb']}")) {
             unlink("{$tmpPath}/{$file['thumb']}");
         }
     }
     $this->redirect(array($this->resource, 'module' => 'informationobject'));
 }
 /**
  * Create video derivatives (either flv movie or thumbnail)
  *
  * @param integer  $usageId  usage type id
  * @return QubitDigitalObject derivative object
  */
 public function createVideoDerivative($usageId, $connection = null)
 {
     // Build new filename and path
     $originalFullPath = $this->getAbsolutePath();
     list($originalNameNoExtension) = explode('.', $this->getName());
     switch ($usageId) {
         case QubitTerm::REFERENCE_ID:
             $derivativeName = $originalNameNoExtension . '_' . $usageId . '.flv';
             $derivativeFullPath = sfConfig::get('sf_web_dir') . $this->getPath() . $derivativeName;
             self::convertVideoToFlash($originalFullPath, $derivativeFullPath);
             break;
         case QubitTerm::THUMBNAIL_ID:
         default:
             $extension = '.' . self::THUMB_EXTENSION;
             $derivativeName = $originalNameNoExtension . '_' . $usageId . $extension;
             $derivativeFullPath = sfConfig::get('sf_web_dir') . $this->getPath() . $derivativeName;
             $maxDimensions = self::getImageMaxDimensions($usageId);
             self::convertVideoToThumbnail($originalFullPath, $derivativeFullPath, $maxDimensions[0], $maxDimensions[1]);
     }
     if (file_exists($derivativeFullPath) && 0 < ($byteSize = filesize($derivativeFullPath))) {
         $derivative = new QubitDigitalObject();
         $derivative->setPath($this->getPath());
         $derivative->setName($derivativeName);
         $derivative->parentId = $this->id;
         $derivative->setByteSize($byteSize);
         $derivative->usageId = $usageId;
         $derivative->setMimeAndMediaType();
         $derivative->createDerivatives = false;
         $derivative->indexOnSave = false;
         $derivative->save($connection);
         return $derivative;
     }
 }
 /**
  * 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();
     }
 }