Author: ornicar2
Date: 2010-02-12 21:47:27 +0100 (Fri, 12 Feb 2010)
New Revision: 27980

Added:
   plugins/diemPlugin/trunk/dmCorePlugin/lib/view/html/dmPageTreeView.php
Log:
[Diem] complete previous commit

Copied: plugins/diemPlugin/trunk/dmCorePlugin/lib/view/html/dmPageTreeView.php 
(from rev 27942, 
plugins/diemPlugin/trunk/dmCorePlugin/lib/view/html/dmRecursivePageList.php)
===================================================================
--- plugins/diemPlugin/trunk/dmCorePlugin/lib/view/html/dmPageTreeView.php      
                        (rev 0)
+++ plugins/diemPlugin/trunk/dmCorePlugin/lib/view/html/dmPageTreeView.php      
2010-02-12 20:47:27 UTC (rev 27980)
@@ -0,0 +1,94 @@
+<?php
+
+abstract class dmPageTreeView extends dmConfigurable
+{
+  protected
+  $tree,
+  $culture,
+  $html,
+  $level,
+  $lastLevel;
+
+  public function __construct($culture, array $options)
+  {
+    $this->initialize($options);
+    
+    $this->culture  = $culture;
+    $this->tree     = $this->getTree();
+  }
+
+  protected function initialize(array $options)
+  {
+    $this->configure($options);
+  }
+
+  abstract protected function getPageLink(array $page);
+
+  protected function getTree()
+  {
+    $pageTable = dmDb::table('DmPage');
+
+    $q = $pageTable->createQuery('page')
+    ->withI18n($this->culture, null, 'page')
+    ->select('page.id, page.action, pageTranslation.name, 
pageTranslation.slug');
+
+    $pageTable->getTree()->setBaseQuery($q);
+
+    $tree = $pageTable->getTree()->fetchTree(array(), 
Doctrine_Core::HYDRATE_NONE);
+    
+    $pageTable->getTree()->resetBaseQuery();
+
+    return $tree;
+  }
+
+  public function render($options = array())
+  {
+    $this->options = array_merge(dmString::toArray($options, true), 
$this->options);
+
+    $this->html = isset($this->options['class'])
+    ? '<ul class="'.$this->options['class'].'">'
+    : '<ul>';
+
+    $this->lastLevel = false;
+    foreach($this->tree as $node)
+    {
+      $this->level = $node[4];
+      $this->html .= $this->renderNode($node);
+      $this->lastLevel = $this->level;
+    }
+
+    $this->html .= str_repeat('</li></ul>', $this->lastLevel+1);
+
+    return $this->html;
+  }
+
+  protected function renderNode(array $page)
+  {
+    /*
+     * First time, don't insert nothing
+     */
+    if ($this->lastLevel === false)
+    {
+      $html = '';
+    }
+    elseif ($this->level === $this->lastLevel)
+    {
+      $html = '</li>';
+    }
+    elseif ($this->level > $this->lastLevel)
+    {
+      $html = '<ul>';
+    }
+    else // $this->level < $this->lastLevel
+    {
+      $html = str_repeat('</li></ul>', $this->lastLevel - 
$this->level).'</li>';
+    }
+
+    $html .= '<li id="dmp'.$page[0].'">';
+
+    $html .= $this->getPageLink($page);
+
+    return $html;
+  }
+
+}
\ No newline at end of file

-- 
You received this message because you are subscribed to the Google Groups 
"symfony SVN" 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/symfony-svn?hl=en.

Reply via email to