mirror of
https://github.com/wiosna-dev/limesurvey-api-client.git
synced 2026-03-12 18:11:50 +01:00
composer.json - move tests-related classes to "autoload-dev" section (used for development purposes only and avoid polluting the autoloader in production)
This commit is contained in:
143
src/Result/Collection/Participants.php
Normal file
143
src/Result/Collection/Participants.php
Normal file
@@ -0,0 +1,143 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
* (c) Meritoo.pl, http://www.meritoo.pl
|
||||
* For the full copyright and license information, please view the LICENSE
|
||||
* file that was distributed with this source code.
|
||||
*/
|
||||
|
||||
namespace Meritoo\LimeSurvey\ApiClient\Result\Collection;
|
||||
|
||||
use Meritoo\Common\Collection\Collection;
|
||||
use Meritoo\Common\Exception\Method\DisabledMethodException;
|
||||
use Meritoo\LimeSurvey\ApiClient\Result\Item\Participant;
|
||||
|
||||
/**
|
||||
* Participants of survey.
|
||||
* All participants grouped per survey.
|
||||
*
|
||||
* It's a collection of participants' collections.
|
||||
* The survey ID is used as an index per each collection of participants, so they are grouped by survey.
|
||||
*
|
||||
* @author Krzysztof Niziol <krzysztof.niziol@meritoo.pl>
|
||||
* @copyright Meritoo.pl
|
||||
*/
|
||||
class Participants extends Collection
|
||||
{
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function add($element, $index = null)
|
||||
{
|
||||
throw new DisabledMethodException(__METHOD__, 'addParticipants');
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function addMultiple($elements, $useIndexes = false)
|
||||
{
|
||||
throw new DisabledMethodException(__METHOD__, 'addParticipants');
|
||||
}
|
||||
|
||||
/**
|
||||
* Adds participants of given survey
|
||||
*
|
||||
* @param Collection $participants Participants to add. Collection of Participant classes.
|
||||
* @param int $surveyId ID of survey
|
||||
* @return $this
|
||||
*/
|
||||
public function addParticipants(Collection $participants, $surveyId)
|
||||
{
|
||||
/*
|
||||
* No participants?
|
||||
* Nothing to do
|
||||
*/
|
||||
if ($participants->isEmpty()) {
|
||||
return $this;
|
||||
}
|
||||
|
||||
$this
|
||||
->getBySurvey($surveyId)
|
||||
->addMultiple($participants);
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Adds participant of given survey
|
||||
*
|
||||
* @param Participant $participant Participant to add
|
||||
* @param int $surveyId ID of survey
|
||||
* @return $this
|
||||
*/
|
||||
public function addParticipant(Participant $participant, $surveyId)
|
||||
{
|
||||
$this
|
||||
->getBySurvey($surveyId)
|
||||
->add($participant);
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns information if there are participants of given survey
|
||||
*
|
||||
* @param int $surveyId ID of survey
|
||||
* @return bool
|
||||
*/
|
||||
public function hasParticipantsOfSurvey($surveyId)
|
||||
{
|
||||
return false === $this
|
||||
->getBySurvey($surveyId)
|
||||
->isEmpty();
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns participants of given survey
|
||||
*
|
||||
* If there are no participants of given survey, adds an empty collection who will store participants.
|
||||
* So, this method will return collection always.
|
||||
*
|
||||
* @param int $surveyId ID of survey
|
||||
* @return Collection
|
||||
*/
|
||||
public function getBySurvey($surveyId)
|
||||
{
|
||||
/*
|
||||
* There are no participants of given survey?
|
||||
* Let's add an empty collection who will store participants
|
||||
*/
|
||||
if (!isset($this[$surveyId])) {
|
||||
$this[$surveyId] = new Collection();
|
||||
}
|
||||
|
||||
return $this[$surveyId];
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns participant of given survey
|
||||
*
|
||||
* @param int $surveyId ID of survey
|
||||
* @param string $participantEmail E-mail of searched participant
|
||||
* @return Participant|null
|
||||
*/
|
||||
public function getParticipantOfSurvey($surveyId, $participantEmail)
|
||||
{
|
||||
/* @var Collection $participants */
|
||||
$participants = $this->getBySurvey($surveyId);
|
||||
|
||||
if ($participants->isEmpty()) {
|
||||
return null;
|
||||
}
|
||||
|
||||
/* @var Participant $participant */
|
||||
foreach ($participants as $participant) {
|
||||
if ($participant->getEmail() == $participantEmail) {
|
||||
return $participant;
|
||||
}
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
}
|
||||
397
src/Result/Item/Participant.php
Normal file
397
src/Result/Item/Participant.php
Normal file
@@ -0,0 +1,397 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
* (c) Meritoo.pl, http://www.meritoo.pl
|
||||
* For the full copyright and license information, please view the LICENSE
|
||||
* file that was distributed with this source code.
|
||||
*/
|
||||
|
||||
namespace Meritoo\LimeSurvey\ApiClient\Result\Item;
|
||||
|
||||
use DateTime;
|
||||
use Meritoo\Common\Utilities\Date;
|
||||
use Meritoo\LimeSurvey\ApiClient\Base\Result\BaseItem;
|
||||
|
||||
/**
|
||||
* One item of the result/data: full data of participant
|
||||
*
|
||||
* @author Krzysztof Niziol <krzysztof.niziol@meritoo.pl>
|
||||
* @copyright Meritoo.pl
|
||||
*/
|
||||
class Participant extends BaseItem
|
||||
{
|
||||
/**
|
||||
* ID of the participant
|
||||
*
|
||||
* @var int
|
||||
*/
|
||||
private $id;
|
||||
|
||||
/**
|
||||
* Another ID of the participant?
|
||||
* Don't know where it is used.
|
||||
*
|
||||
* @var int
|
||||
*/
|
||||
private $participantId;
|
||||
|
||||
/**
|
||||
* MP ID
|
||||
*
|
||||
* @var int
|
||||
*/
|
||||
private $mpId;
|
||||
|
||||
/**
|
||||
* First name of the participant
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
private $firstName;
|
||||
|
||||
/**
|
||||
* Last name of the participant
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
private $lastName;
|
||||
|
||||
/**
|
||||
* E-mail of the participant
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
private $email;
|
||||
|
||||
/**
|
||||
* Status of the e-mail
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
private $emailStatus;
|
||||
|
||||
/**
|
||||
* Token of the participant
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
private $token;
|
||||
|
||||
/**
|
||||
* Language of the participant
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
private $language;
|
||||
|
||||
/**
|
||||
* Information if participant is blacklisted
|
||||
*
|
||||
* @var bool
|
||||
*/
|
||||
private $blacklisted;
|
||||
|
||||
/**
|
||||
* Information if token was sent to participant/user
|
||||
*
|
||||
* @var bool
|
||||
*/
|
||||
private $sent;
|
||||
|
||||
/**
|
||||
* Information if reminder about token was sent to participant/user
|
||||
*
|
||||
* @var bool
|
||||
*/
|
||||
private $reminderSent;
|
||||
|
||||
/**
|
||||
* Count of sent reminders to participant/user
|
||||
*
|
||||
* @var int
|
||||
*/
|
||||
private $reminderCount;
|
||||
|
||||
/**
|
||||
* Information if the participant has completed the survey
|
||||
*
|
||||
* @var bool
|
||||
*/
|
||||
private $completed;
|
||||
|
||||
/**
|
||||
* Count of left uses of the token
|
||||
*
|
||||
* @var int
|
||||
*/
|
||||
private $usesLeft;
|
||||
|
||||
/**
|
||||
* Information from which day the token is valid
|
||||
*
|
||||
* @var DateTime
|
||||
*/
|
||||
private $validFrom;
|
||||
|
||||
/**
|
||||
* Information until which day the token is valid
|
||||
*
|
||||
* @var DateTime
|
||||
*/
|
||||
private $validUntil;
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function setValue($property, $value)
|
||||
{
|
||||
switch ($property) {
|
||||
case 'tid':
|
||||
$this->id = (int)$value;
|
||||
break;
|
||||
|
||||
case 'participant_id':
|
||||
$this->participantId = (int)$value;
|
||||
break;
|
||||
|
||||
case 'mpid':
|
||||
$this->mpId = (int)$value;
|
||||
break;
|
||||
|
||||
case 'firstname':
|
||||
$this->firstName = trim($value);
|
||||
break;
|
||||
|
||||
case 'lastname':
|
||||
$this->lastName = trim($value);
|
||||
break;
|
||||
|
||||
case 'email':
|
||||
$this->email = trim($value);
|
||||
break;
|
||||
|
||||
case 'emailstatus':
|
||||
$this->emailStatus = trim($value);
|
||||
break;
|
||||
|
||||
case 'token':
|
||||
$this->token = trim($value);
|
||||
break;
|
||||
|
||||
case 'language':
|
||||
$this->language = trim($value);
|
||||
break;
|
||||
|
||||
case 'blacklisted':
|
||||
$this->blacklisted = 'Y' === trim($value);
|
||||
break;
|
||||
|
||||
case 'sent':
|
||||
$this->sent = 'Y' === trim($value);
|
||||
break;
|
||||
|
||||
case 'remindersent':
|
||||
$this->reminderSent = 'Y' === trim($value);
|
||||
break;
|
||||
|
||||
case 'remindercount':
|
||||
$this->reminderCount = (int)$value;
|
||||
break;
|
||||
|
||||
case 'completed':
|
||||
$this->completed = 'Y' === trim($value);
|
||||
break;
|
||||
|
||||
case 'usesleft':
|
||||
$this->usesLeft = (int)$value;
|
||||
break;
|
||||
|
||||
case 'validfrom':
|
||||
if (null === $value) {
|
||||
break;
|
||||
}
|
||||
|
||||
$this->validFrom = Date::getDateTime($value, false, 'Y-m-d H:i:s');
|
||||
break;
|
||||
|
||||
case 'validuntil':
|
||||
if (null === $value) {
|
||||
break;
|
||||
}
|
||||
|
||||
$this->validUntil = Date::getDateTime($value, false, 'Y-m-d H:i:s');
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns ID of the participant
|
||||
*
|
||||
* @return int
|
||||
*/
|
||||
public function getId()
|
||||
{
|
||||
return $this->id;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns another ID of the participant?
|
||||
* Don't know where it is used.
|
||||
*
|
||||
* @return int
|
||||
*/
|
||||
public function getParticipantId()
|
||||
{
|
||||
return $this->participantId;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns MP ID
|
||||
*
|
||||
* @return int
|
||||
*/
|
||||
public function getMpId()
|
||||
{
|
||||
return $this->mpId;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns first name of the participant
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function getFirstName()
|
||||
{
|
||||
return $this->firstName;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns last name of the participant
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function getLastName()
|
||||
{
|
||||
return $this->lastName;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns e-mail of the participant
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function getEmail()
|
||||
{
|
||||
return $this->email;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns status of the e-mail
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function getEmailStatus()
|
||||
{
|
||||
return $this->emailStatus;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns token of the participant
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function getToken()
|
||||
{
|
||||
return $this->token;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns language of the participant
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function getLanguage()
|
||||
{
|
||||
return $this->language;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns information if participant is blacklisted
|
||||
*
|
||||
* @return bool
|
||||
*/
|
||||
public function isBlacklisted()
|
||||
{
|
||||
return $this->blacklisted;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns information if token was sent to participant/user
|
||||
*
|
||||
* @return bool
|
||||
*/
|
||||
public function isSent()
|
||||
{
|
||||
return $this->sent;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns information if reminder about token was sent to participant/user
|
||||
*
|
||||
* @return bool
|
||||
*/
|
||||
public function isReminderSent()
|
||||
{
|
||||
return $this->reminderSent;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns count of sent reminders to participant/user
|
||||
*
|
||||
* @return int
|
||||
*/
|
||||
public function getReminderCount()
|
||||
{
|
||||
return $this->reminderCount;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns information if the participant has completed the survey
|
||||
*
|
||||
* @return bool
|
||||
*/
|
||||
public function isCompleted()
|
||||
{
|
||||
return $this->completed;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns count of left uses of the token
|
||||
*
|
||||
* @return int
|
||||
*/
|
||||
public function getUsesLeft()
|
||||
{
|
||||
return $this->usesLeft;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns information from which day the token is valid
|
||||
*
|
||||
* @return DateTime
|
||||
*/
|
||||
public function getValidFrom()
|
||||
{
|
||||
return $this->validFrom;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns information until which day the token is valid
|
||||
*
|
||||
* @return DateTime
|
||||
*/
|
||||
public function getValidUntil()
|
||||
{
|
||||
return $this->validUntil;
|
||||
}
|
||||
}
|
||||
106
src/Result/Item/ParticipantShort.php
Normal file
106
src/Result/Item/ParticipantShort.php
Normal file
@@ -0,0 +1,106 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
* (c) Meritoo.pl, http://www.meritoo.pl
|
||||
* For the full copyright and license information, please view the LICENSE
|
||||
* file that was distributed with this source code.
|
||||
*/
|
||||
|
||||
namespace Meritoo\LimeSurvey\ApiClient\Result\Item;
|
||||
|
||||
use Meritoo\LimeSurvey\ApiClient\Base\Result\BaseItem;
|
||||
|
||||
/**
|
||||
* One item of the result/data: short data of one participant
|
||||
*
|
||||
* @author Krzysztof Niziol <krzysztof.niziol@meritoo.pl>
|
||||
* @copyright Meritoo.pl
|
||||
*/
|
||||
class ParticipantShort extends BaseItem
|
||||
{
|
||||
/**
|
||||
* ID of the participant
|
||||
*
|
||||
* @var int
|
||||
*/
|
||||
private $id;
|
||||
|
||||
/**
|
||||
* First name of the participant
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
private $firstName;
|
||||
|
||||
/**
|
||||
* Last name of the participant
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
private $lastName;
|
||||
|
||||
/**
|
||||
* E-mail of the participant
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
private $email;
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function setValue($property, $value)
|
||||
{
|
||||
switch ($property) {
|
||||
case 'tid':
|
||||
$this->id = (int)$value;
|
||||
break;
|
||||
|
||||
case 'participant_info':
|
||||
$this->firstName = trim($value['firstname']);
|
||||
$this->lastName = trim($value['lastname']);
|
||||
$this->email = trim($value['email']);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns ID of the participant
|
||||
*
|
||||
* @return int
|
||||
*/
|
||||
public function getId()
|
||||
{
|
||||
return $this->id;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns first name of the participant
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function getFirstName()
|
||||
{
|
||||
return $this->firstName;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns last name of the participant
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function getLastName()
|
||||
{
|
||||
return $this->lastName;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns e-mail of the participant
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function getEmail()
|
||||
{
|
||||
return $this->email;
|
||||
}
|
||||
}
|
||||
153
src/Result/Item/Question.php
Normal file
153
src/Result/Item/Question.php
Normal file
@@ -0,0 +1,153 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
* (c) Meritoo.pl, http://www.meritoo.pl
|
||||
* For the full copyright and license information, please view the LICENSE
|
||||
* file that was distributed with this source code.
|
||||
*/
|
||||
|
||||
namespace Meritoo\LimeSurvey\ApiClient\Result\Item;
|
||||
|
||||
/**
|
||||
* One item of the result/data: full data of one question of survey
|
||||
*
|
||||
* @author Krzysztof Niziol <krzysztof.niziol@meritoo.pl>
|
||||
* @copyright Meritoo.pl
|
||||
*/
|
||||
class Question extends QuestionShort
|
||||
{
|
||||
/**
|
||||
* Available answers
|
||||
*
|
||||
* @var array
|
||||
*/
|
||||
private $availableAnswers;
|
||||
|
||||
/**
|
||||
* Sub-questions
|
||||
* @var array
|
||||
*/
|
||||
private $subQuestions;
|
||||
|
||||
/**
|
||||
* Attributes
|
||||
*
|
||||
* @var array
|
||||
*/
|
||||
private $attributes;
|
||||
|
||||
/**
|
||||
* Attributes in languages
|
||||
*
|
||||
* @var array
|
||||
*/
|
||||
private $attributesLanguages;
|
||||
|
||||
/**
|
||||
* Answer's options
|
||||
*
|
||||
* @var array
|
||||
*/
|
||||
private $answerOptions;
|
||||
|
||||
/**
|
||||
* Default value
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
private $defaultValue;
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function setValue($property, $value)
|
||||
{
|
||||
parent::setValue($property, $value);
|
||||
|
||||
switch ($property) {
|
||||
case 'available_answers':
|
||||
$this->availableAnswers = $value;
|
||||
break;
|
||||
|
||||
case 'subquestions':
|
||||
$this->subQuestions = $value;
|
||||
break;
|
||||
|
||||
case 'attributes':
|
||||
$this->attributes = $value;
|
||||
break;
|
||||
|
||||
case 'attributes_lang':
|
||||
$this->attributesLanguages = $value;
|
||||
break;
|
||||
|
||||
case 'answeroptions':
|
||||
$this->answerOptions = $value;
|
||||
break;
|
||||
|
||||
case 'defaultvalue':
|
||||
$this->defaultValue = $value;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns available answers
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function getAvailableAnswers()
|
||||
{
|
||||
return $this->availableAnswers;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns sub-questions
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function getSubQuestions()
|
||||
{
|
||||
return $this->subQuestions;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns attributes
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function getAttributes()
|
||||
{
|
||||
return $this->attributes;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns attributes in languages
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function getAttributesLanguages()
|
||||
{
|
||||
return $this->attributesLanguages;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns answer's options
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function getAnswerOptions()
|
||||
{
|
||||
return $this->answerOptions;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns default value
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function getDefaultValue()
|
||||
{
|
||||
return $this->defaultValue;
|
||||
}
|
||||
}
|
||||
398
src/Result/Item/QuestionShort.php
Normal file
398
src/Result/Item/QuestionShort.php
Normal file
@@ -0,0 +1,398 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
* (c) Meritoo.pl, http://www.meritoo.pl
|
||||
* For the full copyright and license information, please view the LICENSE
|
||||
* file that was distributed with this source code.
|
||||
*/
|
||||
|
||||
namespace Meritoo\LimeSurvey\ApiClient\Result\Item;
|
||||
|
||||
use Meritoo\LimeSurvey\ApiClient\Base\Result\BaseItem;
|
||||
|
||||
/**
|
||||
* One item of the result/data: short data of one question of survey
|
||||
*
|
||||
* @author Krzysztof Niziol <krzysztof.niziol@meritoo.pl>
|
||||
* @copyright Meritoo.pl
|
||||
*/
|
||||
class QuestionShort extends BaseItem
|
||||
{
|
||||
/**
|
||||
* ID of the question
|
||||
*
|
||||
* @var int
|
||||
*/
|
||||
private $id;
|
||||
|
||||
/**
|
||||
* ID of the parent question
|
||||
*
|
||||
* @var int
|
||||
*/
|
||||
private $parentId;
|
||||
|
||||
/**
|
||||
* ID of the survey
|
||||
*
|
||||
* @var int
|
||||
*/
|
||||
private $surveyId;
|
||||
|
||||
/**
|
||||
* ID of the group of questions
|
||||
*
|
||||
* @var int
|
||||
*/
|
||||
private $groupId;
|
||||
|
||||
/**
|
||||
* ID of the scale
|
||||
* (what does it mean?)
|
||||
*
|
||||
* @var int
|
||||
*/
|
||||
private $scaleId;
|
||||
|
||||
/**
|
||||
* Type of the question
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
private $type;
|
||||
|
||||
/**
|
||||
* Title of the question
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
private $title;
|
||||
|
||||
/**
|
||||
* Content of the question
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
private $content;
|
||||
|
||||
/**
|
||||
* Explanation of the question
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
private $contentHelp;
|
||||
|
||||
/**
|
||||
* Regular expression
|
||||
* (what does it mean? used to validate answer?)
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
private $regularExpression;
|
||||
|
||||
/**
|
||||
* Information if type of question is other
|
||||
* (what does it mean?)
|
||||
*
|
||||
* @var bool
|
||||
*/
|
||||
private $other;
|
||||
|
||||
/**
|
||||
* Information if the question mandatory
|
||||
*
|
||||
* @var bool
|
||||
*/
|
||||
private $mandatory;
|
||||
|
||||
/**
|
||||
* Position/Order of the question
|
||||
*
|
||||
* @var int
|
||||
*/
|
||||
private $position;
|
||||
|
||||
/**
|
||||
* Language of the question
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
private $language;
|
||||
|
||||
/**
|
||||
* Same as default
|
||||
* (what does it mean?)
|
||||
*
|
||||
* @var int
|
||||
*/
|
||||
private $sameDefault;
|
||||
|
||||
/**
|
||||
* Relevant equation
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
private $relevance;
|
||||
|
||||
/**
|
||||
* Name of module
|
||||
* (what does it mean?)
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
private $moduleName;
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function setValue($property, $value)
|
||||
{
|
||||
switch ($property) {
|
||||
case 'qid':
|
||||
$this->id = (int)$value;
|
||||
break;
|
||||
|
||||
case 'parent_qid':
|
||||
$this->parentId = (int)$value;
|
||||
break;
|
||||
|
||||
case 'sid':
|
||||
$this->surveyId = (int)$value;
|
||||
break;
|
||||
|
||||
case 'gid':
|
||||
$this->groupId = (int)$value;
|
||||
break;
|
||||
|
||||
case 'scale_id':
|
||||
$this->scaleId = (int)$value;
|
||||
break;
|
||||
|
||||
case 'type':
|
||||
$this->type = trim($value);
|
||||
break;
|
||||
|
||||
case 'title':
|
||||
$this->title = trim($value);
|
||||
break;
|
||||
|
||||
case 'question':
|
||||
$this->content = trim($value);
|
||||
break;
|
||||
|
||||
case 'help':
|
||||
$this->contentHelp = trim($value);
|
||||
break;
|
||||
|
||||
case 'preg':
|
||||
if (null === $value) {
|
||||
break;
|
||||
}
|
||||
|
||||
$this->regularExpression = trim($value);
|
||||
break;
|
||||
|
||||
case 'other':
|
||||
$this->other = 'Y' === trim($value);
|
||||
break;
|
||||
|
||||
case 'mandatory':
|
||||
$this->mandatory = 'Y' === trim($value);
|
||||
break;
|
||||
|
||||
case 'question_order':
|
||||
$this->position = (int)$value;
|
||||
break;
|
||||
|
||||
case 'language':
|
||||
$this->language = trim($value);
|
||||
break;
|
||||
|
||||
case 'same_default':
|
||||
$this->sameDefault = (int)$value;
|
||||
break;
|
||||
|
||||
case 'relevance':
|
||||
$this->relevance = trim($value);
|
||||
break;
|
||||
|
||||
case 'modulename':
|
||||
if (null === $value) {
|
||||
break;
|
||||
}
|
||||
|
||||
$this->moduleName = trim($value);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns ID of the question
|
||||
*
|
||||
* @return int
|
||||
*/
|
||||
public function getId()
|
||||
{
|
||||
return $this->id;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns ID of the parent question
|
||||
*
|
||||
* @return int
|
||||
*/
|
||||
public function getParentId()
|
||||
{
|
||||
return $this->parentId;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns ID of the survey
|
||||
*
|
||||
* @return int
|
||||
*/
|
||||
public function getSurveyId()
|
||||
{
|
||||
return $this->surveyId;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns ID of the group of questions
|
||||
*
|
||||
* @return int
|
||||
*/
|
||||
public function getGroupId()
|
||||
{
|
||||
return $this->groupId;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns ID of the scale
|
||||
*
|
||||
* @return int
|
||||
*/
|
||||
public function getScaleId()
|
||||
{
|
||||
return $this->scaleId;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns type of the question
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function getType()
|
||||
{
|
||||
return $this->type;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns title of the question
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function getTitle()
|
||||
{
|
||||
return $this->title;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns content of the question
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function getContent()
|
||||
{
|
||||
return $this->content;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns explanation of the question
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function getContentHelp()
|
||||
{
|
||||
return $this->contentHelp;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns regular expression
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function getRegularExpression()
|
||||
{
|
||||
return $this->regularExpression;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns information if type of question is other
|
||||
*
|
||||
* @return bool
|
||||
*/
|
||||
public function isOther()
|
||||
{
|
||||
return $this->other;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns information if the question mandatory
|
||||
*
|
||||
* @return bool
|
||||
*/
|
||||
public function isMandatory()
|
||||
{
|
||||
return $this->mandatory;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns position/Order of the question
|
||||
*
|
||||
* @return int
|
||||
*/
|
||||
public function getPosition()
|
||||
{
|
||||
return $this->position;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns language of the question
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function getLanguage()
|
||||
{
|
||||
return $this->language;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns information related to same as default
|
||||
*
|
||||
* @return int
|
||||
*/
|
||||
public function getSameDefault()
|
||||
{
|
||||
return $this->sameDefault;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns relevant equation
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function getRelevance()
|
||||
{
|
||||
return $this->relevance;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns name of module
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function getModuleName()
|
||||
{
|
||||
return $this->moduleName;
|
||||
}
|
||||
}
|
||||
143
src/Result/Item/Survey.php
Normal file
143
src/Result/Item/Survey.php
Normal file
@@ -0,0 +1,143 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
* (c) Meritoo.pl, http://www.meritoo.pl
|
||||
* For the full copyright and license information, please view the LICENSE
|
||||
* file that was distributed with this source code.
|
||||
*/
|
||||
|
||||
namespace Meritoo\LimeSurvey\ApiClient\Result\Item;
|
||||
|
||||
use DateTime;
|
||||
use Meritoo\Common\Utilities\Date;
|
||||
use Meritoo\LimeSurvey\ApiClient\Base\Result\BaseItem;
|
||||
|
||||
/**
|
||||
* One item of the result/data: survey
|
||||
*
|
||||
* @author Krzysztof Niziol <krzysztof.niziol@meritoo.pl>
|
||||
* @copyright Meritoo.pl
|
||||
*/
|
||||
class Survey extends BaseItem
|
||||
{
|
||||
/**
|
||||
* ID of the survey
|
||||
*
|
||||
* @var int
|
||||
*/
|
||||
private $id;
|
||||
|
||||
/**
|
||||
* Title of the survey
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
private $title;
|
||||
|
||||
/**
|
||||
* Date when the survey starts
|
||||
*
|
||||
* @var DateTime
|
||||
*/
|
||||
private $startsAt;
|
||||
|
||||
/**
|
||||
* Date when the survey expires
|
||||
*
|
||||
* @var DateTime
|
||||
*/
|
||||
private $expiresAt;
|
||||
|
||||
/**
|
||||
* Information if the survey is active
|
||||
*
|
||||
* @var bool
|
||||
*/
|
||||
private $active = false;
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function setValue($property, $value)
|
||||
{
|
||||
switch ($property) {
|
||||
case 'sid':
|
||||
$this->id = (int)$value;
|
||||
break;
|
||||
|
||||
case 'surveyls_title':
|
||||
$this->title = trim($value);
|
||||
break;
|
||||
|
||||
case 'startdate':
|
||||
if (null === $value) {
|
||||
break;
|
||||
}
|
||||
|
||||
$this->startsAt = Date::getDateTime($value, false, 'Y-m-d H:i:s');
|
||||
break;
|
||||
|
||||
case 'expires':
|
||||
if (null === $value) {
|
||||
break;
|
||||
}
|
||||
|
||||
$this->expiresAt = Date::getDateTime($value, false, 'Y-m-d H:i:s');
|
||||
break;
|
||||
|
||||
case 'active':
|
||||
$this->active = 'Y' === trim($value);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns ID of the survey
|
||||
*
|
||||
* @return int
|
||||
*/
|
||||
public function getId()
|
||||
{
|
||||
return $this->id;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns title of the survey
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function getTitle()
|
||||
{
|
||||
return $this->title;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns date when the survey starts
|
||||
*
|
||||
* @return DateTime|null
|
||||
*/
|
||||
public function getStartsAt()
|
||||
{
|
||||
return $this->startsAt;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns date when the survey expires
|
||||
*
|
||||
* @return DateTime|null
|
||||
*/
|
||||
public function getExpiresAt()
|
||||
{
|
||||
return $this->expiresAt;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns information if the survey is active
|
||||
*
|
||||
* @return bool
|
||||
*/
|
||||
public function isActive()
|
||||
{
|
||||
return $this->active;
|
||||
}
|
||||
}
|
||||
119
src/Result/Processor/ResultProcessor.php
Normal file
119
src/Result/Processor/ResultProcessor.php
Normal file
@@ -0,0 +1,119 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
* (c) Meritoo.pl, http://www.meritoo.pl
|
||||
* For the full copyright and license information, please view the LICENSE
|
||||
* file that was distributed with this source code.
|
||||
*/
|
||||
|
||||
namespace Meritoo\LimeSurvey\ApiClient\Result\Processor;
|
||||
|
||||
use Meritoo\LimeSurvey\ApiClient\Base\Result\BaseItem;
|
||||
use Meritoo\LimeSurvey\ApiClient\Exception\UnknownInstanceOfResultItem;
|
||||
use Meritoo\LimeSurvey\ApiClient\Result\Item\Participant;
|
||||
use Meritoo\LimeSurvey\ApiClient\Result\Item\ParticipantShort;
|
||||
use Meritoo\LimeSurvey\ApiClient\Result\Item\Question;
|
||||
use Meritoo\LimeSurvey\ApiClient\Result\Item\QuestionShort;
|
||||
use Meritoo\LimeSurvey\ApiClient\Result\Item\Survey;
|
||||
use Meritoo\LimeSurvey\ApiClient\Type\MethodType;
|
||||
|
||||
/**
|
||||
* Processor of the raw data fetched while talking to the LimeSurvey's API
|
||||
*
|
||||
* @author Krzysztof Niziol <krzysztof.niziol@meritoo.pl>
|
||||
* @copyright Meritoo.pl
|
||||
*/
|
||||
class ResultProcessor
|
||||
{
|
||||
/**
|
||||
* Returns processed data based on the raw data returned by the LimeSurvey's API
|
||||
*
|
||||
* @param string $method Name of called method while talking to the LimeSurvey's API. One of the MethodType
|
||||
* class constants.
|
||||
* @param array $rawData Data returned by the LimeSurvey's API
|
||||
* @return null|BaseItem|array
|
||||
*/
|
||||
public function process($method, array $rawData)
|
||||
{
|
||||
$method = MethodType::getValidatedMethod($method);
|
||||
|
||||
/*
|
||||
* No data?
|
||||
* Nothing to do
|
||||
*/
|
||||
if (empty($rawData)) {
|
||||
return null;
|
||||
}
|
||||
|
||||
/*
|
||||
* Prepare instance of one item
|
||||
*/
|
||||
$item = $this->getItemInstance($method);
|
||||
|
||||
/*
|
||||
* The raw data is or, actually, should be iterable?
|
||||
*/
|
||||
if (MethodType::isResultIterable($method)) {
|
||||
$items = [];
|
||||
|
||||
foreach ($rawData as $itemData) {
|
||||
$emptyItem = clone $item;
|
||||
$items[] = $emptyItem->setValues($itemData);
|
||||
}
|
||||
|
||||
return $items;
|
||||
}
|
||||
|
||||
return $item->setValues($rawData);
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns instance of one item of the result
|
||||
*
|
||||
* @param string $method Name of called method while talking to the LimeSurvey's API. One of the MethodType
|
||||
* class constants.
|
||||
* @return BaseItem
|
||||
* @throws UnknownInstanceOfResultItem
|
||||
*/
|
||||
private function getItemInstance($method)
|
||||
{
|
||||
$item = null;
|
||||
$method = MethodType::getValidatedMethod($method);
|
||||
|
||||
switch ($method) {
|
||||
case MethodType::ADD_PARTICIPANTS:
|
||||
case MethodType::GET_PARTICIPANT_PROPERTIES:
|
||||
$item = new Participant();
|
||||
break;
|
||||
|
||||
case MethodType::GET_QUESTION_PROPERTIES:
|
||||
$item = new Question();
|
||||
break;
|
||||
|
||||
case MethodType::LIST_PARTICIPANTS:
|
||||
$item = new ParticipantShort();
|
||||
break;
|
||||
|
||||
case MethodType::LIST_QUESTIONS:
|
||||
$item = new QuestionShort();
|
||||
break;
|
||||
|
||||
case MethodType::LIST_SURVEYS:
|
||||
$item = new Survey();
|
||||
break;
|
||||
|
||||
/*
|
||||
* todo: Use other types of methods and create proper classes (used to get instances of one item)
|
||||
*/
|
||||
}
|
||||
|
||||
/*
|
||||
* Instance of the item is unknown?
|
||||
*/
|
||||
if (null === $item) {
|
||||
throw new UnknownInstanceOfResultItem($method);
|
||||
}
|
||||
|
||||
return $item;
|
||||
}
|
||||
}
|
||||
176
src/Result/Result.php
Normal file
176
src/Result/Result.php
Normal file
@@ -0,0 +1,176 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
* (c) Meritoo.pl, http://www.meritoo.pl
|
||||
* For the full copyright and license information, please view the LICENSE
|
||||
* file that was distributed with this source code.
|
||||
*/
|
||||
|
||||
namespace Meritoo\LimeSurvey\ApiClient\Result;
|
||||
|
||||
use Meritoo\Common\Collection\Collection;
|
||||
use Meritoo\LimeSurvey\ApiClient\Base\Result\BaseItem;
|
||||
use Meritoo\LimeSurvey\ApiClient\Exception\CannotProcessDataException;
|
||||
use Meritoo\LimeSurvey\ApiClient\Result\Processor\ResultProcessor;
|
||||
use Meritoo\LimeSurvey\ApiClient\Type\MethodType;
|
||||
|
||||
/**
|
||||
* Result with data fetched while talking to the LimeSurvey's API
|
||||
*
|
||||
* @author Krzysztof Niziol <krzysztof.niziol@meritoo.pl>
|
||||
* @copyright Meritoo.pl
|
||||
*/
|
||||
class Result
|
||||
{
|
||||
/**
|
||||
* Name of called method while talking to the LimeSurvey's API. One of the MethodType class constants.
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
private $method;
|
||||
|
||||
/**
|
||||
* Raw data returned by the LimeSurvey's API
|
||||
*
|
||||
* @var array
|
||||
*/
|
||||
private $rawData;
|
||||
|
||||
/**
|
||||
* Status, information returned instead of usual/normal result
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
private $status;
|
||||
|
||||
/**
|
||||
* Processor of the raw data fetched while talking to the LimeSurvey's API
|
||||
*
|
||||
* @var ResultProcessor
|
||||
*/
|
||||
private $resultProcessor;
|
||||
|
||||
/**
|
||||
* Class constructor
|
||||
*
|
||||
* @param string $method Name of called method while talking to the LimeSurvey's API. One of the MethodType
|
||||
* class constants.
|
||||
* @param array $rawData Raw data returned by the LimeSurvey's API
|
||||
*/
|
||||
public function __construct($method, array $rawData)
|
||||
{
|
||||
$this->method = MethodType::getValidatedMethod($method);
|
||||
$this->setRawDataAndStatus($rawData);
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns information if the result contains any data
|
||||
*
|
||||
* @return bool
|
||||
*/
|
||||
public function isEmpty()
|
||||
{
|
||||
return empty($this->rawData);
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns data returned by the LimeSurvey's API
|
||||
*
|
||||
* @param bool $raw (optional) If is set to true, raw data provided by the LimeSurvey's API will be returned.
|
||||
* Otherwise - prepared/processed.
|
||||
* @return array|Collection|BaseItem
|
||||
* @throws CannotProcessDataException
|
||||
*/
|
||||
public function getData($raw = false)
|
||||
{
|
||||
/*
|
||||
* Raw data should be returned only?
|
||||
* Let's do it
|
||||
*/
|
||||
if ($raw) {
|
||||
return $this->rawData;
|
||||
}
|
||||
|
||||
/*
|
||||
* Status is unknown?
|
||||
* Let's process the raw data
|
||||
*/
|
||||
if (empty($this->status)) {
|
||||
return $this->getProcessedData($this->rawData);
|
||||
}
|
||||
|
||||
/*
|
||||
* Oops, the raw data returned by the LimeSurvey's API cannot be processed, because status was provided.
|
||||
* Well, probably something is broken and... there is no data.
|
||||
*/
|
||||
throw new CannotProcessDataException($this->status);
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns status, information returned instead of usual/normal result
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function getStatus()
|
||||
{
|
||||
return $this->status;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns processed data based on the raw data returned by the LimeSurvey's API
|
||||
*
|
||||
* @param array $rawData Raw data returned by the LimeSurvey's API
|
||||
* @return Collection|BaseItem
|
||||
*/
|
||||
private function getProcessedData(array $rawData)
|
||||
{
|
||||
$processed = $this
|
||||
->getResultProcessor()
|
||||
->process($this->method, $rawData);
|
||||
|
||||
if (null === $processed || is_array($processed)) {
|
||||
$collection = new Collection();
|
||||
|
||||
if (is_array($processed)) {
|
||||
$collection->addMultiple($processed);
|
||||
}
|
||||
|
||||
return $collection;
|
||||
}
|
||||
|
||||
return $processed;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns processor of the raw data fetched while talking to the LimeSurvey's API
|
||||
*
|
||||
* @return ResultProcessor
|
||||
*/
|
||||
private function getResultProcessor()
|
||||
{
|
||||
if (null === $this->resultProcessor) {
|
||||
$this->resultProcessor = new ResultProcessor();
|
||||
}
|
||||
|
||||
return $this->resultProcessor;
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets status, information returned instead of usual/normal result and raw data returned by the LimeSurvey's API
|
||||
*
|
||||
* @param array $rawData Raw data returned by the LimeSurvey's API
|
||||
*/
|
||||
private function setRawDataAndStatus(array $rawData)
|
||||
{
|
||||
/*
|
||||
* Status was provided?
|
||||
* Well, probably something is broken and... there is no data
|
||||
*/
|
||||
if (isset($rawData['status'])) {
|
||||
$this->status = trim($rawData['status']);
|
||||
$rawData = [];
|
||||
}
|
||||
|
||||
$this->rawData = $rawData;
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user