本文整理匯總了PHP中UserData::entries方法的典型用法代碼示例。如果您正苦於以下問題:PHP UserData::entries方法的具體用法?PHP UserData::entries怎麽用?PHP UserData::entries使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類UserData
的用法示例。
在下文中一共展示了UserData::entries方法的1個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的PHP代碼示例。
示例1: SetMembers
/**
* Sets the Members of a group
*/
public function SetMembers()
{
$db =& $this->db;
$response = new ResponseManager();
$groupObject = new UserGroup($db);
$groupId = Kit::GetParam('GroupID', _REQUEST, _INT);
$users = Kit::GetParam('UserID', _POST, _ARRAY, array());
// We will receive a list of users from the UI which are in the "assign column" at the time the form is
// submitted.
// We want to go through and unlink any users that are NOT in that list, but that the current user has access
// to edit.
// We want to add any users that are in that list (but aren't already assigned)
// All users that this session has access to
if (!($allUsers = $this->user->userList())) {
trigger_error(__('Error getting all users'), E_USER_ERROR);
}
// Convert to an array of ID's for convenience
$allUserIds = array_map(function ($array) {
return $array['userid'];
}, $allUsers);
// Users in group
$usersAssigned = UserData::entries(null, array('groupIds' => array($groupId)));
Debug::Audit('All userIds we want to assign: ' . var_export($users, true));
Debug::Audit('All userIds we have access to: ' . var_export($allUserIds, true));
foreach ($usersAssigned as $user) {
/* @var Userdata $user */
// Did this session have permission to do anything to this user?
// If not, move on
if (!in_array($user->userId, $allUserIds)) {
continue;
}
Debug::Audit('Logged in user has permission to make changes to this assigned user ' . $user->userId);
// Is this user in the provided list of users?
if (in_array($user->userId, $users)) {
// This user is already assigned, so we remove it from the $users array
Debug::Audit('This user is already assigned ' . $user->userId);
if (($key = array_search($user->userId, $users)) !== false) {
unset($users[$key]);
}
} else {
Debug::Audit('This user is assigned, but not in the list of assignments ' . $user->userId);
// It isn't therefore needs to be removed
if (!$groupObject->Unlink($groupId, $user->userId)) {
trigger_error($groupObject->GetErrorMessage(), E_USER_ERROR);
}
}
}
Debug::Audit('All userIds we want to assign after sorting: ' . var_export($users, true));
// Add any users that are still missing after tha assignment process
foreach ($users as $userId) {
Debug::Audit('User was missing, linking them: ' . $userId);
// Add any that are missing
if (!$groupObject->Link($groupId, $userId)) {
trigger_error($groupObject->GetErrorMessage(), E_USER_ERROR);
}
}
$response->SetFormSubmitResponse(__('Group membership set'), false);
$response->Respond();
}