/// <summary>
        ///     Fills out the offered_answer of the question for question type "PickAll", from all selected choice from a group of
        ///     <see cref="Toggle" />.
        /// </summary>
        /// <param name="go"></param>
        /// <param name="questionDetails"></param>
        /// <returns></returns>
        private string PickAllGetAnswer(GameObject go,
                                        ref SurveyQuestion questionDetails)
        {
            var toggles = go.transform.GetChild(1).GetChild(0)
                          .GetComponentsInChildren <Toggle>().ToList();

            questionDetails.offered_answer = "";
            for (var i = 0; i < toggles.Count; ++i)
            {
                if (toggles[i].isOn)
                {
                    questionDetails.offered_answer += "|" +
                                                      ReplaceApostropy(
                        questionDetails
                        .offered_answer_text
                        [
                            i]);
                }
            }

            if (questionDetails.offered_answer.Length > 1)
            {
                questionDetails.offered_answer =
                    questionDetails.offered_answer.Substring(1);
                StartCoroutine(UploadQuery(questionDetails));
                return(AnswerMessege);
            }

            return(NoAnswerMessege);
        }
예제 #2
0
 /// <summary>
 ///     Sets up a question with an <see cref="InputField" />
 /// </summary>
 /// <param name="questionDetails">A list consisting of a question and the rest is answers</param>
 /// <returns>returns an instantiated GameObject</returns>
 public static GameObject FreeResponseSetUp(
     SurveyQuestion questionDetails)
 {
     var tempPrefab =
         InstatiatePrefabAndPopulateAnswer(
             Resources.Load<GameObject>("SurveyQuestion/FreeResponse"),
             questionDetails.question_text);
     return tempPrefab;
 }
        /// <summary>
        ///     Fills out the offered_answer of the question for question type "Scale", from the selected choice in a
        ///     <see cref="Dropdown" />.
        /// </summary>
        /// <param name="go"></param>
        /// <param name="questionDetails"></param>
        /// <returns></returns>
        private string ScaleGetAnswer(GameObject go,
                                      ref SurveyQuestion questionDetails)
        {
            var rawValue =
                go.transform.GetChild(1).GetChild(0).GetChild(0)
                .GetChild(0).GetComponent <Slider>().normalizedValue;
            var percent = 5 * Mathf.CeilToInt(rawValue * 100 / 5);

            questionDetails.offered_answer = percent + "%";
            StartCoroutine(UploadQuery(questionDetails));
            return(AnswerMessege);
        }
예제 #4
0
 /// <summary>
 ///     Sets up a question prefab with a several <see cref="Button" />
 /// </summary>
 /// <param name="questionDetails">A list consisting of a question and the rest is answers</param>
 /// <returns>returns an instantiated GameObject</returns>
 /// <remarks>ToList() is used because Unity's <see cref="Dropdown" /> does not accept Itterables.</remarks>
 public static GameObject ScalarSetup(SurveyQuestion questionDetails)
 {
     var tempPrefab =
         InstatiatePrefabAndPopulateAnswer(
             Resources.Load<GameObject>("SurveyQuestion/Scalar"),
             questionDetails.question_text);
     var answerSelection = tempPrefab.transform.GetChild(1).GetChild(0)
         .GetChild(1);
     //Debug.Log(answerSelection.name + " is in ScalarSetup");
     PopulateAnswers(answerSelection,
         questionDetails.offered_answer_text);
     return tempPrefab;
 }
        /// <summary>
        ///     Fills out the offered_answer of the question for question type "Numeric", from the number given by
        ///     <see cref="Slider" />.
        /// </summary>
        /// <param name="go"></param>
        /// <param name="questionDetails"></param>
        /// <returns></returns>
        private string NumericGetAnswer(GameObject go,
                                        ref SurveyQuestion questionDetails)
        {
            var answer = go.transform.GetChild(1).GetChild(0).GetChild(0)
                         .GetChild(0).GetChild(0).GetChild(0).GetComponent <Text>().text;

            if (answer == questionDetails.offered_answer_text[0])
            {
                return(NoAnswerMessege);
            }

            questionDetails.offered_answer = ReplaceApostropy(answer);
            StartCoroutine(UploadQuery(questionDetails));
            return(AnswerMessege);
        }
예제 #6
0
        /// <summary>
        ///     Converter from JToken to question list.
        /// </summary>
        /// <param name="questionsJToken"></param>
        /// <returns></returns>
        private static List <SurveyQuestion> JTokenToQuestionDetailList(
            JToken questionsJToken)

        {
            Debug.Log(questionsJToken);
            var surveyList = new List <SurveyQuestion>();

            foreach (var question in questionsJToken)
            {
                Debug.Log(question.ToString());
                var q = SurveyQuestion.CreateFromJson(question);
                surveyList.Add(q);
            }

            Debug.Log("List begins");
            Debug.Log(surveyList);
            Debug.Log("List of size " + surveyList.Count);
            return(surveyList);
        }
        /// <summary>
        ///     A way to initilize the question information and force all relevant information to be know prior to using this
        ///     object.
        /// </summary>
        /// <param name="text"></param>
        /// <param name="type"></param>
        /// <param name="offeredAnswerList"></param>
        /// <param name="offeredAnswerId"></param>
        /// <param name="questionId"></param>
        /// <returns></returns>
        public static SurveyQuestion Init(
            string text,
            string type,
            List <string> offeredAnswerList,
            string offeredAnswerId,
            string questionId)

        {
            var temp = new SurveyQuestion
            {
                question_text       = text,
                type                = type,
                offered_answer_text = offeredAnswerList,
                offered_answer_id   = offeredAnswerId,
                question_id         = questionId
            };

            return(temp);
        }
예제 #8
0
        /// <summary>
        ///     Sets up a question prefab with <see cref="Slider" />
        /// </summary>
        /// <param name="questionDetails"></param>
        /// <returns></returns>
        public static GameObject TLXSetup(
            SurveyQuestion questionDetails)
        {
            var tempPrefab =
                InstatiatePrefabAndPopulateAnswer(
                    Resources.Load<GameObject>("SurveyQuestion/TLX"),
                    questionDetails.question_text);

            //Sets the text on the right side of the scale.
            tempPrefab.transform.GetChild(1).GetChild(0)
                    .GetChild(0).GetChild(0).GetChild(0).GetChild(0)
                    .GetComponent<Text>().text =
                questionDetails.offered_answer_text[0];

            //Sets the text on the right side of the scale.
            tempPrefab.transform.GetChild(1).GetChild(0)
                    .GetChild(0).GetChild(0).GetChild(0).GetChild(1)
                    .GetComponent<Text>().text =
                questionDetails.offered_answer_text[1];
            return tempPrefab;
        }
        /// <summary>
        ///     Fills out the offered_answer of the question for question type "Multiple", from the first selected choice from a
        ///     group of <see cref="Toggle" />.
        /// </summary>
        /// <param name="go"></param>
        /// <param name="questionDetails"></param>
        /// <returns></returns>
        private string MultipleGetAnswer(GameObject go,
                                         ref SurveyQuestion questionDetails)
        {
            var toggles = go.transform.GetChild(1).GetChild(0)
                          .GetComponentsInChildren <Toggle>().ToList();

            Debug.Log("Toggle count = " + toggles.Count);
            for (var i = 0; i < toggles.Count; ++i)
            {
                if (toggles[i].isOn)
                {
                    if (questionDetails
                        .offered_answer_text[i][0] == '@')
                    {
                        var inputField = go.transform.GetChild(1).GetChild(1)
                                         .GetChild(2).GetComponentInChildren <Text>().text;
                        Debug.Log(inputField);
                        //if (inputField == "")
                        //    break;
                        questionDetails.offered_answer =
                            ReplaceApostropy(questionDetails
                                             .offered_answer_text[i]) + "|" + inputField;
                    }
                    else
                    {
                        questionDetails.offered_answer =
                            ReplaceApostropy(questionDetails
                                             .offered_answer_text[i]);
                    }


                    StartCoroutine(UploadQuery(questionDetails));
                    return(AnswerMessege);
                }
            }

            return(NoAnswerMessege);
        }
        /// <summary>
        ///     Sets up a mysql query to upload to databse.
        /// </summary>
        /// <param name="questionDetails"></param>
        /// <returns></returns>
        private IEnumerator UploadQuery(SurveyQuestion questionDetails)
        {
            const string sql = "INSERT INTO dbsurveys.participant_result " +
                               "(survey_id, question_id, offered_answer_id, participant_answer_text, participant_id)" +
                               " VALUE ('{0}','{1}','{2}','{3}','{4}');";
            var particiapantId = 0;

            if (ParticipantBehavior.Instance != null)
            {
                particiapantId = ParticipantBehavior.Participant.Data.Id;
            }

            var sqlQuery = string.Format(
                sql,
                _surveyNumber,
                questionDetails.question_id,
                questionDetails.offered_answer_id,
                questionDetails.offered_answer,
                particiapantId);

            Debug.Log("Nope just a Tide Ad " + sqlQuery);
            StartCoroutine(UploadQueryEnumerator(sqlQuery));
            yield return(null);
        }
 /// <summary>
 ///     Stores question locally.
 /// </summary>
 /// <param name="question"></param>
 public void Init(SurveyQuestion question)
 {
     _question = question;
 }
        /// <summary>
        ///     Figures out which prefab needs to be instantiated.
        ///     Asks the <see cref="GenerateSurveyQuestionPrefab" /> to instantiate given prefab
        /// </summary>
        /// <param name="currentDetails"></param>
        /// <returns></returns>
        private GameObject SurveyQuestionToGameObject(
            SurveyQuestion currentDetails)
        {
            //  Debug.Log(currentDetails.type);
            switch (currentDetails.type)
            {
            case "FreeResponse":
                return(GenerateSurveyQuestionPrefab.FreeResponseSetUp(
                           currentDetails));

            case "Multiple":
                return(GenerateSurveyQuestionPrefab.MultipleSetup(
                           currentDetails));

            case "Scalar":
                return(GenerateSurveyQuestionPrefab.ScalarSetup(
                           currentDetails));

            case "Numerical":
                return(GenerateSurveyQuestionPrefab.NumericSetup(
                           currentDetails));

            //special cases bellow
            case "Intro":
                return(GenerateSurveyQuestionPrefab.MessegeSetup(
                           currentDetails));

            case "Outro":
                return(GenerateSurveyQuestionPrefab.MessegeSetup(
                           currentDetails));

            case "IfYesRespond":
                return(GenerateSurveyQuestionPrefab.MultipleSetup(
                           currentDetails));

            case "IfNoRespond":
                return(GenerateSurveyQuestionPrefab.MultipleSetup(
                           currentDetails));

            case "IfScalarLessThan3Respond":
                return(GenerateSurveyQuestionPrefab.MultipleSetup(
                           currentDetails));

            case "Scale":
                return(GenerateSurveyQuestionPrefab
                       .TLXSetup(currentDetails));

            case "TLX":
                return(GenerateSurveyQuestionPrefab
                       .TLXSetup(currentDetails));

            case "PickAll":
                return(GenerateSurveyQuestionPrefab.PickAllSetup(
                           currentDetails));
            }

            Debug.Log(string.Format("Question of type '{0}' does not exist",
                                    currentDetails.type));
            //In case a they type has never been implemented.
            return(GenerateSurveyQuestionPrefab.FreeResponseSetUp(
                       currentDetails));
        }