Toggle menu
913
3.8K
30.2K
279.2K
Catglobe Wiki
Toggle preferences menu
Toggle personal menu
Not logged in
Your IP address will be publicly visible if you make any edits.

QuestionTemplate class: Difference between revisions

From Catglobe Wiki
No edit summary
No edit summary
ย 
Line 1: Line 1:
{{CGscriptClass_Template
{{CGscriptClass_Template
|Name=<nowiki>QuestionTemplate</nowiki>
|Name=<nowiki>QuestionTemplate</nowiki>
|Description=<nowiki>The question template. Implemented serialization</nowiki>
|Description=<nowiki>A question in a questionnaire template</nowiki>
|InheritsFrom=object|Constructors=
|InheritsFrom=Array|Constructors=
{{CGscriptConstructors_Template|Parameters=
{{CGscriptConstructors_Template|Parameters=
{{CGscriptParameters_Template|Type=int|Name=<nowiki>id</nowiki>|Description=<nowiki>Question id</nowiki>}}
{{CGscriptParameters_Template|Type=int|Name=<nowiki>id</nowiki>|Description=<nowiki>Question id</nowiki>}}
Line 22: Line 22:
{{CGscriptParameters_Template|Type=PropertyType constant|Name=<nowiki>type</nowiki>|Description=<nowiki>Use constant Question_Property_xxxx</nowiki>|Comma=,}}{{CGscriptParameters_Template|Type=int|Name=<nowiki>gridNumber</nowiki>|Description=<nowiki>Index of sub question that the property belong to</nowiki>|Comma=,}}{{CGscriptParameters_Template|Type=object|Name=<nowiki>value</nowiki>|Description=<nowiki>String or LocalizedString depend on property type. If value is empty then the property will be removed</nowiki>}}
{{CGscriptParameters_Template|Type=PropertyType constant|Name=<nowiki>type</nowiki>|Description=<nowiki>Use constant Question_Property_xxxx</nowiki>|Comma=,}}{{CGscriptParameters_Template|Type=int|Name=<nowiki>gridNumber</nowiki>|Description=<nowiki>Index of sub question that the property belong to</nowiki>|Comma=,}}{{CGscriptParameters_Template|Type=object|Name=<nowiki>value</nowiki>|Description=<nowiki>String or LocalizedString depend on property type. If value is empty then the property will be removed</nowiki>}}
|Description=<nowiki>Set value for property type</nowiki>}}
|Description=<nowiki>Set value for property type</nowiki>}}
{{CGscriptMethods_Template|ReturnType=string|Name=<nowiki>ToString</nowiki>|Inherited=object|Description=<nowiki>The string representation of the object.</nowiki>}}
{{CGscriptMethods_Template|ReturnType=string|Name=<nowiki>ToString</nowiki>|Description=<nowiki>The string representation of the object.</nowiki>}}
{{CGscriptMethods_Template|ReturnType=object|Name=<nowiki>this[] { get; }</nowiki>|Parameters=
{{CGscriptParameters_Template|Type=int|Name=<nowiki>index</nowiki>|Description=<nowiki>Index</nowiki>}}
|Description=<nowiki>Backward-compatible indexer</nowiki>}}
{{CGscriptMethods_Template|ReturnType=Empty|Name=<nowiki>this[] { get; }</nowiki>|Parameters=
{{CGscriptParameters_Template|Type=int|Name=<nowiki>index</nowiki>|Description=<nowiki>Index</nowiki>|Comma=,}}{{CGscriptParameters_Template|Type=object|Name=<nowiki>value</nowiki>|Description=<nowiki>Value to set</nowiki>}}
|Description=<nowiki>Backward-compatible indexer</nowiki>}}
|Properties=
|Properties=
{{CGscriptProperties_Template|ReturnType=array|Name=<nowiki>AnswerOptions</nowiki>|HasGetter=1|Description=<nowiki>Get configuration answer options of this question template. Item type is AnswerOption</nowiki>}}
{{CGscriptProperties_Template|ReturnType=Array of AnswerOption|Name=<nowiki>AnswerOptions</nowiki>|HasGetter=1|Description=<nowiki>Get configuration answer options of this question template. Item type is AnswerOption</nowiki>}}
{{CGscriptProperties_Template|ReturnType=array|Name=<nowiki>Conditions</nowiki>|HasGetter=1|Description=<nowiki>Get configuration conditional of this question template. Item type is QuestionCondition</nowiki>}}
{{CGscriptProperties_Template|ReturnType=number|Name=<nowiki>Average</nowiki>|HasGetter=1|Description=<nowiki>Average of the objects in the Array object. Can only use if all the elements are of type Number</nowiki>}}
{{CGscriptProperties_Template|ReturnType=Array of QuestionCondition|Name=<nowiki>Conditions</nowiki>|HasGetter=1|Description=<nowiki>Get configuration conditional of this question template. Item type is QuestionCondition</nowiki>}}
{{CGscriptProperties_Template|ReturnType=bool|Name=<nowiki>HasData</nowiki>|HasGetter=1|Description=<nowiki>Check if this question contains data or not</nowiki>}}
{{CGscriptProperties_Template|ReturnType=bool|Name=<nowiki>HasData</nowiki>|HasGetter=1|Description=<nowiki>Check if this question contains data or not</nowiki>}}
{{CGscriptProperties_Template|ReturnType=int|Name=<nowiki>Id</nowiki>|HasGetter=1|Description=<nowiki>Question id</nowiki>}}
{{CGscriptProperties_Template|ReturnType=int|Name=<nowiki>Id</nowiki>|HasGetter=1|Description=<nowiki>Question id</nowiki>}}
{{CGscriptProperties_Template|ReturnType=string|Name=<nowiki>Label</nowiki>|HasGetter=1|HasSetter=1|Description=<nowiki>Question label</nowiki>}}
{{CGscriptProperties_Template|ReturnType=string|Name=<nowiki>Label</nowiki>|HasGetter=1|HasSetter=1|Description=<nowiki>Question label</nowiki>}}
{{CGscriptProperties_Template|ReturnType=number|Name=<nowiki>Max</nowiki>|HasGetter=1|Description=<nowiki>Largest of all the objects in the Array object. Can only use if all the elements are of type Number</nowiki>}}
{{CGscriptProperties_Template|ReturnType=number|Name=<nowiki>Min</nowiki>|HasGetter=1|Description=<nowiki>Smallest of all the objects in the Array object. Can only use if all the elements are of type Number</nowiki>}}
{{CGscriptProperties_Template|ReturnType=string|Name=<nowiki>ObjectTypeName</nowiki>|HasGetter=1|Description=<nowiki>The name of the type of object.</nowiki>}}
{{CGscriptProperties_Template|ReturnType=string|Name=<nowiki>ObjectTypeName</nowiki>|HasGetter=1|Description=<nowiki>The name of the type of object.</nowiki>}}
{{CGscriptProperties_Template|ReturnType=array|Name=<nowiki>Properties</nowiki>|HasGetter=1|Description=<nowiki>Get configuration properties of this question template. Item type is QuestionProperty</nowiki>}}
{{CGscriptProperties_Template|ReturnType=Array of QuestionProperty|Name=<nowiki>Properties</nowiki>|HasGetter=1|Description=<nowiki>Get configuration properties of this question template. Item type is QuestionProperty</nowiki>}}
{{CGscriptProperties_Template|ReturnType=array|Name=<nowiki>SubQuestions</nowiki>|HasGetter=1|Description=<nowiki>Get configuration answer options of this question template. Item type is SubQuestion</nowiki>}}
{{CGscriptProperties_Template|ReturnType=Array of SubQuestion|Name=<nowiki>SubQuestions</nowiki>|HasGetter=1|Description=<nowiki>Get configuration sub questions options of this question template. Item type is SubQuestion</nowiki>}}
{{CGscriptProperties_Template|ReturnType=number|Name=<nowiki>Sum</nowiki>|HasGetter=1|Description=<nowiki>Sum of all the objects in the Array object. Can only use if all the elements are of type Number</nowiki>}}
{{CGscriptProperties_Template|ReturnType=LocalizedString|Name=<nowiki>Text</nowiki>|HasGetter=1|HasSetter=1|Description=<nowiki>Question text</nowiki>}}
{{CGscriptProperties_Template|ReturnType=LocalizedString|Name=<nowiki>Text</nowiki>|HasGetter=1|HasSetter=1|Description=<nowiki>Question text</nowiki>}}
{{CGscriptProperties_Template|ReturnType=QuestionType constant|Name=<nowiki>Type</nowiki>|HasGetter=1|HasSetter=1|Description=<nowiki>Question type, use constant Question_Type_xxx</nowiki>}}
{{CGscriptProperties_Template|ReturnType=QuestionType constant|Name=<nowiki>Type</nowiki>|HasGetter=1|HasSetter=1|Description=<nowiki>Question type, use constant Question_Type_xxx</nowiki>}}
{{CGscriptProperties_Template|ReturnType=TypeInformation|Name=<nowiki>TypeInformation</nowiki>|HasGetter=1|Inherited=object|Description=<nowiki>Get information about this class.</nowiki>}}
{{CGscriptProperties_Template|ReturnType=TypeInformation|Name=<nowiki>TypeInformation</nowiki>|HasGetter=1|Description=<nowiki>Get information about this class.</nowiki>}}
|StaticMethods=
{{CGscriptMethods_Template|ReturnType=array|Name=<nowiki>QuestionTemplate_getAll</nowiki>|Description=<nowiki>Returns all questions in the current Questionnaire context</nowiki>}}
{{CGscriptMethods_Template|ReturnType=array|Name=<nowiki>QuestionTemplate_getAll</nowiki>|Parameters=
{{CGscriptParameters_Template|Type=int|Name=<nowiki>Questionnaire resource id</nowiki>|Description=<nowiki>The Questionnaire resource id</nowiki>}}
|Description=<nowiki>Returns all questions for the given Questionnaire resource id</nowiki>}}
{{CGscriptMethods_Template|ReturnType=QuestionTemplate|Name=<nowiki>QuestionTemplate_getQuestion</nowiki>|Parameters=
{{CGscriptParameters_Template|Type=string|Name=<nowiki>Question label</nowiki>|Description=<nowiki>Label of the question</nowiki>}}
|Description=<nowiki>Returns the question object for the given label</nowiki>}}
{{CGscriptMethods_Template|ReturnType=QuestionTemplate|Name=<nowiki>QuestionTemplate_getQuestionByIndex</nowiki>|Parameters=
{{CGscriptParameters_Template|Type=int|Name=<nowiki>Question index</nowiki>|Description=<nowiki>Index of the question</nowiki>}}
|Description=<nowiki>Returns the question at the given index in the current Questionnaire context</nowiki>}}
{{CGscriptMethods_Template|ReturnType=QuestionTemplate|Name=<nowiki>QuestionTemplate_getQuestionByIndex</nowiki>|Parameters=
{{CGscriptParameters_Template|Type=int|Name=<nowiki>Question index</nowiki>|Description=<nowiki>Index of the question</nowiki>|Comma=,}}{{CGscriptParameters_Template|Type=int|Name=<nowiki>Questionnaire resource id</nowiki>|Description=<nowiki>The Questionnaire resource id</nowiki>}}
|Description=<nowiki>Returns the question at the given index for the specified Questionnaire</nowiki>}}
{{CGscriptMethods_Template|ReturnType=array|Name=<nowiki>QuestionTemplate_getQuestions</nowiki>|Parameters=
{{CGscriptParameters_Template|Type=int|Name=<nowiki>questionnaireId</nowiki>|Description=<nowiki>The Questionnaire resource id</nowiki>}}
|Description=<nowiki>Returns question objects for all questions in a Questionnaire</nowiki>}}
{{CGscriptMethods_Template|ReturnType=array|Name=<nowiki>QuestionTemplate_getQuestions</nowiki>|Parameters=
{{CGscriptParameters_Template|Type=int|Name=<nowiki>questionnaireId</nowiki>|Description=<nowiki>The Questionnaire resource id</nowiki>|Comma=,}}{{CGscriptParameters_Template|Type=array|Name=<nowiki>questionLabels</nowiki>|Description=<nowiki>Array of question labels to return</nowiki>}}
|Description=<nowiki>Returns question objects for the specified labels in a Questionnaire</nowiki>}}
}}
}}
=== <span style="color:#DF8621">'''Examples'''</span> ===
=== <span style="color:#DF8621">'''Examples'''</span> ===

Latest revision as of 04:03, 29 May 2026

QuestionTemplate


A question in a questionnaire template

Parent class

Inherits from Array

Constructors

  • (int id "Question id") - Fetch exists question
  • (string label "Question label", QuestionType constant type "Question type, use constant Question_Type_xxx", QuestionnaireTemplate qt "Questionnaire template") - Create new question and add it to questionnaire template

Methods

  • object GetProperty(PropertyType constant type "Use constant Question_Property_xxxx") - Get value of property type, return empty if not found
  • object GetProperty(PropertyType constant type "Use constant Question_Property_xxxx", int gridNumber "Index of sub question that the property belong to") - Get value of property type, return empty if not found
  • Empty SetProperty(PropertyType constant type "Use constant Question_Property_xxxx", object value "String or LocalizedString depend on property type. If value is empty then the property will be removed") - Set value for property type
  • Empty SetProperty(PropertyType constant type "Use constant Question_Property_xxxx", int gridNumber "Index of sub question that the property belong to", object value "String or LocalizedString depend on property type. If value is empty then the property will be removed") - Set value for property type
  • string ToString() - The string representation of the object.
  • object this[] { get; }(int index "Index") - Backward-compatible indexer
  • Empty this[] { get; }(int index "Index", object value "Value to set") - Backward-compatible indexer

Properties

  • Array of AnswerOption AnswerOptions { get; } - Get configuration answer options of this question template. Item type is AnswerOption
  • number Average { get; } - Average of the objects in the Array object. Can only use if all the elements are of type Number
  • Array of QuestionCondition Conditions { get; } - Get configuration conditional of this question template. Item type is QuestionCondition
  • bool HasData { get; } - Check if this question contains data or not
  • int Id { get; } - Question id
  • string Label { get; set; } - Question label
  • number Max { get; } - Largest of all the objects in the Array object. Can only use if all the elements are of type Number
  • number Min { get; } - Smallest of all the objects in the Array object. Can only use if all the elements are of type Number
  • string ObjectTypeName { get; } - The name of the type of object.
  • Array of QuestionProperty Properties { get; } - Get configuration properties of this question template. Item type is QuestionProperty
  • Array of SubQuestion SubQuestions { get; } - Get configuration sub questions options of this question template. Item type is SubQuestion
  • number Sum { get; } - Sum of all the objects in the Array object. Can only use if all the elements are of type Number
  • LocalizedString Text { get; set; } - Question text
  • QuestionType constant Type { get; set; } - Question type, use constant Question_Type_xxx
  • TypeInformation TypeInformation { get; } - Get information about this class.

Static Methods

  • array QuestionTemplate_getAll() - Returns all questions in the current Questionnaire context
  • array QuestionTemplate_getAll(int Questionnaire resource id "The Questionnaire resource id") - Returns all questions for the given Questionnaire resource id
  • QuestionTemplate QuestionTemplate_getQuestion(string Question label "Label of the question") - Returns the question object for the given label
  • QuestionTemplate QuestionTemplate_getQuestionByIndex(int Question index "Index of the question") - Returns the question at the given index in the current Questionnaire context
  • QuestionTemplate QuestionTemplate_getQuestionByIndex(int Question index "Index of the question", int Questionnaire resource id "The Questionnaire resource id") - Returns the question at the given index for the specified Questionnaire
  • array QuestionTemplate_getQuestions(int questionnaireId "The Questionnaire resource id") - Returns question objects for all questions in a Questionnaire
  • array QuestionTemplate_getQuestions(int questionnaireId "The Questionnaire resource id", array questionLabels "Array of question labels to return") - Returns question objects for the specified labels in a Questionnaire

Examples

// create a new question (Open type)
Questionnaire qnaire = new Questionnaire (17148177);
QuestionnaireTemplate qt = new QuestionnaireTemplate (qnaire.TemplateId);
QuestionTemplate q = new QuestionTemplate ("Q1", Question_Type_Open, qt);
q.Text = new LocalizedString ({"": "Q1 text"}, "");
new AnswerOption (q).Text.SetTranslation ("", "Don't know");
qt.Save(true);
// create a new question (singleGrid type)
Questionnaire qnaire = new Questionnaire (17148177);
QuestionnaireTemplate qt = new QuestionnaireTemplate (qnaire.TemplateId);
QuestionTemplate q = new QuestionTemplate ("Q2", Question_Type_SingleGrid, qt);
q.Text = new LocalizedString ({"": "Q2 text"}, "");
new AnswerOption (q).Text.SetTranslation ("", "Option 1");
new AnswerOption (q).Text.SetTranslation ("", "Option 2");
new SubQuestion (q).Text.SetTranslation ("", "Sub question 1");
new SubQuestion (q).Text.SetTranslation ("", "Sub question 2");
qt.Save(true);
//create a new question (scaleGrid type)
Questionnaire qnaire = new Questionnaire (17148177);
QuestionnaireTemplate qt = new QuestionnaireTemplate (qnaire.TemplateId);
QuestionTemplate q = new QuestionTemplate ("Q3", Question_Type_ScaleGrid, qt);
q.Text = new LocalizedString ({"": "Q3 text"}, "");
new SubQuestion (q).Text.SetTranslation ("", "Sub question 1");
new SubQuestion (q).Text.SetTranslation ("", "Sub question 2");
for(i for 0; q.SubQuestions.Count){
	new QuestionProperty (Question_Property_Minimum, i, q).Value = "1";
	new QuestionProperty (Question_Property_Maximum, i, q).Value = "5";
	new QuestionProperty (Question_Property_MinimumText, i, q).Value.SetTranslation("", "Min text");
	new QuestionProperty (Question_Property_MaximumText, i, q).Value.SetTranslation("", "Max text");
}
qt.Save(true);
//Get all existing properties of a quesion
Questionnaire qnaire = new Questionnaire (17148177);
QuestionnaireTemplate qt = new QuestionnaireTemplate (qnaire.TemplateId);
QuestionTemplate q = qt.GetQuestion("Q1");
print(q.Properties);//{QuestionProperty,....}
for(i for 0; q.Properties.Count){
	QuestionProperty p = q.Properties[i];
	if(p.IsLocalize)
		print(p.PropertyTypeAsString +": "+ convertToString(p.Value.ToDictionary()));
	else print (p.PropertyTypeAsString +": "+ p.Value);
}
// set, get property of a question
Questionnaire qnaire = new Questionnaire (17148177);//unittest: 17148147 tแปฑ test: 17148177
QuestionnaireTemplate qt = new QuestionnaireTemplate (qnaire.TemplateId);
QuestionTemplate q = qt.GetQuestion("Q1");
q.SetProperty (Question_Property_EndPoints, "60");
qt.Save(false);
print(q.GetProperty (Question_Property_EndPoints));//60
//get all condition of a question 
Questionnaire qnaire = new Questionnaire (17148177);
QuestionnaireTemplate qt = new QuestionnaireTemplate (qnaire.TemplateId);
QuestionTemplate q = qt.GetQuestion("Q1");
print(q.Conditions);//{QuestionCondition,...}
	for(i for 0; q.Conditions.Count){
	QuestionCondition c = q.Conditions[i];
	print(c.ConditionTypeAsString +" "+ c.Label +" "+c.Expression);
}
//get answerOption of a question 
Questionnaire qnaire = new Questionnaire (17148177);
QuestionnaireTemplate qt = new QuestionnaireTemplate (qnaire.TemplateId);
QuestionTemplate q = qt.GetQuestion("Q1");
print(q.AnswerOptions);//{AnswerOption,...}
	for(i for 0; q.AnswerOptions.Count){
	AnswerOption ao = q.AnswerOptions[i];
	print(ao.Value);
}
//get subQuesion of a grid question 
Questionnaire qnaire = new Questionnaire (17148177);
QuestionnaireTemplate qt = new QuestionnaireTemplate (qnaire.TemplateId);
QuestionTemplate q = qt.GetQuestion("Q2");
print(q.SubQuestions);//{SubQuestion,...}
	for(i for 0; q.SubQuestions.Count){
	SubQuestion sq = q.SubQuestions[i];
	print(sq.Text.ToDictionary());
}