API16

JTableUsergroup/delete

From Joomla! Documentation

< API16:JTableUsergroup

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]

Delete this object and it's dependancies



Syntax[edit]

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

Defined in[edit]

libraries/joomla/database/table/usergroup.php

Importing[edit]

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

Source Body[edit]

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



Examples[edit]

Code Examples[edit]