API16:JTableNested/rebuildPath
From Joomla! Documentation
This Namespace has been archived - Please Do Not Edit or Create Pages in this namespace. Pages contain information for a Joomla! version which is no longer supported. It exists only as a historical reference, will not be improved and its content may be incomplete.
Contents |
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.
Description:JTableNested/rebuildPath
Syntax
rebuildPath($pk=null)
| Parameter Name | Default Value | Description |
|---|---|---|
| $pk | null | Primary key of the node for which to get the path. |
Returns
boolean True on success.
Defined in
libraries/joomla/database/tablenested.php
Importing
jimport( 'joomla.database.tablenested' );
Source Body
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] SeeAlso:JTableNested/rebuildPath
Examples
<CodeExamplesForm />
