Author: david
Date: Fri Oct  2 13:44:51 2009
New Revision: 3646

Log:
Fix digital object representation upload.

Modified:
   trunk/apps/qubit/modules/digitalobject/actions/editAction.class.php
   trunk/apps/qubit/modules/digitalobject/templates/editSuccess.php

Modified: trunk/apps/qubit/modules/digitalobject/actions/editAction.class.php
==============================================================================
--- trunk/apps/qubit/modules/digitalobject/actions/editAction.class.php Fri Oct 
 2 13:22:48 2009        (r3645)
+++ trunk/apps/qubit/modules/digitalobject/actions/editAction.class.php Fri Oct 
 2 13:44:51 2009        (r3646)
@@ -77,6 +77,16 @@
       {
         $this->form->setDefault('displayAsCompound', 
$compoundProperty->getValue(array('sourceCulture' => true)));
       }
+
+      // If reference represenation doesn't exist, include upload widget
+      foreach ($this->representations as $usageId => $representation)
+      {
+        if (null === $representation)
+        {
+          $this->form->setValidator('repFile_'.$usageId, new sfValidatorFile);
+          $this->form->setWidget('repFile_'.$usageId, new 
sfWidgetFormInputFile);
+        }
+      }
     }
   }
 
@@ -87,6 +97,8 @@
     $this->digitalObject = new QubitDigitalObject;
     $this->informationObject = new QubitInformationObject;
 
+    $this->maxUploadSize = QubitDigitalObject::getMaxUploadSize();
+
     // If digital object already exists
     if (isset($request->id))
     {
@@ -97,17 +109,15 @@
         $this->forward404();
       }
 
+      // Get representations
+      $this->representations = array(
+        QubitTerm::REFERENCE_ID => 
$this->digitalObject->getChildByUsageId(QubitTerm::REFERENCE_ID),
+        QubitTerm::THUMBNAIL_ID => 
$this->digitalObject->getChildByUsageId(QubitTerm::THUMBNAIL_ID)
+      );
+
       $this->informationObject = $this->digitalObject->informationObject;
 
       $this->addFormFields();
-
-      // Get related digital object with all representations
-      if (null !== $this->digitalObject)
-      {
-        $representations[QubitTerm::REFERENCE_ID] = 
$this->digitalObject->getChildByUsageId(QubitTerm::REFERENCE_ID);
-        $representations[QubitTerm::THUMBNAIL_ID] = 
$this->digitalObject->getChildByUsageId(QubitTerm::THUMBNAIL_ID);
-        $this->representations = $representations;
-      }
     }
 
     // Upload a new digital object
@@ -128,8 +138,6 @@
       $this->form->setWidget('informationObject', new sfWidgetFormInputHidden);
       $this->form->setDefault('informationObject', 
$this->informationObject->id);
 
-      $this->maxUploadSize = QubitDigitalObject::getMaxUploadSize();
-
       $this->setTemplate('uploadForm');
     }
 
@@ -152,6 +160,10 @@
           $this->redirect(array('module' => 'informationobject', 'action' => 
'show', 'id' => $this->informationObject->id));
         }
       }
+      else
+      {
+        echo 'BOO-URNS!';
+      }
     }
   }
 
@@ -188,34 +200,24 @@
     $this->digitalObject->mediaTypeId = $this->form->getValue('mediaType');
 
     // Upload new representations
-    if (false && null !== ($uploadedFiles = $this->form->getFiles()))
+    $uploadedFiles = array();
+    foreach ($this->representations as $usageId => $representation)
     {
-      var_dump($uploadedFiles);
-      die();
-
-      foreach ($uploadedFiles['name'] as $usageId => $filename)
+      if (null !== ($uf = $this->form->getValue('repFile_'.$usageId)))
       {
-        if ($uploadedFiles['error'][$usageId])
-        {
-          continue;
-        }
-
-        if (!file_exists($tmpFile = $uploadedFiles['tmp_name'][$usageId]))
-        {
-          continue; // Skip to next $uploadFile if no valid filename
-        }
-
-        // Upload asset and create digital object
-        $digitalObject = new QubitDigitalObject;
-        $asset = new QubitAsset($filename, file_get_contents($tmpFile));
-
-        $digitalObject->assets[] = $asset;
-        $digitalObject->setUsageId($usageId);
-
-        $this->informationObject->digitalObjects[] = $digitalObject;
+        $uploadedFiles[$usageId] = $uf;
+      }
+    }
 
-      } // endforeach
-    } // end if
+    foreach ($uploadedFiles as $usageId => $uploadFile)
+    {
+      $representation = new QubitDigitalObject;
+      $representation->usageId = $usageId;
+      $representation->assets[] = new 
QubitAsset($uploadFile->getOriginalName(), 
file_get_contents($uploadFile->getTempName()));
+      $representation->parentId = $this->digitalObject->id;
+      $representation->createDerivatives = false;
+      $representation->save();
+    }
 
     // Generate new derivatives from existing MASTER
     if (null != ($createDeriviates = 
$this->form->getValue('createDerivative')))

Modified: trunk/apps/qubit/modules/digitalobject/templates/editSuccess.php
==============================================================================
--- trunk/apps/qubit/modules/digitalobject/templates/editSuccess.php    Fri Oct 
 2 13:22:48 2009        (r3645)
+++ trunk/apps/qubit/modules/digitalobject/templates/editSuccess.php    Fri Oct 
 2 13:44:51 2009        (r3646)
@@ -2,6 +2,10 @@
 
 <div class="headerCell"><?php if (0 < (strlen($label = 
$informationObject->getLabel()))): ?><?php echo $label ?><?php endif; ?></div>
 
+<?php if ($form->hasGlobalErrors()): ?>
+<div><?php echo $form->renderGlobalErrors() ?></div>
+<?php endif; ?>
+
 <?php if (null !== $digitalObject): ?>
   <div class="form-item" style="text-align: center">
     <?php include_component('digitalobject', 'show', array(
@@ -53,11 +57,11 @@
           <td>
             <?php echo __('Select a %1% to upload', 
array('%1%'=>sfConfig::get('app_ui_label_digitalobject'))) ?>
             <span class="note"><?php echo __('max. size ~%1%', array('%1%' => 
hr_filesize($maxUploadSize))) ?></span>
-            <?php //echo input_file_tag('upload_file['.$usageId.']', 
'size=40') ?>
+            <?php echo $form['repFile_'.$usageId]->renderRow() ?>
 
             <?php if ($digitalObject->canThumbnail()): ?>
               <?php echo __('<i>or</i> Auto-generate a new representation from 
master image'); ?>
-              <?php // echo checkbox_tag('createDerivative', $usageId, false, 
array('class'=>'checkbox')); ?>
+              <?php //echo checkbox_tag('createDerivative', $usageId, false, 
array('class'=>'checkbox')); ?>
             <?php endif; ?>
           </td>
         </tr>

--~--~---------~--~----~------------~-------~--~----~
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.ca/group/qubit-commits?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to