Difference between revisions of "Question class"

From Catglobe Wiki
Jump to: navigation, search
 
(17 intermediate revisions by the same user not shown)
Line 2: Line 2:
 
|Name=<nowiki>Question</nowiki>
 
|Name=<nowiki>Question</nowiki>
 
|Description=<nowiki>Base class for all question types</nowiki>
 
|Description=<nowiki>Base class for all question types</nowiki>
|Methods=
+
|InheritsFrom=object|Methods=
 
{{CGscriptMethods_Template|ReturnType=object|Name=<nowiki>AsValue</nowiki>|Description=<nowiki>Convert the Question to plain object</nowiki>}}
 
{{CGscriptMethods_Template|ReturnType=object|Name=<nowiki>AsValue</nowiki>|Description=<nowiki>Convert the Question to plain object</nowiki>}}
 +
{{CGscriptMethods_Template|ReturnType=Empty|Name=<nowiki>Set</nowiki>|Parameters=
 +
{{CGscriptParameters_Template|Type=object|Name=<nowiki>value</nowiki>|Description=<nowiki>New value for question</nowiki>}}
 +
|Description=<nowiki>Update the question with the given value</nowiki>}}
 
{{CGscriptMethods_Template|ReturnType=string|Name=<nowiki>ToString</nowiki>|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>}}
 
|Properties=
 
|Properties=
{{CGscriptProperties_Template|ReturnType=string|Name=<nowiki>ObjectTypeName</nowiki>|HasGetter=1|Description=<nowiki>The name of the type of object.</nowiki>}}
+
{{CGscriptProperties_Template|ReturnType=bool|Name=<nowiki>IsChanged</nowiki>|HasGetter=1|Description=<nowiki>True if the value of the question has changed</nowiki>}}
{{CGscriptProperties_Template|ReturnType=TypeInformation|Name=<nowiki>TypeInformation</nowiki>|HasGetter=1|Description=<nowiki>Get information about this class.</nowiki>}}
+
{{CGscriptProperties_Template|ReturnType=string|Name=<nowiki>ObjectTypeName</nowiki>|HasGetter=1|Inherited=object|Description=<nowiki>The name of the type of object.</nowiki>}}
 +
{{CGscriptProperties_Template|ReturnType=int|Name=<nowiki>QasId</nowiki>|HasGetter=1|Description=<nowiki>Id of the qas. 0 if no stored data.</nowiki>}}
 +
{{CGscriptProperties_Template|ReturnType=string|Name=<nowiki>QuestionLabel</nowiki>|HasGetter=1|Description=<nowiki>Label of the question</nowiki>}}
 +
{{CGscriptProperties_Template|ReturnType=TypeInformation|Name=<nowiki>TypeInformation</nowiki>|HasGetter=1|Inherited=object|Description=<nowiki>Get information about this class.</nowiki>}}
 +
{{CGscriptProperties_Template|ReturnType=int|Name=<nowiki>UserId</nowiki>|HasGetter=1|Description=<nowiki>Id of the user. 0 if no user or no stored data.</nowiki>}}
 
|StaticMethods=
 
|StaticMethods=
 
{{CGscriptMethods_Template|ReturnType=array|Name=<nowiki>Question_getLabelsOfLoadedQuestions</nowiki>|Description=<nowiki>Get labels of the questions that have been loaded in current session and might be saved upon completion</nowiki>}}
 
{{CGscriptMethods_Template|ReturnType=array|Name=<nowiki>Question_getLabelsOfLoadedQuestions</nowiki>|Description=<nowiki>Get labels of the questions that have been loaded in current session and might be saved upon completion</nowiki>}}
 +
{{CGscriptMethods_Template|ReturnType=Array of Question|Name=<nowiki>Question_loadQuestionFromQuestionnaire</nowiki>|Parameters=
 +
{{CGscriptParameters_Template|Type=int|Name=<nowiki>questionnaireId</nowiki>|Description=<nowiki>Id of the questionnaire to load from. 0 to use context</nowiki>|Comma=,}}{{CGscriptParameters_Template|Type=string|Name=<nowiki>questionLabel</nowiki>|Description=<nowiki>Label of the question to load</nowiki>|Comma=,}}{{CGscriptParameters_Template|Type=bool|Name=<nowiki>latestOnly</nowiki>|Description=<nowiki>If user has multiple qas, only include last created</nowiki>|Comma=,}}{{CGscriptParameters_Template|Type=bool|Name=<nowiki>completedOnly</nowiki>|Description=<nowiki>Limit by qas that is completed</nowiki>}}
 +
|Description=<nowiki>Load all question from questionnaire</nowiki>}}
 +
{{CGscriptMethods_Template|ReturnType=Array of Question|Name=<nowiki>Question_loadQuestionFromQuestionnaire</nowiki>|Parameters=
 +
{{CGscriptParameters_Template|Type=int|Name=<nowiki>questionnaireId</nowiki>|Description=<nowiki>Id of the questionnaire to load from. 0 to use context</nowiki>|Comma=,}}{{CGscriptParameters_Template|Type=string|Name=<nowiki>questionLabel</nowiki>|Description=<nowiki>Label of the question to load</nowiki>|Comma=,}}{{CGscriptParameters_Template|Type=bool|Name=<nowiki>latestOnly</nowiki>|Description=<nowiki>If user has multiple qas, only include last created</nowiki>|Comma=,}}{{CGscriptParameters_Template|Type=bool|Name=<nowiki>completedOnly</nowiki>|Description=<nowiki>Limit by qas that is completed</nowiki>|Comma=,}}{{CGscriptParameters_Template|Type=int|Name=<nowiki>limitByQuestionnaireId</nowiki>|Description=<nowiki>Limit by users that participated in this questionnaire</nowiki>|Comma=,}}{{CGscriptParameters_Template|Type=bool|Name=<nowiki>limitByCompletedQuestionnaireId</nowiki>|Description=<nowiki>Limit by qas that is completed the limitByQuestionnaireId</nowiki>}}
 +
|Description=<nowiki>Load all question from questionnaire</nowiki>}}
 
{{CGscriptMethods_Template|ReturnType=Dictionary|Name=<nowiki>Question_loadQuestions</nowiki>|Description=<nowiki>Load questions</nowiki>}}
 
{{CGscriptMethods_Template|ReturnType=Dictionary|Name=<nowiki>Question_loadQuestions</nowiki>|Description=<nowiki>Load questions</nowiki>}}
 
{{CGscriptMethods_Template|ReturnType=Dictionary|Name=<nowiki>Question_loadQuestions</nowiki>|Parameters=
 
{{CGscriptMethods_Template|ReturnType=Dictionary|Name=<nowiki>Question_loadQuestions</nowiki>|Parameters=
Line 19: Line 32:
 
{{CGscriptMethods_Template|ReturnType=Empty|Name=<nowiki>Question_saveQuestions</nowiki>|Parameters=
 
{{CGscriptMethods_Template|ReturnType=Empty|Name=<nowiki>Question_saveQuestions</nowiki>|Parameters=
 
{{CGscriptParameters_Template|Type=Dictionary|Name=<nowiki>questionData</nowiki>|Description=<nowiki>Dictionary of labels and data</nowiki>|Comma=,}}{{CGscriptParameters_Template|Type=QAS|Name=<nowiki>qas</nowiki>|Description=<nowiki>Qas to save data to</nowiki>}}
 
{{CGscriptParameters_Template|Type=Dictionary|Name=<nowiki>questionData</nowiki>|Description=<nowiki>Dictionary of labels and data</nowiki>|Comma=,}}{{CGscriptParameters_Template|Type=QAS|Name=<nowiki>qas</nowiki>|Description=<nowiki>Qas to save data to</nowiki>}}
|Description=<nowiki>Save questions</nowiki>}}
+
|Description=<nowiki>Change questions</nowiki>}}
 
{{CGscriptMethods_Template|ReturnType=Empty|Name=<nowiki>Question_unloadAll</nowiki>|Description=<nowiki>Save and remove all loaded questions. Useful if a called script is expected to change current values. Only deletes those referenced directly through question variables.</nowiki>}}
 
{{CGscriptMethods_Template|ReturnType=Empty|Name=<nowiki>Question_unloadAll</nowiki>|Description=<nowiki>Save and remove all loaded questions. Useful if a called script is expected to change current values. Only deletes those referenced directly through question variables.</nowiki>}}
 
}}
 
}}
 +
 +
 +
 +
=== <span style="color:#DF8621">'''See more '''</span> ===
 +
 +
* [[PageQuestion_class]]
 +
 +
* [[SingleQuestion_class]]
 +
 +
* [[MultiQuestion_class]]
 +
 +
* [[TextQuestion_class]]
 +
 +
* [[ScaleQuestion_class]]
 +
 +
* [[NumberQuestion_class]]
 +
 +
* [[OpenQuestion_class]]
 +
 +
* [[SingleGridQuestion_class]]
 +
 +
* [[MultiGridQuestion_class]]
 +
 +
* [[TextGridQuestion_class]]
 +
 +
* [[ScaleGridQuestion_class]]
 +
 +
* [[MultimediaQuestion_class]]
 +
 
=== <span style="color:#DF8621">'''Examples'''</span> ===
 
=== <span style="color:#DF8621">'''Examples'''</span> ===
 
<span style="color:#DF8621"> Question_getLabelsOfLoadedQuestions </span>
 
<span style="color:#DF8621"> Question_getLabelsOfLoadedQuestions </span>
Line 40: Line 82:
 
Question_loadQuestions({"Q2Single","Q3Multi","Q4Text"});
 
Question_loadQuestions({"Q2Single","Q3Multi","Q4Text"});
 
//then working with Q2Single, Q3Multi, Q4Text as normal
 
//then working with Q2Single, Q3Multi, Q4Text as normal
 +
</source>
 +
 +
<span style="color:#DF8621"> Question_saveQuestions </span>
 +
<source lang="javascript">
 +
//Load questions
 +
Dictionary d = Question_loadQuestions ({"Q2Single","Q3Multi","Q4Text"}, new QAS (118108496));
 +
//for load all questions from target qas, use empty at question array: Question_loadQuestions (empty, new QAS (118108496))
 +
print(d);//{"Q2Single": 1, "Q3Multi": {True,False,False,True}, "Q4Text":  string test}
 +
//Create new qas
 +
QAS qas = new QAS (15723782, 0);
 +
qas.Save();
 +
//set data for new rpq by copy form rpq 118108496
 +
Question_saveQuestions(d, qas);
 +
//print data
 +
qas.MakeCurrentQAS();
 +
print(Q2Single);//1
 +
print(Q3Multi);//{True,False,False,True}
 +
print(Q4Text);//string test
 +
</source>
 +
<span style="color:#DF8621"> Question_saveQuestions </span>
 +
<source lang="javascript">
 +
QAS qas = new QAS (15723782,0);
 +
qas.Save();
 +
Dictionary d = {
 +
"Q2Single": 1,
 +
"Q3Multi": {true,false,false,true},
 +
"Q4Text": "test",
 +
"Q5Scale": 2,
 +
"Q6Number": 3,
 +
"Q7OPen": "open",
 +
"Q8SingleGrid": {1,2},
 +
"Q9MutiGrid": {{true,false},{false, true}},
 +
"Q10TextGrid": {"test1","test2"},
 +
"Q11ScaleGrid": {3,5}
 +
};
 +
Question_saveQuestions(d, qas);
 +
</source>
 +
 +
<span style="color:#DF8621"> Question_saveQuestions </span>
 +
<source lang="javascript">
 +
 +
setRPQId(118108530);
 +
Dictionary d = {
 +
"Q2Single": Q2Single,
 +
"Q3Multi": Q3Multi,
 +
"Q4Text": Q4Text,
 +
"Q5Scale": Q5Scale,
 +
"Q6Number": Q6Number,
 +
"Q7OPen": Q7OPen,
 +
"Q8SingleGrid": Q8SingleGrid,
 +
"Q9MutiGrid": Q9MutiGrid,
 +
"Q10TextGrid": Q10TextGrid,
 +
"Q11ScaleGrid": Q11ScaleGrid
 +
};
 +
QAS qas = new QAS (15725032,0);
 +
qas.Save();
 +
Question_saveQuestions(d, qas);
 +
</source>
 +
 +
<span style="color:#DF8621"> Question.Set()  Question.AsValue() and Question.IsChanged </span>
 +
<source lang="javascript">
 +
setRPQId(118108496);
 +
print(Q2Single.IsChanged);//False
 +
Q2Single.Set(1);
 +
number value = Q2Single.AsValue();
 +
print(value);//1
 +
print(Q2Single.IsChanged);//True
 +
</source>
 +
 +
<span style="color:#DF8621"> Question_loadQuestionFromQuestionnaire</span>
 +
<source lang="javascript">
 +
//ex script for copying data from another qnaire (it works same as the way getQuestion run on batchmode)
 +
Array  fromCurrentQnaire = Question_loadQuestionFromQuestionnaire(currentQnaireId, "Zipcode", true, false);
 +
Dictionary fromSourceQnaire = Question_loadQuestionFromQuestionnaire(sourceQnaireId, "Zipcode", true, false, currentQnaireId, false).ToDictionary(function(Question q) {q.UserId;});
 +
 +
for(i for 0; fromCurrentQnaire.Count) {
 +
Question cur = fromCurrentQnaire[i];
 +
Question o = fromSourceQnaire.TryGetValue(cur.UserId);
 +
if (o == empty) continue;
 +
cur.Set(o);
 +
}
 
</source>
 
</source>

Latest revision as of 11:40, 31 May 2024

Question



Base class for all question types

Parent class

Inherits from object

Methods

  • object AsValue() - Convert the Question to plain object
  • Empty Set(object value "New value for question") - Update the question with the given value
  • string ToString() - The string representation of the object.

Properties

  • bool IsChanged { get; } - True if the value of the question has changed
  • (From object) string ObjectTypeName { get; } - The name of the type of object.
  • int QasId { get; } - Id of the qas. 0 if no stored data.
  • string QuestionLabel { get; } - Label of the question
  • (From object) TypeInformation TypeInformation { get; } - Get information about this class.
  • int UserId { get; } - Id of the user. 0 if no user or no stored data.

Static Methods

  • array Question_getLabelsOfLoadedQuestions() - Get labels of the questions that have been loaded in current session and might be saved upon completion
  • Array of Question Question_loadQuestionFromQuestionnaire(int questionnaireId "Id of the questionnaire to load from. 0 to use context", string questionLabel "Label of the question to load", bool latestOnly "If user has multiple qas, only include last created", bool completedOnly "Limit by qas that is completed") - Load all question from questionnaire
  • Array of Question Question_loadQuestionFromQuestionnaire(int questionnaireId "Id of the questionnaire to load from. 0 to use context", string questionLabel "Label of the question to load", bool latestOnly "If user has multiple qas, only include last created", bool completedOnly "Limit by qas that is completed", int limitByQuestionnaireId "Limit by users that participated in this questionnaire", bool limitByCompletedQuestionnaireId "Limit by qas that is completed the limitByQuestionnaireId") - Load all question from questionnaire
  • Dictionary Question_loadQuestions() - Load questions
  • Dictionary Question_loadQuestions(array questionLabels "Labels of the questions to load") - Load questions
  • Dictionary Question_loadQuestions(array questionLabels "Labels of the questions to load", QAS qas "Qas to load data from") - Load questions
  • Empty Question_saveQuestions(Dictionary questionData "Dictionary of labels and data", QAS qas "Qas to save data to") - Change questions
  • Empty Question_unloadAll() - Save and remove all loaded questions. Useful if a called script is expected to change current values. Only deletes those referenced directly through question variables.


See more

Examples

Question_getLabelsOfLoadedQuestions

//run in questionnaire context
number a = Q2Single;
array b = Q3Multi;
string c = Q4Text;
//...
array loadedQuestions = Question_getLabelsOfLoadedQuestions();
print(loadedQuestions);//{Q2Single,Q3Multi,Q4Text}

Question_loadQuestions

//run in questionnaire context
//Add this line to the top of script to increase performance
Question_loadQuestions({"Q2Single","Q3Multi","Q4Text"});
//then working with Q2Single, Q3Multi, Q4Text as normal

Question_saveQuestions

//Load questions
Dictionary d = Question_loadQuestions ({"Q2Single","Q3Multi","Q4Text"}, new QAS (118108496));
//for load all questions from target qas, use empty at question array: Question_loadQuestions (empty, new QAS (118108496))
print(d);//{"Q2Single": 1, "Q3Multi": {True,False,False,True}, "Q4Text":  string test}
//Create new qas
QAS qas = new QAS (15723782, 0);
qas.Save();
//set data for new rpq by copy form rpq 118108496 
Question_saveQuestions(d, qas);
//print data
qas.MakeCurrentQAS();
print(Q2Single);//1
print(Q3Multi);//{True,False,False,True}
print(Q4Text);//string test

Question_saveQuestions

QAS qas = new QAS (15723782,0);
qas.Save();
Dictionary d = {
"Q2Single": 1,
"Q3Multi": {true,false,false,true},
"Q4Text": "test",
"Q5Scale": 2,
"Q6Number": 3,
"Q7OPen": "open",
"Q8SingleGrid": {1,2},
"Q9MutiGrid": {{true,false},{false, true}},
"Q10TextGrid": {"test1","test2"},
"Q11ScaleGrid": {3,5}
};
Question_saveQuestions(d, qas);

Question_saveQuestions

setRPQId(118108530);
Dictionary d = {
"Q2Single": Q2Single,
"Q3Multi": Q3Multi,
"Q4Text": Q4Text,
"Q5Scale": Q5Scale,
"Q6Number": Q6Number,
"Q7OPen": Q7OPen,
"Q8SingleGrid": Q8SingleGrid,
"Q9MutiGrid": Q9MutiGrid,
"Q10TextGrid": Q10TextGrid,
"Q11ScaleGrid": Q11ScaleGrid
};
QAS qas = new QAS (15725032,0);
qas.Save();
Question_saveQuestions(d, qas);

Question.Set() Question.AsValue() and Question.IsChanged

setRPQId(118108496);
print(Q2Single.IsChanged);//False
Q2Single.Set(1);
number value = Q2Single.AsValue();
print(value);//1
print(Q2Single.IsChanged);//True

Question_loadQuestionFromQuestionnaire

//ex script for copying data from another qnaire (it works same as the way getQuestion run on batchmode)
Array  fromCurrentQnaire = Question_loadQuestionFromQuestionnaire(currentQnaireId, "Zipcode", true, false);
Dictionary fromSourceQnaire = Question_loadQuestionFromQuestionnaire(sourceQnaireId, "Zipcode", true, false, currentQnaireId, false).ToDictionary(function(Question q) {q.UserId;});

for(i for 0; fromCurrentQnaire.Count) {
	Question cur = fromCurrentQnaire[i];
	Question o = fromSourceQnaire.TryGetValue(cur.UserId);
	if (o == empty) continue;
	cur.Set(o);
}