Author: david
Date: Tue Sep  1 16:42:58 2009
New Revision: 3143

Log:
Sort term treeview and show:hierarchical terms alphabetically with culture 
fallback.

Modified:
   trunk/apps/qubit/modules/term/actions/contextMenuComponent.class.php
   trunk/apps/qubit/modules/term/actions/showAction.class.php
   trunk/apps/qubit/modules/term/actions/treeViewAction.class.php
   trunk/lib/model/QubitTerm.php

Modified: trunk/apps/qubit/modules/term/actions/contextMenuComponent.class.php
==============================================================================
--- trunk/apps/qubit/modules/term/actions/contextMenuComponent.class.php        
Tue Sep  1 16:40:20 2009        (r3142)
+++ trunk/apps/qubit/modules/term/actions/contextMenuComponent.class.php        
Tue Sep  1 16:42:58 2009        (r3143)
@@ -82,16 +82,19 @@
   {
     $this->termTree[] = $node;
 
-    foreach ($node->getChildren() as $child)
+    if (0 < count($children = $node->getChildren(array('sortBy' => 'name'))))
     {
-      // Recurse
-      if (in_array($child->id, $lineage))
+      foreach ($children as $child)
       {
-        $this->buildTermTree($child, $lineage);
-      }
-      else
-      {
-        $this->termTree[] = $child;
+        // Recurse
+        if (in_array($child->id, $lineage))
+        {
+          $this->buildTermTree($child, $lineage);
+        }
+        else
+        {
+          $this->termTree[] = $child;
+        }
       }
     }
   }

Modified: trunk/apps/qubit/modules/term/actions/showAction.class.php
==============================================================================
--- trunk/apps/qubit/modules/term/actions/showAction.class.php  Tue Sep  1 
16:40:20 2009        (r3142)
+++ trunk/apps/qubit/modules/term/actions/showAction.class.php  Tue Sep  1 
16:42:58 2009        (r3143)
@@ -29,9 +29,7 @@
     $this->sourceNotes = $this->term->getNotesByType($noteTypeId = 
QubitTerm::SOURCE_NOTE_ID, $exclude = null);
     $this->displayNotes = $this->term->getNotesByType($noteTypeId = 
QubitTerm::DISPLAY_NOTE_ID, $exclude = null);
 
-    $criteria = new Criteria;
-    $criteria->add(QubitTerm::PARENT_ID, $this->term->id, Criteria::EQUAL);
-    $this->children = QubitTerm::get($criteria);
+    $this->children = $this->term->getChildren(array('sortBy' => 'name'));
 
     $this->uses    = QubitRelation::getRelationsByObjectId($this->term->id, 
array('typeId' => QubitTerm::TERM_RELATION_EQUIVALENCE_ID));
     $this->useFors = QubitRelation::getRelationsBySubjectId($this->term->id, 
array('typeId' => QubitTerm::TERM_RELATION_EQUIVALENCE_ID));

Modified: trunk/apps/qubit/modules/term/actions/treeViewAction.class.php
==============================================================================
--- trunk/apps/qubit/modules/term/actions/treeViewAction.class.php      Tue Sep 
 1 16:40:20 2009        (r3142)
+++ trunk/apps/qubit/modules/term/actions/treeViewAction.class.php      Tue Sep 
 1 16:42:58 2009        (r3143)
@@ -23,21 +23,23 @@
   {
     // Get data
     $term = QubitTerm::getById($this->getRequestParameter('id'));
-    $terms = $term->getChildren()->orderBy('lft');
 
     // Objects
     $treeViewObject = array();
     $treeViewObjects = array();
 
-    foreach ($terms as $term)
+    if (0 < count($children = $term->getChildren(array('sortBy' => 'name'))))
     {
-      $treeViewObject['label'] = (string) $term->getName(array('truncate' => 
50));
-      $treeViewObject['href'] = 
$this->getController()->genUrl('term/show?id='.$term->getId());
-      $treeViewObject['id'] = $term->getId();
-      $treeViewObject['parentId'] = $term->getParentId();
-      $treeViewObject['isLeaf'] = (string) count($term->getDescendants()) == 0;
+      foreach ($children as $child)
+      {
+        $treeViewObject['label'] = (string) 
$child->getName(array('cultureFallback' => true, 'truncate' => 50));
+        $treeViewObject['href'] = 
$this->getController()->genUrl('term/show?id='.$child->getId());
+        $treeViewObject['id'] = $child->getId();
+        $treeViewObject['parentId'] = $child->getParentId();
+        $treeViewObject['isLeaf'] = (string) count($child->getDescendants()) 
== 0;
 
-      $treeViewObjects[] = $treeViewObject;
+        $treeViewObjects[] = $treeViewObject;
+      }
     }
 
     // Prepare and print output

Modified: trunk/lib/model/QubitTerm.php
==============================================================================
--- trunk/lib/model/QubitTerm.php       Tue Sep  1 16:40:20 2009        (r3142)
+++ trunk/lib/model/QubitTerm.php       Tue Sep  1 16:42:58 2009        (r3143)
@@ -877,6 +877,19 @@
     $criteria = new Criteria;
     $criteria->add(QubitTerm::PARENT_ID, $this->id, Criteria::EQUAL);
 
+    $sortBy = (isset($options['sortBy'])) ? $options['sortBy'] : 'lft';
+
+    switch ($sortBy)
+    {
+      case 'name':
+        $criteria = QubitCultureFallback::addFallbackCriteria($criteria, 
'QubitTerm');
+        $criteria->addAscendingOrderByColumn('name');
+        break;
+      case 'lft':
+      default:
+        $criteria->addAscendingOrderByColumn('lft');
+    }
+
     return QubitTerm::get($criteria, $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.ca/group/qubit-commits?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to