Difference between revisions of "QAS class"
(3 intermediate revisions by the same user not shown) | |||
Line 11: | Line 11: | ||
{{CGscriptConstructors_Template|Parameters= | {{CGscriptConstructors_Template|Parameters= | ||
{{CGscriptParameters_Template|Type=int|Name=<nowiki>QuestionnaireResourceId</nowiki>|Description=<nowiki>Questionnaire resource id</nowiki>|Comma=,}}{{CGscriptParameters_Template|Type=int|Name=<nowiki>UserResourceId</nowiki>|Description=<nowiki>User resource id. 0 to use current.</nowiki>}} | {{CGscriptParameters_Template|Type=int|Name=<nowiki>QuestionnaireResourceId</nowiki>|Description=<nowiki>Questionnaire resource id</nowiki>|Comma=,}}{{CGscriptParameters_Template|Type=int|Name=<nowiki>UserResourceId</nowiki>|Description=<nowiki>User resource id. 0 to use current.</nowiki>}} | ||
+ | |Description=<nowiki>Create new qas.</nowiki>}} | ||
+ | {{CGscriptConstructors_Template|Parameters= | ||
+ | {{CGscriptParameters_Template|Type=int|Name=<nowiki>QuestionnaireResourceId</nowiki>|Description=<nowiki>Questionnaire resource id</nowiki>|Comma=,}}{{CGscriptParameters_Template|Type=int|Name=<nowiki>UserResourceId</nowiki>|Description=<nowiki>User resource id. 0 to use current.</nowiki>|Comma=,}}{{CGscriptParameters_Template|Type=bool|Name=<nowiki>setTest</nowiki>|Description=<nowiki>Set QAS to test.</nowiki>}} | ||
|Description=<nowiki>Create new qas.</nowiki>}} | |Description=<nowiki>Create new qas.</nowiki>}} | ||
|Methods= | |Methods= | ||
Line 28: | Line 31: | ||
{{CGscriptParameters_Template|Type=Function|Name=<nowiki>selector</nowiki>|Description=<nowiki>A function to test each element for a condition.</nowiki>}} | {{CGscriptParameters_Template|Type=Function|Name=<nowiki>selector</nowiki>|Description=<nowiki>A function to test each element for a condition.</nowiki>}} | ||
|Description=<nowiki>Returns the first element in a sequence that satisfies a specified condition or empty if not found.</nowiki>}} | |Description=<nowiki>Returns the first element in a sequence that satisfies a specified condition or empty if not found.</nowiki>}} | ||
+ | {{CGscriptMethods_Template|ReturnType=Empty|Name=<nowiki>Foreach</nowiki>|Inherited=array|Parameters= | ||
+ | {{CGscriptParameters_Template|Type=Function|Name=<nowiki>function</nowiki>|Description=<nowiki>A function that takes 1 parameter of the types in the array, and an optional 2nd parameter that is the index</nowiki>}} | ||
+ | |Description=<nowiki>Filters a sequence of values based on a predicate.</nowiki>}} | ||
{{CGscriptMethods_Template|ReturnType=int|Name=<nowiki>Frequency</nowiki>|Inherited=array|Parameters= | {{CGscriptMethods_Template|ReturnType=int|Name=<nowiki>Frequency</nowiki>|Inherited=array|Parameters= | ||
{{CGscriptParameters_Template|Type=number|Name=<nowiki>number</nowiki>|Description=<nowiki>The number to search for</nowiki>}} | {{CGscriptParameters_Template|Type=number|Name=<nowiki>number</nowiki>|Description=<nowiki>The number to search for</nowiki>}} | ||
Line 141: | Line 147: | ||
{{CGscriptMethods_Template|ReturnType=Array of QAS|Name=<nowiki>QAS_getByUserResourceId</nowiki>|Parameters= | {{CGscriptMethods_Template|ReturnType=Array of QAS|Name=<nowiki>QAS_getByUserResourceId</nowiki>|Parameters= | ||
{{CGscriptParameters_Template|Type=int|Name=<nowiki>userResourceId</nowiki>|Description=<nowiki>User resource id. 0 to use current.</nowiki>|Comma=,}}{{CGscriptParameters_Template|Type=int|Name=<nowiki>questionnaireResourceId</nowiki>|Description=<nowiki>Questionnaire resource id</nowiki>|Comma=,}}{{CGscriptParameters_Template|Type=bool|Name=<nowiki>createIfNone</nowiki>|Description=<nowiki>Create a new one if there are none</nowiki>}} | {{CGscriptParameters_Template|Type=int|Name=<nowiki>userResourceId</nowiki>|Description=<nowiki>User resource id. 0 to use current.</nowiki>|Comma=,}}{{CGscriptParameters_Template|Type=int|Name=<nowiki>questionnaireResourceId</nowiki>|Description=<nowiki>Questionnaire resource id</nowiki>|Comma=,}}{{CGscriptParameters_Template|Type=bool|Name=<nowiki>createIfNone</nowiki>|Description=<nowiki>Create a new one if there are none</nowiki>}} | ||
+ | |Description=<nowiki>Get a list of qas by the specified user and questionnaire. Ordered by Created date, latest first.</nowiki>}} | ||
+ | {{CGscriptMethods_Template|ReturnType=Array of QAS|Name=<nowiki>QAS_getByUserResourceId</nowiki>|Parameters= | ||
+ | {{CGscriptParameters_Template|Type=int|Name=<nowiki>userResourceId</nowiki>|Description=<nowiki>User resource id. 0 to use current.</nowiki>|Comma=,}}{{CGscriptParameters_Template|Type=int|Name=<nowiki>questionnaireResourceId</nowiki>|Description=<nowiki>Questionnaire resource id</nowiki>|Comma=,}}{{CGscriptParameters_Template|Type=bool|Name=<nowiki>createIfNone</nowiki>|Description=<nowiki>Create a new one if there are none</nowiki>|Comma=,}}{{CGscriptParameters_Template|Type=bool|Name=<nowiki>setTestIfCreate</nowiki>|Description=<nowiki>If creating new, set as test</nowiki>}} | ||
|Description=<nowiki>Get a list of qas by the specified user and questionnaire. Ordered by Created date, latest first.</nowiki>}} | |Description=<nowiki>Get a list of qas by the specified user and questionnaire. Ordered by Created date, latest first.</nowiki>}} | ||
{{CGscriptMethods_Template|ReturnType=Array of QAS|Name=<nowiki>QAS_getByUserResourceIds</nowiki>|Parameters= | {{CGscriptMethods_Template|ReturnType=Array of QAS|Name=<nowiki>QAS_getByUserResourceIds</nowiki>|Parameters= | ||
Line 172: | Line 181: | ||
{{CGscriptMethods_Template|ReturnType=QAS|Name=<nowiki>QAS_new</nowiki>|Parameters= | {{CGscriptMethods_Template|ReturnType=QAS|Name=<nowiki>QAS_new</nowiki>|Parameters= | ||
{{CGscriptParameters_Template|Type=int|Name=<nowiki>questionnaireResourceId</nowiki>|Description=<nowiki>Questionnaire resource id</nowiki>|Comma=,}}{{CGscriptParameters_Template|Type=int|Name=<nowiki>userResourceId</nowiki>|Description=<nowiki>User resource id. 0 to use current.</nowiki>}} | {{CGscriptParameters_Template|Type=int|Name=<nowiki>questionnaireResourceId</nowiki>|Description=<nowiki>Questionnaire resource id</nowiki>|Comma=,}}{{CGscriptParameters_Template|Type=int|Name=<nowiki>userResourceId</nowiki>|Description=<nowiki>User resource id. 0 to use current.</nowiki>}} | ||
+ | |Description=<nowiki>Create new qas.</nowiki>}} | ||
+ | {{CGscriptMethods_Template|ReturnType=QAS|Name=<nowiki>QAS_new</nowiki>|Parameters= | ||
+ | {{CGscriptParameters_Template|Type=int|Name=<nowiki>questionnaireResourceId</nowiki>|Description=<nowiki>Questionnaire resource id</nowiki>|Comma=,}}{{CGscriptParameters_Template|Type=int|Name=<nowiki>userResourceId</nowiki>|Description=<nowiki>User resource id. 0 to use current.</nowiki>|Comma=,}}{{CGscriptParameters_Template|Type=bool|Name=<nowiki>setTest</nowiki>|Description=<nowiki>Set QAS to test.</nowiki>}} | ||
|Description=<nowiki>Create new qas.</nowiki>}} | |Description=<nowiki>Create new qas.</nowiki>}} | ||
{{CGscriptMethods_Template|ReturnType=QAS|Name=<nowiki>QAS_new</nowiki>|Parameters= | {{CGscriptMethods_Template|ReturnType=QAS|Name=<nowiki>QAS_new</nowiki>|Parameters= | ||
{{CGscriptParameters_Template|Type=int|Name=<nowiki>questionnaireResourceId</nowiki>|Description=<nowiki>Questionnaire resource id</nowiki>}} | {{CGscriptParameters_Template|Type=int|Name=<nowiki>questionnaireResourceId</nowiki>|Description=<nowiki>Questionnaire resource id</nowiki>}} | ||
+ | |Description=<nowiki>Create new qas for current user.</nowiki>}} | ||
+ | {{CGscriptMethods_Template|ReturnType=QAS|Name=<nowiki>QAS_new</nowiki>|Parameters= | ||
+ | {{CGscriptParameters_Template|Type=int|Name=<nowiki>questionnaireResourceId</nowiki>|Description=<nowiki>Questionnaire resource id</nowiki>|Comma=,}}{{CGscriptParameters_Template|Type=bool|Name=<nowiki>setTest</nowiki>|Description=<nowiki>Set QAS to test.</nowiki>}} | ||
|Description=<nowiki>Create new qas for current user.</nowiki>}} | |Description=<nowiki>Create new qas for current user.</nowiki>}} | ||
{{CGscriptMethods_Template|ReturnType=Array of ints|Name=<nowiki>QAS_reset</nowiki>|Parameters= | {{CGscriptMethods_Template|ReturnType=Array of ints|Name=<nowiki>QAS_reset</nowiki>|Parameters= | ||
Line 189: | Line 204: | ||
|Description=<nowiki>Set or unset completed state of given qas. When completing, EndDate is set to now, and StartDate is also set to now unless it was already set. Returns list of qas that qas NOT deleted data for.</nowiki>}} | |Description=<nowiki>Set or unset completed state of given qas. When completing, EndDate is set to now, and StartDate is also set to now unless it was already set. Returns list of qas that qas NOT deleted data for.</nowiki>}} | ||
}} | }} | ||
+ | === <span style="color:#DF8621">'''Note'''</span> === | ||
+ | Every function in QAS class that takes userResourceId such as QAS new, QAS_new, QAS_getByUserResourceId, where userResourceId: | ||
+ | * 0 is use current user | ||
+ | * -1 to force no user | ||
+ | * -2 to anonymous | ||
+ | |||
=== <span style="color:#DF8621">'''Examples'''</span> === | === <span style="color:#DF8621">'''Examples'''</span> === | ||
<span style="color:#DF8621"> Get question already viewed</span> | <span style="color:#DF8621"> Get question already viewed</span> |
Latest revision as of 04:39, 23 July 2020
QAS
Questionnaire answer sheet.
Parent class
Inherits from Array
Constructors
- (int qasId "Id of the questionnaire") - Fetch existing qas.
- (string qasGuid "Id of the questionnaire") - Fetch existing qas.
- (int QuestionnaireResourceId "Questionnaire resource id", int UserResourceId "User resource id. 0 to use current.") - Create new qas.
- (int QuestionnaireResourceId "Questionnaire resource id", int UserResourceId "User resource id. 0 to use current.", bool setTest "Set QAS to test.") - Create new qas.
Methods
- (From array) bool Any(Function predicate "A function that takes 1 parameter of the types in the array, and return true/false") - Return true if the array contains the element using the given function.
- (From array) bool Contains(object element "Element to check for") - Return true if the array contains the element using the normal equal operator.
- (From array) array Except(array elements "Elements to remove") - Return all elements that does not exist in the other collection.
- (From array) object First(Function selector "A function to test each element for a condition.") - Returns the first element in a sequence that satisfies a specified condition.
- (From array) object FirstOrDefault(Function selector "A function to test each element for a condition.") - Returns the first element in a sequence that satisfies a specified condition or empty if not found.
- (From array) Empty Foreach(Function function "A function that takes 1 parameter of the types in the array, and an optional 2nd parameter that is the index") - Filters a sequence of values based on a predicate.
- (From array) int Frequency(number number "The number to search for") - Counts the number of times a given Number object exists in the Array. Can only use if all the elements are of type Number
- object this[] { get; }(int index "Index") - Backward-compatible indexer
- QAS GetCaller() - Return the QAS that used GotoQuestionnaire to jump to this QAS. Empty if nothing on callstack
- Empty GotoQuestionnaire() - Jump to this qas. This function never returns
- (From array) int IndexOf(object element "Element to search for") - Return index of the given element, or -1.
- (From array) bool IsCharacterArray() - check if array is an array of characters
- (From array) bool IsNumericArray() - check if array is an array of integer numbers
- (From array) bool IsStringArray() - check if array is an array of string
- Empty MakeCurrentQAS() - Set as the current context qas.
- (From array) array OrderBy(Function comparer "Function that compares two objects of the same type. Must return a signed integer that indicates the relative values of first param A and second param B. Value Less than 0 : A is less than B.Value 0 : A equals B.Value Greater than 0 : A is greater than B.It can also be a function that takes 1 parameter and returns a string or number.") - Sorts the elements of a sequence in ascending order by using a specified comparer.
- (From array) Empty Randomize() - Randomize the order of the elements in the current array.
- Empty Reset() - Reset progress in current QAS without delete data.
- (From array) array Reverse() - Returns an array with all the elements in the opposite order.
- Empty Save() - Save qas.
- (From array) array Select(Function selector "A transform function to apply to each element.") - Projects each element of a sequence into a new form.
- (From array) array SelectMany(Function selector "A transform function to get each sub array.") - Projects each array element of a sequence into a new form.
- Empty this[] { set; }(int index "Index", object value "Value to set") - Backward-compatible indexer
- (From array) array Skip(int n "How many elements to skip") - Get all but the n first elements.
- (From array) array Take(int n "How many elements to take") - Get the n first elements.
- (From array) Dictionary ToDictionary(Function keySelector "A transform function to get the key of each element.") - Return a dictionary with the elements of the array.
- (From array) Dictionary ToDictionary(Function keySelector "A transform function to get the key of each element.", Function valueSelector "A transform function to get the value of each element.") - Return a dictionary with the elements of the array.
- (From Array) string ToString() - The string representation of the object.
- (From array) array Where(Function predicate "A function that takes 1 parameter of the types in the array, and an optional 2nd parameter that is the index and return true/false") - Filters a sequence of values based on a predicate.
Properties
- string AccessCode { get; } - Get the unique access code for use in login or sms-style url.
- (From array) number Average { get; } - Average of the objects in the Array object. Can only use if all the elements are of type Number
- DateTime CatiAppointment { get; set; } - When should Cati attempt to call this Qas, assuming they are on appointment or retry list.
- DateTime CatiCallTime { get; } - If meeting or retry, when will this qas be schedule for.
- int CatiList { get; set; } - Which type of cati call. 1 = main, 2 = ongoing, 3 = appointment, 4 = done, 5 = retry.
- int CatiPriority { get; set; } - Priority of call. Only used on mainlist.
- bool Completed { get; set; } - Get/set completed. Warning: Quotas will not be updated on save, use setUserProjectQuestionnaireCompleted/setRPQCompleted.
- DateTime CreatedDate { get; } - When was this qas created.
- bool Deleted { get; } - Get if marked deleted.
- DateTime EndDate { get; set; } - When was this qas finished.
- string Guid { get; } - Id of the QAS in GUID format
- int Id { get; } - Id of the QAS
- bool IsInSyncWithQuestionnaire { get; } - Return true if the version the Qas was last active on is also the current questionnaire version.
- (From array) number Max { get; } - Largest of all the objects in the Array object. Can only use if all the elements are of type Number
- (From array) 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.
- int QuestionnaireResourceId { get; } - Resource Id of the questionnaire.
- Array of string QuestionSequence { get; } - Get the expected sequence of questions to be viewed following the question group rules etc, but not any CgScript or Conditions, only accurate if IsInSyncWithQuestionnaire is true
- int QuestionSequenceIndex { get; } - Get the index into QuestionSequence of what is current question, only accurate if IsInSyncWithQuestionnaire is true
- int SampleRuleId { get; } - Id of the sample rule
- DateTime StartDate { get; set; } - When was this qas started.
- int Status { get; set; } - Current status of qas. See UserProjectQuestionnaire_Status_xxx/RPQ_Status_xxx.
- (From array) number Sum { get; } - Sum of all the objects in the Array object. Can only use if all the elements are of type Number
- bool Test { get; set; } - Get/set if test qas.
- (From object) TypeInformation TypeInformation { get; } - Get information about this class.
- int UserId { get; set; } - Get/set user the qas belongs to. May be 0 for anonymous
- int UserResourceId { get; set; } - Get/set user the qas belongs to. May be 0 for anonymous
- Array of int ViewedQuestions { get; } - Get the questions the viewed as index into QuestionSequence, only accurate if IsInSyncWithQuestionnaire is true
Static Methods
- Array of int QAS_anonymize(Array of int qasIds "List of qas ids") - Delete all user references for the qas and data. Returns list of qas that qas NOT anonymized.
- string QAS_createUniqueAccessCode(int qasId "Id of the questionnaire") - Return the unique access code for this qas.
- Array of int QAS_deleteData(Array of int qasIds "List of qas ids") - Delete data for the given qas. Returns list of qas that qas NOT deleted data for.
- bool QAS_exists(int questionnaireResourceId "Questionnaire resource id") - Check if a QAS exists.
- bool QAS_exists(int questionnaireResourceId "Questionnaire resource id", int userResourceId "User resource id. 0 to use current.") - Check if a QAS exists.
- object QAS_flushCallStack() - Flush the call stack of current context qas and return what stack was. Only works on subs (called qas) when called from the questionnaire viewer.
- QAS QAS_getByGuid(string qasGuid "Id of the questionnaire") - Fetch existing qas.
- Array of QAS QAS_getByQuestionnaireResourceId(int questionnaireResourceId "Questionnaire resource id") - Fetch existing qas.
- QAS QAS_getByUniqueAccessCode(string accessCode "Access code") - Find qas by the access code.
- Array of QAS QAS_getByUserResourceId(int userResourceId "User resource id. 0 to use current.") - Get a list of qas by the specified user for all questionnaires. Ordered by Created date, latest first.
- Array of QAS QAS_getByUserResourceId(int userResourceId "User resource id. 0 to use current.", Array of int questionnaireResourceIds "Limit list to these questionnaires") - Get a list of qas by the specified user for all questionnaires. Ordered by Created date, latest first.
- Array of QAS QAS_getByUserResourceId(int userResourceId "User resource id. 0 to use current.", int questionnaireResourceId "Questionnaire resource id") - Get a list of qas by the specified user and questionnaire. Ordered by Created date, latest first.
- Array of QAS QAS_getByUserResourceId(int userResourceId "User resource id. 0 to use current.", int questionnaireResourceId "Questionnaire resource id", bool createIfNone "Create a new one if there are none") - Get a list of qas by the specified user and questionnaire. Ordered by Created date, latest first.
- Array of QAS QAS_getByUserResourceId(int userResourceId "User resource id. 0 to use current.", int questionnaireResourceId "Questionnaire resource id", bool createIfNone "Create a new one if there are none", bool setTestIfCreate "If creating new, set as test") - Get a list of qas by the specified user and questionnaire. Ordered by Created date, latest first.
- Array of QAS QAS_getByUserResourceIds(Array of int userResourceIds "List of user resource id", int questionnaireResourceId "Questionnaire resource id") - Get a list of qas by the specified users and questionnaire. Ordered by Created date, latest first.
- array QAS_getCallStack() - Get the call stack of current context qas. Only works on subs (called qas) when called from the questionnaire viewer.
- Array of int QAS_getCATIListAppointments() - Return the list of qas that has appointments for the current user for the given questionnaire.
- Array of int QAS_getCATIListAppointments(int questionnaireResourceId "Questionnaire resource id. Use 0 to use context") - Return the list of qas that has appointments for the current user for the given questionnaire.
- QAS QAS_getCurrentQAS() - Fetch current context qas.
- Array of int QAS_getIdsByBulkMail(int bulkMailResourceId "Resource id of the bulkmail to get info from", int questionnaireResourceId "Resource id of the questionnaire to get info from", bool getLatest "If true, only fetch those that got the most recent mailout") - Return a list of all qas ids who received a given bulkmail.
- object QAS_getLastInterviewerId() - Return the user unique id for final interviewer of current context qas.
- Dictionary QAS_getParameters() - Return the url parameters given in the url that opened the viewer for this qas. Only works when called from viewer.
- QAS QAS_getQASById(int qasId "Id of the questionnaire") - Fetch existing qas. Returns empty if qas is deleted
- Array of QAS QAS_getQASByIds(Array of int qasIds "Ids of the questionnaire") - Fetch existing qas.
- object QAS_getSampleRuleId() - Return the sample rule id for the current context qas.
- bool QAS_hasCurrentQAS() - True if there is a context qas.
- Empty QAS_initAllQuestionnaires(Array of QAS qas "List of qas") - Initialize all questionnaires from the db in an optimized way.
- Empty QAS_initAllUsers(Array of QAS qas "List of qas") - Initialize all users from the db in an optimized way.
- QAS QAS_new(int questionnaireResourceId "Questionnaire resource id", int userResourceId "User resource id. 0 to use current.") - Create new qas.
- QAS QAS_new(int questionnaireResourceId "Questionnaire resource id", int userResourceId "User resource id. 0 to use current.", bool setTest "Set QAS to test.") - Create new qas.
- QAS QAS_new(int questionnaireResourceId "Questionnaire resource id") - Create new qas for current user.
- QAS QAS_new(int questionnaireResourceId "Questionnaire resource id", bool setTest "Set QAS to test.") - Create new qas for current user.
- Array of int QAS_reset(Array of int qasIds "List of qas ids") - Reset QAS without delete data. Returns list of qas that qas NOT reset.
- Empty QAS_resetFullCallstack(QAS qas "QAS to reset", bool resetCati "True to also reset cati settings") - Reset QAS and all children without delete data.
- Empty QAS_save(QAS qas "Qas to save") - Fetch current context qas.
- Array of int QAS_setCompleted(Array of int qasIds "List of qas ids", bool completed "True to set all to completed, false to unset all") - Set or unset completed state of given qas. When completing, EndDate is set to now, and StartDate is also set to now unless it was already set. Returns list of qas that qas NOT deleted data for.
Note
Every function in QAS class that takes userResourceId such as QAS new, QAS_new, QAS_getByUserResourceId, where userResourceId:
- 0 is use current user
- -1 to force no user
- -2 to anonymous
Examples
Get question already viewed
//The qnaire have 7 questions in order: Intro,Q1,Q2,Q3,Q4,Q5,End
//And the qas is partly at Q4
QAS qas = new QAS (123456);
print(qas.IsInSyncWithQuestionnaire);// true
print(qas.QuestionSequence);//{Intro,Q1,Q2,Q3,Q4,Q5,End}
print(qas.ViewedQuestions);//{3,2,1,0}
print(qas.QuestionSequenceIndex);//4