From 409aa132910dffe42cacae598e75c7cc765db08b Mon Sep 17 00:00:00 2001 From: Jon Goldberg Date: Wed, 3 Jan 2018 03:59:23 -0500 Subject: [PATCH] Write a membership get request --- getmemberships.php | 31 ++++++++++++++++++++++++++++--- 1 file changed, 28 insertions(+), 3 deletions(-) diff --git a/getmemberships.php b/getmemberships.php index 3494e3c..debe738 100755 --- a/getmemberships.php +++ b/getmemberships.php @@ -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. */