/** * Функция рекурсивно удаляет роль и ее детей. * * Если дети используются в других ролях, то они только открепляются от текущей роли. * Операции не удаляются * Задачи только открепляются */ function RemoveAuthItemPortal($AuthItem = '', $authitemparent = '') { if ($AuthItem === '') { throw new CHttpException(500, 'RemoveAuthItemPortal($AuthItem): Отсутствует параметр $AuthItem'); } $auth = Yii::app()->authManager; /* Если CAuthItem корневая роль или ее родитель является ролью */ if ($authitemparent === '' || $auth->getAuthItem($authitemparent)->type === 2) { /* $parentsarray = Массив родителей $AuthItem */ $parentsarray = AuthItemChild::GetItemParent($AuthItem); /* Открепляем текущую CAuthItem от родителя, если он есть */ if ($authitemparent !== '' && count((array) $parentsarray) > 0) { $auth->removeItemChild($authitemparent, $AuthItem); } /* Если после открепления от своего родителя CAuthItem больше не имеет родителей */ if (count((array) $parentsarray) === 0) { /* Создаем список с именами детей текущего CAuthItem */ $childrenarray = array_keys($auth->getItemChildren($AuthItem)); /* Идем по детям и применяем рекурсивно текущую функцию */ foreach ($childrenarray as $childitem) { $this->RemoveAuthItemPortal($childitem, $AuthItem); } /* Удаляем текущую роль, если она нигде больше не прикреплена */ if ($auth->getAuthItem($AuthItem)->type === 2) { $auth->removeAuthItem($AuthItem); } } } }