Commit 48318fc8741e6f2148c35bc69620ad0d4f021200
1 parent
469536e3
Use Group's addMember and removeMember instead of fiddling with link
objects. git-svn-id: https://kt-dms.svn.sourceforge.net/svnroot/kt-dms/trunk@3423 c91229c3-7414-0410-bfa2-8a42b809f60b
Showing
1 changed file
with
29 additions
and
26 deletions
presentation/lookAndFeel/knowledgeTree/administration/groupmanagement/editGroupUsersBL.php
| @@ -34,35 +34,38 @@ KTUtil::extractGPC('fAssign', 'fGroupID', 'userAddedLeft', 'userAddedRight', 'us | @@ -34,35 +34,38 @@ KTUtil::extractGPC('fAssign', 'fGroupID', 'userAddedLeft', 'userAddedRight', 'us | ||
| 34 | * 0 if fail | 34 | * 0 if fail |
| 35 | */ | 35 | */ |
| 36 | function updateUsers($iGroupID, $aToAddIDs, $aToRemoveIDs) { | 36 | function updateUsers($iGroupID, $aToAddIDs, $aToRemoveIDs) { |
| 37 | + $oGroup = Group::get($iGroupID); | ||
| 38 | + if (PEAR::isError($oGroup)) { | ||
| 39 | + return false; | ||
| 40 | + } | ||
| 37 | 41 | ||
| 38 | - // Add Users | ||
| 39 | - foreach ($aToAddIDs as $iUserID ) { | ||
| 40 | - if ($iUserID > 0) { | ||
| 41 | - $oUserGroup = new GroupUserLink($iGroupID, $iUserID); | ||
| 42 | - if($oUserGroup->create()) { | ||
| 43 | - // update user group search permissions | ||
| 44 | - $oUserGroup->updateSearchPermissions(); | ||
| 45 | - } else { | ||
| 46 | - return false; | ||
| 47 | - } | ||
| 48 | - } | ||
| 49 | - } | 42 | + if ($oGroup === false) { |
| 43 | + return false; | ||
| 44 | + } | ||
| 50 | 45 | ||
| 51 | - // Remove Users | ||
| 52 | - foreach ($aToRemoveIDs as $iUserID ) { | ||
| 53 | - if ($iUserID > 0) { | ||
| 54 | - $oUserGroup = new GroupUserLink($iGroupID, $iUserID); | ||
| 55 | - $oUserGroup->setUserGroupID($iGroupID,$iUserID); | ||
| 56 | - if($oUserGroup->delete()) { | ||
| 57 | - // update group search permissions | ||
| 58 | - $oUserGroup->updateSearchPermissions(); | ||
| 59 | - } else { | ||
| 60 | - return false; | ||
| 61 | - } | ||
| 62 | - } | ||
| 63 | - } | 46 | + // Add Users |
| 47 | + foreach ($aToAddIDs as $iUserID ) { | ||
| 48 | + if ($iUserID > 0) { | ||
| 49 | + $oUser = User::get($iUserID); | ||
| 50 | + $res = $oGroup->addMember($oUser); | ||
| 51 | + if (PEAR::isError($res)) { | ||
| 52 | + $_SESSION["KTErrorMessage"][] = "Failed to add " . $oUser->getName() . " to " . $oGroup->getName(); | ||
| 53 | + } | ||
| 54 | + } | ||
| 55 | + } | ||
| 56 | + | ||
| 57 | + // Remove Users | ||
| 58 | + foreach ($aToRemoveIDs as $iUserID ) { | ||
| 59 | + if ($iUserID > 0) { | ||
| 60 | + $oUser = User::get($iUserID); | ||
| 61 | + $res = $oGroup->removeMember($oUser); | ||
| 62 | + if (PEAR::isError($res)) { | ||
| 63 | + $_SESSION["KTErrorMessage"][] = "Failed to remove " . $oUser->getName() . " from " . $oGroup->getName(); | ||
| 64 | + } | ||
| 65 | + } | ||
| 66 | + } | ||
| 64 | 67 | ||
| 65 | - return true; | 68 | + return true; |
| 66 | } | 69 | } |
| 67 | 70 | ||
| 68 | if (checkSession()) { | 71 | if (checkSession()) { |