mirror of
https://github.com/wiosna-dev/limesurvey-api-client.git
synced 2026-03-12 02:11:45 +01:00
Compare commits
15 Commits
develop
...
feature/WZ
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
a61c52fe1c | ||
|
|
06fcaf07a8 | ||
|
|
e025b71059 | ||
|
|
b658e04445 | ||
|
|
d4e74bc270 | ||
|
|
8127330642 | ||
|
|
f0c213fb53 | ||
|
|
24f9a237ae | ||
|
|
81ea8e748f | ||
|
|
bab7e25c85 | ||
|
|
6423195cc6 | ||
|
|
b2d4552fb3 | ||
|
|
53d82841e0 | ||
|
|
c8ffcafbd8 | ||
|
|
7551f6db95 |
@@ -12,7 +12,7 @@
|
|||||||
"require": {
|
"require": {
|
||||||
"php": ">=5.6",
|
"php": ">=5.6",
|
||||||
"fguillot/json-rpc": "^1.2",
|
"fguillot/json-rpc": "^1.2",
|
||||||
"wiosna-dev/common-library": "^0.1.0"
|
"wiosna-dev/common-library": "^0.1.9"
|
||||||
},
|
},
|
||||||
"require-dev": {
|
"require-dev": {
|
||||||
"friendsofphp/php-cs-fixer": "^2.6",
|
"friendsofphp/php-cs-fixer": "^2.6",
|
||||||
|
|||||||
@@ -39,6 +39,13 @@ abstract class BaseParticipant extends BaseItem
|
|||||||
*/
|
*/
|
||||||
protected $email;
|
protected $email;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Token of the participant
|
||||||
|
*
|
||||||
|
* @var string
|
||||||
|
*/
|
||||||
|
protected $token;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Returns ID of the participant
|
* Returns ID of the participant
|
||||||
*
|
*
|
||||||
@@ -78,4 +85,14 @@ abstract class BaseParticipant extends BaseItem
|
|||||||
{
|
{
|
||||||
return $this->email;
|
return $this->email;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Returns token of the participant
|
||||||
|
*
|
||||||
|
* @return string
|
||||||
|
*/
|
||||||
|
public function getToken()
|
||||||
|
{
|
||||||
|
return $this->token;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -42,13 +42,6 @@ class Participant extends BaseParticipant
|
|||||||
*/
|
*/
|
||||||
private $emailStatus;
|
private $emailStatus;
|
||||||
|
|
||||||
/**
|
|
||||||
* Token of the participant
|
|
||||||
*
|
|
||||||
* @var string
|
|
||||||
*/
|
|
||||||
private $token;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Language of the participant
|
* Language of the participant
|
||||||
*
|
*
|
||||||
@@ -232,16 +225,6 @@ class Participant extends BaseParticipant
|
|||||||
return $this->emailStatus;
|
return $this->emailStatus;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* Returns token of the participant
|
|
||||||
*
|
|
||||||
* @return string
|
|
||||||
*/
|
|
||||||
public function getToken()
|
|
||||||
{
|
|
||||||
return $this->token;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Returns language of the participant
|
* Returns language of the participant
|
||||||
*
|
*
|
||||||
|
|||||||
@@ -28,6 +28,10 @@ class ParticipantShort extends BaseParticipant
|
|||||||
$this->id = (int)$value;
|
$this->id = (int)$value;
|
||||||
break;
|
break;
|
||||||
|
|
||||||
|
case 'token':
|
||||||
|
$this->token = trim($value);
|
||||||
|
break;
|
||||||
|
|
||||||
case 'participant_info':
|
case 'participant_info':
|
||||||
$this->firstName = trim($value['firstname']);
|
$this->firstName = trim($value['firstname']);
|
||||||
$this->lastName = trim($value['lastname']);
|
$this->lastName = trim($value['lastname']);
|
||||||
@@ -52,6 +56,7 @@ class ParticipantShort extends BaseParticipant
|
|||||||
|
|
||||||
$data = [
|
$data = [
|
||||||
'tid' => $participant->getId(),
|
'tid' => $participant->getId(),
|
||||||
|
'token' => $participant->getToken(),
|
||||||
'participant_info' => $info,
|
'participant_info' => $info,
|
||||||
];
|
];
|
||||||
|
|
||||||
|
|||||||
@@ -57,9 +57,14 @@ class Result
|
|||||||
* class constants.
|
* class constants.
|
||||||
* @param array $rawData Raw data returned by the LimeSurvey's API
|
* @param array $rawData Raw data returned by the LimeSurvey's API
|
||||||
*/
|
*/
|
||||||
public function __construct($method, array $rawData)
|
public function __construct($method, $rawData)
|
||||||
{
|
{
|
||||||
$this->method = MethodType::getValidatedMethod($method);
|
$this->method = MethodType::getValidatedMethod($method);
|
||||||
|
|
||||||
|
if (true === is_string($rawData)) {
|
||||||
|
$rawData = base64_decode($rawData);
|
||||||
|
$rawData = json_decode($rawData, true);
|
||||||
|
}
|
||||||
$this->setRawDataAndStatus($rawData);
|
$this->setRawDataAndStatus($rawData);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -12,6 +12,8 @@ use Meritoo\Common\Collection\Collection;
|
|||||||
use Meritoo\LimeSurvey\ApiClient\Client\Client;
|
use Meritoo\LimeSurvey\ApiClient\Client\Client;
|
||||||
use Meritoo\LimeSurvey\ApiClient\Exception\CannotProcessDataException;
|
use Meritoo\LimeSurvey\ApiClient\Exception\CannotProcessDataException;
|
||||||
use Meritoo\LimeSurvey\ApiClient\Exception\MissingSurveySummaryException;
|
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\Participants;
|
||||||
use Meritoo\LimeSurvey\ApiClient\Result\Collection\Surveys;
|
use Meritoo\LimeSurvey\ApiClient\Result\Collection\Surveys;
|
||||||
use Meritoo\LimeSurvey\ApiClient\Result\Collection\SurveysSummaries;
|
use Meritoo\LimeSurvey\ApiClient\Result\Collection\SurveysSummaries;
|
||||||
@@ -126,6 +128,8 @@ class SurveyService
|
|||||||
* @return Surveys
|
* @return Surveys
|
||||||
*
|
*
|
||||||
* @throws CannotProcessDataException
|
* @throws CannotProcessDataException
|
||||||
|
* @throws UnknownInstanceOfResultItem
|
||||||
|
* @throws UnknownMethodException
|
||||||
*/
|
*/
|
||||||
public function getAllSurveys($onlyActive = false)
|
public function getAllSurveys($onlyActive = false)
|
||||||
{
|
{
|
||||||
@@ -160,10 +164,13 @@ class SurveyService
|
|||||||
/**
|
/**
|
||||||
* Returns information if survey with given ID exists
|
* 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
|
* @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).
|
* be returned, even if exists. Otherwise - it doesn't matter (default behaviour).
|
||||||
* @return bool
|
* @return bool
|
||||||
|
* @throws CannotProcessDataException
|
||||||
|
* @throws UnknownInstanceOfResultItem
|
||||||
|
* @throws UnknownMethodException
|
||||||
*/
|
*/
|
||||||
public function isExistingSurvey($surveyId, $shouldBeActive = false)
|
public function isExistingSurvey($surveyId, $shouldBeActive = false)
|
||||||
{
|
{
|
||||||
@@ -221,12 +228,15 @@ class SurveyService
|
|||||||
/**
|
/**
|
||||||
* Returns participants of given survey
|
* 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.
|
* @param bool $onlyCompleted (optional) If is set to true, participants who completed survey are returned only.
|
||||||
* Otherwise - all (default behaviour).
|
* Otherwise - all (default behaviour).
|
||||||
* @return Collection
|
* @return Collection
|
||||||
*
|
*
|
||||||
* @throws CannotProcessDataException
|
* @throws CannotProcessDataException
|
||||||
|
* @throws MissingSurveySummaryException
|
||||||
|
* @throws UnknownInstanceOfResultItem
|
||||||
|
* @throws UnknownMethodException
|
||||||
*/
|
*/
|
||||||
public function getSurveyParticipants($surveyId, $onlyCompleted = false)
|
public function getSurveyParticipants($surveyId, $onlyCompleted = false)
|
||||||
{
|
{
|
||||||
@@ -275,11 +285,14 @@ class SurveyService
|
|||||||
/**
|
/**
|
||||||
* Adds participant with given data to survey with given ID
|
* 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 $firstName First name of the participant to add
|
||||||
* @param string $lastName Last ame 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 $email E-mail address of the participant to add
|
||||||
* @return Participant
|
* @return Participant
|
||||||
|
* @throws CannotProcessDataException
|
||||||
|
* @throws UnknownInstanceOfResultItem
|
||||||
|
* @throws UnknownMethodException
|
||||||
*/
|
*/
|
||||||
public function addParticipant($surveyId, $firstName, $lastName, $email)
|
public function addParticipant($surveyId, $firstName, $lastName, $email)
|
||||||
{
|
{
|
||||||
@@ -318,9 +331,13 @@ class SurveyService
|
|||||||
/**
|
/**
|
||||||
* Returns short data of one participant with given e-mail (participant of given survey)
|
* Returns short data of one participant with given e-mail (participant of given survey)
|
||||||
*
|
*
|
||||||
* @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 ParticipantShort|null
|
* @return ParticipantShort|null
|
||||||
|
* @throws CannotProcessDataException
|
||||||
|
* @throws MissingSurveySummaryException
|
||||||
|
* @throws UnknownInstanceOfResultItem
|
||||||
|
* @throws UnknownMethodException
|
||||||
*/
|
*/
|
||||||
public function getParticipant($surveyId, $email)
|
public function getParticipant($surveyId, $email)
|
||||||
{
|
{
|
||||||
@@ -343,7 +360,10 @@ class SurveyService
|
|||||||
* @param int $surveyId ID of survey
|
* @param int $surveyId ID of survey
|
||||||
* @return int
|
* @return int
|
||||||
*
|
*
|
||||||
|
* @throws CannotProcessDataException
|
||||||
* @throws MissingSurveySummaryException
|
* @throws MissingSurveySummaryException
|
||||||
|
* @throws UnknownInstanceOfResultItem
|
||||||
|
* @throws UnknownMethodException
|
||||||
*/
|
*/
|
||||||
public function getSurveyTokenCount($surveyId)
|
public function getSurveyTokenCount($surveyId)
|
||||||
{
|
{
|
||||||
@@ -374,6 +394,9 @@ class SurveyService
|
|||||||
*
|
*
|
||||||
* @param int $surveyId ID of survey
|
* @param int $surveyId ID of survey
|
||||||
* @return SurveySummary|null
|
* @return SurveySummary|null
|
||||||
|
* @throws CannotProcessDataException
|
||||||
|
* @throws UnknownInstanceOfResultItem
|
||||||
|
* @throws UnknownMethodException
|
||||||
*/
|
*/
|
||||||
private function getSurveySummary($surveyId)
|
private function getSurveySummary($surveyId)
|
||||||
{
|
{
|
||||||
@@ -395,4 +418,85 @@ class SurveyService
|
|||||||
|
|
||||||
return $surveySummary;
|
return $surveySummary;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @param $surveyId
|
||||||
|
* @param $email
|
||||||
|
* @return bool
|
||||||
|
* @throws CannotProcessDataException
|
||||||
|
* @throws UnknownInstanceOfResultItem
|
||||||
|
* @throws UnknownMethodException
|
||||||
|
*/
|
||||||
|
public function hasSurveyBeenCompletedByEmail($surveyId, $email)
|
||||||
|
{
|
||||||
|
$arguments = [
|
||||||
|
$surveyId,
|
||||||
|
$offset = 0,
|
||||||
|
$limit = 10,
|
||||||
|
$includeUnused = false,
|
||||||
|
['completed'],
|
||||||
|
['email' => $email]
|
||||||
|
];
|
||||||
|
|
||||||
|
try {
|
||||||
|
/** @var Collection $participants */
|
||||||
|
$participants = $this
|
||||||
|
->client
|
||||||
|
->run(MethodType::LIST_PARTICIPANTS, $arguments)
|
||||||
|
->getData(true);
|
||||||
|
|
||||||
|
foreach ($participants as $participant) {
|
||||||
|
if ('N' !== $participant['completed']) {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
} catch (CannotProcessDataException $exception) {
|
||||||
|
if (ReasonType::NO_PARTICIPANTS_FOUND !== $exception->getReason()) {
|
||||||
|
throw $exception;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
public function getResponseIds($surveyId, $token)
|
||||||
|
{
|
||||||
|
$arguments = [
|
||||||
|
$surveyId,
|
||||||
|
$token,
|
||||||
|
];
|
||||||
|
|
||||||
|
return $this
|
||||||
|
->client
|
||||||
|
->run('get_response_ids', $arguments)
|
||||||
|
->getData(true);
|
||||||
|
}
|
||||||
|
|
||||||
|
public function exportResponsesByToken($surveyId, $token)
|
||||||
|
{
|
||||||
|
$arguments = [
|
||||||
|
$surveyId,
|
||||||
|
'json',
|
||||||
|
$token,
|
||||||
|
];
|
||||||
|
|
||||||
|
return $this
|
||||||
|
->client
|
||||||
|
->run('export_responses_by_token', $arguments)
|
||||||
|
->getData(true);
|
||||||
|
}
|
||||||
|
|
||||||
|
public function exportUploadedFilesByToken($surveyId, $token)
|
||||||
|
{
|
||||||
|
$arguments = [
|
||||||
|
$surveyId,
|
||||||
|
'json',
|
||||||
|
$token,
|
||||||
|
];
|
||||||
|
|
||||||
|
return $this
|
||||||
|
->client
|
||||||
|
->run('get_uploaded_files', $arguments)
|
||||||
|
->getData(true);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -93,6 +93,12 @@ class MethodType extends BaseType
|
|||||||
*/
|
*/
|
||||||
const LIST_USERS = 'list_users';
|
const LIST_USERS = 'list_users';
|
||||||
|
|
||||||
|
const EXPORT_RESPONSES_BY_TOKEN = 'export_responses_by_token';
|
||||||
|
|
||||||
|
const GET_RESPONSE_IDS = 'get_response_ids';
|
||||||
|
|
||||||
|
const EXPORT_UPLOADED_FILES_BY_TOKEN = 'get_uploaded_files';
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Returns validated name of method to call or throws an exception (if method is incorrect)
|
* Returns validated name of method to call or throws an exception (if method is incorrect)
|
||||||
*
|
*
|
||||||
@@ -126,6 +132,9 @@ class MethodType extends BaseType
|
|||||||
static::LIST_QUESTIONS,
|
static::LIST_QUESTIONS,
|
||||||
static::LIST_SURVEYS,
|
static::LIST_SURVEYS,
|
||||||
static::LIST_USERS,
|
static::LIST_USERS,
|
||||||
|
static::EXPORT_RESPONSES_BY_TOKEN,
|
||||||
|
static::GET_RESPONSE_IDS,
|
||||||
|
static::EXPORT_UPLOADED_FILES_BY_TOKEN
|
||||||
]);
|
]);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user