Author: sevein
Date: Fri Jun  8 18:33:33 2012
New Revision: 11752

Log:
Showing treeview active item siblings, slice items to keep a limited number of 
items below and above the active one, needs some fixes

Modified:
   
branches/2.0/apps/qubit/modules/informationobject/actions/treeViewComponent.class.php
   branches/2.0/apps/qubit/modules/informationobject/templates/_treeView.php

Modified: 
branches/2.0/apps/qubit/modules/informationobject/actions/treeViewComponent.class.php
==============================================================================
--- 
branches/2.0/apps/qubit/modules/informationobject/actions/treeViewComponent.class.php
       Fri Jun  8 00:02:55 2012        (r11751)
+++ 
branches/2.0/apps/qubit/modules/informationobject/actions/treeViewComponent.class.php
       Fri Jun  8 18:33:33 2012        (r11752)
@@ -19,6 +19,8 @@
 
 class InformationObjectTreeViewComponent extends sfComponent
 {
+  const SIBLINGS = 10;
+
   public function execute($request)
   {
     $this->resource = $request->getAttribute('sf_route')->resource;
@@ -51,7 +53,7 @@
       $this->resource->lft,
       $this->resource->rgt));
 
-    // Find siblings
+    // Previous N siblings
     $sql = 'SELECT
         io.*,
         i18n.*,
@@ -67,11 +69,75 @@
       WHERE
         io.parent_id = ?
         AND i18n.culture = ?
-      ORDER BY i18n.title';
+        AND io.lft < ?
+      ORDER BY io.lft DESC
+      LIMIT '.self::SIBLINGS;
+
+    // Notice usage of array_reverse to invert the order
+    $this->treeview['prevSiblings'] = array_reverse(
+      QubitPdo::fetchAll($sql, array(
+        $this->resource->parentId,
+        $this->context->user->getCulture(),
+        $this->resource->lft)));
 
-    $this->treeview['siblings'] = QubitPdo::fetchAll($sql, array(
+    // Next N siblings
+    $sql = 'SELECT
+        io.*,
+        i18n.*,
+        slug.slug,
+        pubstat.status_id as publication_status_id
+      FROM '.QubitInformationObject::TABLE_NAME.' io
+      JOIN '.QubitInformationObjectI18n::TABLE_NAME.' i18n
+        ON io.id = i18n.id
+      JOIN '.QubitSlug::TABLE_NAME.' slug
+        ON io.id = slug.object_id
+      JOIN '.QubitStatus::TABLE_NAME.' pubstat
+        ON io.id = pubstat.object_id
+      WHERE
+        io.parent_id = ?
+        AND i18n.culture = ?
+        AND io.lft > ?
+      ORDER BY io.lft ASC
+      LIMIT '.self::SIBLINGS;
+
+    $this->treeview['nextSiblings'] = QubitPdo::fetchAll($sql, array(
       $this->resource->parentId,
-      $this->context->user->getCulture()));
+      $this->context->user->getCulture(),
+      $this->resource->lft));
+
+    // Slice prevSiblings and nextSiblings arrays
+    $prevSiblingsCount = count($this->treeview['prevSiblings']);
+    $nextSiblingsCount = count($this->treeview['nextSiblings']);
+
+    function array_cut($operation, &$array, $iterate)
+    {
+      while (($iterate--) != false)
+      {
+        call_user_func_array("array_$operation", array(&$array));
+      }
+
+      return $array;
+    }
+
+    if (floor(self::SIBLINGS / 2) > floor($nextSiblingsCount))
+    {
+      $prevSiblingsSlice = $nextSiblingsCount;
+    }
+    else
+    {
+      $prevSiblingsSlice = floor(self::SIBLINGS / 2);
+    }
+
+    if (floor(self::SIBLINGS / 2) > floor($prevSiblingsCount))
+    {
+      $nextSiblingsSlice = $prevSiblingsCount;
+    }
+    else
+    {
+      $nextSiblingsSlice = floor(self::SIBLINGS / 2);
+    }
 
+    array_cut('shift', $this->treeview['prevSiblings'], $prevSiblingsSlice);
+    array_cut('pop', $this->treeview['nextSiblings'], $nextSiblingsSlice);
   }
 }

Modified: 
branches/2.0/apps/qubit/modules/informationobject/templates/_treeView.php
==============================================================================
--- branches/2.0/apps/qubit/modules/informationobject/templates/_treeView.php   
Fri Jun  8 00:02:55 2012        (r11751)
+++ branches/2.0/apps/qubit/modules/informationobject/templates/_treeView.php   
Fri Jun  8 18:33:33 2012        (r11752)
@@ -5,19 +5,39 @@
     <li class="back"><i></i><?php echo link_to(__('Show all'), array('module' 
=> 'informationobject', 'action' => 'browse')) ?></li>
 
     <?php foreach ($treeview['ancestors'] as $item): ?>
-      <li class="ancestor"><i></i><?php echo link_to($item->title, 
array('module' => 'informationobject', 'slug' => $item->slug)) ?> 
<strong>LOD</strong></li>
+      <li class="ancestor"><i></i><?php echo link_to($item->id . '-' . 
$item->lft . '-' . $item->rgt, array('module' => 'informationobject', 'slug' => 
$item->slug)) ?> <strong>LOD</strong></li>
     <?php endforeach; ?>
 
-    <?php if (1 < $resource->lft - $parent->lft): ?>
-      <li class="more"><a href="#">...</a></li>
+    <?php if (isset($treeview['prevSiblings']) && 0 < 
count($treeview['prevSiblings'])): ?>
+      <?php if (1 < $treeview['prevSiblings'][0]->lft - $parent->lft): ?>
+        <li class="more"><a href="#">...</a></li>
+      <?php endif; ?>
     <?php endif; ?>
 
-    <?php $expand = 1 < $item->rgt - $item->lft ?>
+    <?php foreach ($treeview['prevSiblings'] as $prev): ?>
+      <?php $expand = 1 < $prev->rgt - $prev->lft ?>
+      <li class="<?php if ($expand) echo 'expand' ?>">
+        <?php if ($expand) echo '<i></i>' ?>
+        <?php echo link_to('p' . $prev->id . '-' . $prev->lft . '-' . 
$prev->rgt, array('module' => 'informationobject', 'slug' => $prev->slug)) ?> 
<strong>LOD</strong>
+      </li>
+    <?php endforeach; ?>
+
+    <?php $expand = 1 < $resource->rgt - $resource->lft ?>
     <li class="<?php if ($expand) echo 'expand' ?> active">
       <?php if ($expand) echo '<i></i>' ?>
-      <?php echo link_to($item->title, array('module' => 'informationobject', 
'slug' => $item->slug)) ?> <strong>LOD</strong></li>
+      <?php echo link_to($resource->id . '-' . $resource->lft . '-' . 
$resource->rgt, array('module' => 'informationobject', 'slug' => 
$resource->slug)) ?> <strong>LOD</strong>
+    </li>
+
+    <?php foreach ($treeview['nextSiblings'] as $next): ?>
+      <?php $expand = 1 < $next->rgt - $next->lft ?>
+      <li class="<?php if ($expand) echo 'expand' ?>">
+        <?php if ($expand) echo '<i></i>' ?>
+        <?php echo link_to('n' . $next->id . '-' . $next->lft . '-' . 
$next->rgt, array('module' => 'informationobject', 'slug' => $next->slug)) ?> 
<strong>LOD</strong>
+      </li>
+    <?php endforeach; ?>
 
-    <?php if (1 < $parent->rgt - $resource->lft): ?>
+    <?php $last = isset($next) ? $next : $resource ?>
+    <?php if ($parent->rgt - $last->rgt > 1): ?>
       <li class="more"><a href="#">...</a></li>
     <?php endif; ?>
 

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