Interface description of SourceInterface for (external) survey sources.

package Gems
subpackage Tracker
copyright Copyright (c) 2011 Erasmus MC
license New BSD License
since Class available since version 1.2

 Methods

Standard constructor for sources

__construct(array $sourceData, \Zend_Db_Adapter_Abstract $gemsDb) 

Parameters

$sourceData

array

The information from gems__sources for this source.

$gemsDb

\Zend_Db_Adapter_Abstract

Do not want to copy db using registry because that is public and this should be private

Checks wether this particular source is active or not and should handle updating the gems-db with the right information about this source

checkSourceActive(integer $userId) : boolean

Parameters

$userId

integer

Id of the user who takes the action (for logging)

Returns

boolean

Survey source synchronization check function

checkSurvey(string $sourceSurveyId, integer $surveyId, integer $userId) : mixed

Parameters

$sourceSurveyId

string

$surveyId

integer

$userId

integer

Returns

mixedmessage string or array of messages

Inserts the token in the source (if needed) and sets those attributes the source wants to set.

copyTokenToSource(\Gems_Tracker_Token $token, string $language, integer $surveyId, string $sourceSurveyId = null) : integer

Parameters

$token

\Gems_Tracker_Token

$language

string

$surveyId

integer

Gems Survey Id

$sourceSurveyId

string

Optional Survey Id used by source

Exceptions

\Gems_Tracker_Source_SurveyNotFoundException

Returns

integer1 of the token was inserted or changed, 0 otherwise

Returns a field from the raw answers as a date object.

getAnswerDateTime(string $fieldName, \Gems_Tracker_Token $token, integer $surveyId, string $sourceSurveyId = null) : \MUtil_Date

A seperate function as only the source knows what format the date/time value has.

Parameters

$fieldName

string

Name of answer field

$token

\Gems_Tracker_Token

Gems token object

$surveyId

integer

Gems Survey Id

$sourceSurveyId

string

Optional Survey Id used by source

Returns

\MUtil_Datedate time or null

Gets the time the survey was completed according to the source

getCompletionTime(\Gems_Tracker_Token $token, integer $surveyId, string $sourceSurveyId = null) : \MUtil_Date

A source always return null when it does not know this time (or does not know it well enough). In the case \Gems_Tracker_Token will do it's best to keep track by itself.

Parameters

$token

\Gems_Tracker_Token

Gems token object

$surveyId

integer

Gems Survey Id

$sourceSurveyId

string

Optional Survey Id used by source

Returns

\MUtil_Datedate time or null

Returns an array containing fieldname => label for each date field in the survey.

getDatesList(string $language, integer $surveyId, string $sourceSurveyId = null) : array

Used in dropdown list etc..

Parameters

$language

string

(ISO) language string

$surveyId

integer

Gems Survey Id

$sourceSurveyId

string

Optional Survey Id used by source

Returns

arrayfieldname => label

getId()

getId() : integer

Returns

integerThe source Id of this source

Returns an array of arrays with the structure: question => string, class => question|question_sub group => is for grouping type => (optional) source specific type answers => string for single types, array for selection of, nothing for no answer

getQuestionInformation(string $language, integer $surveyId, string $sourceSurveyId = null) : array

Parameters

$language

string

(ISO) language string

$surveyId

integer

Gems Survey Id

$sourceSurveyId

string

Optional Survey Id used by source

Returns

arrayNested array

Returns an array containing fieldname => label for dropdown list etc.

getQuestionList(string $language, integer $surveyId, string $sourceSurveyId = null) : array

.

Parameters

$language

string

(ISO) language string

$surveyId

integer

Gems Survey Id

$sourceSurveyId

string

Optional Survey Id used by source

Returns

arrayfieldname => label

Returns the answers in simple raw array format, without value processing etc.

getRawTokenAnswerRow(string $tokenId, integer $surveyId, string $sourceSurveyId = null) : array

Function may return more fields than just the answers.

Parameters

$tokenId

string

Gems Token Id

$surveyId

integer

Gems Survey Id

$sourceSurveyId

string

Optional Survey Id used by source

Returns

arrayField => Value array

Returns the answers of multiple tokens in simple raw nested array format, without value processing etc.

getRawTokenAnswerRows(array $filter, integer $surveyId, string $sourceSurveyId = null) : array

Function may return more fields than just the answers. The $filter param is an array of filters to apply to the selection, it has some special formatting rules. The key is the db-field to filter on and the value could be a value or an array of values to filter on.

Special keys that should be mapped to the right field by the source are: respondentid organizationid consentcode token

So a filter of [token]=>[abc-def][def-abc] will return the results for these two tokens while a filter of [organizationid] => 70 will return all results for this organization.

Parameters

$filter

array

filter array

$surveyId

integer

Gems Survey Id

$sourceSurveyId

string

Optional Survey Id used by source

Returns

arrayOf nested Field => Value arrays indexed by tokenId

Returns the recordcount for a given filter

getRawTokenAnswerRowsCount(array $filter, integer $surveyId, string $sourceSurveyId = null) : integer

Parameters

$filter

array

filter array

$surveyId

integer

Gems Survey Id

$sourceSurveyId

string

Optional Survey Id used by source

Returns

integer

Get the db adapter for this source

getSourceDatabase() : \Zend_Db_Adapter_Abstract

Returns

\Zend_Db_Adapter_Abstract

Gets the time the survey was started according to the source.

getStartTime(\Gems_Tracker_Token $token, integer $surveyId, string $sourceSurveyId = null) : \MUtil_Date

A source always return null when it does not know this time (or does not know it well enough). In the case \Gems_Tracker_Token will do it's best to keep track by itself.

Parameters

$token

\Gems_Tracker_Token

Gems token object

$surveyId

integer

Gems Survey Id

$sourceSurveyId

string

Optional Survey Id used by source

Returns

\MUtil_Datedate time or null

Returns a model for the survey answers

getSurveyAnswerModel(\Gems_Tracker_Survey $survey, string $language = null, string $sourceSurveyId = null) : \MUtil_Model_ModelAbstract

Parameters

$survey

\Gems_Tracker_Survey

$language

string

Optional (ISO) language string

$sourceSurveyId

string

Optional Survey Id used by source

Returns

\MUtil_Model_ModelAbstract

Returns the url that (should) start the survey for this token

getTokenUrl(\Gems_Tracker_Token $token, string $language, integer $surveyId, string $sourceSurveyId) : string

Parameters

$token

\Gems_Tracker_Token

Gems token object

$language

string

$surveyId

integer

Gems Survey Id

$sourceSurveyId

string

Optional Survey Id used by source

Returns

stringThe url to start the survey

Returns true if a batch is set

inSource(\Gems_Tracker_Token $token, integer $surveyId, string $sourceSurveyId = null) : boolean: boolean

Parameters

$token

\Gems_Tracker_Token

Gems token object

$surveyId

integer

Gems Survey Id

$sourceSurveyId

string

Optional Survey Id used by source

Returns

boolean/ public function hasBatch(); Checks whether the token is in the source.
boolean

Returns true if the survey was completed according to the source

isCompleted(\Gems_Tracker_Token $token, integer $surveyId, string $sourceSurveyId = null) : boolean

Parameters

$token

\Gems_Tracker_Token

Gems token object

$surveyId

integer

Gems Survey Id

$sourceSurveyId

string

Optional Survey Id used by source

Returns

booleanTrue if the token has completed

Set the batch to be used by this source

setRawTokenAnswers(\Gems_Tracker_Token $token, $answers, integer $surveyId, string $sourceSurveyId = null) : true

Use $this->hasBatch to check for existence

Parameters

$token

\Gems_Tracker_Token

Gems token object

$answers

array Field => Value array

$surveyId

integer

Gems Survey Id

$sourceSurveyId

string

Optional Survey Id used by source

Returns

trueWhen answers changed

Sets the completion time.

setTokenCompletionTime(\Gems_Tracker_Token $token, \Zend_Date|null $completionTime, integer $surveyId, string $sourceSurveyId = null

Parameters

$token

\Gems_Tracker_Token

Gems token object

$completionTime

\Zend_Datenull

\Zend_Date or null

$surveyId

integer

Gems Survey Id (actually required)

$sourceSurveyId

string

Optional Survey Id used by source

Updates the gems database with the latest information about the surveys in this source adapter

synchronizeSurveyBatch(\Gems_Task_TaskRunnerBatch $batch, integer $userId) : array

Parameters

$batch

\Gems_Task_TaskRunnerBatch

$userId

integer

Id of the user who takes the action (for logging)

Returns

arrayReturns an array of messages

Updates the gems database with the latest information about the surveys in this source adapter

updateConsent(\Gems_Tracker_Token $token, integer $surveyId, string $sourceSurveyId = null, string $consentCode = null) : array: integer

Parameters

$token

\Gems_Tracker_Token

$surveyId

integer

Gems Survey Id

$sourceSurveyId

string

Optional Survey Id used by source

$consentCode

string

Optional consent code, otherwise code from token is used.

Returns

arrayReturns an array of messages / public function synchronizeSurveys($userId); Updates the consent code of the the token in the source (if needed)
integer1 of the token was inserted or changed, 0 otherwise