use only one organisation id

This commit is contained in:
Marc Michalsky forumZFD 2020-12-14 17:25:05 +01:00
parent 2b5ca596a4
commit 7a52e18418
Signed by untrusted user who does not match committer: marc.koch
GPG key ID: 12406554CFB028B9

View file

@ -45,32 +45,28 @@ class CRM_TwingleCampaign_BAO_TwingleApiCall {
"Twingle API call failed. Please check your api key."); "Twingle API call failed. Please check your api key.");
} }
$this->organisationId = array_column($response, 'id'); $this->organisationId = array_column($response, 'id')[0];
} }
/** /**
* If $id parameter is empty, this function returns all projects for all * If $id parameter is empty, this function returns all projects for all
* organisations this API key is assigned to. * organisations this API key is assigned to.
* *
* TODO: Keys can only get assigned to one organisation. Save multiple keys
* in settings instead.
*
* If $id parameter is given, this function returns a single project. * If $id parameter is given, this function returns a single project.
* *
* @param int|null $projectId * @param int|null $projectId
* *
* @return mixed * @return mixed
* @throws \Exception
*/ */
public function getProject(int $projectId = NULL) { public function getProject(int $projectId = NULL) {
$response = []; $response = [];
foreach ($this->organisationId as $organisationId) {
$url = empty($projectId)
? $this->protocol . 'project' . $this->baseUrl . 'by-organisation/' . $organisationId
: $this->protocol . 'project' . $this->baseUrl . $projectId;
$response = array_merge($this->curlGet($url)); $url = empty($projectId)
} ? $this->protocol . 'project' . $this->baseUrl . 'by-organisation/' . $this->organisationId
return $response; : $this->protocol . 'project' . $this->baseUrl . $projectId;
return $this->curlGet($url);
} }
/** /**