Difference between revisions of "QuestionTemplate class"
Line 119: | Line 119: | ||
</source> | </source> | ||
<source lang="javascript"> | <source lang="javascript"> | ||
− | //get subQuesion of a | + | //get subQuesion of a grid question |
Questionnaire qnaire = new Questionnaire (17148177); | Questionnaire qnaire = new Questionnaire (17148177); | ||
QuestionnaireTemplate qt = new QuestionnaireTemplate (qnaire.TemplateId); | QuestionnaireTemplate qt = new QuestionnaireTemplate (qnaire.TemplateId); |
Latest revision as of 06:09, 11 May 2022
QuestionTemplate
The question template. Implemented serialization
Parent class
Inherits from object
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
- (From object) string ToString() - The string representation of the object.
Properties
- array AnswerOptions { get; } - Get configuration answer options of this question template. Item type is AnswerOption
- array 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
- string ObjectTypeName { get; } - The name of the type of object.
- array Properties { get; } - Get configuration properties of this question template. Item type is QuestionProperty
- array SubQuestions { get; } - Get configuration answer options of this question template. Item type is SubQuestion
- LocalizedString Text { get; set; } - Question text
- QuestionType constant Type { get; set; } - Question type, use constant Question_Type_xxx
- (From object) TypeInformation TypeInformation { get; } - Get information about this class.
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());
}