From 6423195cc6ced3530014b85d213bf447ed793569 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Micha=C5=82=20Frankiewicz?= Date: Tue, 29 Jun 2021 17:09:27 +0200 Subject: [PATCH] [UW-2538] adds method to check survey completion --- src/Service/SurveyService.php | 36 +++++++++++++++++++++++++++++++++++ 1 file changed, 36 insertions(+) diff --git a/src/Service/SurveyService.php b/src/Service/SurveyService.php index fa0d4d9..1312db6 100644 --- a/src/Service/SurveyService.php +++ b/src/Service/SurveyService.php @@ -421,4 +421,40 @@ class SurveyService return $surveySummary; } + + /** + * @param $surveyId + * @param $email + * @return bool + * @throws CannotProcessDataException + * @throws UnknownInstanceOfResultItem + * @throws UnknownMethodException + */ + public function hasSurveyBeenCompletedByEmail($surveyId, $email) + { + $arguments = [ + $surveyId, + $offset = 0, + $limit = 1, + $includeUnused = false, + $attributes = false, + ['email' => $email] + ]; + + try { + /** @var Collection $participants */ + $participants = $this + ->client + ->run(MethodType::LIST_PARTICIPANTS, $arguments) + ->getData(); + + return $participants->count() > 0; + } catch (CannotProcessDataException $exception) { + if (ReasonType::NO_PARTICIPANTS_FOUND !== $exception->getReason()) { + throw $exception; + } + } + + return false; + } }