QuestionAttributeHelper

package

Default

Methods

Check if question attribute applies to a specific question type

attributeAppliesToQuestionType(array $attribute,string $questionType): boolean

Arguments

$attribute

array

question attribute definition

$questionType

string

the question type that the attribute should apply to

Response

boolean

returns true if the question attribute applies to the specified question type

Comparison function for sorting question attributes by category with uasort().

categorySort(\LimeSurvey\Models\Services\array<string,mixed> $a,\LimeSurvey\Models\Services\array<string,mixed> $b): integer
todo

No state used, so no OOP needed, move to function at some point.

Arguments

$a

\LimeSurvey\Models\Services\array

First question attribute to compare

$b

\LimeSurvey\Models\Services\array

Second question attribute to compare

Response

integer

Returns the received array of attributes filled with the values specified, taking into account the 'i18n' property of the attributes.

fillAttributesWithValues(array $attributes,array $attributeValues,array $languages = array()): array

Both this and rewriteQuestionAttributeArray() are helper methods and accomplish quite similar tasks, but the output is different: rewriteQuestionAttributeArray returns a name -> value array, while here we return a complete definition map and the value as a piece of information mingled into it.

todo

Pure function - move outside class?

Arguments

$attributes

array

the attributes to be filled

$attributeValues

array

the values for the attributes

$languages

array

the languages to use for i18n attributes

Response

array

the same source attributes with their corresponding values (when available)

Makes sure all the question attributes in an array have a category. If an attribute's category is missing, it's filled with the specified category name.

fillMissingCategory(array $attributes, $categoryName): array

Arguments

$attributes

array

array of question attribute definitions

$categoryName

Response

array

returns the array attributes with Category field complete

Filters an array of question attribute definitions by question type

filterAttributesByQuestionType(array $attributes,string $questionType): array

Arguments

$attributes

array

array of question attribute definitions to filter

$questionType

string

the question type that the attributes should apply to

Response

array

an array containing only the question attributes that match the specified question type

Returns the array of categories with their assigned order.

getCategoryOrders(): \LimeSurvey\Models\Services\array<string,int>

The array doesn't contain all the posible categories, only those with an order assigned.

Response

\LimeSurvey\Models\Services\array

This function returns an array of the attributes for the particular question including their values set in the database

getQuestionAttributesWithValues(\Question $question,string|null $language = null,string|null $questionThemeOverride = null,boolean $advancedOnly = false): array

Arguments

$question

\Question

The question object

$language

string|null

If you give a language then only the attributes for that language are returned

$questionThemeOverride

string|null

Name of the question theme to use instead of the question's current theme

$advancedOnly

boolean

If set to true, only the advanced attributes will be returned

Response

array

Returns the user's default values for the specified question type

getUserDefaultsForQuestionType(string $questionType): \LimeSurvey\Models\Services\array<string,mixed>

Arguments

$questionType

string

Response

\LimeSurvey\Models\Services\array

Receives an array of question attributes and groups them by category.

groupAttributesByCategory(array $attributes): array

Used by advanced settings widget.

todo

Pure function - move outside class?

Arguments

$attributes

array

Response

array

Grouped question attributes, with category as array key

Merges the 'base' attributes (ex: core question attributes) with the extended question attributes (ex: question theme attributes). It also removes all attributes where extended attribute's inputType is empty.

mergeQuestionAttributes(array $baseAttributes,array $extendedAttributes): array

If an extended attribute's name cannot be determined, it's omitted.

Arguments

$baseAttributes

array

the base set of attributes

$extendedAttributes

array

the attributes to merge into the base set

Response

array

the merged attributes

Sanitizes an array of question attributes.

sanitizeQuestionAttributes(array $attributes): \LimeSurvey\Models\Services\array<string,array>

Current tasks:

  • makes sure that attributes have a name (removes them if name cannot be determined)
  • replaces empty arrays (generally resulting from empty xml nodes) with null.
todo

Pure function - move outside class?

Arguments

$attributes

array

the array of attributes to sanitize

Response

\LimeSurvey\Models\Services\array

the array of sanitized attributes

Sorts an array of question attributes by category.

sortAttributesByCategory(\LimeSurvey\Models\Services\array<string,array> $attributes): \LimeSurvey\Models\Services\array<string,array>

Sorting is based on a predefined list of orders (see QuestionAtributeHelper::getCategoryOrders()). Categories without a predefined order are considered less relevant. Categories with the same order are sorted alphabetically.

Arguments

$attributes

\LimeSurvey\Models\Services\array

Response

\LimeSurvey\Models\Services\array