Author: david
Date: Fri Sep 23 15:56:52 2011
New Revision: 9808

Log:
Use information object slug for linking a digital object

Added:
   
trunk/apps/qubit/modules/informationobject/actions/addDigitalObjectAction.class.php
      - copied, changed from r9804, 
trunk/apps/qubit/modules/digitalobject/actions/editAction.class.php
   
trunk/apps/qubit/modules/informationobject/templates/addDigitalObjectSuccess.php
      - copied, changed from r9803, 
trunk/apps/qubit/modules/digitalobject/templates/uploadFormSuccess.php
Deleted:
   trunk/apps/qubit/modules/digitalobject/templates/uploadFormSuccess.php
Modified:
   trunk/apps/qubit/modules/informationobject/templates/_actions.php

Copied and modified: 
trunk/apps/qubit/modules/informationobject/actions/addDigitalObjectAction.class.php
 (from r9804, 
trunk/apps/qubit/modules/digitalobject/actions/editAction.class.php)
==============================================================================
--- trunk/apps/qubit/modules/digitalobject/actions/editAction.class.php Fri Sep 
23 14:47:33 2011        (r9804, copy source)
+++ 
trunk/apps/qubit/modules/informationobject/actions/addDigitalObjectAction.class.php
 Fri Sep 23 15:56:52 2011        (r9808)
@@ -25,99 +25,26 @@
  * @author     david juhasz <[email protected]>
  * @version    SVN: $Id$
  */
-class DigitalObjectEditAction extends sfAction
+class InformationObjectAddDigitalObjectAction extends sfAction
 {
-  protected function addFormFields()
+  protected function addFields($request)
   {
-    // Media type field
-    $choices = array();
-    $criteria = new Criteria;
-    $criteria->add(QubitTerm::TAXONOMY_ID, QubitTaxonomy::MEDIA_TYPE_ID);
-    foreach (QubitTerm::get($criteria) as $item)
+    // Single upload
+    if (0 < count($request->getFiles()))
     {
-      $choices[$item->id] = $item->getName(array('cultureFallback' => true));
+      $this->form->setValidator('file', new sfValidatorFile);
     }
 
-    asort($choices); // Sort media types by name
+    $this->form->setWidget('file', new sfWidgetFormInputFile);
 
-    $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)
+    // URL
+    if (isset($request->url) && 'http://' != $request->url)
     {
-      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)));
-      }
+      $this->form->setValidator('url', new sfValidatorUrl);
     }
 
-    // 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)));
-      }
-      // Otherwise, load right component
-      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);
-      }
-    }
+    $this->form->setDefault('url', 'http://');
+    $this->form->setWidget('url', new sfWidgetFormInput);
   }
 
   public function execute($request)
@@ -125,103 +52,49 @@
     $this->form = new sfForm;
     $this->form->getValidatorSchema()->setOption('allow_extra_fields', true);
 
-    $this->resource = new QubitDigitalObject;
-
-    $this->informationObject = new QubitInformationObject;
+    $this->resource = $this->getRoute()->resource;
 
-    // If digital object already exists (template: edit)
-    if (isset($this->getRoute()->resource))
+    // Check that object exists and that it is not the root
+    if (!isset($this->resource) || !isset($this->resource->parent))
     {
-      $this->resource = $this->getRoute()->resource;
-
-      $this->informationObject = $this->resource->informationObject;
-
-      // Check user authorization
-      if (!QubitAcl::check($this->informationObject, 'update'))
-      {
-        QubitAcl::forwardUnauthorized();
-      }
-
-      // Get representations
-      $this->representations = array(
-        QubitTerm::REFERENCE_ID => 
$this->resource->getChildByUsageId(QubitTerm::REFERENCE_ID),
-        QubitTerm::THUMBNAIL_ID => 
$this->resource->getChildByUsageId(QubitTerm::THUMBNAIL_ID));
-
-      $this->addFormFields();
+      $this->forward404();
     }
 
-    // Upload a new digital object (template: uploadForm)
-    else
+    // Check if already exists a digital object
+    if (null !== $digitalObject = $this->resource->getDigitalObject())
     {
-      $this->informationObject = 
QubitInformationObject::getById($request->informationObject);
-
-      // Check that object exists and that it is not the root
-      if (!isset($this->informationObject) || 
!isset($this->informationObject->parent))
-      {
-        $this->forward404();
-      }
-
-      // Check if already exists a digital object
-      if (null !== $digitalObject = 
$this->informationObject->getDigitalObject())
-      {
-        $this->redirect(array($digitalObject, 'module' => 'digitalobject', 
'action' => 'edit'));
-      }
-
-      // Check user authorization
-      if (!QubitAcl::check($this->informationObject, 'update'))
-      {
-        QubitAcl::forwardUnauthorized();
-      }
-
-      // Check repository file upload limit
-      $repo = $this->informationObject->getRepository(array('inherit' => 
true));
-      if (null !== $repo
-        && $repo->uploadLimit != -1
-        && $repo->getDiskUsage(array('units' => 'G')) >= 
floatval($repo->uploadLimit))
-      {
-        $this->redirect(array($repo, 'module' => 'repository', 'action' => 
'uploadLimitExceeded'));
-      }
-
-      // Single upload
-      if (0 < count($request->getFiles()))
-      {
-        $this->form->setValidator('file', new sfValidatorFile);
-      }
-
-      $this->form->setWidget('file', new sfWidgetFormInputFile);
-
-      // URL
-      if (isset($request->url) && 'http://' != $request->url)
-      {
-        $this->form->setValidator('url', new sfValidatorUrl);
-      }
-
-      $this->form->setDefault('url', 'http://');
-      $this->form->setWidget('url', new sfWidgetFormInput);
+      $this->redirect(array($digitalObject, 'module' => 'digitalobject', 
'action' => 'edit'));
+    }
 
-      $this->form->setValidator('informationObject', new sfValidatorInteger);
-      $this->form->setWidget('informationObject', new sfWidgetFormInputHidden);
-      $this->form->setDefault('informationObject', 
$this->informationObject->id);
+    // Check user authorization
+    if (!QubitAcl::check($this->resource, 'update'))
+    {
+      QubitAcl::forwardUnauthorized();
+    }
 
-      $this->setTemplate('uploadForm');
+    // Check repository file upload limit
+    $repo = $this->resource->getRepository(array('inherit' => true));
+    if (null !== $repo
+      && $repo->uploadLimit != -1
+      && $repo->getDiskUsage(array('units' => 'G')) >= 
floatval($repo->uploadLimit))
+    {
+      $this->redirect(array($repo, 'module' => 'repository', 'action' => 
'uploadLimitExceeded'));
     }
 
-    // Process forms
+    // Add form fields
+    $this->addFields($request);
+
+    // Process form
     if ($request->isMethod('post'))
     {
       $this->form->bind($request->getPostParameters(), $request->getFiles());
       if ($this->form->isValid())
       {
-        if (null !== $this->form->getValue('file') || null !== 
$this->form->getValue('url'))
-        {
-          // Process single-upload form
-          $this->processUploadForm();
-        }
-        else
-        {
-          // Process update form
-          $this->processUpdateForm();
-        }
+        $this->processForm();
+
+        $this->resource->save();
+
+        $this->redirect(array($this->resource, 'module' => 
'informationobject'));
       }
     }
   }
@@ -232,108 +105,23 @@
    *
    * @return DigitalObjectEditAction this action
    */
-  public function processUploadForm()
+  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());
 
-      $this->resource->assets[] = new QubitAsset($name, $content);
-      $this->resource->usageId = QubitTerm::MASTER_ID;
+      $digitalObject->assets[] = new QubitAsset($name, $content);
+      $digitalObject->usageId = QubitTerm::MASTER_ID;
     }
     else if (null !== $this->form->getValue('url'))
     {
-      $this->resource->importFromURI($this->form->getValue('url'));
-    }
-
-    $this->informationObject->digitalObjects[] = $this->resource;
-
-    $this->informationObject->save();
-
-    $this->redirect(array($this->informationObject, 'module' => 
'informationobject'));
-  }
-
-  /**
-   * Update digital object properties, or upload new digital object 
derivatives.
-   *
-   * @return DigitalObjectEditAction this action
-   */
-  public function processUpdateForm()
-  {
-    // 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();
+      $digitalObject->importFromURI($this->form->getValue('url'));
     }
 
-    // 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();
-    }
-
-    $this->resource->save();
-
-    $this->redirect(array($this->informationObject, 'module' => 
'informationobject'));
+    $this->resource->digitalObjects[] = $digitalObject;
   }
 }

Modified: trunk/apps/qubit/modules/informationobject/templates/_actions.php
==============================================================================
--- trunk/apps/qubit/modules/informationobject/templates/_actions.php   Fri Sep 
23 15:27:42 2011        (r9807)
+++ trunk/apps/qubit/modules/informationobject/templates/_actions.php   Fri Sep 
23 15:56:52 2011        (r9808)
@@ -27,7 +27,7 @@
           <?php if (0 < count($resource->digitalObjects)): ?>
             <li><?php echo link_to(__('Edit digital object'), 
array($resource->digitalObjects[0], 'module' => 'digitalobject', 'action' => 
'edit')) ?></li>
           <?php else: ?>
-            <li><?php echo link_to(__('Link digital object'), array('module' 
=> 'digitalobject', 'action' => 'add', 'informationObject' => $resource->id)) 
?></li>
+            <li><?php echo link_to(__('Link digital object'), array($resource, 
'module' => 'informationobject', 'action' => 'addDigitalObject')) ?></li>
           <?php endif; // has digital object ?>
 
           <li><?php echo link_to(__('Import digital objects'), 
array($resource, 'module' => 'informationobject', 'action' => 
'multiFileUpload')) ?></li>

Copied and modified: 
trunk/apps/qubit/modules/informationobject/templates/addDigitalObjectSuccess.php
 (from r9803, 
trunk/apps/qubit/modules/digitalobject/templates/uploadFormSuccess.php)
==============================================================================
--- trunk/apps/qubit/modules/digitalobject/templates/uploadFormSuccess.php      
Fri Sep 23 11:11:22 2011        (r9803, copy source)
+++ 
trunk/apps/qubit/modules/informationobject/templates/addDigitalObjectSuccess.php
    Fri Sep 23 15:56:52 2011        (r9808)
@@ -1,10 +1,10 @@
 <h1><?php echo __('Upload digital objects') ?></h1>
 
-<h1 class="label"><?php echo render_title(new 
sfIsadPlugin($informationObject)) ?> </h1>
+<h1 class="label"><?php echo render_title(new sfIsadPlugin($resource)) ?> </h1>
 
 <?php echo $form->renderGlobalErrors() ?>
 
-<?php echo $form->renderFormTag(url_for(array('module' => 'digitalobject', 
'action' => 'add')), array('id' => 'uploadForm')) ?>
+<?php echo $form->renderFormTag(url_for(array($resource, 'module' => 
'informationobject', 'action' => 'addDigitalObject')), array('id' => 
'uploadForm')) ?>
 
   <?php echo $form->renderHiddenFields() ?>
 
@@ -30,7 +30,7 @@
 
     <div class="content">
       <ul class="clearfix links">
-        <li><?php echo link_to(__('Cancel'), array($informationObject, 
'module' => 'informationobject')) ?></li>
+        <li><?php echo link_to(__('Cancel'), array($resource, 'module' => 
'informationobject')) ?></li>
         <li><input class="form-submit" type="submit" value="<?php echo 
__('Create') ?>"/></li>
       </ul>
     </div>

-- 
You received this message because you are subscribed to the Google Groups 
"Qubit Toolkit Commits" group.
To post to this group, send email to [email protected].
To unsubscribe from this group, send email to 
[email protected].
For more options, visit this group at 
http://groups.google.com/group/qubit-commits?hl=en.

Reply via email to