From b2d4552fb3600c0953c904a5320f2aa3d72a099c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Micha=C5=82=20Frankiewicz?= Date: Tue, 29 Jun 2021 17:01:03 +0200 Subject: [PATCH 1/3] [UW-2538] updates docs --- src/Service/SurveyService.php | 38 ++++++++++++++++++++++++++++------- 1 file changed, 31 insertions(+), 7 deletions(-) diff --git a/src/Service/SurveyService.php b/src/Service/SurveyService.php index b2a9272..fa0d4d9 100644 --- a/src/Service/SurveyService.php +++ b/src/Service/SurveyService.php @@ -12,6 +12,8 @@ use Meritoo\Common\Collection\Collection; use Meritoo\LimeSurvey\ApiClient\Client\Client; use Meritoo\LimeSurvey\ApiClient\Exception\CannotProcessDataException; use Meritoo\LimeSurvey\ApiClient\Exception\MissingSurveySummaryException; +use Meritoo\LimeSurvey\ApiClient\Exception\UnknownInstanceOfResultItem; +use Meritoo\LimeSurvey\ApiClient\Exception\UnknownMethodException; use Meritoo\LimeSurvey\ApiClient\Result\Collection\Participants; use Meritoo\LimeSurvey\ApiClient\Result\Collection\Surveys; use Meritoo\LimeSurvey\ApiClient\Result\Collection\SurveysSummaries; @@ -126,6 +128,8 @@ class SurveyService * @return Surveys * * @throws CannotProcessDataException + * @throws UnknownInstanceOfResultItem + * @throws UnknownMethodException */ public function getAllSurveys($onlyActive = false) { @@ -160,10 +164,13 @@ class SurveyService /** * Returns information if survey with given ID exists * - * @param int $surveyId ID of survey to verify + * @param int $surveyId ID of survey to verify * @param bool $shouldBeActive (optional) If is set to true, survey should be active. If it's not, it shouldn't * be returned, even if exists. Otherwise - it doesn't matter (default behaviour). * @return bool + * @throws CannotProcessDataException + * @throws UnknownInstanceOfResultItem + * @throws UnknownMethodException */ public function isExistingSurvey($surveyId, $shouldBeActive = false) { @@ -221,12 +228,16 @@ class SurveyService /** * Returns participants of given survey * - * @param int $surveyId ID of survey + * @param int $surveyId ID of survey * @param bool $onlyCompleted (optional) If is set to true, participants who completed survey are returned only. * Otherwise - all (default behaviour). + * @param array $criteria * @return Collection * * @throws CannotProcessDataException + * @throws MissingSurveySummaryException + * @throws UnknownInstanceOfResultItem + * @throws UnknownMethodException */ public function getSurveyParticipants($surveyId, $onlyCompleted = false, array $criteria = []) { @@ -277,11 +288,14 @@ class SurveyService /** * Adds participant with given data to survey with given ID * - * @param int $surveyId ID of survey + * @param int $surveyId ID of survey * @param string $firstName First name of the participant to add - * @param string $lastName Last ame of the participant to add - * @param string $email E-mail address of the participant to add + * @param string $lastName Last ame of the participant to add + * @param string $email E-mail address of the participant to add * @return Participant + * @throws CannotProcessDataException + * @throws UnknownInstanceOfResultItem + * @throws UnknownMethodException */ public function addParticipant($surveyId, $firstName, $lastName, $email) { @@ -320,9 +334,13 @@ class SurveyService /** * Returns short data of one participant with given e-mail (participant of given survey) * - * @param int $surveyId ID of survey - * @param string $email E-mail address of the participant + * @param int $surveyId ID of survey + * @param string $email E-mail address of the participant * @return ParticipantShort|null + * @throws CannotProcessDataException + * @throws MissingSurveySummaryException + * @throws UnknownInstanceOfResultItem + * @throws UnknownMethodException */ public function getParticipant($surveyId, $email) { @@ -345,7 +363,10 @@ class SurveyService * @param int $surveyId ID of survey * @return int * + * @throws CannotProcessDataException * @throws MissingSurveySummaryException + * @throws UnknownInstanceOfResultItem + * @throws UnknownMethodException */ public function getSurveyTokenCount($surveyId) { @@ -376,6 +397,9 @@ class SurveyService * * @param int $surveyId ID of survey * @return SurveySummary|null + * @throws CannotProcessDataException + * @throws UnknownInstanceOfResultItem + * @throws UnknownMethodException */ private function getSurveySummary($surveyId) { 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 2/3] [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; + } } From bab7e25c85c78db2710bc9c5b3cf07b65bf0eb29 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Micha=C5=82=20Frankiewicz?= Date: Tue, 29 Jun 2021 17:11:50 +0200 Subject: [PATCH 3/3] [UW-2538] removes broken argument --- src/Service/SurveyService.php | 5 +---- 1 file changed, 1 insertion(+), 4 deletions(-) diff --git a/src/Service/SurveyService.php b/src/Service/SurveyService.php index 1312db6..4efb519 100644 --- a/src/Service/SurveyService.php +++ b/src/Service/SurveyService.php @@ -231,7 +231,6 @@ class SurveyService * @param int $surveyId ID of survey * @param bool $onlyCompleted (optional) If is set to true, participants who completed survey are returned only. * Otherwise - all (default behaviour). - * @param array $criteria * @return Collection * * @throws CannotProcessDataException @@ -239,7 +238,7 @@ class SurveyService * @throws UnknownInstanceOfResultItem * @throws UnknownMethodException */ - public function getSurveyParticipants($surveyId, $onlyCompleted = false, array $criteria = []) + public function getSurveyParticipants($surveyId, $onlyCompleted = false) { $hasSurvey = $this ->allParticipants @@ -255,8 +254,6 @@ class SurveyService $offset, $limit, $includeUnused, - $attributes = false, - $criteria ]; try {