Commit d2536d94b780ab5ccf921ba7a2583c351581a73e

Authored by nbm
1 parent bb8d94f8

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
presentation/lookAndFeel/knowledgeTree/administration/groupmanagement/editGroupUsersBL.php
... ... @@ -34,35 +34,38 @@ KTUtil::extractGPC('fAssign', 'fGroupID', 'userAddedLeft', 'userAddedRight', 'us
34 34 * 0 if fail
35 35 */
36 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 71 if (checkSession()) {
... ...