QuestionAttribute

Extends\LSActiveRecord

Class QuestionAttribute

todo

Should probably change question_attributes table to question_attribute_values

see

and participant_attribute_values

package

Default

Methods

Insert additional attributes from an extended question theme

addAdditionalAttributesFromExtendedTheme(array $aAttributeNames,\Question $oQuestion): array|mixed
static

Arguments

$aAttributeNames

array

array of attributes (see getQuestionAttributesSettings())

$oQuestion

\Question

Response

array|mixed

returns $aAttributeNames with appended additional attributes

Lists the behaviors of this model

behaviors(): array
inherited

Below is a list of all behaviors we register:

see \PluginEventBehavior\CTimestampBehavior

Response

array

Decrypt values from database

decrypt( $value = '')
inherited

Arguments

$value

Encrypt/decrypt values

decryptEncryptAttributes( $action = 'decrypt')
inherited

Arguments

$action

Decrypt single value

decryptSingle(string $value = ''): string
inheritedstatic

Arguments

$value

string

String value which needs to be decrypted

Response

string

the decrypted string

Decrypt single value

decryptSingleOld(string $value = ''): string
inheritedstatic

Arguments

$value

string

String value which needs to be decrypted

Response

string

the decrypted string

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.

defaultScope(): array

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

Response

array

Scope that indexes the records by their attribute bane

deleteAllByAttributes

deleteAllByAttributes(array $attributes,string $condition = '',array $params = array()): integer
inherited
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 {@link find()} for detailed explanation about $condition and $params.

Arguments

$attributes

array

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

parameters to be bound to an SQL statement.

Response

integer

number of rows affected by the execution.

dispatchPluginModelEvent

dispatchPluginModelEvent(string $sEventName,\CDbCriteria $criteria = null,array $eventParams = []): \PluginEvent
inherited

Arguments

$sEventName

string

$criteria

\CDbCriteria

$eventParams

array

Response

\PluginEvent

Encrypt values

encrypt()
inherited

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

encryptAttributeValues(array $attributes = null, $bEncryptedOnly = false, $bReplaceValues = true): array
inherited

Arguments

$attributes

array

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

$bReplaceValues

Response

array

attributes array with encrypted atrribute values is returned

Encrypt values before saving to the database

encryptSave( $runValidation = false)
inherited

Arguments

$runValidation

Enrypt single value

encryptSingle(string $value = '')
inheritedstatic

Arguments

$value

string

String value which needs to be encrypted

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

filterXss(string $attribute,\array<mixed> $params): void

Arguments

$attribute

string

the name of the attribute to be validated.

$params

\array

additional parameters passed with rule when being executed.

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

findAllAsArray(mixed $condition = '',array $params = array()): array
inherited

See \find() for detailed explanation about $condition and $params.

Arguments

$condition

mixed

query condition or criteria.

$params

array

parameters to be bound to an SQL statement.

Response

array

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

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

findAllByAttributes(array $attributes,mixed $condition = '',array $params = array()): array<mixed,static>
inherited

Arguments

$attributes

array

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

parameters to be bound to an SQL statement.

Response

array<mixed,static>

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

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

findByAttributes(array $attributes,mixed $condition = '',array $params = array()): static|null
inherited

Arguments

$attributes

array

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

parameters to be bound to an SQL statement.

Response

static|null

the record found. Null if none is found.

Read question attributes from XML file and convert it to array

getAdvancedAttributesFromXml(string $sXmlFilePath): \?array
static

Arguments

$sXmlFilePath

string

Path to XML

Response

\?array

The advanced attribute settings for this question type

getAllEncryptedAttributes

getAllEncryptedAttributes(integer $iSurveyId,string $sClassName): array
inherited

Arguments

$iSurveyId

integer

$sClassName

string

Response

array

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

Get whole existing attribute for one question as array

getAttributesAsArrayFromDB(integer $iQuestionID): array
static

Arguments

$iQuestionID

integer

the question id

Response

array

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

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

getDefaultSettings(): \array<string,
static
todo

Move to static property?

Response

\array

mixed>

Read question attributes from XML file and convert it to array

getGeneralAttibutesFromXml(string $sXmlFilePath): \?array
static
todo

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

Arguments

$sXmlFilePath

string

Path to XML

Response

\?array

The general attribute settings for this question type

Return the max value for a field

getMaxId(string $field = null,boolean $forceRefresh = false): false|integer
inherited

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

Throws
\Exception

Arguments

$field

string

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

$forceRefresh

boolean

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

Response

false|integer

Return the min value for a field

getMinId(string $field = null,boolean $forceRefresh = false): false|integer
inherited

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

Throws
\Exception

Arguments

$field

string

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

$forceRefresh

boolean

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

Response

false|integer

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

getOwnQuestionAttributesViaPlugin(): array
static

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 ]

Response

array

the event attributes as array or an empty array

getQuestion

getQuestion(): \Question

Response

\Question

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

getQuestionAttributes(integer $iQuestionID,string $sLanguage = null): array|false

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

access

public

Throws
\CException

throws exception if questiontype is null

Arguments

$iQuestionID

integer

$sLanguage

string

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

Response

array|false

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

getQuestionAttributesSettings(string $sType,boolean $advancedOnly = false): array
static
Throws
\CException

Arguments

$sType

string

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

$advancedOnly

boolean

If true, only fetch advanced attributes

Response

array

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

getQuestionsForStatistics

getQuestionsForStatistics(string $fields,mixed $condition,string|false $orderby = false): array

Arguments

$fields

string

$condition

mixed

$orderby

string|false

Response

array

Returns the value for attribute 'question_template'.

getQuestionTemplateValue( $questionID): string
static

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.

deprecated

use $question->question_theme_name instead (Question model)

Arguments

$questionID

Response

string

question_template or 'core' if it not exists

getSurvey

getSurvey(): \Survey

Response

\Survey

model

model( $className = __CLASS__): static
static

Arguments

$className

Response

static

primaryKey

primaryKey()
inheritdoc

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

query(\CDbCriteria $criteria,boolean $all = false,boolean $asAR = true): mixed
inherited

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.

since 1.1.7

Arguments

$criteria

\CDbCriteria

the query criteria

$all

boolean

whether to return all data

$asAR

boolean

Response

mixed

the AR objects populated with the query result

relations

relations()
inheritdoc
todo

Remove?

rules

rules()
inheritdoc

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

setEncryptedAttributeLabel(integer $surveyId,string $className,string $attributeName): string
inherited
Throws
\CException

Arguments

$surveyId

integer

$className

string

$attributeName

string

Response

string

Set attributes for multiple questions

setMultiple( $iSid, $aQids, $aAttributesToUpdate, $aValidQuestionTypes)

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

var

the sid to update (only to check permission)

an array containing the list of primary keys for questions

array containing the list of attributes to update

the question types we can update for those attributes

todo

Missign noun in function name - set multiple what?

Arguments

$iSid

$aQids

$aAttributesToUpdate

$aValidQuestionTypes

setQuestionAttribute

setQuestionAttribute(integer $iQuestionID,string $sAttributeName,string $sValue): \CDbDataReader|boolean
todo

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

Arguments

$iQuestionID

integer

$sAttributeName

string

$sValue

string

Response

\CDbDataReader|boolean

setQuestionAttributeWithLanguage

setQuestionAttributeWithLanguage(integer $iQuestionID,string $sAttributeName,string $sValue,string $sLanguage): \CDbDataReader
todo

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

Arguments

$iQuestionID

integer

$sAttributeName

string

$sValue

string

$sLanguage

string

Response

\CDbDataReader

tableName

tableName()
inheritdoc

Updates records with the specified condition.

updateAll(array $attributes,mixed $condition = '',array $params = array()): integer
inherited

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

Arguments

$attributes

array

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

$condition

mixed

query condition or criteria.

$params

array

parameters to be bound to an SQL statement.

Response

integer

the number of rows being updated

Properties

questionAttributesSettings

questionAttributesSettings :
static

Type(s)

Array of attributes that should be XSS filtered on mass updates

xssFilterAttributes :array<mixed,string>
inherited
var

Array of attributes that should be XSS filtered on mass updates

Type(s)

array<mixed,string>

bEncryption

bEncryption :
inherited

Type(s)

qaid

qaid :integer

ID Primary key

Type(s)

integer

qid

qid :integer

Question ID

Type(s)

integer

attribute

attribute :string

attribute name (max 50 chars)

Type(s)

string

value

value :string

Attribute value

Type(s)

string

language

language :string

Language code eg:'en'

Type(s)

string

question

question :\Question

Type(s)

\Question

survey

survey :\Survey

Type(s)

\Survey