Specifications

This class contains the functionality that drives the tree view in this application.
One instance of the treenode class contains details about a single posting and links to all the
reply postings of that class. This gives us the following member variables:
var $m_postid;
var $m_title;
var $m_poster;
var $m_posted;
var $m_children;
var $m_childlist;
var $m_depth;
Notice that the treenode does not contain the body of the article. There is no need to load this
until a user goes to the view_post.php script. We need to try to make this relatively fast, as we
are doing a lot of data manipulation to display the tree list, and need to recalculate when the
page is refreshed, or a button is pressed.
The naming scheme for these variables follows a naming scheme commonly used in OO appli-
cationsstarting variables with m_ to remind us that they are member variables of the class.
Most of these variables correspond directly to rows from the header table in our database.
The exceptions are $m_childlist and $m_depth. We will use the variable $m_childlist to
hold the replies to this article. The variable $m_depth will hold the number of tree levels that
we are downthis will be used for creating the display.
The constructor function sets up the values of all the variables, as follows:
function treenode($postid, $title, $poster, $posted, $children,
$expand, $depth, $expanded, $sublist)
{
// the constructor sets up the member variables, but more
// importantly recursively creates lower parts of the tree
$this->m_postid = $postid;
$this->m_title = $title;
$this->m_poster = $poster;
$this->m_posted = $posted;
$this->m_children =$children;
$this->m_childlist = array();
$this->m_depth = $depth;
Building Practical PHP and MySQL Projects
P
ART V
728
35 7842 CH29 3/6/01 3:34 PM Page 728