Bitrix Site Manager

OnBeforeGroupDelete

bool
event_handler(
 int group_id
);

The OnBeforeGroupDelete event fires before the user group deletion. A common use of this module is to allow or disallow the user group deletion.

Parameters

ParameterDescription
group_id The ID of the user group which is to be deleted.

Return Values

To cancel the user deletion and terminate the CGroup::Delete method, raise an exception from within the handler using the method $APPLICATION->ThrowException() and return false.

See Also

Example


<?
// file /bitrix/php_interface/init.php
// register handler
AddEventHandler("main", 
                "OnBeforeGroupDelete", 
                Array("MyClass", 
                      "OnBeforeGroupDeleteHandler"));

class MyClass
{
    // create handler "OnBeforeGroupDelete"
    function OnBeforeGroupDeleteHandler($group_id)
    {
        // check if any records exist bound to the deleted group
        $strSql = "SELECT * FROM my_table WHERE GROUP_ID=".intval($group_id);
        $rs = $DB->Query($strSql, false, "FILE: ".__FILE__."<br>LINE: ".__LINE__);

        // if found...
        if ($ar = $rs->Fetch()) 
        {
            // cancel deletion.
            global $APPLICATION;
            $APPLICATION->throwException("My table has bound records.");
            return false;
        }
    }
}
?>

Example of handler registration


<?
// register handler "OnBeforeGroupDelete" for module my_module_id
RegisterModuleDependences("main", 
                          "OnBeforeGroupDelete", 
                          "my_module_id", 
                          "MyClass", 
                          "OnBeforeGroupDeleteHandler");
?>