LimeSurvey API - Master branch

Template extends LSActiveRecord
in package

Class Template

Table of Contents

Properties

$aAllTemplatesDir  : array<string|int, mixed>
$aNamesFiltered  : array<string|int, mixed>
$api_version  : string
$aTemplatesFileFolder  : array<string|int, mixed>
$author  : string
$author_email  : string
$author_url  : string
$bEncryption  : mixed
$copyright  : string
$creation_date  : string
$description  : string
$extends  : string
$files_folder  : string
$folder  : string
$last_update  : string
$license  : string
$name  : string
$owner_id  : int
$sTemplateNameIllegalChars  : mixed
$title  : string
$version  : string
$view_folder  : string
$xssFilterAttributes  : array<string|int, string>
$instance  : Template

Methods

attributeLabels()  : array<string|int, mixed>
behaviors()  : array<string|int, mixed>
Lists the behaviors of this model
checkExtendsItSelf()  : bool
checkIfTemplateExists()  : bool
checkTemplate()  : bool
checkTemplateExtends()  : bool
Throws exception if any of the extended templates are not installed; otherwise returns true.
checkTemplateName()  : mixed
Template name rule function.
checkTemplateXML()  : bool
Check if a given Template has a valid XML File
decrypt()  : mixed
Decrypt values from database
decryptEncryptAttributes()  : mixed
Encrypt/decrypt values
decryptSingle()  : string
Decrypt single value
decryptSingleOld()  : string
Decrypt single value
deleteAllByAttributes()  : int
deleteAssetVersion()  : int
Delete asset related to this template Using DB only
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
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
forceAssets()  : void
Alias function for resetAssetVersion() Don't delete this one to maintain updgrade compatibility
getAllEncryptedAttributes()  : array<string|int, mixed>
getAllTemplatesDirectories()  : mixed
getDeprecatedTemplates()  : mixed
Retrieves a list of deprecated templates (the templates in upload/templates/)
getInstance()  : self
Get instance of template object.
getLastInstance()  : self
Return last instance if it exists, else generate it or throw an exception depending on $bAutoGenerate.
getMaxId()  : false|int
Return the max value for a field
getMinId()  : false|int
Return the min value for a field
getOtherFiles()  : array<string|int, mixed>
Return the list of ALL files present in the file directory
getStandardTemplateList()  : array<string|int, string>
Return the standard template list
getTemplateConfiguration()  : TemplateConfiguration|TemplateManifest
This method construct a template object, having all the needed configuration datas.
getTemplateInFolder()  : mixed
getTemplateInStandard()  : mixed
getTemplateInUpload()  : mixed
getTemplateList()  : string|array<string|int, mixed>
Returns an array of all available template names - check if template exist key is template name, value is template folder
getTemplateListWithPreviews()  : array<string|int, array<string|int, mixed>>
Return the array of existing and installed template with the preview images
getTemplatePath()  : string
Get the template path for any template : test if template exists
getTemplatesFileFolder()  : string
This function returns the complete URL path to a given template name
getTemplateURL()  : string
This function returns the complete URL path to a given template name
hasInheritance()  : mixed
isCorrectInstance()  : bool
Check if the current instance is the correct one. Could be more complex in the future
isStandardTemplate()  : bool
isStandardTemplate returns true if a template is a standard template This function does not check if a template actually exists
model()  : Template
Returns the static model of the specified AR class.
primaryKey()  : string
Returns this table's primary key
relations()  : array<string|int, mixed>
renameTo()  : mixed
Change the template name inside DB and the manifest (called from template editor) NOTE: all tests (like template exist, etc) are done from template controller.
resetAssetVersion()  : void
Reset assets for this template Using DB only
resetInstance()  : mixed
Sets self::$instance to null; Needed for unit test.
rules()  : array<string|int, mixed>
search()  : CActiveDataProvider
Retrieves a list of models based on the current search/filter conditions.
setEncryptedAttributeLabel()  : string
Function to show encryption symbol in gridview attribute header if value ois encrypted
tableName()  : string
templateNameFilter()  : string
Filter the template name : test if template exists
updateAll()  : int
Updates records with the specified condition.
validateTemplateName()  : mixed
Validate the template name.
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

$aAllTemplatesDir

public static array<string|int, mixed> $aAllTemplatesDir = \null

cache for the method getAllTemplatesDirectories

$aNamesFiltered

public static array<string|int, mixed> $aNamesFiltered = \null

cache for the method templateNameFilter

$aTemplatesFileFolder

public static array<string|int, mixed> $aTemplatesFileFolder = \null

cache for the method getTemplateFilesFolder

$author_email

public string $author_email

$creation_date

public string $creation_date

$files_folder

public string $files_folder

$folder

public string $folder

Template folder name eg: 'default'

$sTemplateNameIllegalChars

public static mixed $sTemplateNameIllegalChars = "#\$%^&*()+=[]';,./{}|:<>?~"

$xssFilterAttributes

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

Array of attributes that should be XSS filtered on mass updates

Methods

attributeLabels()

public attributeLabels() : array<string|int, mixed>
Return values
array<string|int, mixed>

customized attribute labels (name=>label)

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>

checkExtendsItSelf()

public checkExtendsItSelf() : bool
Tags
throws
Exception

if name equals extends.

Return values
bool

checkIfTemplateExists()

public static checkIfTemplateExists(string $sTemplateName) : bool
Parameters
$sTemplateName : string
Return values
bool

checkTemplate()

public checkTemplate() : bool
Tags
throws
Exception

if extended template is not installed.

Return values
bool

checkTemplateExtends()

Throws exception if any of the extended templates are not installed; otherwise returns true.

public checkTemplateExtends() : bool
Tags
throws
Exception

if extended template is not installed.

Return values
bool

checkTemplateName()

Template name rule function.

public checkTemplateName(mixed $attributes, mixed $params) : mixed
Parameters
$attributes : mixed
$params : mixed

checkTemplateXML()

Check if a given Template has a valid XML File

public static checkTemplateXML(string $templateName, string $templateFolder) : bool
Parameters
$templateName : string

the template name

$templateFolder : string

the template folder name where to look for the XML

Tags
throws
CDbException
Return values
bool

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

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.

deleteAssetVersion()

Delete asset related to this template Using DB only

public deleteAssetVersion() : int
Return values
int

(0|1)

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

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.

forceAssets()

Alias function for resetAssetVersion() Don't delete this one to maintain updgrade compatibility

public forceAssets() : void

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.

getAllTemplatesDirectories()

public static getAllTemplatesDirectories() : mixed

getDeprecatedTemplates()

Retrieves a list of deprecated templates (the templates in upload/templates/)

public static getDeprecatedTemplates() : mixed

getInstance()

Get instance of template object.

public static getInstance([string $sTemplateName = null ][, int|string $iSurveyId = null ][, int|string $iSurveyGroupId = null ][, bool $bForceXML = null ][, mixed $abstractInstance = false ][, bool $last = false ]) : self

Will instantiate the template object first time it is called.

NOTE 1: This function will call prepareTemplateRendering that create/update all the packages needed to render the template, which imply to do the same for all mother templates NOTE 2: So if you just want to access the TemplateConfiguration AR Object, you don't need to use this one. Call it only before rendering anything related to the template. NOTE 3: If you need to get the related configuration to this template, rather use: getTemplateConfiguration() NOTE 4: If you want the lastest generated theme, just call Template::getLastInstance()

Parameters
$sTemplateName : string = null
$iSurveyId : int|string = null
$iSurveyGroupId : int|string = null
$bForceXML : bool = null
$abstractInstance : mixed = false
$last : bool = false

if you want to get the last instace without providing template name or sid

Return values
self

getLastInstance()

Return last instance if it exists, else generate it or throw an exception depending on $bAutoGenerate.

public static getLastInstance([bool $bAutoGenerate = true ]) : self
Parameters
$bAutoGenerate : bool = true

: should the function try to generate an instance if it doesn't exist?

Return values
self

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

getOtherFiles()

Return the list of ALL files present in the file directory

public static getOtherFiles(string $filesDir) : array<string|int, mixed>
Parameters
$filesDir : string
Return values
array<string|int, mixed>

getStandardTemplateList()

Return the standard template list

public static getStandardTemplateList() : array<string|int, string>
Tags
throws
Exception
deprecated

Use SurveyThemeHelper::getStandardTemplateList() instead.

Return values
array<string|int, string>

getTemplateConfiguration()

This method construct a template object, having all the needed configuration datas.

public static getTemplateConfiguration([string $sTemplateName = null ][, int $iSurveyId = null ][, mixed $iSurveyGroupId = null ][, bool $bForceXML = false ][, mixed $abstractInstance = false ]) : TemplateConfiguration|TemplateManifest

It checks if the required template is a core one or a user one. If it's a user template, it will check if it's an old 2.0x template to provide default configuration values corresponding to the old template system If it's not an old template, it will check if it has a configuration file to load its datas. If it's not the case (template probably doesn't exist), it will load the default template configuration TODO : more tests should be done, with a call to private function _is_valid_template(), testing not only if it has a config.xml, but also id this file is correct, if the files refered in css exist, etc.

Parameters
$sTemplateName : string = null

the name of the template to load. The string come from the template selector in survey settings

$iSurveyId : int = null

the id of the survey.

$iSurveyGroupId : mixed = null
$bForceXML : bool = false

the id of the survey.

$abstractInstance : mixed = false
Return values
TemplateConfiguration|TemplateManifest

getTemplateInFolder()

public static getTemplateInFolder(mixed $sFolder) : mixed
Parameters
$sFolder : mixed
Tags
deprecated

Use SurveyThemeHelper::getTemplateInFolder() instead.

getTemplateInStandard()

public static getTemplateInStandard() : mixed
Tags
deprecated

Use SurveyThemeHelper::getTemplateInStandard() instead.

getTemplateInUpload()

public static getTemplateInUpload() : mixed
Tags
deprecated

Use SurveyThemeHelper::getTemplateInUpload() instead.

getTemplateList()

Returns an array of all available template names - check if template exist key is template name, value is template folder

public static getTemplateList() : string|array<string|int, mixed>
Return values
string|array<string|int, mixed>

getTemplateListWithPreviews()

Return the array of existing and installed template with the preview images

public static getTemplateListWithPreviews() : array<string|int, array<string|int, mixed>>
Tags
deprecated
2024-04-25

use directly Template::getTemplateList

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

getTemplatePath()

Get the template path for any template : test if template exists

public static getTemplatePath([string $sTemplateName = "" ]) : string
Parameters
$sTemplateName : string = ""
Tags
throws
Exception
Return values
string

template path

getTemplatesFileFolder()

This function returns the complete URL path to a given template name

public static getTemplatesFileFolder([string $sTemplateName = "" ]) : string
Parameters
$sTemplateName : string = ""
Return values
string

template url

getTemplateURL()

This function returns the complete URL path to a given template name

public static getTemplateURL([string $sTemplateName = "" ]) : string
Parameters
$sTemplateName : string = ""
Return values
string

template url

hasInheritance()

public static hasInheritance(mixed $sTemplateName) : mixed
Parameters
$sTemplateName : mixed

isCorrectInstance()

Check if the current instance is the correct one. Could be more complex in the future

public static isCorrectInstance([string $sTemplateName = null ]) : bool
Parameters
$sTemplateName : string = null
Return values
bool

isStandardTemplate()

isStandardTemplate returns true if a template is a standard template This function does not check if a template actually exists

public static isStandardTemplate(mixed $sTemplateName) : bool
Parameters
$sTemplateName : mixed

template name to look for

Tags
deprecated

Use SurveyThemeHelper::getStandardTemplateList() instead.

Return values
bool

True if standard template, otherwise false

model()

Returns the static model of the specified AR class.

public static model([string $className = __CLASS__ ]) : Template

Please note that you should have this exact method in all your CActiveRecord descendants!

Parameters
$className : string = __CLASS__

active record class name.

Return values
Template

the static model class

primaryKey()

Returns this table's primary key

public primaryKey() : string
Tags
access

public

Return values
string

relations()

public relations() : array<string|int, mixed>
Return values
array<string|int, mixed>

relational rules.

renameTo()

Change the template name inside DB and the manifest (called from template editor) NOTE: all tests (like template exist, etc) are done from template controller.

public renameTo(string $sNewName) : mixed
Parameters
$sNewName : string

The newname of the template

resetAssetVersion()

Reset assets for this template Using DB only

public resetAssetVersion() : void

resetInstance()

Sets self::$instance to null; Needed for unit test.

public static resetInstance() : mixed

rules()

public rules() : array<string|int, mixed>
Return values
array<string|int, mixed>

validation rules for model attributes.

Retrieves a list of models based on the current search/filter conditions.

public search() : CActiveDataProvider

Typical usecase:

  • Initialize the model fields with values from filter form.
  • Execute this method to get CActiveDataProvider instance which will filter models according to data in model fields.
  • Pass data provider to CGridView, CListView or any similar widget.
Return values
CActiveDataProvider

the data provider that can return the models based on the search/filter conditions.

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

tableName()

public tableName() : string
Return values
string

the associated database table name

templateNameFilter()

Filter the template name : test if template exists

public static templateNameFilter(string $sTemplateName) : string
Parameters
$sTemplateName : string
Tags
throws
Exception
Return values
string

existing $sTemplateName

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

validateTemplateName()

Validate the template name.

public static validateTemplateName(string $templateName) : mixed
Parameters
$templateName : string

The name of the template

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