PHP Classes

This Looks rather nice

Recommend this page to a friend!

      Simple Tree  >  All threads  >  This Looks rather nice  >  (Un) Subscribe thread alerts  
Subject:This Looks rather nice
Summary:I was wondering maybe you might please post an example of how to
Messages:3
Author:Tony
Date:2011-07-30 11:02:38
Update:2011-07-30 15:14:27
 

  1. This Looks rather nice   Reply   Report abuse  
Picture of Tony Tony - 2011-07-30 11:02:38
I was wondering maybe you might please post an example of how to use this tree. I have an idea though, but an example will make things easier.
I am currently developing a php framework, and i was thinking that if this class really functions well, i might use it.

  2. Re: This Looks rather nice   Reply   Report abuse  
Picture of Leigh Edwards Leigh Edwards - 2011-07-30 15:08:19 - In reply to message 1 from Tony
sure, but it is a 'simple' tree and can only display one branch as is. I was coding it for another project that only required that,

here is how I use it

$tree = new tree ( "Comps" );
$tree->setBranches ( $compGroupsArray );
$tree->buildTree ( $compsArray, 2, 0, 3 );
$treeArray = $tree->getTree ();

where $compGroupsArray in an array like this
Array
(
[1] => CAL Comp Form
[2] => LL Comp Form
[3] => LL Comp Form - Directors
[4] => Forgotten Pass
[5] => Misc Comp Sheet
[6] => SBLLS
[7] => Coupon/Voucher
[8] => Head Office ONLY
[9] => TESTING COMPS
[13] => Groups/Events
[14] => Ticket/Pass Issues
[17] => Summer Comps
[16] => Volunteers
)

and $compsArray looks like this

Array
(
[2] => Array
(
[0] => 2
[CompID] => 2
[1] => 3
[ResortID] => 3
[2] => 1
[CompGroup] => 1
[3] => Murray Edwards
[Description] => Murray Edwards
[4] =>
[Account] =>
[5] => May 1 2004 12:00:00:000AM
[StartDate] => May 1 2004 12:00:00:000AM
[6] => Oct 24 2009 12:00:00:000AM
[EndDate] => Oct 24 2009 12:00:00:000AM
[7] => 1
[PrintReceipt] => 1
[8] =>
[CreditAmount] =>
[9] => 1
[FunctionID] => 1
[10] => 0
[NeedReason] => 0
[11] => 0
[NeedMemberID] => 0
[12] => 0
[NeedPassNumber] => 0
[13] => -1
[AmountAllowed] => -1
[14] =>
[TotalUsed] =>
[15] => 1
[SubGroup] => 1
[16] => 0
[ShowTickets] => 0
[17] => 0
[ShowPass] => 0
[18] => Jul 27 2011 11:45:00:000AM
[UpdateDate] => Jul 27 2011 11:45:00:000AM
[19] => 1
[UpdateBy] => 1
[20] => 1
[IncludeInReports] => 1
[21] => 1
[22] => CAL Comp Form
[GroupName] => CAL Comp Form
[23] => 1
)

[6] => Array
(
[0] => 6
[CompID] => 6
[1] => 3
[ResortID] => 3
[2] => 1
[CompGroup] => 1
[3] => Charlie Locke
[Description] => Charlie Locke
[4] =>
[Account] =>
[5] => Nov 1 2004 12:00:00:000AM
[StartDate] => Nov 1 2004 12:00:00:000AM
[6] => May 4 2012 12:00:00:000AM
[EndDate] => May 4 2012 12:00:00:000AM
[7] => 0
[PrintReceipt] => 0
[8] =>
[CreditAmount] =>
[9] => 61
[FunctionID] => 1
[10] => 1
[NeedReason] => 1
[11] => 0
[NeedMemberID] => 0
[12] => 0
[NeedPassNumber] => 0
[13] => -1
[AmountAllowed] => -1
[14] =>
[TotalUsed] =>
[15] => 1
[SubGroup] => 1
[16] => 1
[ShowTickets] => 1
[17] => 1
[ShowPass] => 1
[18] => Jul 26 2011 04:08:00:000PM
[UpdateDate] => Jul 26 2011 04:08:00:000PM
[19] => 4
[UpdateBy] => 4
[20] => 1
[IncludeInReports] => 1
[21] => 1
[22] => CAL Comp Form
[GroupName] => CAL Comp Form
[23] => 1
)
}


the buildTree method takes the comps array as branches and the other as the leaves for that branch and using the params ( 2,0,3 in this case) to id the elements of the compsArray to use to relate to the compGroupsArray.

so the param 2 tells its to group the comps by the group id in compsArray[2].

The param 0 tells it to give the comp the id value in compsArray[0]

and the param 3 tells it to use the value of compsArray[3] as the text to display in the tree.


in my case this is what I get back from the getTree method


<div class="treeRoot" id="treeName" name="treeName"><a href="#" class="treeTitle">Click To Expand</a><div class="tree" id="tree1"><a href="#" class="branchTitle" onclick="treeshow('Comps-1')">1 : CAL Comp Form</a><div class="treeBranch" id="Comps-1" style="display: none;"><a href="#" onclick="ajax('ajax/comps.ajax.php','loadComp=true&amp;compIDtoLoad=2','popupFormDiv')" class="leafTitle">2 : Edwards</a><a href="#" onclick="ajax('ajax/comps.ajax.php','loadComp=true&amp;compIDtoLoad=6','popupFormDiv')" class="leafTitle">6 : Locke</a><a href="#" onclick="ajax('ajax/comps.ajax.php','loadComp=true&amp;compIDtoLoad=155','popupFormDiv')" class="leafTitle">155 : Sport Check 2 for 1</a><a href="#" onclick="ajax('ajax/comps.ajax.php','loadComp=true&amp;compIDtoLoad=172','popupFormDiv')" class="leafTitle">172 : Louise </a><a href="#" onclick="ajax('ajax/comps.ajax.php','loadComp=true&amp;compIDtoLoad=176','popupFormDiv')" class="leafTitle">176 : Ross</a><a href="#" onclick="ajax('ajax/comps.ajax.php','loadComp=true&amp;compIDtoLoad=177','popupFormDiv')" class="leafTitle">177 : Kwasney</a></div>



I hope that helps. I want to expand this to be a bit more dynamic and to handle multiple levels when I have time.



  3. Re: This Looks rather nice   Reply   Report abuse  
Picture of Tony Tony - 2011-07-30 15:14:27 - In reply to message 2 from Leigh Edwards
That is very fantastic amigo. With that simple example, you have helped a lot of people.
- Hasta la vista