Abstract implementation of SourceInterface containing basic utilities and logical separation between the Gems database and the Source database
package | Gems |
---|---|
subpackage | OpenRosa |
copyright | Copyright (c) 2011 Erasmus MC |
license | New BSD License |
since | Class available since version 1.5 |
inherited_from | \Gems_Tracker_Source_SourceAbstract |
__construct(array $sourceData, \Zend_Db_Adapter_Abstract $gemsDb)
inherited_from | \Gems_Tracker_Source_SourceAbstract::__construct() |
---|
array
The information from gems__sources for this source.
\Zend_Db_Adapter_Abstract
Do not want to copy db using registry because that is public and this should be private
__construct(array $sourceData, \Zend_Db_Adapter_Abstract $gemsDb)
inherited_from | \Gems_Tracker_Source_SourceInterface::__construct() |
---|
array
The information from gems__sources for this source.
\Zend_Db_Adapter_Abstract
Do not want to copy db using registry because that is public and this should be private
checkSourceActive(integer $userId) : boolean
integer
Id of the user who takes the action (for logging)
boolean
checkSurvey(string $sourceSurveyId, integer $surveyId, integer $userId) : mixed
string
integer
integer
mixed
message string or array of messagescopyTokenToSource(\Gems_Tracker_Token $token, string $language, integer $surveyId, string $sourceSurveyId = null
) : integer
\Gems_Tracker_Token
string
integer
Gems Survey Id
string
Optional Survey Id used by source
\Gems_Tracker_Source_SurveyNotFoundException |
---|
integer
1 of the token was inserted or changed, 0 otherwisegetAnswerDateTime(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.
string
Name of answer field
\Gems_Tracker_Token
Gems token object
integer
Gems Survey Id
string
Optional Survey Id used by source
\MUtil_Date
date time or nullgetCompletionTime(\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.
\Gems_Tracker_Token
Gems token object
integer
Gems Survey Id
string
Optional Survey Id used by source
\MUtil_Date
date time or nullgetDatesList(string $language, integer $surveyId, string $sourceSurveyId = null
) : array
Used in dropdown list etc..
string
(ISO) language string
integer
Gems Survey Id
string
Optional Survey Id used by source
array
fieldname => labelgetId() : integer
inherited_from | \Gems_Tracker_Source_SourceInterface::getId() |
---|
integer
The source Id of this sourcegetQuestionInformation(string $language, integer $surveyId, string $sourceSurveyId = null
) : array
string
(ISO) language string
integer
Gems Survey Id
string
Optional Survey Id used by source
array
Nested arraygetQuestionList(string $language, integer $surveyId, string $sourceSurveyId = null
) : array
.
string
(ISO) language string
integer
Gems Survey Id
string
Optional Survey Id used by source
array
fieldname => labelgetRawTokenAnswerRow(string $tokenId, integer $surveyId, string $sourceSurveyId = null
) : array
Function may return more fields than just the answers.
string
Gems Token Id
integer
Gems Survey Id
string
Optional Survey Id used by source
array
Field => Value arraygetRawTokenAnswerRows(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.
array
filter array
integer
Gems Survey Id
string
Optional Survey Id used by source
array
Of nested Field => Value arrays indexed by tokenIdgetRawTokenAnswerRowsCount(array $filter, integer $surveyId, string $sourceSurveyId = null
) : integer
Abstract implementation is not efficient, sources should handle this as efficient as possible.
inherited_from | \Gems_Tracker_Source_SourceAbstract::getRawTokenAnswerRowsCount() |
---|
array
filter array
integer
Gems Survey Id
string
Optional Survey Id used by source
integer
getRawTokenAnswerRowsCount(array $filter, integer $surveyId, string $sourceSurveyId = null
) : integer
Abstract implementation is not efficient, sources should handle this as efficient as possible.
inherited_from | \Gems_Tracker_Source_SourceInterface::getRawTokenAnswerRowsCount() |
---|
array
filter array
integer
Gems Survey Id
string
Optional Survey Id used by source
integer
getRawTokenAnswerRowsSelect(array $filter, \type $surveyId, \type $sourceSurveyId = null
) : \Zend_Db_Select
array
\type
\type
\Zend_Db_Select
getSourceDatabase() : \Zend_Db_Adapter_Abstract
inherited_from | \Gems_Tracker_Source_SourceInterface::getSourceDatabase() |
---|
\Zend_Db_Adapter_Abstract
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.
\Gems_Tracker_Token
Gems token object
integer
Gems Survey Id
string
Optional Survey Id used by source
\MUtil_Date
date time or nullgetSurvey(\type $surveyId, \type $sourceSurveyId = null
) : \OpenRosa_Tracker_Source_OpenRosa_Form
\type
\type
\OpenRosa_Tracker_Source_OpenRosa_Form
getSurveyAnswerModel(\Gems_Tracker_Survey $survey, string $language= null
, string $sourceSurveyId= null
) : \MUtil_Model_ModelAbstract
\Gems_Tracker_Survey
string
Optional (ISO) language string
string
Optional Survey Id used by source
\MUtil_Model_ModelAbstract
getSurveyInfo(integer $sourceSurveyId) : array
integer
array
getTokenUrl(\Gems_Tracker_Token $token, string $language, integer $surveyId, string $sourceSurveyId) : string
\Gems_Tracker_Token
Gems token object
string
integer
Gems Survey Id
string
Optional Survey Id used by source
string
The url to start the surveyinSource(\Gems_Tracker_Token $token, integer $surveyId, string $sourceSurveyId = null
) : boolean
\Gems_Tracker_Token
Gems token object
integer
Gems Survey Id
string
Optional Survey Id used by source
boolean
isCompleted(\Gems_Tracker_Token $token, integer $surveyId, string $sourceSurveyId = null
) : boolean
\Gems_Tracker_Token
Gems token object
integer
Gems Survey Id
string
Optional Survey Id used by source
boolean
True if the token has completedsetRawTokenAnswers(\Gems_Tracker_Token $token, $answers, integer $surveyId, string $sourceSurveyId = null
)
\Gems_Tracker_Token
Gems token object
array Field => Value array
integer
Gems Survey Id
string
Optional Survey Id used by source
setTokenCompletionTime(\Gems_Tracker_Token $token, \Zend_Date|null $completionTime, integer $surveyId, string $sourceSurveyId = null
)
\Gems_Tracker_Token
Gems token object
\Zend_Date
null
\Zend_Date or null
integer
Gems Survey Id (actually required)
string
Optional Survey Id used by source
synchronizeSurveyBatch(\Gems_Task_TaskRunnerBatch $batch, integer $userId) : array
inherited_from | \Gems_Tracker_Source_SourceInterface::synchronizeSurveyBatch() |
---|
\Gems_Task_TaskRunnerBatch
integer
Id of the user who takes the action (for logging)
array
Returns an array of messagesupdateConsent(\Gems_Tracker_Token $token, integer $surveyId, string $sourceSurveyId= null
, string $consentCode= null
) : array: integer
\Gems_Tracker_Token
integer
Gems Survey Id
string
Optional Survey Id used by source
string
Optional consent code, otherwise code from token is used.
array
Returns an array of messages
/
public function synchronizeSurveys($userId)
{
$messages = $this->_scanForms();
// Surveys in LS
$db = $this->getSourceDatabase();
$select = $db->select();
$select->from('gems__openrosaforms');
$openRosaSurveys = $db->fetchAssoc($select);
if (!$openRosaSurveys) {
//If no surveys present, just use an empty array as array_combine fails
$openRosaSurveys = array();
$openRosaSurveyIds = array();
} else {
$openRosaSurveyIds = array_combine(array_keys($openRosaSurveys), array_keys($openRosaSurveys));
}
// Surveys in Gems
$gemsSurveys = $this->_getGemsSurveysForSynchronisation();
foreach ($gemsSurveys as $surveyId => $sourceSurveyId) {
$survey = $this->tracker->getSurveyBySourceId($sourceSurveyId, $this->getId());
if (isset($openRosaSurveyIds[$sourceSurveyId])) {
// Exists
$values['gsu_survey_name'] = $openRosaSurveys[$sourceSurveyId]['gof_form_title'] . ' [' . $openRosaSurveys[$sourceSurveyId]['gof_form_version'] . ']';
$values['gsu_surveyor_active'] = $openRosaSurveys[$sourceSurveyId]['gof_form_active'];
$values['gsu_status'] = 'OK';
} else {
// No longer exists
$values['gsu_surveyor_active'] = 0;
$values['gsu_status'] = 'No longer exists';
}
$survey->saveSurvey($values, $userId);
}
foreach (array_diff($openRosaSurveyIds, $gemsSurveys) as $sourceSurveyId) {
// New survey
$values = array();
$values['gsu_survey_name'] = $openRosaSurveys[$sourceSurveyId]['gof_form_title'] . ' [' . $openRosaSurveys[$sourceSurveyId]['gof_form_version'] . ']';
$values['gsu_surveyor_active'] = $openRosaSurveys[$sourceSurveyId]['gof_form_active'];
$values['gsu_active'] = 0;
$values['gsu_status'] = '';
$survey = $this->tracker->getSurveyBySourceId($sourceSurveyId, $this->getId());
$survey->exists = false;
$survey->saveSurvey($values, $userId);
}
return $messages;
}
Updates the consent code of the the token in the source (if needed)integer
1 of the token was inserted or changed, 0 otherwise_checkDir(\type $directory) : \Directory
\type
\Directory
_getGemsSurveysForSynchronisation() : array
array
Pairs gemsId => sourceId_getSourceSurveysForSynchronisation() : array
inherited_from | \Gems_Tracker_Source_SourceAbstract::_getSourceSurveysForSynchronisation() |
---|
array
of sourceId values or false_getSourceSurveysForSynchronisation() : array
array
of sourceId values or false_getTokenFromSqlWhere(string $from, string $fieldName) : string
string
The tokens that should not occur
string
Name of database field to use
string
_getTokenFromToSql(string $from, string $to, string $fieldName) : string
string
The tokens that should not occur
string
The tokens that replace them
string
Name of database field to use
string
_scanForms()
_updateGemsSurveyExists(array $surveyorSids, integer $userId) : array
array
The gsu_surveyor_id's that ARE in the source
integer
Id of the user who takes the action (for logging)
array
The names of the surveys that no longer exist_updateSource(array $values, integer $userId) : integer
array
The values that this source should be set to
integer
The current user
integer
1 if data changed, 0 otherwiseaddDatabasePrefix(\return $tableName, boolean $addDatabaseName = true
) : string
\return
boolean
Optional, when true (= default) and there is a database name then it is prepended to the name.
string
filterLimitOffset(array $filter, \Zend_Db_Select $select)
array
\Zend_Db_Select
getBaseUrl() : string
string
Base url for sourcegetSurveyData(integer $surveyId, string $field = null
) : array
Uses internal caching to prevent multiple db lookups during a program run (so no caching beyond page generation time)
integer
string
Optional field to retrieve data for
array
updateTokens(integer $userId, $updateTokens = true
) : integer
integer
Id of the user who takes the action (for logging)
integer
The number of tokens changed_getSid(\type $surveyId) : \type
\type
\type
$baseDir : string
Will be set on init to: GEMS_ROOT_DIR . '/var/uploads/openrosa/';
$formDir : string
$loader : \Gems_Loader
$project : \Gems_Project_ProjectSettings
$tracker : \Gems_Tracker
$translate : \Zend_Translate
$_gemsDb : \Gems_Task_TaskRunnerBatch: \Zend_Db_Adapter_Abstract
$_sourceData : array
$_sourceDb : \Zend_Db_Adapter_Abstract