Write a membership get request

This commit is contained in:
Jon Goldberg 2018-01-03 03:59:23 -05:00
parent ac99bcd7ce
commit 409aa13291
1 changed files with 28 additions and 3 deletions

View File

@ -8,13 +8,38 @@ $client->setCheckSslCertificate(true);
$limit = 100;
$offset = 0;
$projectList = getProjectList($limit, $offset, $client);
print_r($getProjectList);
die;
list($projectsById, $projectsByDomain) = getProjectList($limit, $offset, $client);
$userList = getUserList($limit, $offset, $client);
$membershipMapping = getUserMemberships($userList, $client);
//print_r($projectsById);
//print_r($projectsByDomain);
//print_r($membershipMapping);
function getProjectList($limit, $offset, $client) {
// We'll set a more realistic total user count after the first loop.
$totalProjects = 99999;
// Get a complete user list with email address.
while ($offset + $limit < $totalProjects) {
$listing = $client->project->all([
'limit' => $limit,
'offset' => $offset,
]);
foreach ($listing['projects'] as $project) {
// 0 is a magic number. This might(?) fail if we ever add other project custom fields.
if ($project['custom_fields'][0]['value']) {
$domain = $project['custom_fields'][0]['value'];
$projectsByDomain[$domain] = $project['identifier'];
}
$projectsById[$project['id']] = $project['identifier'];
}
$totalProjects = $listing['total_count'];
$offset += $limit;
};
$projects[] = $projectsById;
$projects[] = $projectsByDomain;
return $projects;
}
/*
* Returns an array of all users. Key is user ID, value is email address.
*/