Actions

API16

JTableUser/delete

From Joomla! Documentation

< API16:JTableUser
Revision as of 17:43, 22 March 2010 by Doxiki (Talk | contribs)

(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)
Replacement filing cabinet.png
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 delete a user, user groups, and any other necessary data from the database.

[Edit Descripton]

Description:JTableUser/delete

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;
}

[Edit See Also] SeeAlso:JTableUser/delete

Examples

<CodeExamplesForm />