Jump to content
Toggle menu
  • 915 articles
  • 3.8K files
  • 30.2K users
  • 279.2K edits
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

From Catglobe Wiki

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

  • 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. Use 0 for context") - Returns the question at the given index for the specified Questionnaire
  • array QuestionTemplate_getQuestions(int questionnaireId "The Questionnaire resource id. Use 0 for context") - 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());
}