From 2314e91adc7cc8e55fa7c3df8a99209c17280db5 Mon Sep 17 00:00:00 2001 From: nbm Date: Wed, 5 Jan 2005 12:58:39 +0000 Subject: [PATCH] Allow the admin to remove a group despite it having members, since all they're going to do is remove the users from that group, and remove a group despite it being a member of the unit, since all they're going to do is remove it from the unit. So do it for them. They still have to confirm that they want to delete that group. --- lib/groups/Group.inc | 33 +++++++++++++++++++++++++++++++++ presentation/lookAndFeel/knowledgeTree/administration/groupmanagement/removeGroupBL.php | 38 +++++++++++++++----------------------- 2 files changed, 48 insertions(+), 23 deletions(-) diff --git a/lib/groups/Group.inc b/lib/groups/Group.inc index 5e411a2..51c4b5a 100644 --- a/lib/groups/Group.inc +++ b/lib/groups/Group.inc @@ -209,7 +209,40 @@ class Group extends KTEntity { $sName = lookupField("$default->groups_table", "name", "id", $id ); return $sName; } + + function &getMembers() { + require_once(KT_LIB_DIR . '/groups/GroupUserLink.inc'); + require_once(KT_LIB_DIR . '/users/User.inc'); + $aLinks = GroupUserLink::getList(array('group_id = ?', $this->getID())); + $aMembers = array(); + foreach ($aLinks as $oLink) { + $oUser = User::get($oLink->getUserID()); + if ($oUser !== false) { + $aMembers[] =& $oUser; + } + } + return $aMembers; + } + + function delete() { + require_once(KT_LIB_DIR . '/groups/GroupUserLink.inc'); + require_once(KT_LIB_DIR . '/groups/GroupUnitLink.inc'); + + // XXX: Urg, should I just DELETE instead? + $aLinks = GroupUserLink::getList(array('group_id = ?', $this->getID())); + foreach ($aLinks as $oLink) { + $oLink->delete(); + } + + $aLinks = GroupUnitLink::getList(array('group_id = ?', $this->getID())); + foreach ($aLinks as $oLink) { + $oLink->delete(); + } + return parent::delete(); + } } + + /* * static function * diff --git a/presentation/lookAndFeel/knowledgeTree/administration/groupmanagement/removeGroupBL.php b/presentation/lookAndFeel/knowledgeTree/administration/groupmanagement/removeGroupBL.php index 8f080ef..860cd71 100644 --- a/presentation/lookAndFeel/knowledgeTree/administration/groupmanagement/removeGroupBL.php +++ b/presentation/lookAndFeel/knowledgeTree/administration/groupmanagement/removeGroupBL.php @@ -45,29 +45,21 @@ if (checkSession()) { if (isset($fGroupID)) { $oGroup = Group::get($fGroupID); - if (!$oGroup->hasUsers()) { - if (!$oGroup->hasUnit()) { - if (!$oGroup->hasRoutingSteps()) { - if (isset($fForDelete)) { - if ($oGroup->delete()) { - // FIXME: refactor getStatusPage in Html.inc - $oPatternCustom->setHtml(statusPage(_("Remove Group"), _("Group successfully removed"), "", "listGroups")); - } else { - $oPatternCustom->setHtml(statusPage(_("Remove Group"), _("Group deletion failed!"), _("There was an error deleting this group. Please try again later."), "listGroups")); - } - } else { - $oPatternCustom->setHtml(getDeletePage($fGroupID)); - $main->setFormAction($_SERVER["PHP_SELF"] . "?fForDelete=1"); - } - } else { - $oPatternCustom->setHtml(statusPage(_("Remove Group"), _("This group is part of a document routing step!"), _("This group can not be deleted because it is involved in the document routing process."), "listGroups")); - } - } else { - $oPatternCustom->setHtml(statusPage(_("Remove Group"), _("This group is in a unit!"), _("This group can not be deleted because it belongs to a unit."), "listGroups")); - } - } else { - $oPatternCustom->setHtml(statusPage(_("Remove Group"), _("This group has users!"), _("This group can not be deleted because there are still users in it."), "listGroups")); - } + if (!$oGroup->hasRoutingSteps()) { + if (isset($fForDelete)) { + if ($oGroup->delete()) { + // FIXME: refactor getStatusPage in Html.inc + $oPatternCustom->setHtml(statusPage(_("Remove Group"), _("Group successfully removed"), "", "listGroups")); + } else { + $oPatternCustom->setHtml(statusPage(_("Remove Group"), _("Group deletion failed!"), _("There was an error deleting this group. Please try again later."), "listGroups")); + } + } else { + $oPatternCustom->setHtml(getDeletePage($fGroupID)); + $main->setFormAction($_SERVER["PHP_SELF"] . "?fForDelete=1"); + } + } else { + $oPatternCustom->setHtml(statusPage(_("Remove Group"), _("This group is part of a document routing step!"), _("This group can not be deleted because it is involved in the document routing process."), "listGroups")); + } } else { $oPatternCustom->setHtml(statusPage(_("Remove Group"), _("No group was selected for deletion"), "", "listGroups")); } -- libgit2 0.21.4