API16

JTableNested/rebuildPath

From Joomla! Documentation

< API16:JTableNested
Revision as of 17:43, 22 March 2010 by Doxiki (talk | contribs) (New page: ===Description=== Method to rebuild the node's path field from the alias values of the nodes from the current node to the root node of the tree. <span class="editsection" style="font-si...)
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)
The printable version is no longer supported and may have rendering errors. Please update your browser bookmarks and please use the default browser print function instead.

The "API16" namespace is an archived namespace. This page contains information for a Joomla! version which is no longer supported. It exists only as a historical reference, it will not be improved and its content may be incomplete and/or contain broken links.

Description[edit]

Method to rebuild the node's path field from the alias values of the nodes from the current node to the root node of the tree.

[Edit Descripton]

Template:Description:JTableNested/rebuildPath

Syntax[edit]

rebuildPath($pk=null)
Parameter Name Default Value Description
$pk null Primary key of the node for which to get the path.

Returns[edit]

boolean True on success.

Defined in[edit]

libraries/joomla/database/tablenested.php

Importing[edit]

jimport( 'joomla.database.tablenested' );

Source Body[edit]

public function rebuildPath($pk = null)
{
        // If there is no alias or path field, just return true.
        if (!property_exists($this, 'alias') || !property_exists($this, 'path')) {
                return true;
        }

        // Initialise variables.
        $k = $this->_tbl_key;
        $pk = (is_null($pk)) ? $this->$k : $pk;

        // Get the aliases for the path from the node to the root node.
        $this->_db->setQuery(
                'SELECT p.alias' .
                ' FROM '.$this->_tbl.' AS n, '.$this->_tbl.' AS p' .
                ' WHERE n.lft BETWEEN p.lft AND p.rgt' .
                ' AND n.'.$this->_tbl_key.' = '. (int) $pk .
                ' ORDER BY p.lft'
        );
        $segments = $this->_db->loadResultArray();

        // Make sure to remove the root path if it exists in the list.
        if ($segments[0] == 'root') {
                array_shift($segments);
        }

        // Build the path.
        $path = trim(implode('/', $segments), ' /\\');

        // Update the path field for the node.
        $this->_db->setQuery(
                'UPDATE `'.$this->_tbl.'`' .
                ' SET `path` = '.$this->_db->quote($path) .
                ' WHERE `'.$this->_tbl_key.'` = '.(int) $pk
        );
        $this->_db->query();

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

        return true;
}

[Edit See Also] Template:SeeAlso:JTableNested/rebuildPath

Examples[edit]

<CodeExamplesForm />