QuestionAttributeHelper
in package
Table of Contents
Methods
- attributeAppliesToQuestionType() : bool
- Check if question attribute applies to a specific question type
- fillAttributesWithValues() : array<string|int, mixed>
- Returns the received array of attributes filled with the values specified, taking into account the 'i18n' property of the attributes.
- fillMissingCategory() : array<string|int, mixed>
- 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.
- filterAttributesByQuestionType() : array<string|int, mixed>
- Filters an array of question attribute definitions by question type
- getCategoryOrders() : array<string, int>
- Returns the array of categories with their assigned order.
- getQuestionAttributesWithValues() : array<string|int, mixed>
- This function returns an array of the attributes for the particular question including their values set in the database
- getUserDefaultsForQuestionType() : array<string, mixed>
- Returns the user's default values for the specified question type
- groupAttributesByCategory() : array<string|int, mixed>
- Receives an array of question attributes and groups them by category.
- mergeQuestionAttributes() : array<string|int, mixed>
- 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.
- sanitizeQuestionAttributes() : array<string, array<string|int, mixed>>
- Sanitizes an array of question attributes.
- sortAttributesByCategory() : array<string, array<string|int, mixed>>
- Sorts an array of question attributes by category.
- categorySort() : int
- Comparison function for sorting question attributes by category with uasort().
Methods
attributeAppliesToQuestionType()
Check if question attribute applies to a specific question type
public
attributeAppliesToQuestionType(array<string|int, mixed> $attribute, string $questionType) : bool
Parameters
- $attribute : array<string|int, mixed>
-
question attribute definition
- $questionType : string
-
the question type that the attribute should apply to
Return values
bool —returns true if the question attribute applies to the specified question type
fillAttributesWithValues()
Returns the received array of attributes filled with the values specified, taking into account the 'i18n' property of the attributes.
public
fillAttributesWithValues(array<string|int, mixed> $attributes, array<string|int, mixed> $attributeValues[, array<string|int, mixed> $languages = [] ]) : array<string|int, mixed>
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.
Parameters
- $attributes : array<string|int, mixed>
-
the attributes to be filled
- $attributeValues : array<string|int, mixed>
-
the values for the attributes
- $languages : array<string|int, mixed> = []
-
the languages to use for i18n attributes
Tags
Return values
array<string|int, mixed> —the same source attributes with their corresponding values (when available)
fillMissingCategory()
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.
public
fillMissingCategory(array<string|int, mixed> $attributes, mixed $categoryName) : array<string|int, mixed>
Parameters
- $attributes : array<string|int, mixed>
-
array of question attribute definitions
- $categoryName : mixed
Return values
array<string|int, mixed> —returns the array attributes with Category field complete
filterAttributesByQuestionType()
Filters an array of question attribute definitions by question type
public
filterAttributesByQuestionType(array<string|int, mixed> $attributes, string $questionType) : array<string|int, mixed>
Parameters
- $attributes : array<string|int, mixed>
-
array of question attribute definitions to filter
- $questionType : string
-
the question type that the attributes should apply to
Return values
array<string|int, mixed> —an array containing only the question attributes that match the specified question type
getCategoryOrders()
Returns the array of categories with their assigned order.
public
getCategoryOrders() : array<string, int>
The array doesn't contain all the posible categories, only those with an order assigned.
Return values
array<string, int>getQuestionAttributesWithValues()
This function returns an array of the attributes for the particular question including their values set in the database
public
getQuestionAttributesWithValues(Question $question[, string|null $language = null ][, string|null $questionThemeOverride = null ][, bool $advancedOnly = false ]) : array<string|int, mixed>
Parameters
- $question : Question
-
The question object
- $language : string|null = null
-
If you give a language then only the attributes for that language are returned
- $questionThemeOverride : string|null = null
-
Name of the question theme to use instead of the question's current theme
- $advancedOnly : bool = false
-
If set to true, only the advanced attributes will be returned
Return values
array<string|int, mixed>getUserDefaultsForQuestionType()
Returns the user's default values for the specified question type
public
getUserDefaultsForQuestionType(string $questionType) : array<string, mixed>
Parameters
- $questionType : string
Return values
array<string, mixed>groupAttributesByCategory()
Receives an array of question attributes and groups them by category.
public
groupAttributesByCategory(array<string|int, mixed> $attributes) : array<string|int, mixed>
Used by advanced settings widget.
Parameters
- $attributes : array<string|int, mixed>
Tags
Return values
array<string|int, mixed> —Grouped question attributes, with category as array key
mergeQuestionAttributes()
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.
public
mergeQuestionAttributes(array<string|int, mixed> $baseAttributes, array<string|int, mixed> $extendedAttributes) : array<string|int, mixed>
If an extended attribute's name cannot be determined, it's omitted.
Parameters
- $baseAttributes : array<string|int, mixed>
-
the base set of attributes
- $extendedAttributes : array<string|int, mixed>
-
the attributes to merge into the base set
Return values
array<string|int, mixed> —the merged attributes
sanitizeQuestionAttributes()
Sanitizes an array of question attributes.
public
sanitizeQuestionAttributes(array<string|int, mixed> $attributes) : array<string, array<string|int, mixed>>
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.
Parameters
- $attributes : array<string|int, mixed>
-
the array of attributes to sanitize
Tags
Return values
array<string, array<string|int, mixed>> —the array of sanitized attributes
sortAttributesByCategory()
Sorts an array of question attributes by category.
public
sortAttributesByCategory(array<string, array<string|int, mixed>> $attributes) : array<string, array<string|int, mixed>>
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.
Parameters
- $attributes : array<string, array<string|int, mixed>>
Return values
array<string, array<string|int, mixed>>categorySort()
Comparison function for sorting question attributes by category with uasort().
protected
categorySort(array<string, mixed> $a, array<string, mixed> $b) : int
Parameters
- $a : array<string, mixed>
-
First question attribute to compare
- $b : array<string, mixed>
-
Second question attribute to compare