Author: david
Date: Mon Sep 28 14:14:06 2009
New Revision: 3568

Log:
Make 'display as compound object' a digital object property.  Fix 'show 
children as compound digital object' toggle on digitalobject/edit page.

Modified:
   trunk/apps/qubit/modules/digitalobject/actions/editAction.class.php
   trunk/apps/qubit/modules/digitalobject/templates/editSuccess.php
   trunk/apps/qubit/modules/informationobject/actions/showAction.class.php
   trunk/apps/qubit/modules/informationobject/templates/showIsadSuccess.php
   trunk/lib/model/QubitDigitalObject.php
   trunk/lib/model/QubitInformationObject.php

Modified: trunk/apps/qubit/modules/digitalobject/actions/editAction.class.php
==============================================================================
--- trunk/apps/qubit/modules/digitalobject/actions/editAction.class.php Mon Sep 
28 13:24:51 2009        (r3567)
+++ trunk/apps/qubit/modules/digitalobject/actions/editAction.class.php Mon Sep 
28 14:14:06 2009        (r3568)
@@ -27,7 +27,7 @@
  */
 class DigitalObjectEditAction extends sfAction
 {
-  protected function addUpdateFormFields()
+  protected function addFormFields()
   {
     // Media type field
     $choices = $validChoices = array();
@@ -61,21 +61,21 @@
 
     if ($this->showCompoundObjectToggle)
     {
-      $this->form->setValidator('isCompound', new sfValidatorPass);
-      $this->form->setWidget('isCompound', new sfWidgetFormSelectRadio(
+      $this->form->setValidator('displayAsCompound', new sfValidatorPass);
+      $this->form->setWidget('displayAsCompound', new sfWidgetFormSelectRadio(
         array('choices' => array(
           '1' => $this->getContext()->getI18N()->__('yes'),
           '0' => $this->getContext()->getI18N()->__('no')
         ))
       ));
-      // Set 'isCompound' value from QubitProperty
+      // Set 'displayAsCompound' value from QubitProperty
       $c = new Criteria;
       $c->add(QubitProperty::OBJECT_ID, $this->digitalObject->id, 
Criteria::EQUAL);
-      $c->add(QubitProperty::NAME, 'is_compound_object', Criteria::EQUAL);
+      $c->add(QubitProperty::NAME, 'display_as_compound_object', 
Criteria::EQUAL);
 
       if (null != ($compoundProperty = QubitProperty::getOne($c)))
       {
-        $this->form->setDefault('isCompound', 
$compoundProperty->getValue(array('sourceCulture' => true)));
+        $this->form->setDefault('displayAsCompound', 
$compoundProperty->getValue(array('sourceCulture' => true)));
       }
     }
   }
@@ -87,6 +87,7 @@
     $this->digitalObject = new QubitDigitalObject;
     $this->informationObject = new QubitInformationObject;
 
+    // If digital object already exists
     if (isset($request->id))
     {
       $this->digitalObject = QubitDigitalObject::getById($request->id);
@@ -98,7 +99,7 @@
 
       $this->informationObject = $this->digitalObject->informationObject;
 
-      $this->addUpdateFormFields();
+      $this->addFormFields();
 
       // Get related digital object with all representations
       if (null !== $this->digitalObject)
@@ -108,6 +109,8 @@
         $this->representations = $representations;
       }
     }
+
+    // Upload a new digital object
     else if (isset($request->informationObject))
     {
       $this->informationObject = 
QubitInformationObject::getById($request->informationObject);
@@ -130,6 +133,7 @@
       $this->setTemplate('uploadForm');
     }
 
+    // Process forms
     if ($request->isMethod('post'))
     {
       $this->form->bind($request->getPostParameters(), $request->getFiles());
@@ -138,11 +142,13 @@
       {
         if (null != $this->form->getValue('file'))
         {
-          $this->uploadNewDigitalObject();
+          // Process upload form
+          $this->processUploadForm();
         }
         else
         {
-          $this->processForm();
+          // Process update form
+          $this->processUpdateForm();
           $this->redirect(array('module' => 'informationobject', 'action' => 
'show', 'id' => $this->informationObject->id));
         }
       }
@@ -155,7 +161,7 @@
    *
    * @return DigitalObjectEditAction this action
    */
-  public function uploadNewDigitalObject()
+  public function processUploadForm()
   {
     $this->digitalObject->usageId = QubitTerm::MASTER_ID;
     $this->digitalObject->assets[] = new 
QubitAsset($this->form->getValue('file')->getOriginalName(), 
file_get_contents($this->form->getValue('file')->getTempName()));
@@ -172,13 +178,11 @@
    *
    * @return DigitalObjectEditAction this action
    */
-  public function processForm()
+  public function processUpdateForm()
   {
     // Set property 'display_as_compound_object'
-    if ($isCompound = $this->form->getValue('isCompound'))
-    {
-      $this->digital->setDisplayAsCompoundObject($isCompound);
-    }
+    $displayAsCompound = $this->form->getValue('displayAsCompound');
+    $this->digitalObject->setDisplayAsCompoundObject($displayAsCompound);
 
     // Update media type
     $this->digitalObject->mediaTypeId = $this->form->getValue('mediaType');
@@ -186,6 +190,9 @@
     // Upload new representations
     if (false && null !== ($uploadedFiles = $this->form->getFiles()))
     {
+      var_dump($uploadedFiles);
+      die();
+
       foreach ($uploadedFiles['name'] as $usageId => $filename)
       {
         if ($uploadedFiles['error'][$usageId])

Modified: trunk/apps/qubit/modules/digitalobject/templates/editSuccess.php
==============================================================================
--- trunk/apps/qubit/modules/digitalobject/templates/editSuccess.php    Mon Sep 
28 13:24:51 2009        (r3567)
+++ trunk/apps/qubit/modules/digitalobject/templates/editSuccess.php    Mon Sep 
28 14:14:06 2009        (r3568)
@@ -2,9 +2,24 @@
 
 <div class="headerCell"><?php if (0 < (strlen($label = 
$informationObject->getLabel()))): ?><?php echo $label ?><?php endif; ?></div>
 
-<?php if (null != ($reference = 
$digitalObject->getRepresentationByUsage(QubitTerm::REFERENCE_ID))): ?>
 <div class="form-item" style="text-align: center">
-<?php echo image_tag($reference->getFullPath(), array('alt' => __('reference 
representation'))) ?>
+<?php if 
($digitalObject->showAsCompoundDigitalObject(QubitTerm::REFERENCE_ID)): ?>
+  <tr>
+    <td colspan="2">
+      <div style="text-align: center">
+      <?php include_component('digitalobject', 'showCompound', 
array('informationObject' => $informationObject)) ?>
+      </div>
+    </td>
+  </tr>
+<?php elseif (null !== $digitalObject->id): ?>
+  <tr>
+    <td colspan="2">
+      <div style="text-align: center">
+      <?php include_component('digitalobject', 'show', array(
+        'digitalObject' => $digitalObject, 'usageType' => 
QubitTerm::REFERENCE_ID, 'link' => $digitalObjectLink)) ?>
+      </div>
+    </td>
+  </tr>
 <?php endif; ?>
 </div>
 
@@ -17,21 +32,20 @@
     <label for="filename"><?php echo __('filename'); ?></label>
     <?php echo $digitalObject->getName() ?>
   </div>
-  
+
   <div class="form-item">
     <label for="filesize"><?php echo __('filesize'); ?></label>
     <?php echo hr_filesize($digitalObject->getByteSize()) ?>
   </div>
-  
-  <div class="form-item"> 
+
+  <div class="form-item">
     <?php echo $form->mediaType->renderRow() ?>
   </div>
 
   <?php if ($showCompoundObjectToggle): ?>
   <div class="form-item">
-    <?php echo $form->isCompound->renderErrors() ?>
-    <?php echo $form->isCompound->label(__('view children as a compound 
digital object?'))->renderLabel() ?>
-    <?php echo $form->isCompound->render() ?>
+    <?php $form->displayAsCompound->label(__('view children as a compound 
digital object?')) ?>
+    <?php echo $form->displayAsCompound->renderRow() ?>
   </div>
   <?php endif; ?>
 </fieldset>
@@ -53,11 +67,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 input_file_tag('upload_file['.$usageId.']', 
'size=40') ?>
+
             <?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>

Modified: 
trunk/apps/qubit/modules/informationobject/actions/showAction.class.php
==============================================================================
--- trunk/apps/qubit/modules/informationobject/actions/showAction.class.php     
Mon Sep 28 13:24:51 2009        (r3567)
+++ trunk/apps/qubit/modules/informationobject/actions/showAction.class.php     
Mon Sep 28 14:14:06 2009        (r3568)
@@ -25,7 +25,7 @@
  * @version    svn: $Id$
  * @author     Peter Van Garderen <[email protected]>
  * @author     Jack Bates <[email protected]>
- * @author     David Juhasz <[email protected]> 
+ * @author     David Juhasz <[email protected]>
  */
 class InformationObjectShowAction extends sfAction
 {
@@ -52,6 +52,13 @@
       }
     }
 
+    // Get *one* digital object (relationship must be 1-to-1)
+    $this->digitalObject = null;
+    if (null != ($digitalObjects = $this->informationObject->digitalObjects))
+    {
+      $this->digitalObject = $digitalObjects[0];
+    }
+
     // Physical objects
     $this->physicalObjects = 
QubitRelation::getRelatedSubjectsByObjectId('QubitPhysicalObject', 
$this->informationObject->getId(),
       array('typeId'=>QubitTerm::HAS_PHYSICAL_OBJECT_ID));

Modified: 
trunk/apps/qubit/modules/informationobject/templates/showIsadSuccess.php
==============================================================================
--- trunk/apps/qubit/modules/informationobject/templates/showIsadSuccess.php    
Mon Sep 28 13:24:51 2009        (r3567)
+++ trunk/apps/qubit/modules/informationobject/templates/showIsadSuccess.php    
Mon Sep 28 14:14:06 2009        (r3568)
@@ -9,7 +9,8 @@
   </td>
 </tr>
 
-<?php if 
($informationObject->showAsCompoundDigitalObject(QubitTerm::REFERENCE_ID)): ?>
+<?php if (null !== $digitalObject): ?>
+<?php if 
($digitalObject->showAsCompoundDigitalObject(QubitTerm::REFERENCE_ID)): ?>
   <tr>
     <td colspan="2">
       <div style="text-align: center">
@@ -17,7 +18,7 @@
       </div>
     </td>
   </tr>
-<?php elseif (0 < count($informationObject->digitalObjects)): ?>
+<?php else: ?>
   <tr>
     <td colspan="2">
       <div style="text-align: center">
@@ -27,6 +28,7 @@
     </td>
   </tr>
 <?php endif; ?>
+<?php endif; ?>
 
 <!-- ******************************************** -->
 <!--   START IDENTITY AREA                         -->

Modified: trunk/lib/model/QubitDigitalObject.php
==============================================================================
--- trunk/lib/model/QubitDigitalObject.php      Mon Sep 28 13:24:51 2009        
(r3567)
+++ trunk/lib/model/QubitDigitalObject.php      Mon Sep 28 14:14:06 2009        
(r3568)
@@ -269,7 +269,7 @@
         $this->createCompoundChildren();
 
         // Set parent digital object to be displayed as compound
-        $this->getInformationObject()->setDisplayAsCompoundObject(1);
+        $this->setDisplayAsCompoundObject(1);
 
         // We don't need reference image because a compound will be displayed 
instead of it
         // But thumbnails are necessary for image flow
@@ -1647,4 +1647,88 @@
 
     return $this;
   }
+
+  /* -----------------------------------------------------------------------
+   * Display as compound object
+   * --------------------------------------------------------------------- */
+
+  /**
+   * Setter for "display_as_compound_object" property
+   *
+   * @param string $value new value for property
+   * @return QubitInformationObject this object
+   */
+  public function setDisplayAsCompoundObject($value)
+  {
+    $criteria = new Criteria;
+    $criteria->add(QubitProperty::OBJECT_ID, $this->id, Criteria::EQUAL);
+    $criteria->add(QubitProperty::NAME, 'display_as_compound_object');
+
+    $displayAsCompoundProp = QubitProperty::getOne($criteria);
+    if (is_null($displayAsCompoundProp))
+    {
+      $displayAsCompoundProp = new QubitProperty;
+      $displayAsCompoundProp->setObjectId($this->getId());
+      $displayAsCompoundProp->setName('display_as_compound_object');
+    }
+
+    $displayAsCompoundProp->setValue($value, array('sourceCulture' => true));
+    $displayAsCompoundProp->save();
+
+    return $this;
+  }
+
+
+  /**
+   * Decide whether to show child digital objects as a compound object based
+   * on 'display_as_compound_object' toggle and available digital objects.
+   *
+   * @return boolean
+   */
+  public function showAsCompoundDigitalObject($usageId)
+  {
+    // 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->getId(), 
'display_as_compound_object');
+    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::INNER_JOIN);
+    $criteria->add(QubitInformationObject::PARENT_ID, 
$this->informationObjectId, Criteria::EQUAL);
+
+    if (0 === count(QubitDigitalObject::get($criteria)))
+    {
+
+      return false;
+    }
+
+    return true;
+  }
+
+  /**
+   * Getter for related "display_as_compound_object" property
+   *
+   * @return string property value
+   */
+  public function getDisplayAsCompoundObject()
+  {
+    $displayAsCompoundProp = 
QubitProperty::getOneByObjectIdAndName($this->getId(), 
'display_as_compound_object');
+    if (null !== $displayAsCompoundProp)
+    {
+
+      return $displayAsCompoundProp->getValue(array('sourceCulture' => true));
+    }
+  }
 }

Modified: trunk/lib/model/QubitInformationObject.php
==============================================================================
--- trunk/lib/model/QubitInformationObject.php  Mon Sep 28 13:24:51 2009        
(r3567)
+++ trunk/lib/model/QubitInformationObject.php  Mon Sep 28 14:14:06 2009        
(r3568)
@@ -1105,80 +1105,6 @@
     }
   }
 
-  /**
-   * Decide whether to show child digital objects as a compound object based
-   * on 'display_as_compound_object' toggle and available digital objects.
-   *
-   * @return boolean
-   */
-  public function showAsCompoundDigitalObject($usageId)
-  {
-    // Return false if this object has it's own digital object image to display
-    if (null !== $digitalObject = $this->getDigitalObject())
-    {
-      if ($digitalObject->getRepresentationByUsage($usageId))
-      {
-        return false;
-      }
-    }
-
-    // Return false if "show compound" toggle is not set to '1' (yes)
-    $showCompoundProp = QubitProperty::getOneByObjectIdAndName($this->getId(), 
'display_as_compound_object', array('scope' => 'information_object'));
-    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::INNER_JOIN);
-    $criteria->add(QubitInformationObject::PARENT_ID, $this->id, 
Criteria::EQUAL);
-
-    if (0 === count(QubitDigitalObject::get($criteria)))
-    {
-      return false;
-    }
-
-    return true;
-  }
-
-    /**
-   * Setter for "display_as_compound_object" property
-   *
-   * @param string $value new value for property
-   * @return QubitInformationObject this object
-   */
-  public function setDisplayAsCompoundObject($value)
-  {
-    $displayAsCompoundProp = 
QubitProperty::getOneByObjectIdAndName($this->getId(), 
'display_as_compound_object');
-    if (is_null($displayAsCompoundProp))
-    {
-      $displayAsCompoundProp = new QubitProperty;
-      $displayAsCompoundProp->setObjectId($this->getId());
-      $displayAsCompoundProp->setName('display_as_compound_object');
-      $displayAsCompoundProp->setScope('information_object');
-    }
-
-    $displayAsCompoundProp->setValue($value, array('sourceCulture' => true));
-    $displayAsCompoundProp->save();
-
-    return $this;
-  }
-
-  /**
-   * Getter for related "display_as_compound_object" property
-   *
-   * @return string property value
-   */
-  public function getDisplayAsCompoundObject()
-  {
-    $displayAsCompoundProp = 
QubitProperty::getOneByObjectIdAndName($this->getId(), 
'display_as_compound_object');
-    if (null !== $displayAsCompoundProp)
-    {
-
-      return $displayAsCompoundProp->getValue(array('sourceCulture' => true));
-    }
-  }
 
   /****************
    Import methods

--~--~---------~--~----~------------~-------~--~----~
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