Actions

API16

JTableUsergroup/delete

From Joomla! Documentation

< API16:JTableUsergroup
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

Delete this object and it's dependancies

[Edit Descripton]

Description:JTableUsergroup/delete

Syntax

delete($oid=null)
Parameter Name Default Value Description
$oid null

Defined in

libraries/joomla/database/table/usergroup.php

Importing

jimport( 'joomla.database.table.usergroup' );

Source Body

function delete($oid = null)
{
        $k = $this->_tbl_key;
 
        if ($oid) {
                $this->load($oid);
        }
        if ($this->id == 0) {
                return new JException(JText::_('Category not found'));
        }
        if ($this->parent_id == 0) {
                return new JException(JText::_('Root categories cannot be deleted'));
        }
        if ($this->lft == 0 or $this->rgt == 0) {
                return new JException(JText::_('Left-Right data inconsistency. Cannot delete category.'));
        }
 
        $db = &$this->getDbo();
 
        // Select the category ID and it's children
        $db->setQuery(
                'SELECT c.id' .
                ' FROM `'.$this->_tbl.'` AS c' .
                ' WHERE c.lft >= '.(int) $this->lft.' AND c.rgt <= '.$this->rgt
        );
        $ids = $db->loadResultArray();
        if (empty($ids)) {
                return new JException(JText::_('Left-Right data inconsistency. Cannot delete category.'));
        }
        $ids = implode(',', $ids);
 
        // Delete the category dependancies
        // @todo Remove all related threads, posts and subscriptions
 
        // Delete the category and it's children
        $db->setQuery(
                'DELETE FROM `'.$this->_tbl.'`' .
                ' WHERE id IN ('.$ids.')'
        );
        if (!$db->query()) {
                $this->setError($db->getErrorMsg());
                return false;
        }
 
        // Delete the user to usergroup mappings for the group(s) from the database.
        $db->setQuery(
                'DELETE FROM `#__user_usergroup_map`' .
                ' WHERE `group_id` IN ('.$ids.')'
        );
        $db->query();
 
        // Check for a database error.
        if ($db->getErrorNum()) {
                $this->setError($db->getErrorMsg());
                return false;
        }
 
        return true;
}

[Edit See Also] SeeAlso:JTableUsergroup/delete

Examples

<CodeExamplesForm />