LimeSurvey API - Master branch

SingleOptionProcessor extends AbstractQuestionProcessor
in package

Base abstract class for all question processors used in statistics.

A chart plan is: ['title' => string, 'legend' => string[], 'data' => array[]] with each data item shaped like ['key' => ..., 'title' => ..., 'value' => callable].

Table of Contents

Constants

SPECIAL_TYPES  = [\Question::QT_G_GENDER, \Question::QT_Y_YES_NO_RADIO, \Question::QT_I_LANGUAGE, \Question::QT_5_POINT_CHOICE]

Properties

$answers  : array<string|int, mixed>
$batch  : ResponseAggregateBatch
$noAnswerTypes  : array<string|int, mixed>
$question  : array<string|int, mixed>
$rt  : string
$surveyId  : int

Methods

getQuestion()  : array<string|int, mixed>
Returns the question data as assigned to the processor (title flattened).
getTotalCount()  : callable
Returns a deferred total response count for the survey.
process()  : array<string|int, mixed>
Plan a question into one or more statistics chart plans.
rt()  : void
Build the identifier for current question.
setAnswers()  : void
Assign available answers to the processor (if applicable).
setBatch()  : void
Assign the shared aggregate batch for the current statistics run.
setQuestion()  : void
Assign question metadata to the processor.
batchGetResponseCounts()  : array<string, callable>
Returns deferred non-empty response counts for multiple columns.
buildBatchItemsForSubquestions()  : array<string, array{0: string[], 1: array[]}>
Plan multiple subquestion fields × answer codes.
buildItemsFromCodes()  : array<string|int, mixed>
Build chart items (legend + values) from a list of answer codes.
countFieldResponses()  : callable
Returns a deferred count of non-empty responses for a column.
read()  : callable
Closure resolving a batch alias once the batch has executed.
addOtherOption()  : void
addSpecialOptions()  : void
Add special options based on question type
buildChartDataByType()  : array<string|int, mixed>
Build chart data based on question type
handle5PointChoice()  : array<string|int, mixed>
handleDefault()  : array<string|int, mixed>
handleGender()  : array<string|int, mixed>
handleLanguage()  : array<string|int, mixed>
handleYesNo()  : array<string|int, mixed>
planAggregateItems()  : array<string, array{0: string[], 1: array[]}>
Register value counts (and a NoAnswer/blank count for the applicable question types) for fields against specific answer codes.

Constants

SPECIAL_TYPES

private array<string|int, mixed> SPECIAL_TYPES = [\Question::QT_G_GENDER, \Question::QT_Y_YES_NO_RADIO, \Question::QT_I_LANGUAGE, \Question::QT_5_POINT_CHOICE]

Properties

$noAnswerTypes

protected array<string|int, mixed> $noAnswerTypes = [\Question::QT_L_LIST, \Question::QT_EXCLAMATION_LIST_DROPDOWN, \Question::QT_O_LIST_WITH_COMMENT, \Question::QT_Y_YES_NO_RADIO, \Question::QT_G_GENDER, \Question::QT_5_POINT_CHOICE, \Question::QT_A_ARRAY_5_POINT, \Question::QT_B_ARRAY_10_CHOICE_QUESTIONS, \Question::QT_C_ARRAY_YES_UNCERTAIN_NO, \Question::QT_E_ARRAY_INC_SAME_DEC, \Question::QT_F_ARRAY, \Question::QT_H_ARRAY_COLUMN, \Question::QT_1_ARRAY_DUAL, \Question::QT_SEMICOLON_ARRAY_TEXT, \Question::QT_S_SHORT_FREE_TEXT, \Question::QT_T_LONG_FREE_TEXT, \Question::QT_Q_MULTIPLE_SHORT_TEXT]

List of question types which contain no answer option

Methods

getQuestion()

Returns the question data as assigned to the processor (title flattened).

public getQuestion() : array<string|int, mixed>
Return values
array<string|int, mixed>

getTotalCount()

Returns a deferred total response count for the survey.

public getTotalCount() : callable
Return values
callable

Resolves to an int once the batch has executed

process()

Plan a question into one or more statistics chart plans.

public process() : array<string|int, mixed>
Tags
inheritDoc
Return values
array<string|int, mixed>

Single chart plan

setAnswers()

Assign available answers to the processor (if applicable).

public setAnswers(array<string|int, mixed> $answers) : void
Parameters
$answers : array<string|int, mixed>

List of answers

setQuestion()

Assign question metadata to the processor.

public setQuestion(array<string|int, mixed> $question) : void
Parameters
$question : array<string|int, mixed>

Question data (from DB/metadata fetch)

Tags
throws
InvalidArgumentException

if question data is invalid

batchGetResponseCounts()

Returns deferred non-empty response counts for multiple columns.

protected batchGetResponseCounts(array<string|int, string> $fieldNames) : array<string, callable>
Parameters
$fieldNames : array<string|int, string>

Column names in the response table

Return values
array<string, callable>

fieldName => deferred count

buildBatchItemsForSubquestions()

Plan multiple subquestion fields × answer codes.

protected buildBatchItemsForSubquestions(array<string|int, string> $fieldNames, array<string|int, string> $codes[, array<string|int, string> $labels = [] ]) : array<string, array{0: string[], 1: array[]}>
Parameters
$fieldNames : array<string|int, string>

Column names (one per subquestion)

$codes : array<string|int, string>

Answer codes to count

$labels : array<string|int, string> = []

Display labels aligned with $codes

Return values
array<string, array{0: string[], 1: array[]}>

fieldName => [legend[], items[]]

buildItemsFromCodes()

Build chart items (legend + values) from a list of answer codes.

protected buildItemsFromCodes(string $fieldname, array<string|int, string> $codes[, array<string|int, string> $labels = [] ]) : array<string|int, mixed>
Parameters
$fieldname : string

Column name in the response table

$codes : array<string|int, string>

Answer codes

$labels : array<string|int, string> = []

Display labels aligned with $codes

Return values
array<string|int, mixed>

[legend[], items[]]

countFieldResponses()

Returns a deferred count of non-empty responses for a column.

protected countFieldResponses(string $fieldName) : callable
Parameters
$fieldName : string

Column name in the response table

Return values
callable

Resolves to an int once the batch has executed

read()

Closure resolving a batch alias once the batch has executed.

protected read(string $alias) : callable
Parameters
$alias : string
Return values
callable

addOtherOption()

private addOtherOption(array<string|int, mixed> &$legend, array<string|int, mixed> &$dataItems) : void
Parameters
$legend : array<string|int, mixed>
$dataItems : array<string|int, mixed>

addSpecialOptions()

Add special options based on question type

private addSpecialOptions(array<string|int, mixed> &$legend, array<string|int, mixed> &$dataItems) : void
Parameters
$legend : array<string|int, mixed>
$dataItems : array<string|int, mixed>

buildChartDataByType()

Build chart data based on question type

private buildChartDataByType() : array<string|int, mixed>
Tags
throws
RuntimeException
Return values
array<string|int, mixed>

handle5PointChoice()

private handle5PointChoice() : array<string|int, mixed>
Return values
array<string|int, mixed>

handleDefault()

private handleDefault() : array<string|int, mixed>
Return values
array<string|int, mixed>

handleGender()

private handleGender() : array<string|int, mixed>
Return values
array<string|int, mixed>

handleLanguage()

private handleLanguage() : array<string|int, mixed>
Return values
array<string|int, mixed>

handleYesNo()

private handleYesNo() : array<string|int, mixed>
Return values
array<string|int, mixed>

planAggregateItems()

Register value counts (and a NoAnswer/blank count for the applicable question types) for fields against specific answer codes.

private planAggregateItems(array<string|int, string> $fieldNames, array<string|int, string> $codes, array<string|int, string> $labels) : array<string, array{0: string[], 1: array[]}>
Parameters
$fieldNames : array<string|int, string>
$codes : array<string|int, string>
$labels : array<string|int, string>
Return values
array<string, array{0: string[], 1: array[]}>

fieldName => [legend[], items[]]


        
On this page

Search results