API16:JTableUser/delete
From Joomla! Documentation
Description
Method to delete a user, user groups, and any other necessary data from the database.
Syntax
delete($userId=null)
Parameter Name | Default Value | Description |
---|---|---|
$userId | null | $userId An optional user id. |
Returns
boolean True on success, false on failure.
Defined in
libraries/joomla/database/table/user.php
Importing
jimport( 'joomla.database.table.user' );
Source Body
function delete($userId = null)
{
// Set the primary key to delete.
$k = $this->_tbl_key;
if ($userId) {
$this->$k = intval($userId);
}
// Delete the user.
$this->_db->setQuery(
'DELETE FROM `'.$this->_tbl.'`' .
' WHERE `'.$this->_tbl_key.'` = '.(int) $this->$k
);
$this->_db->query();
// Check for a database error.
if ($this->_db->getErrorNum()) {
$this->setError($this->_db->getErrorMsg());
return false;
}
// Delete the user group maps.
$this->_db->setQuery(
'DELETE FROM `#__user_usergroup_map`' .
' WHERE `user_id` = '.(int) $this->$k
);
$this->_db->query();
// Check for a database error.
if ($this->_db->getErrorNum()) {
$this->setError($this->_db->getErrorMsg());
return false;
}
/*
* Clean Up Related Data.
*/
$this->_db->setQuery(
'DELETE FROM `#__messages_cfg`' .
' WHERE `user_id` = '.(int) $this->$k
);
$this->_db->query();
// Check for a database error.
if ($this->_db->getErrorNum()) {
$this->setError($this->_db->getErrorMsg());
return false;
}
$this->_db->setQuery(
'DELETE FROM `#__messages`' .
' WHERE `user_id_to` = '.(int) $this->$k
);
$this->_db->query();
// Check for a database error.
if ($this->_db->getErrorNum()) {
$this->setError($this->_db->getErrorMsg());
return false;
}
return true;
}
Examples
Code Examples