Author: spikebrehm
Date: 2010-04-28 03:01:07 +0200 (Wed, 28 Apr 2010)
New Revision: 29284
Added:
plugins/srPageChooserPlugin/trunk/lib/srPageChooserTools.class.php
Modified:
plugins/srPageChooserPlugin/trunk/lib/BasesrPageChooserActions.class.php
Log:
properly adding slug to page tree
Modified:
plugins/srPageChooserPlugin/trunk/lib/BasesrPageChooserActions.class.php
===================================================================
--- plugins/srPageChooserPlugin/trunk/lib/BasesrPageChooserActions.class.php
2010-04-28 00:22:55 UTC (rev 29283)
+++ plugins/srPageChooserPlugin/trunk/lib/BasesrPageChooserActions.class.php
2010-04-28 01:01:07 UTC (rev 29284)
@@ -27,6 +27,11 @@
$root = aPageTable::retrieveBySlug('/');
- $this->treeData = $root->getTreeJSONReadySR(false);
+ $this->treeData = $root->getTreeJSONReady(false);
+ $this->treeData = array($this->treeData);
+
+ srPageChooserTools::addSlugToTreeData($this->treeData);
+
+ $this->treeData = $this->treeData[0];
}
}
Added: plugins/srPageChooserPlugin/trunk/lib/srPageChooserTools.class.php
===================================================================
--- plugins/srPageChooserPlugin/trunk/lib/srPageChooserTools.class.php
(rev 0)
+++ plugins/srPageChooserPlugin/trunk/lib/srPageChooserTools.class.php
2010-04-28 01:01:07 UTC (rev 29284)
@@ -0,0 +1,56 @@
+<?php
+
+/**
+ * Helper methods for srPageChooserPlugin.
+ *
+ * @package srPageChooserPlugin
+ * @subpackage lib
+ * @author Alexander "Spike" Brehm <[email protected]>
+ * @version SVN: $Id: BaseActions.class.php 12534 2008-11-01 13:38:27Z
Kris.Wallsmith $
+ */
+class srPageChooserTools
+{
+ static public function addSlugToTreeData(&$treeData, $hash = false)
+ {
+ if (!$hash)
+ {
+ $hash = self::getSlugHash();
+ }
+
+ foreach ($treeData as $pos => &$node)
+ {
+ if (isset($node['children']) && count($node['children']))
+ {
+ self::addSlugToTreeData($node['children'], $hash);
+ }
+
+ // extract page id from i.e. 'tree-1'
+ $id = self::getPageIdFromHtmlId($node['attributes']['id']);
+ $node['slug'] = $hash[$id];
+ }
+ return $treeData;
+ }
+
+ static public function getPageIdFromHtmlId($htmlId)
+ {
+ $id = (int) substr($htmlId, strpos($htmlId, '-')+1);
+ return $id;
+ }
+
+ static public function getSlugHash()
+ {
+ $query = Doctrine_Query::Create()->
+ select("p.id, p.slug")->
+ from("aPage p");
+
+ $pages = $query->execute();
+
+ $hash = array();
+ foreach ($pages as $page)
+ {
+ $hash[$page->getId()] = $page->getSlug();
+ }
+
+ return $hash;
+ }
+}
--
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.