[TEP-COMMIT] [CVS catalog] new method to return the tree structure as an array

hpdl-OfajU3CKLf1/[email protected] 26 Oct 2004 20:07:17 -0000
Newsgroups gmane.comp.web.oscommerce.cvs
Message-ID <[email protected]>
<html>
<head>
<style><!--
  body {background-color:#ffffff;}
  .file {border:1px solid #eeeeee;margin-top:1em;margin-bottom:1em;}
  .pathname {font-family:monospace; float:right;}
  .fileheader {margin-bottom:.5em;}
  .diff {margin:0;}
  .tasklist {padding:4px;border:1px dashed #000000;margin-top:1em;}
  .tasklist ul {margin-top:0;margin-bottom:0;}
  tr.alt {background-color:#eeeeee}
  #added {background-color:#ddffdd;}
  #addedchars {background-color:#99ff99;font-weight:bolder;}
  tr.alt #added {background-color:#ccf7cc;}
  #removed {background-color:#ffdddd;}
  #removedchars {background-color:#ff9999;font-weight:bolder;}
  tr.alt #removed {background-color:#f7cccc;}
  #info {color:#888888;}
  #context {background-color:#eeeeee;}
  td {padding-left:.3em;padding-right:.3em;}
  tr.head {border-bottom-width:1px;border-bottom-style:solid;}
  tr.head td {padding:0;padding-top:.2em;}
  .task {background-color:#ffff00;}
  .comment {padding:4px;border:1px dashed #000000;background-color:#ffffdd}
  .error {color:red;}
  hr {border-width:0px;height:2px;background:black;}
--></style>
</head>
<body>
<table cellspacing="0" cellpadding="0" border="0" rules="cols">
<tr class="head"><td colspan="4">Commit in <b><tt>catalog/catalog/includes/classes</tt></b><span id="info"> on MAIN</span></td></tr>
<tr><td><tt><a href="#file1">category_tree.php</a></tt></td><td align="right" id="added">+35</td><td></td><td nowrap="nowrap" align="center"><a href="http://cvs.oscommerce.com/viewcvs.cgi/catalog/catalog/includes/classes/category_tree.php?rev=1.1&amp;content-type=text/vnd.viewcvs-markup">1.1</a> <a href="http://cvs.oscommerce.com/viewcvs.cgi/catalog/catalog/includes/classes/category_tree.php.diff?r1=1.1&amp;r2=1.2">-&gt;</a> <a href="http://cvs.oscommerce.com/viewcvs.cgi/catalog/catalog/includes/classes/category_tree.php?rev=1.2&amp;content-type=text/vnd.viewcvs-markup">1.2</a></td></tr>
</table>
<pre class="comment">
new method to return the tree structure as an array

(this class will be refined soon as it has grown into a monster)
</pre>
<hr /><a name="file1" /><div class="file">
<span class="pathname"><a href="http://cvs.oscommerce.com/viewcvs.cgi/catalog">catalog</a>/<a href="http://cvs.oscommerce.com/viewcvs.cgi/catalog/catalog">catalog</a>/<a href="http://cvs.oscommerce.com/viewcvs.cgi/catalog/catalog/includes">includes</a>/<a href="http://cvs.oscommerce.com/viewcvs.cgi/catalog/catalog/includes/classes">classes</a><br /></span>
<div class="fileheader"><big><b>category_tree.php</b></big> <small id="info"><a href="http://cvs.oscommerce.com/viewcvs.cgi/catalog/catalog/includes/classes/category_tree.php?rev=1.1&amp;content-type=text/vnd.viewcvs-markup">1.1</a> <a href="http://cvs.oscommerce.com/viewcvs.cgi/catalog/catalog/includes/classes/category_tree.php.diff?r1=1.1&amp;r2=1.2">-&gt;</a> <a href="http://cvs.oscommerce.com/viewcvs.cgi/catalog/catalog/includes/classes/category_tree.php?rev=1.2&amp;content-type=text/vnd.viewcvs-markup">1.2</a></small></div>
<pre class="diff"><small id="info">diff -u -r1.1 -r1.2
--- category_tree.php	2004/02/16 06:39:57	1.1
+++ category_tree.php	2004/10/26 20:07:09	1.2
@@ -142,6 +142,37 @@
</small></pre><pre class="diff" id="context">       return $result;
     }
 
</pre><pre class="diff" id="added">+    function buildBranchArray($parent_id, $level = 0, $result = '') {
+      if (empty($result)) {
+        $result = array();
+      }
+
+      if (isset($this-&gt;data[$parent_id])) {
+        foreach ($this-&gt;data[$parent_id] as $category_id =&gt; $category) {
+          if ($this-&gt;breadcrumb_usage == true) {
+            $category_link = $this-&gt;buildBreadcrumb($category_id);
+          } else {
+            $category_link = $category_id;
+          }
+
+          $result[] = array('id' =&gt; $category_link,
+                            'title' =&gt; str_repeat($this-&gt;spacer_string, $this-&gt;spacer_multiplier * $level) . $category['name']);
+
+          if (isset($this-&gt;data[$category_id]) &amp;&amp; (($this-&gt;max_level == '0') || ($this-&gt;max_level &gt; $level+1))) {
+            if ($this-&gt;follow_cpath === true) {
+              if (in_array($category_id, $this-&gt;cpath_array)) {
+                $result = $this-&gt;buildBranchArray($category_id, $level+1, $result);
+              }
+            } else {
+              $result = $this-&gt;buildBranchArray($category_id, $level+1, $result);
+            }
+          }
+        }
+      }
+
+      return $result;
+    }
+
</pre><pre class="diff" id="context">     function buildBreadcrumb($category_id, $level = 0) {
       $breadcrumb = '';
 
</pre><pre class="diff"><small id="info">@@ -166,6 +197,10 @@
</small></pre><pre class="diff" id="context"> 
     function buildTree() {
       return $this-&gt;buildBranch($this-&gt;root_category_id);
</pre><pre class="diff" id="added">+    }
+
+    function getTree($parent_id = '') {
+      return $this-&gt;buildBranchArray((empty($parent_id) ? $this-&gt;root_category_id : $parent_id));
</pre><pre class="diff" id="context">     }
 
     function calculateCategoryProductCount() {
</pre></div>
<center><small><a href="http://www.badgers-in-foil.co.uk/projects/cvsspam/" title="commit -&gt; email">CVSspam</a> 0.2.9</small></center>
</body></html>


-------------------------------------------------------
This SF.Net email is sponsored by:
Sybase ASE Linux Express Edition - download now for FREE
LinuxWorld Reader's Choice Award Winner for best database on Linux.
http://ads.osdn.com/?ad_id=5588&alloc_id=12065&op=click