示例#1
0
echo $form->renderHiddenFields();
?>

  <fieldset class="collapsible">

    <legend><?php 
echo __('Master');
?>
</legend>

    <?php 
echo render_show(__('Filename'), $resource->name);
?>

    <?php 
echo render_show(__('Filesize'), hr_filesize($resource->byteSize));
?>

    <?php 
echo $form->mediaType->renderRow();
?>

    <?php 
if ($showCompoundObjectToggle) {
    ?>
      <?php 
    echo $form->displayAsCompound->label(__('View children as a compound digital object?'))->renderRow();
    ?>
    <?php 
}
?>
 protected function addFormFields()
 {
     // Media type field
     $choices = array();
     $criteria = new Criteria();
     $criteria->add(QubitTerm::TAXONOMY_ID, QubitTaxonomy::MEDIA_TYPE_ID);
     foreach (QubitTerm::get($criteria) as $item) {
         $choices[$item->id] = $item->getName(array('cultureFallback' => true));
     }
     asort($choices);
     // Sort media types by name
     $this->form->setValidator('mediaType', new sfValidatorChoice(array('choices' => array_keys($choices))));
     $this->form->setWidget('mediaType', new sfWidgetFormSelect(array('choices' => $choices)));
     $this->form->setDefault('mediaType', $this->resource->mediaTypeId);
     // Only display "compound digital object" toggle if we have a child with a
     // digital object
     $this->showCompoundObjectToggle = false;
     foreach ($this->informationObject->getChildren() as $item) {
         if (null !== $item->getDigitalObject()) {
             $this->showCompoundObjectToggle = true;
             break;
         }
     }
     if ($this->showCompoundObjectToggle) {
         $this->form->setValidator('displayAsCompound', new sfValidatorBoolean());
         $this->form->setWidget('displayAsCompound', new sfWidgetFormSelectRadio(array('choices' => array('1' => $this->context->i18n->__('Yes'), '0' => $this->context->i18n->__('No')))));
         // Set "displayAsCompound" value from QubitProperty
         $criteria = new Criteria();
         $criteria->add(QubitProperty::OBJECT_ID, $this->resource->id);
         $criteria->add(QubitProperty::NAME, 'displayAsCompound');
         if (null != ($compoundProperty = QubitProperty::getOne($criteria))) {
             $this->form->setDefault('displayAsCompound', $compoundProperty->getValue(array('sourceCulture' => true)));
         }
     }
     // Add rights component
     $this->rightEditComponent = new RightEditComponent($this->context, 'right', 'edit');
     $this->rightEditComponent->resource = $this->resource;
     $this->rightEditComponent->execute($this->request);
     $maxUploadSize = QubitDigitalObject::getMaxUploadSize();
     ProjectConfiguration::getActive()->loadHelpers('Qubit');
     // If reference representation doesn't exist, include upload widget
     foreach ($this->representations as $usageId => $representation) {
         if (null === $representation) {
             $repName = "repFile_{$usageId}";
             $derName = "generateDerivative_{$usageId}";
             $this->form->setValidator($repName, new sfValidatorFile());
             $this->form->setWidget($repName, new sfWidgetFormInputFile());
             if (-1 < $maxUploadSize) {
                 $this->form->getWidgetSchema()->{$repName}->setHelp($this->context->i18n->__('Max. size ~%1%', array('%1%' => hr_filesize($maxUploadSize))));
             } else {
                 $this->form->getWidgetSchema()->{$repName}->setHelp('');
             }
             // Add "auto-generate" checkbox
             $this->form->setValidator($derName, new sfValidatorBoolean());
             $this->form->setWidget($derName, new sfWidgetFormInputCheckbox(array(), array('value' => 1)));
         } else {
             $this["rightEditComponent_{$usageId}"] = new RightEditComponent($this->context, 'right', 'edit');
             $this["rightEditComponent_{$usageId}"]->resource = $representation;
             $this["rightEditComponent_{$usageId}"]->nameFormat = 'editRight' . $usageId . '[%s]';
             $this["rightEditComponent_{$usageId}"]->execute($this->request);
         }
     }
 }
<div>

  <div style="float: right;">

    <?php 
echo get_component('digitalobject', 'show', array('iconOnly' => true, 'link' => public_path($representation->getFullPath()), 'resource' => $representation, 'usageType' => QubitTerm::THUMBNAIL_ID));
?>

  </div>

  <div>

    <?php 
echo render_show(__('Filename'), $representation->name);
?>

    <?php 
echo render_show(__('Filesize'), hr_filesize($representation->byteSize));
?>

    <?php 
echo link_to(__('Delete'), array($representation, 'module' => 'digitalobject', 'action' => 'delete'), array('class' => 'delete'));
?>

  </div>

</div>
 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));
 }