QuestionTemplate
extends CFormModel
in package
Class QuestionTemplate
Handles question-level template overrides. Each question can have its own template that replaces default views and registers custom CSS/JS assets.
Tags
Table of Contents
Properties
- $aCustomAttributes : array<string|int, mixed>
- $aViews : array<string|int, mixed>
- $bHasCustomAttributes : bool
- $bHasTemplate : bool
- $oConfig : SimpleXMLElement
- $oQuestion : Question
- $sTemplateFolderName : string
- $bHasConfigFile : bool
- $bLoadCoreCss : bool
- $bLoadCoreJs : bool
- $bLoadCorePackage : bool
- $instance : QuestionTemplate
- $sTemplatePath : string
- $sTemplateQuestionPath : string
- $sTemplateUrl : string
- $xmlFile : string
Methods
- checkIfTemplateHasView() : bool
- Check if the question template offers a specific replacement for the given view file.
- getCustomAttributes() : array<string|int, mixed>|null
- Return the custom attributes defined by the question template.
- getFolderName() : string|null
- getNewInstance() : QuestionTemplate
- Get a new instance of the template object Each question on the page could have a different template.
- getQuestionTemplateFolderName() : false|string
- Get the template folder name
- getQuestionTemplateList() : array<string|int, mixed>
- Called from admin, to generate the template list for a given question type
- getTemplatePath() : null|string
- Retrieve the template base path if exist
- getTemplateUrl() : string
- getTypeToFolder() : array<string|int, mixed>
- Correspondence between question type and the view folder name Rem: should be in question model. We keep it here for easy access
- registerAssets() : void
- Register custom CSS and JavaScript assets defined in the question template config.
- registerCssFile() : mixed
- Register a core css file
- registerPackage() : mixed
- Register a core package file
- registerScript() : mixed
- Register a core script
- registerScriptFile() : mixed
- Register a core script file
- setConfig() : void
- Load and parse the question template XML configuration.
- templateLoadsCoreCss() : bool|null
- Return true if the core CSS should be loaded.
- templateLoadsCoreJs() : bool|null
- Return true if the core JavaScript should be loaded.
- templateLoadsCorePackage() : bool|null
- Return true if the core packages should be loaded.
Properties
$aCustomAttributes
public
array<string|int, mixed>
$aCustomAttributes
array (attribute=>value)
$aViews
public
array<string|int, mixed>
$aViews
Array of views the template can handle ($aViews['path_to_my_view']==true)
$bHasCustomAttributes
public
bool
$bHasCustomAttributes
Does the template provides custom attributes?
$bHasTemplate
public
bool
$bHasTemplate
Does this question has a template?
$oConfig
public
SimpleXMLElement
$oConfig
$oQuestion
public
Question
$oQuestion
The current question
$sTemplateFolderName
public
string
$sTemplateFolderName
The folder of the template applied to this question (if no template applied, it's false)
$bHasConfigFile
private
bool
$bHasConfigFile
$bLoadCoreCss
private
bool
$bLoadCoreCss
Should it render the core CSS of this question (script are registered in qanda)
$bLoadCoreJs
private
bool
$bLoadCoreJs
Should it render the core javascript of this question (script are registered in qanda)
$bLoadCorePackage
private
bool
$bLoadCorePackage
Should it render the core packages of this question (script are registered in qanda)
$instance
private
static QuestionTemplate
$instance
The instance of question template object
$sTemplatePath
private
string
$sTemplatePath
The path to the template
$sTemplateQuestionPath
private
string
$sTemplateQuestionPath
The path to the folder corresponding to the current question type
$sTemplateUrl
private
string
$sTemplateUrl
$xmlFile
private
string
$xmlFile
The path to the xml file
Methods
checkIfTemplateHasView()
Check if the question template offers a specific replacement for the given view file.
public
checkIfTemplateHasView(string $sView) : bool
Parameters
- $sView : string
-
The view name to check
Return values
bool —True if the template provides a replacement for the view
getCustomAttributes()
Return the custom attributes defined by the question template.
public
getCustomAttributes() : array<string|int, mixed>|null
Return values
array<string|int, mixed>|null —Array of attribute name => value pairs, or null if no custom attributes
getFolderName()
public
static getFolderName(string $type) : string|null
Parameters
- $type : string
Tags
Return values
string|nullgetNewInstance()
Get a new instance of the template object Each question on the page could have a different template.
public
static getNewInstance(Question $oQuestion) : QuestionTemplate
So each question must have a new instance
Parameters
- $oQuestion : Question
Return values
QuestionTemplategetQuestionTemplateFolderName()
Get the template folder name
public
getQuestionTemplateFolderName() : false|string
Return values
false|stringgetQuestionTemplateList()
Called from admin, to generate the template list for a given question type
public
static getQuestionTemplateList(string $type) : array<string|int, mixed>
Parameters
- $type : string
Tags
Return values
array<string|int, mixed>getTemplatePath()
Retrieve the template base path if exist
public
getTemplatePath() : null|string
Return values
null|stringgetTemplateUrl()
public
getTemplateUrl() : string
Return values
stringgetTypeToFolder()
Correspondence between question type and the view folder name Rem: should be in question model. We keep it here for easy access
public
static getTypeToFolder() : array<string|int, mixed>
Tags
Return values
array<string|int, mixed>registerAssets()
Register custom CSS and JavaScript assets defined in the question template config.
public
registerAssets() : void
registerCssFile()
Register a core css file
public
registerCssFile(string $sCssFile[, string $media = '' ]) : mixed
Parameters
- $sCssFile : string
- $media : string = ''
registerPackage()
Register a core package file
public
registerPackage(string $sPackage) : mixed
Parameters
- $sPackage : string
registerScript()
Register a core script
public
registerScript(string $sScript[, int $pos = CClientScript::POS_BEGIN ]) : mixed
Parameters
- $sScript : string
- $pos : int = CClientScript::POS_BEGIN
registerScriptFile()
Register a core script file
public
registerScriptFile(string $sFile[, int $pos = CClientScript::POS_BEGIN ]) : mixed
Parameters
- $sFile : string
- $pos : int = CClientScript::POS_BEGIN
setConfig()
Load and parse the question template XML configuration.
public
setConfig() : void
Sets template paths, engine flags (JS/CSS/package loading), and custom attributes.
templateLoadsCoreCss()
Return true if the core CSS should be loaded.
public
templateLoadsCoreCss() : bool|null
Return values
bool|nulltemplateLoadsCoreJs()
Return true if the core JavaScript should be loaded.
public
templateLoadsCoreJs() : bool|null
Return values
bool|nulltemplateLoadsCorePackage()
Return true if the core packages should be loaded.
public
templateLoadsCorePackage() : bool|null