english/libraries/joomla/database/table/usergroup.php
/**
	 * Delete this object and its dependancies
	 *
	 * @param   integer  $oid  The primary key of the user group to delete.
	 *
	 * @return  mixed  Boolean or Exception.
	 *
	 * @since   11.1
	 */
Delete this object and its dependancies
@param   integer  $oid  The primary key of the user group to delete.

@return  mixed  Boolean or Exception.


Delete this object and its dependancies @param integer $oid The primary key of the user group to delete . @return mixed Boolean or Exception .
function delete($oid = null)
	{
		$k = $this->_tbl_key;
		if ($oid) {
			$this->load($oid);
		}
		if ($this->id == 0) {
			return new JException(JText::_('JGLOBAL_CATEGORY_NOT_FOUND'));
		}
		if ($this->parent_id == 0) {
			return new JException(JText::_('JLIB_DATABASE_ERROR_DELETE_ROOT_CATEGORIES'));
		}
		if ($this->lft == 0 or $this->rgt == 0) {
			return new JException(JText::_('JLIB_DATABASE_ERROR_DELETE_CATEGORY'));
		}
		$db = $this->getDbo();
		$db->setQuery(
			'SELECT c.id' .
			' FROM '.$db->quoteName($this->_tbl).' AS c' .
			' WHERE c.lft >= '.(int) $this->lft.' AND c.rgt <= '.$this->rgt
		);
		$ids = $db->loadColumn();
		if (empty($ids)) {
			return new JException(JText::_('JLIB_DATABASE_ERROR_DELETE_CATEGORY'));
		}
		$db->setQuery(
			'DELETE FROM '.$db->quoteName($this->_tbl).
			' WHERE id IN ('.implode(',', $ids).')'
		);
		if (!$db->query()) {
			$this->setError($db->getErrorMsg());
			return false;
		}
		$replace = array();
		foreach ($ids as $id)
		{
			$replace []= ','.$db->quote("[$id,").','.$db->quote("[").')';
			$replace []= ','.$db->quote(",$id,").','.$db->quote(",").')';
			$replace []= ','.$db->quote(",$id]").','.$db->quote("]").')';
			$replace []= ','.$db->quote("[$id]").','.$db->quote("[]").')';
		}
		$query = $db->getQuery(true);
		$query->set('rules='.str_repeat('replace(',4*count($ids)).'rules'.implode('',$replace));
		$query->update('#__viewlevels');
		$query->where('rules REGEXP "(,|\\\\[)('.implode('|', $ids).')(,|\\\\])"');
		$db->setQuery($query);
		if (!$db->query()) {
			$this->setError($db->getErrorMsg());
			return false;
		}
		$db->setQuery(
			'DELETE FROM `#__user_usergroup_map`' .
			' WHERE `group_id` IN ('.implode(',', $ids).')'
		);
		$db->query();
		if ($db->getErrorNum()) {
			$this->setError($db->getErrorMsg());
			return false;
		}
		return true;
	}
function delete ( $ oid = null ) { $ k = $ this -> _tbl_key ; if ( $ oid ) { $ this -> load ( $ oid ) ; } if ( $ this -> id == 0 ) { return new JException ( JText :: _ ( 'JGLOBAL_CATEGORY_NOT_FOUND' ) ) ; } if ( $ this -> parent_id == 0 ) { return new JException ( JText :: _ ( 'JLIB_DATABASE_ERROR_DELETE_ROOT_CATEGORIES' ) ) ; } if ( $ this -> lft == 0 or $ this -> rgt == 0 ) { return new JException ( JText :: _ ( 'JLIB_DATABASE_ERROR_DELETE_CATEGORY' ) ) ; } $ db = $ this -> getDbo ( ) ; $ db -> setQuery ( 'SELECT c.id' . ' FROM ' . $ db -> quoteName ( $ this -> _tbl ) . ' AS c' . ' WHERE c.lft >= ' . ( int ) $ this -> lft . ' AND c.rgt <= ' . $ this -> rgt ) ; $ ids = $ db -> loadColumn ( ) ; if ( empty ( $ ids ) ) { return new JException ( JText :: _ ( 'JLIB_DATABASE_ERROR_DELETE_CATEGORY' ) ) ; } $ db -> setQuery ( 'DELETE FROM ' . $ db -> quoteName ( $ this -> _tbl ) . ' WHERE id IN (' . implode ( ',' , $ ids ) . ')' ) ; if ( ! $ db -> query ( ) ) { $ this -> setError ( $ db -> getErrorMsg ( ) ) ; return false ; } $ replace = array ( ) ; foreach ( $ ids as $ id ) { $ replace [ ] = ',' . $ db -> quote ( " [ $ id , " ) . ',' . $ db -> quote ( " [ " ) . ')' ; $ replace [ ] = ',' . $ db -> quote ( " , $ id , " ) . ',' . $ db -> quote ( " , " ) . ')' ; $ replace [ ] = ',' . $ db -> quote ( " , $ id ] " ) . ',' . $ db -> quote ( " ] " ) . ')' ; $ replace [ ] = ',' . $ db -> quote ( " [ $ id ] " ) . ',' . $ db -> quote ( " [] " ) . ')' ; } $ query = $ db -> getQuery ( true ) ; $ query -> set ( 'rules=' . str_repeat ( 'replace(' , 4 * count ( $ ids ) ) . 'rules' . implode ( '' , $ replace ) ) ; $ query -> update ( '#__viewlevels' ) ; $ query -> where ( 'rules REGEXP "(,|\\\\[)(' . implode ( '|' , $ ids ) . ')(,|\\\\])"' ) ; $ db -> setQuery ( $ query ) ; if ( ! $ db -> query ( ) ) { $ this -> setError ( $ db -> getErrorMsg ( ) ) ; return false ; } $ db -> setQuery ( 'DELETE FROM `#__user_usergroup_map`' . ' WHERE `group_id` IN (' . implode ( ',' , $ ids ) . ')' ) ; $ db -> query ( ) ; if ( $ db -> getErrorNum ( ) ) { $ this -> setError ( $ db -> getErrorMsg ( ) ) ; return false ; } return true ; }
Delete this object and its dependancies
 @param   integer  $oid  The primary key of the user group to delete.
Delete this object and its dependancies @param integer $oid The primary key of the user group to delete .
// Select the category ID and it's children // Delete the category dependencies // @todo Remove all related threads, posts and subscriptions // Delete the category and its children // Delete the usergroup in view levels // Delete the user to usergroup mappings for the group(s) from the database. // Check for a database error.