Difference between revisions of "QuestionGroupBranch class"
(4 intermediate revisions by the same user not shown) | |||
Line 2: | Line 2: | ||
|Name=<nowiki>QuestionGroupBranch</nowiki> | |Name=<nowiki>QuestionGroupBranch</nowiki> | ||
|Description=<nowiki>Question group.</nowiki> | |Description=<nowiki>Question group.</nowiki> | ||
+ | |InheritsFrom=QuestionGroupTree|Constructors= | ||
+ | {{CGscriptConstructors_Template|Parameters= | ||
+ | {{CGscriptParameters_Template|Type=string|Name=<nowiki>name</nowiki>|Description=<nowiki>Group name</nowiki>|Comma=,}}{{CGscriptParameters_Template|Type=QuestionnaireTemplate|Name=<nowiki>qt</nowiki>|Description=<nowiki>Questionnaire template</nowiki>}} | ||
+ | |Description=<nowiki>Create a brand group</nowiki>}} | ||
|Methods= | |Methods= | ||
− | {{CGscriptMethods_Template|ReturnType=Array of QuestionGroupTree|Name=<nowiki>GetChildGroups</nowiki>|Description=<nowiki>Return all child groups | + | {{CGscriptMethods_Template|ReturnType=Array of QuestionGroupTree|Name=<nowiki>GetChildGroups</nowiki>|Description=<nowiki>Return all child groups.</nowiki>}} |
− | {{CGscriptMethods_Template|ReturnType=string|Name=<nowiki>ToString</nowiki>|Description=<nowiki>The string representation of the object.</nowiki>}} | + | {{CGscriptMethods_Template|ReturnType=Empty|Name=<nowiki>SetChildGroups</nowiki>|Parameters= |
+ | {{CGscriptParameters_Template|Type=Array of QuestionGroupTree|Name=<nowiki>groups</nowiki>|Description=<nowiki>Question groups</nowiki>}} | ||
+ | |Description=<nowiki>Set child groups.</nowiki>}} | ||
+ | {{CGscriptMethods_Template|ReturnType=string|Name=<nowiki>ToString</nowiki>|Inherited=object|Description=<nowiki>The string representation of the object.</nowiki>}} | ||
|Properties= | |Properties= | ||
− | {{CGscriptProperties_Template|ReturnType=Array of strings|Name=<nowiki>AllQuestions</nowiki>|HasGetter=1|Description=<nowiki>Labels of all questions in this group</nowiki>}} | + | {{CGscriptProperties_Template|ReturnType=Array of strings|Name=<nowiki>AllQuestions</nowiki>|HasGetter=1|Inherited=QuestionGroupTree|Description=<nowiki>Labels of all questions in this group</nowiki>}} |
{{CGscriptProperties_Template|ReturnType=int|Name=<nowiki>Count</nowiki>|HasGetter=1|Description=<nowiki>How many children in this group</nowiki>}} | {{CGscriptProperties_Template|ReturnType=int|Name=<nowiki>Count</nowiki>|HasGetter=1|Description=<nowiki>How many children in this group</nowiki>}} | ||
− | {{CGscriptProperties_Template|ReturnType=string|Name=<nowiki>GroupName</nowiki>|HasGetter=1|Description=<nowiki>Name of question group</nowiki>}} | + | {{CGscriptProperties_Template|ReturnType=string|Name=<nowiki>GroupName</nowiki>|HasGetter=1|HasSetter=1|Inherited=QuestionGroupTree|Description=<nowiki>Name of question group</nowiki>}} |
+ | {{CGscriptProperties_Template|ReturnType=bool|Name=<nowiki>IsLeaf</nowiki>|HasGetter=1|Inherited=QuestionGroupTree|Description=<nowiki>Check if it is leaf group or not</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= | + | {{CGscriptProperties_Template|ReturnType=number|Name=<nowiki>SelectCount</nowiki>|HasGetter=1|HasSetter=1|Inherited=QuestionGroupTree|Description=<nowiki>How many child items will be used for Sequence_Command_RandomizedSelect or Sequence_Command_RotateSelect</nowiki>}} |
− | {{CGscriptProperties_Template|ReturnType=TypeInformation|Name=<nowiki>TypeInformation</nowiki>|HasGetter=1|Description=<nowiki>Get information about this class.</nowiki>}} | + | {{CGscriptProperties_Template|ReturnType=SequenceCommand constant|Name=<nowiki>SequenceCommand</nowiki>|HasGetter=1|HasSetter=1|Inherited=QuestionGroupTree|Description=<nowiki>Which kind of this group is it, use constant Sequence_Command_xxx</nowiki>}} |
+ | {{CGscriptProperties_Template|ReturnType=string|Name=<nowiki>SequenceType</nowiki>|HasGetter=1|Inherited=QuestionGroupTree|Description=<nowiki>Respent SequenceCommand as string</nowiki>}} | ||
+ | {{CGscriptProperties_Template|ReturnType=TypeInformation|Name=<nowiki>TypeInformation</nowiki>|HasGetter=1|Inherited=object|Description=<nowiki>Get information about this class.</nowiki>}} | ||
}} | }} | ||
+ | |||
=== <span style="color:#DF8621">'''Examples'''</span> === | === <span style="color:#DF8621">'''Examples'''</span> === | ||
<source lang="javascript"> | <source lang="javascript"> | ||
− | number qnaireRId = | + | //find a group by its name |
+ | number qnaireRId = 17148177; | ||
QuestionGroupRoot root = Questionnaire_getQuestionGroups(qnaireRId); | QuestionGroupRoot root = Questionnaire_getQuestionGroups(qnaireRId); | ||
+ | //QuestionGroupRoot root = new QuestionnaireTemplate(new Questionnaire(17148177).TemplateId).Groups; | ||
QuestionGroupBranch branch = root.FindByName("G1"); | QuestionGroupBranch branch = root.FindByName("G1"); | ||
print(branch.GroupName);//G1 | print(branch.GroupName);//G1 | ||
+ | </source> | ||
+ | <source lang="javascript"> | ||
+ | //create new group branch | ||
+ | Questionnaire qnaire = new Questionnaire (17148177); | ||
+ | QuestionnaireTemplate qt = new QuestionnaireTemplate (qnaire.TemplateId); | ||
+ | QuestionGroupBranch branch = new QuestionGroupBranch ("G1", qt); | ||
+ | QuestionGroupLeaf leaf = qt.Groups.FindByQuestion("Q1"); | ||
+ | branch.SetChildGroups({leaf}); | ||
+ | //add new group to group root | ||
+ | array groupRoot = qt.Groups.GetChildGroups(); | ||
+ | groupRoot.Remove(leaf); | ||
+ | groupRoot.Add(branch); | ||
+ | qt.Groups.SetChildGroups(groupRoot); | ||
+ | qt.Save(true); | ||
+ | </source> | ||
+ | <source lang="javascript"> | ||
+ | //add more goup leaf to a group branch | ||
+ | Questionnaire qnaire = new Questionnaire (17148177); | ||
+ | QuestionnaireTemplate qt = new QuestionnaireTemplate (qnaire.TemplateId); | ||
+ | QuestionGroupBranch branch = qt.Groups.FindByName("G1"); | ||
+ | QuestionGroupLeaf leaf = qt.Groups.FindByQuestion("Q2"); | ||
+ | array childGroup = branch.GetChildGroups(); | ||
+ | childGroup.Add(leaf);//add the leaf to branch | ||
+ | branch.SetChildGroups(childGroup);//reset group branch | ||
+ | array groupRoot = qt.Groups.GetChildGroups(); | ||
+ | groupRoot.Remove(leaf);// remove the leaf from root | ||
+ | qt.Groups.SetChildGroups(groupRoot);// reset group root | ||
+ | qt.Save(true); | ||
</source> | </source> |
Latest revision as of 10:19, 11 May 2022
QuestionGroupBranch
Question group.
Parent class
Inherits from QuestionGroupTree
Constructors
- (string name "Group name", QuestionnaireTemplate qt "Questionnaire template") - Create a brand group
Methods
- Array of QuestionGroupTree GetChildGroups() - Return all child groups.
- Empty SetChildGroups(Array of QuestionGroupTree groups "Question groups") - Set child groups.
- (From object) string ToString() - The string representation of the object.
Properties
- (From QuestionGroupTree) Array of string AllQuestions { get; } - Labels of all questions in this group
- int Count { get; } - How many children in this group
- (From QuestionGroupTree) string GroupName { get; set; } - Name of question group
- (From QuestionGroupTree) bool IsLeaf { get; } - Check if it is leaf group or not
- string ObjectTypeName { get; } - The name of the type of object.
- (From QuestionGroupTree) number SelectCount { get; set; } - How many child items will be used for Sequence_Command_RandomizedSelect or Sequence_Command_RotateSelect
- (From QuestionGroupTree) SequenceCommand constant SequenceCommand { get; set; } - Which kind of this group is it, use constant Sequence_Command_xxx
- (From QuestionGroupTree) string SequenceType { get; } - Respent SequenceCommand as string
- (From object) TypeInformation TypeInformation { get; } - Get information about this class.
Examples
//find a group by its name
number qnaireRId = 17148177;
QuestionGroupRoot root = Questionnaire_getQuestionGroups(qnaireRId);
//QuestionGroupRoot root = new QuestionnaireTemplate(new Questionnaire(17148177).TemplateId).Groups;
QuestionGroupBranch branch = root.FindByName("G1");
print(branch.GroupName);//G1
//create new group branch
Questionnaire qnaire = new Questionnaire (17148177);
QuestionnaireTemplate qt = new QuestionnaireTemplate (qnaire.TemplateId);
QuestionGroupBranch branch = new QuestionGroupBranch ("G1", qt);
QuestionGroupLeaf leaf = qt.Groups.FindByQuestion("Q1");
branch.SetChildGroups({leaf});
//add new group to group root
array groupRoot = qt.Groups.GetChildGroups();
groupRoot.Remove(leaf);
groupRoot.Add(branch);
qt.Groups.SetChildGroups(groupRoot);
qt.Save(true);
//add more goup leaf to a group branch
Questionnaire qnaire = new Questionnaire (17148177);
QuestionnaireTemplate qt = new QuestionnaireTemplate (qnaire.TemplateId);
QuestionGroupBranch branch = qt.Groups.FindByName("G1");
QuestionGroupLeaf leaf = qt.Groups.FindByQuestion("Q2");
array childGroup = branch.GetChildGroups();
childGroup.Add(leaf);//add the leaf to branch
branch.SetChildGroups(childGroup);//reset group branch
array groupRoot = qt.Groups.GetChildGroups();
groupRoot.Remove(leaf);// remove the leaf from root
qt.Groups.SetChildGroups(groupRoot);// reset group root
qt.Save(true);