Author: david
Date: Thu Feb 16 17:19:36 2012
New Revision: 10928

Log:
Add dates and creators (BROKEN)

Modified:
   trunk/apps/qubit/modules/search/templates/_searchResults.php
   trunk/lib/QubitSearchPdo.class.php

Modified: trunk/apps/qubit/modules/search/templates/_searchResults.php
==============================================================================
--- trunk/apps/qubit/modules/search/templates/_searchResults.php        Thu Feb 
16 16:01:54 2012        (r10927)
+++ trunk/apps/qubit/modules/search/templates/_searchResults.php        Thu Feb 
16 17:19:36 2012        (r10928)
@@ -42,28 +42,24 @@
         <?php echo render_show(__('Reference code'), 
render_value($doc->referenceCode)); ?>
       <?php endif; ?>
 
-      <?php $dates = unserialize($doc->dates) ?>
-      <?php if (0 < count($dates)): ?>
+      <?php $datesOfCreation = unserialize($doc->datesOfCreation) ?>
+      <?php if (0 < count($datesOfCreation)): ?>
         <div class="field">
-          <h3><?php echo __('Date(s)') ?></h3>
+          <h3><?php echo __('Date(s) of creation') ?></h3>
           <div>
             <ul>
-              <?php foreach ($dates as $date): ?>
-                <li>
-
-                  <?php echo $date['rendered'] ?> (<?php echo $date['type'] ?>)
-
-                  <?php if (isset($date['actor']) && null !== $event = 
QubitEvent::getById($date['id'])): ?>
-                    <?php echo link_to($date['actor'], array($event->actor, 
'module' => 'actor')) ?>
-                  <?php endif; ?>
-
-                </li>
+              <?php foreach ($datesOfCreation as $date): ?>
+                <li><?php echo $date ?></li>
               <?php endforeach; ?>
             </ul>
           </div>
         </div>
       <?php endif; ?>
 
+      <?php if ($doc->creators): ?>
+        <?php echo render_show(__('Creator(s)'), render_value($doc->creators)) 
?>
+      <?php endif; ?>
+
       <?php if ($doc->levelOfDescription): ?>
         <?php echo render_show(__('Level of description'), 
render_value($doc->levelOfDescription)) ?>
       <?php endif; ?>

Modified: trunk/lib/QubitSearchPdo.class.php
==============================================================================
--- trunk/lib/QubitSearchPdo.class.php  Thu Feb 16 16:01:54 2012        (r10927)
+++ trunk/lib/QubitSearchPdo.class.php  Thu Feb 16 17:19:36 2012        (r10928)
@@ -24,6 +24,7 @@
 
   protected static
     $conn,
+    $creationEventStatement,
     $infoObjectCount,
     $levelsOfDescription,
     $startTime,
@@ -345,33 +346,12 @@
       $doc->addField(Zend_Search_Lucene_Field::Keyword('hasDigitalObject', 
'false'));
     }
 
-    self::getInstance()->getEngine()->getIndex()->addDocument($doc);
-    return;
-
-    // Store dates as serialized array
-    $dates = array();
-    foreach ($resource->getDates() as $date)
-    {
-      $save_date['id'] = $date->id;
-      $save_date['rendered'] = 
Qubit::renderDateStartEnd($date->getDate(array('cultureFallback' => true)), 
$date->startDate, $date->endDate);
-      $save_date['type'] = $date->getType(array('cultureFallback' => 
true))->__toString();
-
-      if (isset($date->actor))
-      {
-        $save_date['actor'] = $date->actor->__toString();
-      }
-
-      $dates[] = $save_date;
-    }
+    // CREATION DATES AND CREATORS
+    $doc = self::addCreationEvents($doc, $resource);
 
-    $doc->addField(Zend_Search_Lucene_Field::UnIndexed('dates', 
serialize($dates)));
+    self::getInstance()->getEngine()->getIndex()->addDocument($doc);
 
-    // CREATOR
-    $creatorField = Zend_Search_Lucene_Field::Unstored('creator', 
$resource->getCreatorsNameString(array('culture' => $language)));
-    // Boost the hit relevance for the creator field
-    $creatorField->boost = 8;
-    $doc->addField($creatorField);
-    $doc->addField(Zend_Search_Lucene_Field::Unstored('creatorhistory', 
$resource->getCreatorsHistoryString(array('culture' => $language))));
+    return;
 
     // Subjects
     $subjectField = Zend_Search_Lucene_Field::Unstored('subject', 
$resource->getAccessPointsString(QubitTaxonomy::SUBJECT_ID, array('culture' => 
$language)));
@@ -443,6 +423,7 @@
 
     // To come:
     // Add all dynamic metadata fields to index
+    self::getInstance()->getEngine()->getIndex()->addDocument($doc);
   }
 
   protected static function getFallbackTitle($id, $options = array())
@@ -500,5 +481,82 @@
       return self::$levelsOfDescription[$id]->getName(array('culture' => 
$culture));
     }
   }
-}
 
+  protected static function addCreationEvents($doc, $resource)
+  {
+    $dates = array();
+    $startDates = array();
+    $endDates = array();
+    $creators = array();
+    $histories = array();
+
+    if (!isset(self::$creationEventStatement))
+    {
+      $sql  = 'SELECT 
+                  event.id,
+                  event.start_date,
+                  event.end_date,
+                  act_i18n.authorized_form_of_name,
+                  act_i18n.history,
+                  i18n.date';
+      $sql .= ' FROM '.QubitEvent::TABLE_NAME.' event';
+      $sql .= ' JOIN '.QubitEventI18n::TABLE_NAME.' i18n
+                  ON event.id = i18n.id';
+      $sql .= ' LEFT JOIN '.QubitActorI18n::TABLE_NAME.' act_i18n
+                  ON event.actor_id = act_i18n.id';
+      $sql .= ' WHERE event.information_object_id = ?
+                  AND event.type_id = ?
+                  AND i18n.culture = ?
+                  AND act_i18n.culture = ?';
+
+      self::$creationEventStatement = self::$conn->prepare($sql);
+    }
+
+    self::$creationEventStatement->execute(array(
+      $resource->id, 
+      QubitTerm::CREATION_ID,
+      $resource->culture,
+      $resource->culture));
+
+    foreach (self::$creationEventStatement->fetchAll(PDO::FETCH_OBJ) as $item)
+    {
+      if (isset($item->date) || isset($item->start_date) || 
isset($item->end_date))
+      {
+        $dates[] = Qubit::renderDateStartEnd($item->date, $item->start_date, 
$item->end_date);
+      }
+
+      if (isset($item->start_date))
+      {
+        $startDates[] = $item->start_date;
+      }
+
+      if (isset($item->end_date))
+      {
+        $endDates[] = $item->end_date;
+      }
+
+      if (isset($item->authorized_form_of_name))
+      {
+        $creators[] = $item->authorized_form_of_name;
+      }
+
+      if (isset($item->history))
+      {
+        $histories[] = $item->history;
+      }
+    }
+
+    $doc->addField(Zend_Search_Lucene_Field::UnIndexed('datesOfCreation', 
serialize($dates)));
+    $doc->addField(Zend_Search_Lucene_Field::Unstored('startDate', implode(' 
', $startDates)));
+    $doc->addField(Zend_Search_Lucene_Field::Unstored('endDate', implode(' ', 
$endDates)));
+
+    // CREATORS
+    $creatorField = Zend_Search_Lucene_Field::Keyword('creators', implode('; 
', $creators));
+    $creatorField->boost = 8; // Boost the relevance
+    $doc->addField($creatorField);
+
+    $doc->addField(Zend_Search_Lucene_Field::Unstored('creatorHistory', 
implode(' ', $histories)));
+
+    return $doc;
+  }
+}

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