/**
  * Show a representation of a digital object image.
  *
  * @param sfWebRequest $request
  *
  */
 public function execute($request)
 {
     // Get representation by usage type
     $this->representation = $this->resource->getRepresentationByUsage($this->usageType);
     // If we can't find a representation for this object, try their parent
     if (!$this->representation && ($parent = $this->resource->parent)) {
         $this->representation = $parent->getRepresentationByUsage($this->usageType);
     }
     // Set up display of video in flowplayer
     if ($this->representation) {
         $this->response->addJavaScript('/vendor/flowplayer/example/flowplayer-3.1.4.min.js');
         $this->response->addJavaScript('flowplayer');
         // If this is a reference movie, get the thumbnail representation for the
         // place holder image
         $this->showFlashPlayer = true;
         if (QubitTerm::REFERENCE_ID == $this->usageType) {
             $this->thumbnail = $this->resource->getRepresentationByUsage(QubitTerm::THUMBNAIL_ID);
         }
         list($this->width, $this->height) = QubitDigitalObject::getImageMaxDimensions($this->usageType);
         // For javascript_tag()
         $this->representationFullPath = public_path($this->representation->getFullPath());
     } else {
         $this->showFlashPlayer = false;
         $this->representation = QubitDigitalObject::getGenericRepresentation($this->resource->mimeType, $this->usageType);
     }
 }
 /**
  * Show a representation of a digital object image.
  *
  * @param sfWebRequest $request
  *
  */
 public function execute($request)
 {
     // Get representation by usage type
     $this->representation = $this->resource->getRepresentationByUsage($this->usageType);
     // If we can't find a representation for this object, try their parent
     if (!$this->representation && ($parent = $this->resource->parent)) {
         $this->representation = $parent->getRepresentationByUsage($this->usageType);
     }
     // If representation is not a valid digital object, return a generic icon
     if (!$this->representation) {
         $this->representation = QubitDigitalObject::getGenericRepresentation($this->resource->mimeType, $this->usageType);
     }
 }
 /**
  * Upload the asset selected by user and create a digital object with appropriate
  * representations.
  *
  * @return DigitalObjectEditAction this action
  */
 public function processForm()
 {
     $digitalObject = new QubitDigitalObject();
     if (null !== $this->form->getValue('file')) {
         $name = $this->form->getValue('file')->getOriginalName();
         $content = file_get_contents($this->form->getValue('file')->getTempName());
         $digitalObject->assets[] = new QubitAsset($name, $content);
         $digitalObject->usageId = QubitTerm::MASTER_ID;
     } else {
         if (null !== $this->form->getValue('url')) {
             $digitalObject->importFromURI($this->form->getValue('url'));
         }
     }
     $this->resource->digitalObjects[] = $digitalObject;
 }
 /**
  * Show a representation of a digital object image.
  *
  * @param sfWebRequest $request
  *
  */
 public function execute($request)
 {
     // Get representation by usage type
     $this->representation = $this->resource->getRepresentationByUsage($this->usageType);
     // If we can't find a representation for this object, try their parent
     if (!$this->representation && ($parent = $this->resource->parent)) {
         $this->representation = $parent->getRepresentationByUsage($this->usageType);
     }
     // Set up display of video in flowplayer
     if ($this->representation) {
         $this->showFlashPlayer = true;
         $this->response->addJavaScript('/vendor/flowplayer/example/flowplayer-3.1.4.min.js');
         $this->response->addJavaScript('flowplayer');
     } else {
         $this->showFlashPlayer = false;
         $this->representation = QubitDigitalObject::getGenericRepresentation($this->resource->mimeType, $this->usageType);
     }
 }
 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'));
 }
 /**
  * Show a representation of a digital object image.
  *
  * @param sfWebRequest $request
  *
  */
 public function execute($request)
 {
     switch ($this->usageType) {
         case QubitTerm::REFERENCE_ID:
             $this->representation = $this->resource->getRepresentationByUsage(QubitTerm::REFERENCE_ID);
             break;
         case QubitTerm::THUMBNAIL_ID:
             $this->representation = $this->resource->getRepresentationByUsage(QubitTerm::THUMBNAIL_ID);
             break;
         case QubitTerm::MASTER_ID:
         default:
             $this->representation = QubitDigitalObject::getGenericRepresentation($this->resource->mimeType, $this->usageType);
     }
     // If no representation found, then default to generic rep
     if (!$this->representation) {
         $this->representation = QubitDigitalObject::getGenericRepresentation($this->resource->mimeType, $this->usageType);
     }
     // Build a fully qualified URL to this digital object asset
     if ((QubitTerm::IMAGE_ID != $this->resource->mediaTypeId || QubitTerm::REFERENCE_ID == $this->usageType) && QubitAcl::check($this->resource->informationObject, 'readMaster')) {
         $this->link = public_path($this->resource->getFullPath(), true);
     }
 }
 public function execute($request)
 {
     $this->version = '1.3';
     $this->verbose = 'false';
     $this->noOp = 'false';
     $this->maxUploadSize = QubitDigitalObject::getMaxUploadSize() / 1024;
     // From bytes to kilobytes
     $this->mediation = 'false';
     // Should be based in auth + X-On-Behalf-Of
     if (isset($request->getAttribute('sf_route')->resource)) {
         $this->resource = $this->getRoute()->resource;
         $this->title = $this->resource->__toString();
         $this->workspaces = $this->resource->getChildren();
     } else {
         $this->title = sfConfig::get('app_siteTitle');
         $criteria = new Criteria();
         $criteria->add(QubitInformationObject::PARENT_ID, QubitInformationObject::ROOT_ID, Criteria::IN);
         $criteria = QubitAcl::addFilterDraftsCriteria($criteria);
         $this->workspaces = QubitInformationObject::get($criteria);
     }
     $this->response->setHttpHeader('Content-Type', 'application/atom+xml; charset="utf-8"');
     $request->setRequestFormat('xml');
 }
 public function execute($request)
 {
     $this->thumbnails = array();
     // Set limit (null for no limit)
     if (!isset($request->showFullImageflow) || 'true' != $request->showFullImageflow) {
         $this->limit = sfConfig::get('app_hits_per_page', 10);
     }
     // Add thumbs
     $criteria = new Criteria();
     $criteria->addJoin(QubitInformationObject::ID, QubitDigitalObject::INFORMATION_OBJECT_ID);
     $criteria->add(QubitInformationObject::LFT, $this->resource->lft, Criteria::GREATER_THAN);
     $criteria->add(QubitInformationObject::RGT, $this->resource->rgt, Criteria::LESS_THAN);
     if (isset($this->limit)) {
         $criteria->setLimit($this->limit);
     }
     foreach (QubitDigitalObject::get($criteria) as $item) {
         $thumbnail = $item->getRepresentationByUsage(QubitTerm::THUMBNAIL_ID);
         if (!$thumbnail) {
             $thumbnail = QubitDigitalObject::getGenericRepresentation($item->mimeType, QubitTerm::THUMBNAIL_ID);
             $thumbnail->setParent($item);
         }
         $this->thumbnails[] = $thumbnail;
     }
     // Get total number of descendant digital objects
     $this->total = 0;
     if (isset($this->resource)) {
         $criteria = new Criteria();
         $criteria->addJoin(QubitInformationObject::ID, QubitDigitalObject::INFORMATION_OBJECT_ID);
         $criteria->add(QubitInformationObject::LFT, $this->resource->lft, Criteria::GREATER_THAN);
         $criteria->add(QubitInformationObject::RGT, $this->resource->rgt, Criteria::LESS_THAN);
         $this->total = BasePeer::doCount($criteria)->fetchColumn(0);
     }
     if (2 > count($this->thumbnails)) {
         return sfView::NONE;
     }
 }
 /**
  * Move digital objects to repository specific paths like
  * http://code.google.com/p/qubit-toolkit/source/detail?r=9503
  *
  * @return QubitMigrate110 SELF
  */
 protected function updatePathToAssets()
 {
     // Create "uploads/r" subdirectory
     if (!file_exists(sfConfig::get('sf_upload_dir') . '/r')) {
         mkdir(sfConfig::get('sf_upload_dir') . '/r', 0775);
     }
     foreach ($this->data['QubitDigitalObject'] as $key => &$item) {
         if (!isset($item['information_object_id'])) {
             continue;
         }
         // Get the related information object
         $infoObject = $this->getRowByKeyOrId('QubitInformationObject', $item['information_object_id']);
         if (null === $infoObject) {
             continue;
         }
         // Recursively check info object ancestors for repository foreign key
         while (!isset($infoObject['repository_id']) && isset($infoObject['parent_id'])) {
             $infoObject = $this->getRowByKeyOrId('QubitInformationObject', $infoObject['parent_id']);
         }
         // Get repository
         if (isset($infoObject['repository_id'])) {
             $repo = $this->getRowByKeyOrId('QubitRepository', $infoObject['repository_id']);
             if (!isset($repo['slug'])) {
                 continue;
             }
             $repoName = $repo['slug'];
         } else {
             $repoName = 'null';
         }
         // Update digital object and derivatives paths
         foreach ($this->data['QubitDigitalObject'] as $key2 => &$item2) {
             if ($key == $key2 || isset($item2['parent_id']) && $key == $item2['parent_id']) {
                 // Don't try to move remote assets
                 $externalUriKey = $this->getTermKey('<?php echo QubitTerm::EXTERNAL_URI_ID."\\n" ?>');
                 if ($externalUriKey == $item2['usage_id']) {
                     continue;
                 }
                 $oldpath = $item2['path'];
                 // Build new path
                 if (preg_match('|\\d/\\d/\\d{3,}/$|', $oldpath, $matches)) {
                     $newpath = '/uploads/r/' . $repoName . '/' . $matches[0];
                 } else {
                     continue;
                 }
                 if (!file_exists(sfConfig::get('sf_web_dir') . $newpath)) {
                     if (!mkdir(sfConfig::get('sf_web_dir') . $newpath, 0775, true)) {
                         continue;
                     }
                 }
                 if (file_exists(sfConfig::get('sf_web_dir') . $oldpath)) {
                     if (!rename(sfConfig::get('sf_web_dir') . $oldpath . $item2['name'], sfConfig::get('sf_web_dir') . $newpath . $item2['name'])) {
                         continue;
                         // If rename fails, don't update path
                     }
                 }
                 // Delete old dirs, if they are empty
                 QubitDigitalObject::pruneEmptyDirs(sfConfig::get('sf_web_dir') . $oldpath);
                 // Update path in yaml file
                 $item2['path'] = $newpath;
             }
         }
     }
     return $this;
 }
 /**
  * Decide whether to show child digital objects as a compound object based
  * on 'displayAsCompound' toggle and available digital objects.
  *
  * @return boolean
  */
 public function showAsCompoundDigitalObject()
 {
     // Return false if this digital object is not linked directly to an
     // information object
     if (null === $this->informationObjectId) {
         return false;
     }
     // Return false if "show compound" toggle is not set to '1' (yes)
     $showCompoundProp = QubitProperty::getOneByObjectIdAndName($this->id, 'displayAsCompound');
     if (null === $showCompoundProp || '1' != $showCompoundProp->getValue(array('sourceCulture' => true))) {
         return false;
     }
     // Return false if this object has no children with digital objects
     $criteria = new Criteria();
     $criteria->addJoin(QubitInformationObject::ID, QubitDigitalObject::INFORMATION_OBJECT_ID);
     $criteria->add(QubitInformationObject::PARENT_ID, $this->informationObjectId);
     if (0 === count(QubitDigitalObject::get($criteria))) {
         return false;
     }
     return true;
 }
    <?php 
    $doc = $hit->getDocument();
    ?>
    <div class="clearfix search-results <?php 
    echo 0 == @++$row % 2 ? 'even' : 'odd';
    ?>
">

      <?php 
    if ('true' == $doc->hasDigitalObject) {
        ?>
        <?php 
        if (null == $doc->do_mediaTypeId) {
            ?>
          <?php 
            echo link_to(image_tag(QubitDigitalObject::getGenericRepresentation($doc->do_mediaTypeId, QubitTerm::THUMBNAIL_ID)->getFullPath(), array('alt' => $doc->title)), array('slug' => $doc->slug, 'module' => 'informationobject'));
            ?>
        <?php 
        } elseif (QubitTerm::AUDIO_ID == $doc->do_mediaTypeId) {
            ?>
          <?php 
            echo link_to(image_tag('play.png', array('alt' => $doc->title)), array('slug' => $doc->slug, 'module' => 'informationobject'));
            ?>
        <?php 
        } elseif (null !== $doc->do_thumbnail_FullPath) {
            ?>
          <?php 
            echo link_to(image_tag(public_path($doc->do_thumbnail_FullPath), array('alt' => $doc->title)), array('slug' => $doc->slug, 'module' => 'informationobject'));
            ?>
        <?php 
        }
 /**
  * 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();
     }
 }
 /**
  * Wrapper for QubitDigitalObject::importFromBase64() method
  *
  * @param string $encodedString base-64 encoded data
  * @param string $filename name of destination file
  * @return QubitInformationObject $this
  *
  * @TODO allow for different usage types
  */
 public function importDigitalObjectFromBase64($encodedString, $filename)
 {
     $digitalObject = new QubitDigitalObject();
     $digitalObject->usageId = QubitTerm::MASTER_ID;
     $digitalObject->importFromBase64($encodedString, $filename);
     $this->digitalObjects[] = $digitalObject;
 }
        <?php 
echo __('Results');
?>
      </th>
    </tr>
  </thead><tbody>
    <?php 
foreach ($terms as $item) {
    ?>
      <tr class="<?php 
    echo 0 == @++$row % 2 ? 'even' : 'odd';
    ?>
">
        <td>
          <div style="padding-left: 17px;">
            <?php 
    echo link_to($item->getName(array('cultureFallback' => true)), array('module' => 'digitalobject', 'action' => 'browse', 'mediatype' => $item->id));
    ?>
          </div>
        </td><td>
          <?php 
    echo QubitDigitalObject::getCount($item->id);
    ?>
        </td>
      </tr>
    <?php 
}
?>
  </tbody>
</table>
 public static function getdigitalObjectsById($id, array $options = array())
 {
     $criteria = new Criteria();
     self::adddigitalObjectsCriteriaById($criteria, $id);
     return QubitDigitalObject::get($criteria, $options);
 }
 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 execute($request)
 {
     ProjectConfiguration::getActive()->loadHelpers('Qubit');
     $uploadLimt = -1;
     $diskUsage = 0;
     $uploadFiles = array();
     $warning = null;
     $this->informationObject = QubitInformationObject::getById($request->informationObjectId);
     if (!isset($this->informationObject)) {
         $this->forward404();
     }
     // Check user authorization
     if (!QubitAcl::check($this->informationObject, 'update')) {
         throw new sfException();
     }
     $repo = $this->informationObject->getRepository(array('inherit' => true));
     if (isset($repo)) {
         $uploadLimit = $repo->uploadLimit;
         if (0 < $uploadLimit) {
             $uploadLimit *= pow(10, 9);
             // Convert to bytes
         }
         $diskUsage = $repo->getDiskUsage();
     }
     // Create tmp dir, if it doesn't exist already
     $tmpDir = sfConfig::get('sf_upload_dir') . '/tmp';
     if (!file_exists($tmpDir)) {
         mkdir($tmpDir);
         chmod($tmpDir, 0775);
     }
     foreach ($_FILES as $file) {
         if (null != $repo && 0 <= $uploadLimit && $uploadLimit < $diskUsage + $file['size']) {
             $uploadFiles = array('error' => $this->context->i18n->__('%1% upload limit of %2% GB exceeded for %3%', array('%1%' => sfConfig::get('app_ui_label_digitalobject'), '%2%' => round($uploadLimit / pow(10, 9), 2), '%4%' => $this->context->routing->generate(null, array($repo, 'module' => 'repository')), '%3%' => $repo->__toString())));
             continue;
         }
         // Get file extension
         $extension = substr($file['name'], strrpos($file['name'], '.'));
         // Get a unique file name (to avoid clashing file names)
         do {
             $uniqueString = substr(md5(time() . $file['name']), 0, 8);
             $tmpFileName = "TMP{$uniqueString}{$extension}";
             $tmpFilePath = "{$tmpDir}/{$tmpFileName}";
         } while (file_exists($tmpFilePath));
         // Thumbnail name
         $thumbName = "THB{$uniqueString}.jpg";
         $thumbPath = "{$tmpDir}/{$thumbName}";
         // Move file to web/uploads/tmp directory
         if (!move_uploaded_file($file['tmp_name'], $tmpFilePath)) {
             $errorMessage = $this->context->i18n->__('File %1% could not be moved to %2%', array('%1%' => $file['name'], '%2%' => $tmpDir));
             $uploadFiles = array('error' => $errorMessage);
             continue;
         }
         $tmpFileMd5sum = md5_file($tmpFilePath);
         $tmpFileMimeType = QubitDigitalObject::deriveMimeType($tmpFileName);
         if ($canThumbnail = QubitDigitalObject::canThumbnailMimeType($tmpFileMimeType) || QubitDigitalObject::isVideoFile($tmpFilePath)) {
             if (QubitDigitalObject::isImageFile($tmpFilePath) || 'application/pdf' == $tmpFileMimeType) {
                 $resizedObject = QubitDigitalObject::resizeImage($tmpFilePath, 150, 150);
             } else {
                 if (QubitDigitalObject::isVideoFile($tmpFilePath)) {
                     $resizedObject = QubitDigitalObject::createThumbnailFromVideo($tmpFilePath, 150, 150);
                 }
             }
             if (0 < strlen($resizedObject)) {
                 file_put_contents($thumbPath, $resizedObject);
                 chmod($thumbPath, 0644);
             }
             // Show a warning message if object couldn't be thumbnailed when it is
             // supposed to be possible
             if (!file_exists($thumbPath) && 0 >= filesize($thumbPath)) {
                 $warning = $this->context->i18n->__('File %1% could not be thumbnailed', array('%1%' => $file['name']));
             }
         } else {
             $thumbName = '../../images/' . QubitDigitalObject::getGenericIconPath($tmpFileMimeType, QubitTerm::THUMBNAIL_ID);
         }
         $uploadFiles = array('canThumbnail' => $canThumbnail, 'name' => $file['name'], 'md5sum' => $tmpFileMd5sum, 'size' => hr_filesize($file['size']), 'thumb' => $thumbName, 'tmpName' => $tmpFileName, 'warning' => $warning);
         // Keep running total of disk usage
         $diskUsage += $file['size'];
     }
     // Pass file data back to caller for processing on form submit
     $this->response->setHttpHeader('Content-Type', 'application/json; charset=utf-8');
     return $this->renderText(json_encode($uploadFiles));
 }