Abstract implementation of SourceInterface containing basic utilities and logical separation between the Gems database and the Source database

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) 
inherited_from \Gems_Tracker_Source_SourceInterface::__construct()

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

getId()

getId() : integer
inherited_from \Gems_Tracker_Source_SourceInterface::getId()

Returns

integerThe source Id of this source

Returns the recordcount for a given filter

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()

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
inherited_from \Gems_Tracker_Source_SourceInterface::getSourceDatabase()

Returns

\Zend_Db_Adapter_Abstract

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

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

Parameters

$batch

\Gems_Task_TaskRunnerBatch

$userId

integer

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

Returns

arrayReturns an array of messages

Returns all surveys for synchronization

_getGemsSurveysForSynchronisation() : array

Returns

arrayPairs gemsId => sourceId

Returns all surveys for synchronization

_getSourceSurveysForSynchronisation() : array

Returns

arrayof sourceId values or false

Creates a where filter statement for tokens that do not have a correct name and are in a tokens table

_getTokenFromSqlWhere(string $from, string $fieldName) : string

Parameters

$from

string

The tokens that should not occur

$fieldName

string

Name of database field to use

Returns

string

Creates a SQL update statement for tokens that do not have a correct name and are in a tokens table.

_getTokenFromToSql(string $from, string $to, string $fieldName) : string

Parameters

$from

string

The tokens that should not occur

$to

string

The tokens that replace them

$fieldName

string

Name of database field to use

Returns

string

This helper function updates the surveys in the gems_surveys table that no longer exist in in the source and returns a list of their names.

_updateGemsSurveyExists(array $surveyorSids, integer $userId) : array

Parameters

$surveyorSids

array

The gsu_surveyor_id's that ARE in the source

$userId

integer

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

Returns

arrayThe names of the surveys that no longer exist

Updates this source, both in the database and in memory.

_updateSource(array $values, integer $userId) : integer

Parameters

$values

array

The values that this source should be set to

$userId

integer

The current user

Returns

integer1 if data changed, 0 otherwise

Adds database (if needed) and tablename prefix to the table name

addDatabasePrefix(\return $tableName, boolean $addDatabaseName = true) : string

Parameters

$tableName

\return

$addDatabaseName

boolean

Optional, when true (= default) and there is a database name then it is prepended to the name.

Returns

string

Extract limit and offset from the filter and add it to a select

filterLimitOffset(array $filter, \Zend_Db_Select $select) 

Parameters

$filter

array

$select

\Zend_Db_Select

getBaseUrl()

getBaseUrl() : string

Returns

stringBase url for source

Returns all info from the Gems surveys table for a givens Gems Survey Id

getSurveyData(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)

Parameters

$surveyId

integer

$field

string

Optional field to retrieve data for

Returns

array

Updates the gems__tokens table so all tokens stick to the (possibly) new token name rules.

updateTokens(integer $userId, $updateTokens = true) : integer

Parameters

$userId

integer

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

$updateTokens

Returns

integerThe number of tokens changed

 Properties

 

$project

$project : \Gems_Project_ProjectSettings

Default

 

$tracker

$tracker : \Gems_Tracker

Default

 

Holds the current batch if there is any

$_gemsDb : \Gems_Task_TaskRunnerBatch: \Zend_Db_Adapter_Abstract

Default

 

The information from the gems__sources for this source

$_sourceData : array

Default

 

The database connection to the source, usedable by all implementations that use a database

$_sourceDb : \Zend_Db_Adapter_Abstract

Default