Author: mj
Date: Sat Oct 29 20:36:41 2011
New Revision: 10232

Log:
More refactoring & fixes against #140. Implement/fix RAD notes.

Modified:
   trunk/lib/QubitCsvImport.class.php
   trunk/plugins/sfRadPlugin/modules/sfRadPlugin/actions/editAction.class.php
   trunk/plugins/sfRadPlugin/modules/sfRadPlugin/templates/editSuccess.php

Modified: trunk/lib/QubitCsvImport.class.php
==============================================================================
--- trunk/lib/QubitCsvImport.class.php  Fri Oct 28 17:01:39 2011        (r10231)
+++ trunk/lib/QubitCsvImport.class.php  Sat Oct 29 20:36:41 2011        (r10232)
@@ -36,7 +36,6 @@
     // load the CSV document into an array
     $data = $this->loadCSV($csvFile);
 
-    // NOTE: ORDER MATTERS HERE
     // information object schema element names
     $names['rad'] = array_flip(array_map(array('sfInflector', 'underscore'), 
sfRadPluginEditAction::$NAMES));
     $names['isad'] = array_flip(array_map(array('sfInflector', 'underscore'), 
sfIsadPluginEditAction::$NAMES));
@@ -56,12 +55,15 @@
       {
         $match = array_intersect_key($elements, $header);
 
-        // NB: *very* simple test, if 50% of elements match, use that schema
-        if ((count($match)/count($header)) > 0.5)
-        {
-          $importSchema = $name;
-          break;
-        }
+        $scores[$name] = count($match)/count($header);
+      }
+
+      arsort($scores);
+
+      // schema must match at least 50% of elements
+      if (current($scores) > 0.5)
+      {
+        $importSchema = key($scores);
       }
     }
     else
@@ -213,15 +215,26 @@
       $this->culture = sfCultureInfo::getInstance($culture);
     }
 
-    if (!in_array($parameters['language'], $this->culture->getLanguages()))
+    // NB: this only matches ISO-639-2 codes, eg. "en"
+    if (!in_array($parameters['language'], 
array_keys($this->culture->getLanguages())))
     {
-      $parameters['language'] = '';
+      unset($parameters['language']);
     }
 
-    // TODO: FIXME;
-    if (true || !in_array($parameters['script'], $this->culture->getScripts()))
+    if (!in_array($parameters['languageOfDescription'], 
array_keys($this->culture->getLanguages())))
     {
-      $parameters['script'] = '';
+      unset($parameters['languageOfDescription']);
+    }
+
+    // NB: this only matches Symfony script codes, eg. "Latn"
+    if (!in_array($parameters['script'], 
array_keys($this->culture->getScripts())))
+    {
+      unset($parameters['script']);
+    }
+
+    if (!in_array($parameters['scriptOfDescription'], 
array_keys($this->culture->getScripts())))
+    {
+      unset($parameters['scriptOfDescription']);
     }
 
     if (!isset($this->levelsOfDescription))
@@ -234,7 +247,7 @@
 
     if (!in_array($parameters['levelOfDescription'], 
$this->levelsOfDescription))
     {
-      $parameters['levelOfDescription'] = '';
+      unset($parameters['levelOfDescription']);
     }
 
     if (!isset($this->descriptionDetailLevels))
@@ -247,7 +260,7 @@
 
     if (!in_array($parameters['descriptionDetail'], 
$this->descriptionDetailLevels))
     {
-      $parameters['descriptionDetail'] = '';
+      unset($parameters['descriptionDetail']);
     }
 
     if (!isset($this->descriptionStatuss))
@@ -260,7 +273,7 @@
 
     if (!in_array($parameters['descriptionStatus'], $this->descriptionStatuss))
     {
-      $parameters['descriptionStatus'] = '';
+      unset($parameters['descriptionStatus']);
     }
 
     return $parameters;
@@ -268,7 +281,43 @@
 
   protected function mapRad($parameters)
   {
-    // TODO: refactor into here
+
+    if (!isset($this->radTitleNotes))
+    {
+      foreach (QubitTaxonomy::getTermsById(QubitTaxonomy::RAD_TITLE_NOTE_ID) 
as $term)
+      {
+        $this->radTitleNotes[$term->id] = $term;
+      }
+    }
+
+    if (!in_array($parameters['radTitleNoteType'], $this->radTitleNotes))
+    {
+      unset($parameters['radTitleNote']);
+      unset($parameters['radTitleNoteType']);
+    }
+    else
+    {
+      $parameters['radTitleNoteType'] = 
array_search($parameters['radTitleNoteType'], $this->radTitleNotes);
+    }
+
+    if (!isset($this->radNotes))
+    {
+      foreach (QubitTaxonomy::getTermsById(QubitTaxonomy::RAD_NOTE_ID) as 
$term)
+      {
+        $this->radNotes[$term->id] = $term;
+      }
+    }
+
+    if (!in_array($parameters['radNoteType'], $this->radNotes))
+    {
+      unset($parameters['radNote']);
+      unset($parameters['radNoteType']);
+    }
+    else
+    {
+      $parameters['radNoteType'] = array_search($parameters['radNoteType'], 
$this->radNotes);
+    }
+
     return $this->mapEdit($parameters);
   }
 
@@ -283,12 +332,12 @@
     // remove duplicate values
     if ($parameters['parallelName'] == $parameters['authorizedFormOfName'])
     {
-      $parameters['parallelName'] = '';
+      unset($parameters['parallelName']);
     }
 
     if ($parameters['otherName'] == $parameters['authorizedFormOfName'])
     {
-      $parameters['otherName'] = '';
+      unset($parameters['otherName']);
     }
 
     // NB: this is hacky, but required for an inconsistency in repository 
naming

Modified: 
trunk/plugins/sfRadPlugin/modules/sfRadPlugin/actions/editAction.class.php
==============================================================================
--- trunk/plugins/sfRadPlugin/modules/sfRadPlugin/actions/editAction.class.php  
Fri Oct 28 17:01:39 2011        (r10231)
+++ trunk/plugins/sfRadPlugin/modules/sfRadPlugin/actions/editAction.class.php  
Sat Oct 29 20:36:41 2011        (r10232)
@@ -254,6 +254,30 @@
 
   protected function updateNotes()
   {
+    if ($this->request->hasParameter('csvimport'))
+    {
+      // remap notes from parameters to request object
+      if ($this->request->getParameterHolder()->has('radTitleNote'))
+      {
+        $this->request->rad_title_note = 
$this->request->getParameterHolder()->get('radTitleNote');
+      }
+
+      if ($this->request->getParameterHolder()->has('radTitleNoteType'))
+      {
+        $this->request->rad_title_note_type = 
$this->request->getParameterHolder()->get('radTitleNoteType');
+      }
+
+      if ($this->request->getParameterHolder()->has('radNote'))
+      {
+        $this->request->rad_note = 
$this->request->getParameterHolder()->get('radNote');
+      }
+
+      if ($this->request->getParameterHolder()->has('radNoteType'))
+      {
+        $this->request->rad_note_type = 
$this->request->getParameterHolder()->get('radNoteType');
+      }
+    }
+
     if (isset($this->request->rad_title_note) && 0 < 
strlen($this->request->rad_title_note))
     {
       $note = new QubitNote;

Modified: 
trunk/plugins/sfRadPlugin/modules/sfRadPlugin/templates/editSuccess.php
==============================================================================
--- trunk/plugins/sfRadPlugin/modules/sfRadPlugin/templates/editSuccess.php     
Fri Oct 28 17:01:39 2011        (r10231)
+++ trunk/plugins/sfRadPlugin/modules/sfRadPlugin/templates/editSuccess.php     
Sat Oct 29 20:36:41 2011        (r10232)
@@ -315,7 +315,7 @@
           <?php foreach ($resource->getNotesByTaxonomy(array('taxonomyId' => 
QubitTaxonomy::RAD_NOTE_ID)) as $item): ?>
             <tr class="related_obj_<?php echo $item->id ?>">
               <td>
-                <?php echo $item->getContent(array('cultureFallback' => 
'true')) ?><span class="note"><?php echo $item->user ?>, <?php echo 
$item->updatedAt ?></span>
+                <?php echo $item->getContent(array('cultureFallback' => 
'true')) ?><span class="note"><?php echo $item->user ?>, <?php echo 
$item->object->updatedAt ?></span>
               </td><td>
                 <?php echo $item->type ?>
               </td><td style="text-align: center">

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