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
Related to fetch full data of participant of given survey
This commit is contained in:
@@ -51,7 +51,7 @@ class Participants extends Collection
|
||||
/**
|
||||
* Adds participants of given survey
|
||||
*
|
||||
* @param Collection $participants Participants to add. Collection of Participant classes.
|
||||
* @param Collection $participants Participants to add. Collection of ParticipantShort classes.
|
||||
* @param int $surveyId ID of survey
|
||||
* @return $this
|
||||
*/
|
||||
|
||||
@@ -103,4 +103,26 @@ class ParticipantShort extends BaseItem
|
||||
{
|
||||
return $this->email;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns short data of participant created from full data of participant
|
||||
*
|
||||
* @param Participant $participant Full data of participant
|
||||
* @return $this
|
||||
*/
|
||||
public static function fromParticipant(Participant $participant)
|
||||
{
|
||||
$info = [
|
||||
'firstname' => $participant->getFirstName(),
|
||||
'lastname' => $participant->getLastName(),
|
||||
'email' => $participant->getEmail(),
|
||||
];
|
||||
|
||||
$data = [
|
||||
'tid' => $participant->getId(),
|
||||
'participant_info' => $info,
|
||||
];
|
||||
|
||||
return new self($data);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -164,9 +164,16 @@ class ParticipantService
|
||||
->run(MethodType::ADD_PARTICIPANTS, $arguments)
|
||||
->getData();
|
||||
|
||||
/* @var Participant $addedParticipant */
|
||||
$addedParticipant = $participantCollection->getFirst();
|
||||
|
||||
$participants = new Collection([
|
||||
ParticipantShort::fromParticipant($addedParticipant),
|
||||
]);
|
||||
|
||||
$this
|
||||
->allParticipants
|
||||
->addParticipants($participantCollection, $surveyId);
|
||||
->addParticipants($participants, $surveyId);
|
||||
|
||||
return $participantCollection->getFirst();
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user