API16

JTableNested/getTree: Difference between revisions

From Joomla! Documentation

Doxiki (talk | contribs)
New page: ===Description=== Method to get a node and all its child nodes. <span class="editsection" style="font-size:76%;"> <nowiki>[</nowiki>[[Description:JTableNested/getTree|Edit Descripton]...
 
m preparing for archive only
 
(One intermediate revision by the same user not shown)
Line 2: Line 2:
Method to get a node and all its child nodes.
Method to get a node and all its child nodes.


<span class="editsection" style="font-size:76%;">
<nowiki>[</nowiki>[[Description:JTableNested/getTree|Edit Descripton]]<nowiki>]</nowiki>
</span>


{{Description:JTableNested/getTree}}
 
 


===Syntax===
===Syntax===
Line 63: Line 61:
</source>
</source>


<span class="editsection" style="font-size:76%;">
 
<nowiki>[</nowiki>[[SeeAlso:JTableNested/getTree|Edit See Also]]<nowiki>]</nowiki>
 
</span>
{{SeeAlso:JTableNested/getTree}}


===Examples===
===Examples===
<CodeExamplesForm />
=== Code Examples ===
<dpl>
<dpl>
  noresultsheader=\n
  noresultsheader=\n
  category=getTree
  category=getTree
  category=JTableNested
  category=JTableNested
  category=CodeExample
  namespace=CodeExample
  category=MethodExample
  category=MethodExample
  include=*
  include=*
  format= ,,,
  format= ,,,
</dpl>
</dpl>

Latest revision as of 02:11, 25 March 2017

Description

Method to get a node and all its child nodes.



Syntax

getTree($pk=null, $diagnostic=false)
Parameter Name Default Value Description
$pk null Primary key of the node for which to get the tree.
$diagnostic false Only select diagnostic data for the nested sets.

Returns

mixed Boolean false on failure or array of node objects on success.

Defined in

libraries/joomla/database/tablenested.php

Importing

jimport( 'joomla.database.tablenested' );

Source Body

public function getTree($pk = null, $diagnostic = false)
{
        // Initialise variables.
        $k = $this->_tbl_key;
        $pk = (is_null($pk)) ? $this->$k : $pk;

        // Get the node and children as a tree.
        $select = ($diagnostic) ? 'SELECT n.'.$k.', n.parent_id, n.level, n.lft, n.rgt' : 'SELECT n.*';
        $this->_db->setQuery(
                $select .
                ' FROM `'.$this->_tbl.'` AS n, `'.$this->_tbl.'` AS p' .
                ' WHERE n.lft BETWEEN p.lft AND p.rgt' .
                ' AND p.'.$k.' = '.(int) $pk .
                ' ORDER BY n.lft'
        );
        $tree = $this->_db->loadObjectList();

        // Check for a database error.
        if ($this->_db->getErrorNum()) {
                $this->setError($this->_db->getErrorMsg());
                return false;
        }

        return $tree;
}



Examples

Code Examples