Author: david
Date: Fri Feb 10 13:06:14 2012
New Revision: 10853

Log:
Do i18n fallback for collection root title, if necessary

Modified:
   trunk/lib/QubitSearchPdo.class.php

Modified: trunk/lib/QubitSearchPdo.class.php
==============================================================================
--- trunk/lib/QubitSearchPdo.class.php  Fri Feb 10 12:54:50 2012        (r10852)
+++ trunk/lib/QubitSearchPdo.class.php  Fri Feb 10 13:06:14 2012        (r10853)
@@ -177,7 +177,7 @@
     // Title
     // Include an i18n fallback for proper search result display in case the
     // title field was not translated
-    if (0 < strlen($resource->title))
+    if (0 == strlen($resource->title))
     {
       $resource->title = self::getFallbackTitle($resource->id);
     }
@@ -219,9 +219,17 @@
 
     if (isset(self::$collectionRoot))
     {
-      $doc->addField(Zend_Search_Lucene_Field::UnIndexed('collectionRootId', 
$collectionRoot->id));
-      $doc->addField(Zend_Search_Lucene_Field::Keyword('collectionRootSlug', 
$collectionRoot->slug));
-      
$doc->addField(Zend_Search_Lucene_Field::UnIndexed('collectionRootTitle', 
$collectionRoot->title));
+      $doc->addField(Zend_Search_Lucene_Field::UnIndexed('collectionRootId', 
self::$collectionRoot->id));
+      $doc->addField(Zend_Search_Lucene_Field::Keyword('collectionRootSlug', 
self::$collectionRoot->slug));
+
+      // Do fallback if current culture is not the same as the collectionRoot
+      $crTitle = self::$collectionRoot->title;
+      if (0 == strlen($crTitle) || self::$collectionRoot->culture != $language)
+      {
+        $crTitle = self::getFallbackTitle(self::$collectionRoot->id, 
array('culture' => $language));
+      }
+
+      
$doc->addField(Zend_Search_Lucene_Field::UnIndexed('collectionRootTitle', 
$crTitle));
     }
     else
     {
@@ -388,8 +396,9 @@
     // Add all dynamic metadata fields to index
   }
 
-  protected static function getFallbackTitle($id)
+  protected static function getFallbackTitle($id, $options = array())
   {
+    $params = array($id);
     $conn = Propel::getConnection();
 
     // Get info objects (with offset)
@@ -399,14 +408,31 @@
     $sql .= '   ON node.id = i18n.id';
     $sql .= ' WHERE node.id = ?';
 
+    if (isset($options['culture']))
+    {
+      $sql .= ' AND culture = ?';
+      $params[] = $options['culture'];
+    }
+    else
+    {
+      $sql .= ' AND node.source_culture = i18n.culture';
+    }
+
     $statement = $conn->prepare($sql);
-    $statement->execute(array($id));
+    $statement->execute($params);
     $result = $statement->fetch(PDO::FETCH_OBJ);
 
-    if (null != $result)
+    if (false !== $result)
     {
       return $result->title;
     }
+    else if (isset($options['culture']))
+    {
+      // Get source culture title
+      unset ($options['culture']);
+
+      return self::getFallbackTitle($id, $options);
+    }
   }
 }
 

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