HOR-1098-B "PMFuncion para remover usuarios..." SOLVED

This commit is contained in:
root
2016-06-20 12:11:20 -04:00
parent d541f4d583
commit 523b9af898
2 changed files with 84 additions and 0 deletions

View File

@@ -3519,3 +3519,31 @@ function PMFAssociateUploadedFilesWithInputFile($inputDocumentUid, $gridVariable
}
}
/**
* @method
*
* Remove users from a group
*
* @name PMFRemoveUsersToGroup
* @label PMF Remove users from a group
* @link http://wiki.processmaker.com/index.php/ProcessMaker_Functions#PMFRemoveUsersToGroup.28.29
*
* @param string | $groupId | Group Uid | The unique Uid of the group.
* @param array | $users | Array of users | Array of users to remove.
*
* @return array | $result | array
*/
function PMFRemoveUsersToGroup($groupUid, array $users)
{
try {
$user = new \ProcessMaker\BusinessModel\Group\User();
$result = $user->unassignUsers($groupUid, $users);
//Return
return $result;
} catch (Exception $e) {
throw $e;
}
}

View File

@@ -307,5 +307,61 @@ class User
throw $e;
}
}
/**
* Unassign users to group
*
* @param string $groupUid Unique id of Group
* @param array $arrayData Data uid of Users
*
* @return array Return result
*/
public function unassignUsers($groupUid, array $users)
{
try {
$user = new \ProcessMaker\BusinessModel\User();
$result = [];
foreach ($users as $value) {
$userUid = $value;
$flagRemove = 1;
//Verify data
$arrayUserData = $user->getUserRecordByPk($userUid, [], false);
if ($arrayUserData === false) {
$result[$userUid] = 'USER_NOT_EXISTS';
$flagRemove = 0;
}
if ($flagRemove == 1 && $arrayUserData['USR_STATUS'] == 'CLOSED') {
$result[$userUid] = 'USER_CLOSED';
$flagRemove = 0;
}
$groupUser = \GroupUserPeer::retrieveByPK($groupUid, $userUid);
if ($flagRemove == 1 && is_null($groupUser)) {
$result[$userUid] = 'USER_NOT_BELONG_TO_GROUP';
$flagRemove = 0;
}
//Remove
$group = new \Groups();
if ($flagRemove == 1) {
$group->removeUserOfGroup($groupUid, $userUid);
$result[$userUid] = 'USER_SUCCESSFULLY_REMOVED';
}
}
//Return
return $result;
} catch (\Exception $e) {
throw $e;
}
}
}