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 = '')
inheritedstatic

Arguments

$value

string

String value which needs to be decrypted

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

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 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

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(): \(string|boolean|array<mixed,\null)>
static

Response

\(string|boolean|array<mixed,\null)>

Read question attributes from XML file and convert it to array

getGeneralAttibutesFromXml(string $sXmlFilePath): array
static

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|boolean

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

access

public

todo

this function is doing to much things to prepare just an array. Find a better solution (maybe service class)

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|boolean

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 $orderby = false): array

Arguments

$fields

string

$condition

mixed

$orderby

string

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.

Arguments

$questionID

Response

string

question_template or 'core' if it not exists

getSurvey

getSurvey(): \Survey

Response

\Survey

insertRecords

insertRecords( $data): boolean
static
deprecated

at 2018-01-29 use $model->attributes = $data && $model->save()

Arguments

$data

Response

boolean

model

model( $class = __CLASS__): \QuestionAttribute
static
inheritdoc

Arguments

$class

Response

\QuestionAttribute

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

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 continaing the list of attributes to update

the question types we can update for those attributes

Arguments

$iSid

$aQids

$aAttributesToUpdate

$aValidQuestionTypes

setQuestionAttribute

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

Arguments

$iQuestionID

integer

$sAttributeName

string

$sValue

string

Response

\CDbDataReader|boolean

setQuestionAttributeWithLanguage

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

Arguments

$iQuestionID

integer

$sAttributeName

string

$sValue

string

$sLanguage

string

Response

\CDbDataReader

tableName

tableName()
inheritdoc

Properties

questionAttributesSettings

questionAttributesSettings :
static

Type(s)

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