mirror of
https://github.com/wiosna-dev/limesurvey-api-client.git
synced 2026-03-12 02:11:45 +01:00
SurveyService - getStartSurveyUrl() method - returns url used to start survey for given survey and participant
This commit is contained in:
@@ -12,6 +12,7 @@ use Meritoo\Common\Collection\Collection;
|
||||
use Meritoo\LimeSurvey\ApiClient\Client\Client;
|
||||
use Meritoo\LimeSurvey\ApiClient\Exception\CannotProcessDataException;
|
||||
use Meritoo\LimeSurvey\ApiClient\Result\Collection\Surveys;
|
||||
use Meritoo\LimeSurvey\ApiClient\Result\Item\Participant;
|
||||
use Meritoo\LimeSurvey\ApiClient\Result\Item\Survey;
|
||||
use Meritoo\LimeSurvey\ApiClient\Type\MethodType;
|
||||
use Meritoo\LimeSurvey\ApiClient\Type\ReasonType;
|
||||
@@ -39,6 +40,19 @@ class SurveyService
|
||||
*/
|
||||
private $allSurveys;
|
||||
|
||||
/**
|
||||
* Template of the url used to start survey
|
||||
*
|
||||
* Example:
|
||||
* - url: https://your.limesurvey.instance/12345?token=q1w2e3r4t5y6
|
||||
* - LimeSurvey frontend: https://your.limesurvey.instance
|
||||
* - survey ID: 12345
|
||||
* - token: q1w2e3r4t5y6
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
private $startSurveyUrlTemplate = '%s/%d?token=%s';
|
||||
|
||||
/**
|
||||
* Class constructor
|
||||
*
|
||||
@@ -134,4 +148,21 @@ class SurveyService
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns url used to start survey for given survey and participant
|
||||
*
|
||||
* @param int $surveyId ID of survey to start
|
||||
* @param Participant $participant Participant who would like to start survey
|
||||
* @return string
|
||||
*/
|
||||
public function getStartSurveyUrl($surveyId, Participant $participant)
|
||||
{
|
||||
$baseUrl = $this
|
||||
->client
|
||||
->getConfiguration()
|
||||
->getBaseUrl();
|
||||
|
||||
return sprintf($this->startSurveyUrlTemplate, $baseUrl, $surveyId, $participant->getToken());
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user