LimeSurvey API - Master branch

QuestionAttribute extends LSActiveRecord
in package

Class QuestionAttribute

Tags
todo

Should probably change question_attributes table to question_attribute_values

see
participant_attributes

and participant_attribute_values

Table of Contents

Properties

$attribute  : string
$bEncryption  : mixed
$language  : string
$qaid  : int
$qid  : int
$question  : Question
$survey  : Survey
$value  : string
$questionAttributesSettings  : mixed
$xssFilterAttributes  : array<string|int, string>

Methods

addAdditionalAttributesFromExtendedTheme()  : array<string|int, mixed>|mixed
Insert additional attributes from an extended question theme
behaviors()  : array<string|int, mixed>
Lists the behaviors of this model
decrypt()  : mixed
Decrypt values from database
decryptEncryptAttributes()  : mixed
Encrypt/decrypt values
decryptSingle()  : string
Decrypt single value
decryptSingleOld()  : string
Decrypt single value
defaultScope()  : array<string|int, mixed>
This defaultScope indexes the ActiveRecords given back by attribute name Important: This does not work if you want to retrieve records for more than one question at a time.
deleteAllByAttributes()  : int
dispatchPluginModelEvent()  : PluginEvent
encrypt()  : mixed
Encrypt values
encryptAttributeValues()  : array<string|int, mixed>
Attribute values are encrypted ( if needed )to be used for searching purposes
encryptSave()  : mixed
Encrypt values before saving to the database
encryptSingle()  : mixed
Enrypt single value
filterXss()  : void
Apply XSS filter to question attribute value unless 'xssfilter' property is false.
findAllAsArray()  : array<string|int, mixed>
Finds all active records satisfying the specified condition but returns them as array
findAllByAttributes()  : array<string|int, static>
Overriding of Yii's findAllByAttributes method to provide encrypted attribute value search
findByAttributes()  : static|null
Overriding of Yii's findByAttributes method to provide encrypted attribute value search
getAllEncryptedAttributes()  : array<string|int, mixed>
getAttributesAsArrayFromDB()  : array<string|int, mixed>
Get whole existing attribute for one question as array
getDefaultSettings()  : array<string, mixed>
Get default settings for an attribute, return an array of string|null
getMaxId()  : false|int
Return the max value for a field
getMinId()  : false|int
Return the min value for a field
getOwnQuestionAttributesViaPlugin()  : array<string|int, mixed>
New event to allow plugin to add own question attribute (settings)
getQuestion()  : Question
getQuestionAttributes()  : array<string|int, mixed>|false
Returns Question attribute array name=>value --> returns result from emCache if it is set OR --> build the returned array and set the emCache to it
getQuestionAttributesSettings()  : array<string|int, mixed>
Return the question attribute settings for the passed type (parameter)
getQuestionsForStatistics()  : array<string|int, mixed>
getQuestionTemplateValue()  : string
Returns the value for attribute 'question_template'.
getSurvey()  : Survey
model()  : static
primaryKey()  : mixed
relations()  : mixed
rules()  : mixed
setEncryptedAttributeLabel()  : string
Function to show encryption symbol in gridview attribute header if value ois encrypted
setMultiple()  : mixed
Set attributes for multiple questions
setQuestionAttribute()  : CDbDataReader|bool
setQuestionAttributeWithLanguage()  : CDbDataReader
tableName()  : mixed
updateAll()  : int
Updates records with the specified condition.
getAdvancedAttributesFromXml()  : array<string|int, mixed>|null
Read question attributes from XML file and convert it to array
getGeneralAttibutesFromXml()  : array<string|int, mixed>|null
Read question attributes from XML file and convert it to array
query()  : mixed
Modified version that default to do the same as the original, but allows via a third parameter to retrieve the result as array instead of active records. This solves a joining problem. Usage via findAllAsArray method

Properties

$questionAttributesSettings

protected static mixed $questionAttributesSettings = array()

$xssFilterAttributes

protected array<string|int, string> $xssFilterAttributes = ['value']

Array of attributes that should be XSS filtered on mass updates

Methods

addAdditionalAttributesFromExtendedTheme()

Insert additional attributes from an extended question theme

public static addAdditionalAttributesFromExtendedTheme(array<string|int, mixed> $aAttributeNames, Question $oQuestion) : array<string|int, mixed>|mixed
Parameters
$aAttributeNames : array<string|int, mixed>

array of attributes (see getQuestionAttributesSettings())

$oQuestion : Question
Return values
array<string|int, mixed>|mixed

returns $aAttributeNames with appended additional attributes

behaviors()

Lists the behaviors of this model

public behaviors() : array<string|int, mixed>

Below is a list of all behaviors we register:

Tags
see
PluginEventBehavior
see
CTimestampBehavior
Return values
array<string|int, mixed>

decrypt()

Decrypt values from database

public decrypt([mixed $value = '' ]) : mixed
Parameters
$value : mixed = ''

decryptEncryptAttributes()

Encrypt/decrypt values

public decryptEncryptAttributes([mixed $action = 'decrypt' ]) : mixed
Parameters
$action : mixed = 'decrypt'

decryptSingle()

Decrypt single value

public static decryptSingle([string $value = '' ]) : string
Parameters
$value : string = ''

String value which needs to be decrypted

Return values
string

the decrypted string

decryptSingleOld()

Decrypt single value

public static decryptSingleOld([string $value = '' ]) : string
Parameters
$value : string = ''

String value which needs to be decrypted

Return values
string

the decrypted string

defaultScope()

This defaultScope indexes the ActiveRecords given back by attribute name Important: This does not work if you want to retrieve records for more than one question at a time.

public defaultScope() : array<string|int, mixed>

In that case disable the defaultScope by using MyModel::model()->resetScope()->findAll();

Return values
array<string|int, mixed>

Scope that indexes the records by their attribute bane

deleteAllByAttributes()

public deleteAllByAttributes(array<string|int, mixed> $attributes[, string $condition = '' ][, array<string|int, mixed> $params = [] ]) : int
Parameters
$attributes : array<string|int, mixed>

list of attribute values (indexed by attribute names) that the active records should match. An attribute value can be an array which will be used to generate an IN condition.

$condition : string = ''

query condition or criteria.

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

parameters to be bound to an SQL statement.

Tags
todo

This should also be moved to the behavior at some point. This method overrides the parent in order to raise PluginEvents for Bulk delete operations.

Filter Criteria are wrapped into a CDBCriteria instance so we have a single instance responsible for holding the filter criteria to be passed to the PluginEvent, this also enables us to pass the fully configured CDBCriteria instead of the original Parameters.

See for detailed explanation about $condition and $params.

Return values
int

number of rows affected by the execution.

dispatchPluginModelEvent()

public dispatchPluginModelEvent(string $sEventName, CDbCriteria $criteria = null, array<string|int, mixed> $eventParams = []) : PluginEvent
Parameters
$sEventName : string
$criteria = null : CDbCriteria
$eventParams = [] : array<string|int, mixed>
Return values
PluginEvent

encryptAttributeValues()

Attribute values are encrypted ( if needed )to be used for searching purposes

public encryptAttributeValues([array<string|int, mixed> $attributes = null ][, mixed $bEncryptedOnly = false ][, mixed $bReplaceValues = true ]) : array<string|int, mixed>
Parameters
$attributes : array<string|int, mixed> = null

list of attribute values (indexed by attribute names) that the active records should match. An attribute value can be an array which will be used to generate an IN condition.

$bEncryptedOnly : mixed = false
$bReplaceValues : mixed = true
Return values
array<string|int, mixed>

attributes array with encrypted atrribute values is returned

encryptSave()

Encrypt values before saving to the database

public encryptSave([mixed $runValidation = false ]) : mixed
Parameters
$runValidation : mixed = false

encryptSingle()

Enrypt single value

public static encryptSingle([string $value = '' ]) : mixed
Parameters
$value : string = ''

String value which needs to be encrypted

filterXss()

Apply XSS filter to question attribute value unless 'xssfilter' property is false.

public filterXss(string $attribute, array<string|int, mixed> $params) : void
Parameters
$attribute : string

the name of the attribute to be validated.

$params : array<string|int, mixed>

additional parameters passed with rule when being executed.

findAllAsArray()

Finds all active records satisfying the specified condition but returns them as array

public findAllAsArray([mixed $condition = '' ][, array<string|int, mixed> $params = [] ]) : array<string|int, mixed>

See for detailed explanation about $condition and $params.

Parameters
$condition : mixed = ''

query condition or criteria.

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

parameters to be bound to an SQL statement.

Return values
array<string|int, mixed>

list of active records satisfying the specified condition. An empty array is returned if none is found.

findAllByAttributes()

Overriding of Yii's findAllByAttributes method to provide encrypted attribute value search

public findAllByAttributes(array<string|int, mixed> $attributes[, mixed $condition = '' ][, array<string|int, mixed> $params = [] ]) : array<string|int, static>
Parameters
$attributes : array<string|int, mixed>

list of attribute values (indexed by attribute names) that the active records should match. An attribute value can be an array which will be used to generate an IN condition.

$condition : mixed = ''

query condition or criteria.

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

parameters to be bound to an SQL statement.

Return values
array<string|int, static>

the records found. An empty array is returned if none is found.

findByAttributes()

Overriding of Yii's findByAttributes method to provide encrypted attribute value search

public findByAttributes(array<string|int, mixed> $attributes[, mixed $condition = '' ][, array<string|int, mixed> $params = [] ]) : static|null
Parameters
$attributes : array<string|int, mixed>

list of attribute values (indexed by attribute names) that the active record should match. An attribute value can be an array which will be used to generate an IN condition.

$condition : mixed = ''

query condition or criteria.

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

parameters to be bound to an SQL statement.

Return values
static|null

the record found. Null if none is found.

getAllEncryptedAttributes()

public getAllEncryptedAttributes(int $iSurveyId, string $sClassName) : array<string|int, mixed>
Parameters
$iSurveyId : int
$sClassName : string
Return values
array<string|int, mixed>

TODO: Should be split into seperate functions in the appropiate model or helper class TODO: Make an interface for records that support encryption.

getAttributesAsArrayFromDB()

Get whole existing attribute for one question as array

public static getAttributesAsArrayFromDB(int $iQuestionID) : array<string|int, mixed>
Parameters
$iQuestionID : int

the question id

Return values
array<string|int, mixed>

the returning array structure will be like $aAttributeValues[$oAttributeValue->attribute][$oAttributeValue->language] $aAttributeValues[$oAttributeValue->attribute]['']

getDefaultSettings()

Get default settings for an attribute, return an array of string|null

public static getDefaultSettings() : array<string, mixed>
Tags
todo

Move to static property?

Return values
array<string, mixed>

getMaxId()

Return the max value for a field

public getMaxId([string $field = null ][, bool $forceRefresh = false ]) : false|int

This is a convenience method, that uses the primary key of the model to retrieve the highest value.

Parameters
$field : string = null

The field that contains the Id, when null primary key is used if it is a single field

$forceRefresh : bool = false

Don't use value from static cache but always requery the database

Tags
throws
Exception
Return values
false|int

getMinId()

Return the min value for a field

public getMinId([string $field = null ][, bool $forceRefresh = false ]) : false|int

This is a convenience method, that uses the primary key of the model to retrieve the highest value.

Parameters
$field : string = null

The field that contains the Id, when null primary key is used if it is a single field

$forceRefresh : bool = false

Don't use value from static cache but always requery the database

Tags
throws
Exception
Return values
false|int

getOwnQuestionAttributesViaPlugin()

New event to allow plugin to add own question attribute (settings)

public static getOwnQuestionAttributesViaPlugin() : array<string|int, mixed>

Using $event->append('questionAttributes', $questionAttributes);

$questionAttributes=[ attributeName=>[ 'types' : Apply to this question type 'category' : Where to put it 'sortorder' : Qort order in this category 'inputtype' : type of input 'expression' : 2 to force Expression Manager when see the survey logic file (add { } and validate, 1 : allow it : validate in survey logic file 'options' : optional options if input type need it 'default' : the default value 'caption' : the label 'help' : an help ]

Return values
array<string|int, mixed>

the event attributes as array or an empty array

getQuestionAttributes()

Returns Question attribute array name=>value --> returns result from emCache if it is set OR --> build the returned array and set the emCache to it

public getQuestionAttributes(int|Question $q[, string $sLanguage = null ]) : array<string|int, mixed>|false

--get attributes from XML-Files --get additional attributes from extended theme --prepare an easier/smaller array to return

Parameters
$q : int|Question
$sLanguage : string = null

restrict to this language (if null $oQuestion->survey->allLanguages will be used)

Tags
access

public

throws
CException

throws exception if questiontype is null

Return values
array<string|int, mixed>|false

getQuestionAttributesSettings()

Return the question attribute settings for the passed type (parameter)

public static getQuestionAttributesSettings(string $sType[, bool $advancedOnly = false ]) : array<string|int, mixed>
Parameters
$sType : string

: type of question (this is the attribute 'question_type' in table question_theme)

$advancedOnly : bool = false

If true, only fetch advanced attributes

Tags
throws
CException
Return values
array<string|int, mixed>

The attribute settings for this question type returns values from getGeneralAttributesFromXml and getAdvancedAttributesFromXml if this fails getAttributesDefinition and getDefaultSettings are returned

getQuestionsForStatistics()

public getQuestionsForStatistics(string $fields, mixed $condition[, string|false $orderby = false ]) : array<string|int, mixed>
Parameters
$fields : string
$condition : mixed
$orderby : string|false = false
Return values
array<string|int, mixed>

getQuestionTemplateValue()

Returns the value for attribute 'question_template'.

public static getQuestionTemplateValue(mixed $questionID) : string

Fetches the question_template from a question model.

Be carefull this attribute is not present in all questions. Even more, standard question types where question theme are not used (or custom question theme are not used), the attribute is missing. In those cases, the deault "core" is used.

Parameters
$questionID : mixed
Tags
deprecated

use $question->question_theme_name instead (Question model)

Return values
string

question_template or 'core' if it not exists

model()

public static model([mixed $className = __CLASS__ ]) : static
Parameters
$className : mixed = __CLASS__
Return values
static

setEncryptedAttributeLabel()

Function to show encryption symbol in gridview attribute header if value ois encrypted

public setEncryptedAttributeLabel(int $surveyId, string $className, string $attributeName) : string
Parameters
$surveyId : int
$className : string
$attributeName : string
Tags
throws
CException
Return values
string

setMultiple()

Set attributes for multiple questions

public setMultiple(int $iSid, array<string|int, mixed> $aQids, array<string|int, mixed> $aAttributesToUpdate, array<string|int, mixed> $aValidQuestionTypes) : mixed

NOTE: We can't use self::setQuestionAttribute() because it doesn't check for question types first. TODO: the question type check should be done via rules, or via a call to a question method

Parameters
$iSid : int

the sid to update (only to check permission)

$aQids : array<string|int, mixed>

an array containing the list of primary keys for questions

$aAttributesToUpdate : array<string|int, mixed>

array containing the list of attributes to update

$aValidQuestionTypes : array<string|int, mixed>

the question types we can update for those attributes

Tags
todo

Missign noun in function name - set multiple what?

setQuestionAttribute()

public setQuestionAttribute(int $iQuestionID, string $sAttributeName, string $sValue) : CDbDataReader|bool
Parameters
$iQuestionID : int
$sAttributeName : string
$sValue : string
Tags
todo

A function should not both set and get something; split into two functions

Return values
CDbDataReader|bool

setQuestionAttributeWithLanguage()

public setQuestionAttributeWithLanguage(int $iQuestionID, string $sAttributeName, string $sValue, string $sLanguage) : CDbDataReader
Parameters
$iQuestionID : int
$sAttributeName : string
$sValue : string
$sLanguage : string
Tags
todo

A function should not both set and get something; split into two functions

Return values
CDbDataReader

updateAll()

Updates records with the specified condition.

public updateAll(array<string|int, mixed> $attributes[, mixed $condition = '' ][, array<string|int, mixed> $params = array() ]) : int

XSS filtering is enforced for attributes listed in model's $xssFilterAttributes property. See for detailed explanation about $condition and $params. Note, the attributes are not checked for safety and no validation is done.

Parameters
$attributes : array<string|int, mixed>

list of attributes (name=>$value) to be updated

$condition : mixed = ''

query condition or criteria.

$params : array<string|int, mixed> = array()

parameters to be bound to an SQL statement.

Return values
int

the number of rows being updated

getAdvancedAttributesFromXml()

Read question attributes from XML file and convert it to array

protected static getAdvancedAttributesFromXml(string $sXmlFilePath) : array<string|int, mixed>|null
Parameters
$sXmlFilePath : string

Path to XML

Return values
array<string|int, mixed>|null

The advanced attribute settings for this question type

getGeneralAttibutesFromXml()

Read question attributes from XML file and convert it to array

protected static getGeneralAttibutesFromXml(string $sXmlFilePath) : array<string|int, mixed>|null
Parameters
$sXmlFilePath : string

Path to XML

Tags
todo

What's the opposite of a "general" attribute? How many types of attributes are there?

Return values
array<string|int, mixed>|null

The general attribute settings for this question type

query()

Modified version that default to do the same as the original, but allows via a third parameter to retrieve the result as array instead of active records. This solves a joining problem. Usage via findAllAsArray method

protected query(CDbCriteria $criteria[, bool $all = false ][, bool $asAR = true ]) : mixed

Performs the actual DB query and populates the AR objects with the query result. This method is mainly internally used by other AR query methods.

Parameters
$criteria : CDbCriteria

the query criteria

$all : bool = false

whether to return all data

$asAR : bool = true
Tags
since
1.1.7
Return values
mixed

the AR objects populated with the query result


        
On this page

Search results