mirror of
https://github.com/wiosna-dev/limesurvey-api-client.git
synced 2026-03-12 10:11:49 +01:00
Participants collection - store instances of ParticipantShort instead of Participant
Required to fix bug "Call to undefined method Meritoo\LimeSurvey\ApiClient\Result\Item\ParticipantShort::isCompleted() in /src/Service/ParticipantService.php on line 206"
This commit is contained in:
@@ -10,7 +10,7 @@ namespace Meritoo\LimeSurvey\ApiClient\Result\Collection;
|
|||||||
|
|
||||||
use Meritoo\Common\Collection\Collection;
|
use Meritoo\Common\Collection\Collection;
|
||||||
use Meritoo\Common\Exception\Method\DisabledMethodException;
|
use Meritoo\Common\Exception\Method\DisabledMethodException;
|
||||||
use Meritoo\LimeSurvey\ApiClient\Result\Item\Participant;
|
use Meritoo\LimeSurvey\ApiClient\Result\Item\ParticipantShort;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Collection of participants (of surveys).
|
* Collection of participants (of surveys).
|
||||||
@@ -75,11 +75,11 @@ class Participants extends Collection
|
|||||||
/**
|
/**
|
||||||
* Adds participant of given survey
|
* Adds participant of given survey
|
||||||
*
|
*
|
||||||
* @param Participant $participant Participant to add
|
* @param ParticipantShort $participant Participant to add
|
||||||
* @param int $surveyId ID of survey
|
* @param int $surveyId ID of survey
|
||||||
* @return $this
|
* @return $this
|
||||||
*/
|
*/
|
||||||
public function addParticipant(Participant $participant, $surveyId)
|
public function addParticipant(ParticipantShort $participant, $surveyId)
|
||||||
{
|
{
|
||||||
$this
|
$this
|
||||||
->getBySurvey($surveyId)
|
->getBySurvey($surveyId)
|
||||||
@@ -128,7 +128,7 @@ class Participants extends Collection
|
|||||||
*
|
*
|
||||||
* @param int $surveyId ID of survey
|
* @param int $surveyId ID of survey
|
||||||
* @param string $participantEmail E-mail of searched participant
|
* @param string $participantEmail E-mail of searched participant
|
||||||
* @return Participant|null
|
* @return ParticipantShort|null
|
||||||
*/
|
*/
|
||||||
public function getParticipantOfSurvey($surveyId, $participantEmail)
|
public function getParticipantOfSurvey($surveyId, $participantEmail)
|
||||||
{
|
{
|
||||||
@@ -139,7 +139,7 @@ class Participants extends Collection
|
|||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* @var Participant $participant */
|
/* @var ParticipantShort $participant */
|
||||||
foreach ($participants as $participant) {
|
foreach ($participants as $participant) {
|
||||||
if ($participant->getEmail() == $participantEmail) {
|
if ($participant->getEmail() == $participantEmail) {
|
||||||
return $participant;
|
return $participant;
|
||||||
|
|||||||
@@ -128,7 +128,11 @@ class Result
|
|||||||
->getResultProcessor()
|
->getResultProcessor()
|
||||||
->process($this->method, $rawData);
|
->process($this->method, $rawData);
|
||||||
|
|
||||||
if (null === $processed || is_array($processed)) {
|
/*
|
||||||
|
* Result is unknown and it should be iterable the result is an array?
|
||||||
|
* Let's prepare and return collection
|
||||||
|
*/
|
||||||
|
if ((null === $processed && MethodType::isResultIterable($this->method)) || is_array($processed)) {
|
||||||
$collection = new Collection();
|
$collection = new Collection();
|
||||||
|
|
||||||
if (is_array($processed)) {
|
if (is_array($processed)) {
|
||||||
|
|||||||
@@ -14,6 +14,7 @@ use Meritoo\LimeSurvey\ApiClient\Exception\CannotProcessDataException;
|
|||||||
use Meritoo\LimeSurvey\ApiClient\Exception\MissingParticipantOfSurveyException;
|
use Meritoo\LimeSurvey\ApiClient\Exception\MissingParticipantOfSurveyException;
|
||||||
use Meritoo\LimeSurvey\ApiClient\Result\Collection\Participants;
|
use Meritoo\LimeSurvey\ApiClient\Result\Collection\Participants;
|
||||||
use Meritoo\LimeSurvey\ApiClient\Result\Item\Participant;
|
use Meritoo\LimeSurvey\ApiClient\Result\Item\Participant;
|
||||||
|
use Meritoo\LimeSurvey\ApiClient\Result\Item\ParticipantShort;
|
||||||
use Meritoo\LimeSurvey\ApiClient\Type\MethodType;
|
use Meritoo\LimeSurvey\ApiClient\Type\MethodType;
|
||||||
use Meritoo\LimeSurvey\ApiClient\Type\ReasonType;
|
use Meritoo\LimeSurvey\ApiClient\Type\ReasonType;
|
||||||
|
|
||||||
@@ -175,7 +176,7 @@ class ParticipantService
|
|||||||
*
|
*
|
||||||
* @param int $surveyId ID of survey
|
* @param int $surveyId ID of survey
|
||||||
* @param string $email E-mail address of the participant
|
* @param string $email E-mail address of the participant
|
||||||
* @return Participant|null
|
* @return ParticipantShort|null
|
||||||
*/
|
*/
|
||||||
public function getParticipant($surveyId, $email)
|
public function getParticipant($surveyId, $email)
|
||||||
{
|
{
|
||||||
@@ -201,9 +202,17 @@ class ParticipantService
|
|||||||
public function hasParticipantFilledSurvey($surveyId, $email)
|
public function hasParticipantFilledSurvey($surveyId, $email)
|
||||||
{
|
{
|
||||||
if ($this->hasParticipant($surveyId, $email)) {
|
if ($this->hasParticipant($surveyId, $email)) {
|
||||||
return true === $this
|
$arguments = [
|
||||||
->getParticipant($surveyId, $email)
|
'email' => $email,
|
||||||
->isCompleted();
|
];
|
||||||
|
|
||||||
|
/* @var Participant $participant */
|
||||||
|
$participant = $this
|
||||||
|
->client
|
||||||
|
->run(MethodType::GET_PARTICIPANT_PROPERTIES, $arguments)
|
||||||
|
->getData();
|
||||||
|
|
||||||
|
return true === $participant->isCompleted();
|
||||||
}
|
}
|
||||||
|
|
||||||
throw new MissingParticipantOfSurveyException($surveyId, $email);
|
throw new MissingParticipantOfSurveyException($surveyId, $email);
|
||||||
|
|||||||
@@ -14,6 +14,7 @@ use Meritoo\Common\Test\Base\BaseTestCase;
|
|||||||
use Meritoo\Common\Type\OopVisibilityType;
|
use Meritoo\Common\Type\OopVisibilityType;
|
||||||
use Meritoo\LimeSurvey\ApiClient\Result\Collection\Participants;
|
use Meritoo\LimeSurvey\ApiClient\Result\Collection\Participants;
|
||||||
use Meritoo\LimeSurvey\ApiClient\Result\Item\Participant;
|
use Meritoo\LimeSurvey\ApiClient\Result\Item\Participant;
|
||||||
|
use Meritoo\LimeSurvey\ApiClient\Result\Item\ParticipantShort;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Test case of the collection of participants (of surveys)
|
* Test case of the collection of participants (of surveys)
|
||||||
@@ -126,11 +127,13 @@ class ParticipantsTest extends BaseTestCase
|
|||||||
$surveyId = 1;
|
$surveyId = 1;
|
||||||
$email = 'john@scott.com';
|
$email = 'john@scott.com';
|
||||||
|
|
||||||
$participant = new Participant([
|
$participant = new ParticipantShort([
|
||||||
'firstname' => 'John',
|
'tid' => 1,
|
||||||
'lastname' => 'Scott',
|
'participant_info' => [
|
||||||
'email' => $email,
|
'firstname' => 'John',
|
||||||
'completed' => 'Y',
|
'lastname' => 'Scott',
|
||||||
|
'email' => $email,
|
||||||
|
],
|
||||||
]);
|
]);
|
||||||
|
|
||||||
$participants = new Participants();
|
$participants = new Participants();
|
||||||
@@ -148,11 +151,13 @@ class ParticipantsTest extends BaseTestCase
|
|||||||
$surveyId = 1;
|
$surveyId = 1;
|
||||||
$email = 'john@scott.com';
|
$email = 'john@scott.com';
|
||||||
|
|
||||||
$participant = new Participant([
|
$participant = new ParticipantShort([
|
||||||
'firstname' => 'John',
|
'tid' => 1,
|
||||||
'lastname' => 'Scott',
|
'participant_info' => [
|
||||||
'email' => $email,
|
'firstname' => 'John',
|
||||||
'completed' => 'Y',
|
'lastname' => 'Scott',
|
||||||
|
'email' => $email,
|
||||||
|
],
|
||||||
]);
|
]);
|
||||||
|
|
||||||
$result = $this
|
$result = $this
|
||||||
|
|||||||
@@ -202,14 +202,31 @@ class ParticipantServiceTest extends BaseTestCase
|
|||||||
$this->serviceWithoutParticipants->hasParticipantFilledSurvey(1, 'john@scott.com');
|
$this->serviceWithoutParticipants->hasParticipantFilledSurvey(1, 'john@scott.com');
|
||||||
}
|
}
|
||||||
|
|
||||||
public function testHasParticipantFilledSurvey()
|
public function testHasParticipantFilledSurveyUsingExistingParticipant()
|
||||||
{
|
{
|
||||||
$rpcClientManager = $this->getJsonRpcClientManager(0);
|
$runMethodCallResults = [
|
||||||
|
'firstname' => 'John',
|
||||||
|
'lastname' => 'Scott',
|
||||||
|
'email' => 'john@scott.com',
|
||||||
|
'completed' => 'Y',
|
||||||
|
];
|
||||||
|
|
||||||
|
$rpcClientManager = $this->getJsonRpcClientManager(1, $runMethodCallResults);
|
||||||
$sessionManager = $this->getSessionManager();
|
$sessionManager = $this->getSessionManager();
|
||||||
$this->createServiceWithParticipants($rpcClientManager, $sessionManager);
|
$this->createServiceWithParticipants($rpcClientManager, $sessionManager);
|
||||||
|
|
||||||
static::assertTrue($this->serviceWithParticipants->hasParticipantFilledSurvey(1, 'john@scott.com'));
|
static::assertTrue($this->serviceWithParticipants->hasParticipantFilledSurvey(1, 'john@scott.com'));
|
||||||
static::assertFalse($this->serviceWithParticipants->hasParticipantFilledSurvey(1, 'mary@jane.com'));
|
}
|
||||||
|
|
||||||
|
public function testHasParticipantFilledSurveyUsingNotExistingParticipant()
|
||||||
|
{
|
||||||
|
$this->expectException(MissingParticipantOfSurveyException::class);
|
||||||
|
|
||||||
|
$rpcClientManager = $this->getJsonRpcClientManager(1);
|
||||||
|
$sessionManager = $this->getSessionManager();
|
||||||
|
$this->createServiceWithParticipants($rpcClientManager, $sessionManager);
|
||||||
|
|
||||||
|
$this->serviceWithParticipants->hasParticipantFilledSurvey(3, 'mary@jane.com');
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|||||||
Reference in New Issue
Block a user