R/Carousel_5_Array_Writer.R

Defines functions Apply_Carousel_5_Array_Writer

Documented in Apply_Carousel_5_Array_Writer

#' Batch apply the carousel presentation style to a list of questions belonging to various groups
#'
#'This version will form your questions into a slider presentation with five answer buttons: 1 Red, 3 Yellow, 1 Green- the text on them are the numbers 1 (on red) to 5 (on green). This lends itself to 5-point Likert style rating questions. The current incarnation does not allow you to change the colors or text on the buttons- if there is a need for this, please let me know.
#'The information that you need to provide is discussed in the arguments list, but I would encourage you to do a "test merge" of the Text_Question_List (without the "question" column) and the Question_List and check the results, especially if you are using this on a large number of questions or for many different languages- make sure you've added all the questions you think you've added!
#'
#'Basically, this function takes three data.tables as input-
#'\enumerate{
#'\item a data.table of Huge free text questions that will be used as the "data storage"
#'\item a data.table of Text questions- these are the questions that are paired with the huge free text questions in the same group in order to provide the canvas to paste in the html/javascript
#'\item a data.table with the question list- the actual questions you want to pose
#'}
#'And turns them into a mobile-friendly slider-type limesurvey question, with very little effort.
#' @section Limitations:
#' To date it appears that limesurvey has a limit on the amount of code that can be placed in a given question (1000 lines). This roughly translates to 50 of this style of question. This means you have to cap any given Text_Question_List entry to having 50 subquestions. While this is unfortunate, you still have a net positive effect- in exchange for 2 LS questions, you can pose 50. This means that the LS limit of ~1400 questions in any given survey can be increased 25 fold to 35000.
#'
#' @section Results storage:
#' The questions generated for this function store all results as arrays in the Huge_Free_Text_List in the format evaluation-title. For example: 1-ABE303024 or 5-Question1. They are comma separated.
#' The function Parse_Array_Writer (in this package) has been written explicitly to parse these questions into a long format, which is very easy to use in further analysis.
#'
#' @section Advice for usage:
#' This function can be paired nicely with the Get_Question_List function (also in this package). With that function you can retrieve the Huge Free Text questions you need for Huge_Free_Text_List and the text questions you need for the Text_Question_List. The Question_List is up to you to populate how you see fit- but please make sure the Text_Title corresponds to the titles of questions that actually exist in the respective survey!
#'
#' @section Additional comments:
#' One of the many strengths of this question style/approach is that you can change questions on the fly and the data stored is maintained. For example, if you are using this to show the respondent a long list of companies that they should evaluate (how environmentally friendly they think they are) you can change the list while the survey is running without damaging anything. The question codes are not stored in the export column names, they are stored in the fields. So, if you ask respondents about Walmart and Target in the first three days of your survey, the responses from those respondents will look like, "1-Walmart, 3-Target", which will be maintained if you change to Petsmart and Costco on day four, when new respondents will see those companies and have responses like, "3-Petsmart, 4-Costco".
#'
#' @param Huge_Free_Text_List These are the huge free text questions that will hold the array data. One should be placed inside the same group as the TEXT question (that contains the HTML/Javascript). This argument should be a data.table with the following columns, listing all of the questions:
#' \itemize{
#' \item \strong{sid}: <this column is mandatory!> the sid of the survey where this question is found
#' \item \strong{gid}: <this column is mandatory!> the gid of the group that the respective question belongs to
#' \item \strong{qid}: <this column is mandatory!> the qid of the respective question
#' \item \strong{title}: <this column is mandatory!> the title of the question
#' }
#'
#' @param Text_Question_List A data.table with the "TEXT" questions that are in the group with the respective storage question, and that should "receive" the html/javascript payload- this data.table contains the sid, gid, and qid of these questions, as well any other parameters to define their style/presentation. You can think about these questions as the "shell" that provides the prompt (something like, "please respond to the following statements:") and is filled by the questions listed in the Question_List.
#' \itemize{
#' \item \strong{sid}: <this column is mandatory!> the sid of the survey where this question is found
#' \item \strong{gid}: <this column is mandatory!> the gid of the group that the respective question belongs to
#' \item \strong{qid}: <this column is mandatory!> the qid of the respective question
#' \item \strong{title}: <this column is mandatory!> the title of the question
#'
#' \item \strong{left_prompt}: <this column is optional, default is blank> You can optionally place instructions beneath the selection buttons- this would be the prompt on the left side of a separator.
#' \item \strong{right_prompt}: <this column is optional, default is blank> You can optionally place instructions beneath the selection buttons- this would be the prompt on the right side of a separator.
#' \item \strong{separator}: <this column is optional, default is blank> The text that serves as a separator between left prompt and right prompt. Defaults to blank, but my suggestion would be " || " if you intend to use this.
#'
#' \item \strong{top_question}: <this column is optional, default is "Please evaluate the following:"> This is the large text shown above the individual questions.
#' \item \strong{language}: <this column is optional, defaults to base language> the language of the questions you are trying to set. If you have multiple languages, you need to have one row for each!
#'
#' \item \strong{submit_button_text}: <this column is optional, default is "Submit Recommendations"> the text that should be shown on the "Next" button
#' \item \strong{set_mandatory}: <this column is optional, default is FALSE> should next button be disabled until all questions answered? Forces respondents to answer all the slider questions before they can progress.
#'
#' \item \strong{progress_bar}: <this column is optional, default = FALSE> should there be a progress bar shown?
#' \item \strong{progress_bar_start}: <this column is optional, default is "0 completed"> what should the text by the progress bar be before first question is answered?
#' \item \strong{progress_text}: <this column is optional, default is "completed of"> if you opt for a progress bar, it is shown both visually and in text. The text says something like, "1 of 10" and automatically counts everything for you. You just have to use this variable as the text between the numbers (for example, if you ask the question in different languages- these will not be automatically translated like the rest of limesurvey!)
#' \item \strong{progress_indicator}: <this column is optional, default is "Progress"> the text that should be shown next to the visual progress bar
#' }
#' @param Question_List A simple list of questions with at least three columns:
#' \itemize{
#' \item \strong{title} <mandatory!>: This is the code that you want to associate the evaluations with in your output. Your "question code" in other words.
#' \item \strong{question} <mandatory!>: This is the question that will be shown to the respondent
#' \item \strong{Text_Title} <mandatory!>: This is the title of the Limesurvey question this question should be assigned to
#' \item \strong{language} <optional, default is base language>: The target language where this question will be added.
#' }
#'
#' @export
#' @examples \dontrun{
#' Apply_Carousel_5_Array_Writer(Huge_Free_Text_List, Text_Question_List, Question_List)
#' }
#'
Apply_Carousel_5_Array_Writer <- function(Huge_Free_Text_List, Text_Question_List, Question_List){

  cleanFun <- function(htmlString) {
    return(gsub("<.*?>", "", htmlString))
  }


  Text_Question_List <- setDT(Text_Question_List)
  if(!("progress_bar_start" %in% names(Text_Question_List))){
    Text_Question_List[, progress_bar_start := "0 completed"]
  }
  if(!("submit_button_text" %in% names(Text_Question_List))){
    Text_Question_List[, submit_button_text := "Submit Recommendations"]
  }
  if(!("progress_text" %in% names(Text_Question_List))){
    Text_Question_List[, progress_text := "completed of"]
  }
  if(!("set_mandatory" %in% names(Text_Question_List))){
    Text_Question_List[, set_mandatory := FALSE]
  }
  if(!("progress_bar" %in% names(Text_Question_List))){
    Text_Question_List[, progress_bar := FALSE]
  }
  if(!("left_prompt" %in% names(Text_Question_List))){
    Text_Question_List[, left_prompt := ""]
  }
  if(!("right_prompt" %in% names(Text_Question_List))){
    Text_Question_List[, right_prompt := ""]
  }
  if(!("separator" %in% names(Text_Question_List))){
    Text_Question_List[, separator := ""]
  }
  if(!("top_question" %in% names(Text_Question_List))){
    Text_Question_List[, top_question := "Please evaluate the following:"]
  }
  if(!("progress_indicator" %in% names(Text_Question_List))){
    Text_Question_List[, progress_indicator := "Progress"]
  }

  # Prepare the Text_Question_List
  # rename the Text_Question_List columns:
  Text_Question_List <- setDT(Text_Question_List)%>%
    setnames(old = c("title", "qid"), new = c("Text_Title", "Text_qid"), skip_absent = TRUE)
  # subset columns, this is all we need:
  if("language" %in% names(Text_Question_List)){
    Text_Question_List <- Text_Question_List[, .(gid,Text_Title,Text_qid, left_prompt, right_prompt, separator, top_question, language, progress_bar_start, submit_button_text, progress_text, set_mandatory, progress_bar, progress_indicator)]
  }else{
    Text_Question_List <- Text_Question_List[, .(gid,Text_Title,Text_qid, left_prompt, right_prompt, separator, top_question, progress_bar_start, submit_button_text, progress_text, set_mandatory, progress_bar, progress_indicator)]
  }

  # Prepare the Hige Free Text Questions:
  Huge_Free_Text_List <- setDT(Huge_Free_Text_List)%>%
    setnames(old = c("title", "qid", "sid"), new = c("Storage_Title", "Storage_qid", "Storage_sid"), skip_absent = TRUE)
  # subset columns, this is all we need:
  Huge_Free_Text_List <- Huge_Free_Text_List[, .(gid, Storage_Title, Storage_qid, Storage_sid)]%>%
    unique(by = "gid")

  # now fix up the question list
  if("language" %in% names(Question_List)){
    Question_List <- Question_List[, .(title, question, Text_Title, language)]
    # Merge with the Question list to have a basis:
    Questions <- merge(setDT(Question_List), Text_Question_List, by = c("Text_Title", "language"), all.x = TRUE, allow.cartesian = TRUE)%>%
      # Merge with the Huge Free Text
      merge(Huge_Free_Text_List, by = c("gid"), all.x = TRUE, allow.cartesian = TRUE)%>%
      setorderv(cols = c("language", "gid"))
    # Add row ids per parent id
    Questions[, row := rowid(Text_qid, language)]
    Questions[, rowId := paste0("row", row)]
  }else{
    Question_List <- Question_List[, .(title, question, Text_Title)]
    # Merge with the Question list to have a basis:
    Questions <- merge(setDT(Question_List), Text_Question_List, by = c("Text_Title"), all.x = TRUE, allow.cartesian = TRUE)%>%
      # Merge with the Huge Free Text
      merge(Huge_Free_Text_List, by = c("gid"), all.x = TRUE, allow.cartesian = TRUE)%>%
      setorderv(cols = "gid")
    # Add row ids per parent id
    Questions[, row := rowid(Text_qid)]
    Questions[, rowId := paste0("row", row)]
  }


  # For the answer numbers
  Questions[, ':=' (
    answ1 = paste0(rowId,"answ1"),
    answ2 = paste0(rowId,"answ2"),
    answ3 = paste0(rowId,"answ3"),
    answ4 = paste0(rowId,"answ4"),
    answ5 = paste0(rowId,"answ5")
  )]

  # For the carouseldiv1 type objects, and the answers to be placed in the array question
  Questions[, ':=' (
    carouseldiv1 = ifelse(row == 1,
                          # Alternative 1: for the first case the class is "item active random"
                          paste0('<div class="item active random" id="',"carousel-",row,'">','\n','<div class="carouseldiv1">','<span style="font-size:200%;">',question,'</span>','</div>','\n',
                                 '<a class="btn btn-danger btn-lg" data-slide="next" href="#carousel-example-generic2" id="',
                                 answ1,
                                 '" role="button" type="button">1</a>','\n',
                                 '<a class="btn btn-warning btn-lg" data-slide="next" href="#carousel-example-generic2" id="',
                                 answ2,
                                 '" role="button" type="button">2</a>','\n',
                                 '<a class="btn btn-warning btn-lg" data-slide="next" href="#carousel-example-generic2" id="',
                                 answ3,
                                 '" role="button" type="button">3</a>','\n',
                                 '<a class="btn btn-warning btn-lg" data-slide="next" href="#carousel-example-generic2" id="',
                                 answ4,
                                 '" role="button" type="button">4</a>','\n',
                                 '<a class="btn btn-success btn-lg" data-slide="next" href="#carousel-example-generic2" id="',
                                 answ5,
                                 '" role="button" type="button">5</a>','\n',
                                 '</div>','\n'),
                          # Alternative 2: for all the following cases it's "item random"
                          paste0('<div class="item random" id="',"carousel-",row,'">','\n','<div class="carouseldiv1">','<span style="font-size:200%;">',question,'</span>','</div>','\n',
                                 '<a class="btn btn-danger btn-lg" data-slide="next" href="#carousel-example-generic2" id="',
                                 answ1,
                                 '" role="button" type="button">1</a>','\n',
                                 '<a class="btn btn-warning btn-lg" data-slide="next" href="#carousel-example-generic2" id="',
                                 answ2,
                                 '" role="button" type="button">2</a>','\n',
                                 '<a class="btn btn-warning btn-lg" data-slide="next" href="#carousel-example-generic2" id="',
                                 answ3,
                                 '" role="button" type="button">3</a>','\n',
                                 '<a class="btn btn-warning btn-lg" data-slide="next" href="#carousel-example-generic2" id="',
                                 answ4,
                                 '" role="button" type="button">4</a>','\n',
                                 '<a class="btn btn-success btn-lg" data-slide="next" href="#carousel-example-generic2" id="',
                                 answ5,
                                 '" role="button" type="button">5</a>','\n',
                                 '</div>','\n')
    ),
    # These are for the part to dump the results into the array:
    arrayansw1 = paste0("$('#",answ1,"').click(function () {",'\n',
                        "AnswerArray[",row-1,"] = '1-", title, "';", '\n',
                        " $('#answer", Storage_sid,'X',gid,'X',Storage_qid,"').val(AnswerArray);",'\n',
                        "$('#movenextbtn, #movesubmitbtn').show();",'\n',
                        "});",'\n'),
    arrayansw2 = paste0("$('#",answ2,"').click(function () {",'\n',
                        "AnswerArray[",row-1,"] = '2-", title, "';", '\n',
                        " $('#answer", Storage_sid,'X',gid,'X',Storage_qid,"').val(AnswerArray);",'\n',
                        "$('#movenextbtn, #movesubmitbtn').show();",'\n',
                        "});",'\n'),
    arrayansw3 = paste0("$('#",answ3,"').click(function () {",'\n',
                        "AnswerArray[",row-1,"] = '3-", title, "';", '\n',
                        " $('#answer", Storage_sid,'X',gid,'X',Storage_qid,"').val(AnswerArray);",'\n',
                        "$('#movenextbtn, #movesubmitbtn').show();",'\n',
                        "});",'\n'),
    arrayansw4 = paste0("$('#",answ4,"').click(function () {",'\n',
                        "AnswerArray[",row-1,"] = '4-", title, "';", '\n',
                        " $('#answer", Storage_sid,'X',gid,'X',Storage_qid,"').val(AnswerArray);",'\n',
                        "$('#movenextbtn, #movesubmitbtn').show();",'\n',
                        "});",'\n'),
    arrayansw5 = paste0("$('#",answ5,"').click(function () {",'\n',
                        "AnswerArray[",row-1,"] = '5-", title, "';", '\n',
                        " $('#answer", Storage_sid,'X',gid,'X',Storage_qid,"').val(AnswerArray);",'\n',
                        "$('#movenextbtn, #movesubmitbtn').show();",'\n',
                        "});",'\n')
  )]

  if("language" %in% names(Questions)){
    Answers_Melted <- melt.data.table(Questions[,.(Text_qid, title, language, arrayansw1,arrayansw2,arrayansw3,arrayansw4,arrayansw5)],id.vars = c("Text_qid", "title", "language"))%>%
      setorderv(cols = c("Text_qid", "title"))
  }else{
    Answers_Melted <- melt.data.table(Questions[,.(Text_qid, title, arrayansw1,arrayansw2,arrayansw3,arrayansw4,arrayansw5)],id.vars = c("Text_qid", "title"))%>%
      setorderv(cols = c("Text_qid", "title"))
  }
  #-------------------------------------------------------
  # Setting up the "Employer Specifics" Driver questions:
  Text_Question_List <- Text_Question_List[, EmployerSpecificsTop := paste0(top_question,'\n\n',
                                                                            '<div class="Explanation">','\n',
                                                                            '<br /></div>',
                                                                            '<div class="carousel slide" data-interval="false" data-ride="carousel" data-wrap="false" id="carousel-example-generic2"><!-- Wrapper for slides -->','\n',
                                                                            '<div class="carousel-inner" role="listbox">','\n')]

  Text_Question_List <- Text_Question_List[, EmployerSpecificsMiddle := paste0('\n\n\n',
                                                                               '<div class="item">','\n',
                                                                               '<div class="carouseldivend">','</div>','\n',
                                                                               '</div>','\n\n',
                                                                               # Within the txtmini class object you can write additional instructions. Here it is blank
                                                                               '<p class="txtmini">',left_prompt,separator,right_prompt,'</p>','\n\n')]

  Text_Question_List <- Text_Question_List[, EmployerSpecificsProgressBar_HTML := ifelse(progress_bar == TRUE, paste0('<p id="textProgress">',progress_bar_start,'</p>','\n','<label for="file">', progress_indicator,'</label> <progress id="progressBar" max="100" value="0"></progress></div>','\n'), paste0('\n'))]

  Text_Question_List <- Text_Question_List[, EmployerSpecificsRandomizer := paste0(
    # Last closing div
    '</div>','\n',
    '<script type="text/javascript" charset="utf-8">','\n',
    # Change the next button text:
    "$(document).on('ready pjax:scriptcomplete',function(){",'\n',
    "$('#ls-button-submit').text('",submit_button_text,"');",'\n',
    "});",'\n\n',
    # Do the document ready thing:
    '$(document).ready(function() {','\n',
    #JS Randomizer (not to be used here!)
    'var AnswerArray = [];', '\n\n',
    'var elements = $(".random");','\n',
    'var elementsInnerHtmls = [];','\n',
    'var numberOfElements = elements.length;','\n\n',
    'for( var i = 0 ; i < numberOfElements ; i++){','\n',
    'elementsInnerHtmls.push(elements[i].innerHTML);}','\n\n',
    'var checkedIndexes = [];','\n',
    'for( var i = 0 ; i < numberOfElements ; i++){','\n',
    'var randomIndex = Math.floor(Math.random()*numberOfElements) % numberOfElements;','\n',
    'while(checkedIndexes[randomIndex] != undefined){','\n',
    'randomIndex = Math.floor(Math.random()*numberOfElements) % numberOfElements;}','\n',
    'checkedIndexes[randomIndex] = true;','\n',
    'elements[i].innerHTML = elementsInnerHtmls[randomIndex];}','\n\n'
  )]

  Text_Question_List <- Text_Question_List[, EmployerSpecificsSubmitButton_disable := ifelse(set_mandatory == TRUE, paste0('document.getElementById("ls-button-submit").disabled = true;','\n\n'), paste0('\n'))]

  Text_Question_List <- Text_Question_List[, EmployerSpecificsCarouselCounter := paste0('\n\n',
                                                                                        "$('#carousel-example-generic2').on('slide.bs.carousel', function (e) {",'\n',
                                                                                        "var active = $(e.target).find('.carousel-inner > .item.active');",'\n',
                                                                                        "var from = active.index();",'\n',
                                                                                        "var next = $(e.relatedTarget);",'\n',
                                                                                        "var to = next.index();",'\n',
                                                                                        "var totalItems = $('.item').length;",'\n',
                                                                                        "if(to+1 == totalItems){",'\n',
                                                                                        "isVisible();",'\n',
                                                                                        "}",'\n')]

  Text_Question_List <- Text_Question_List[, EmployerSpecificsProgressBar_JS := ifelse(progress_bar == TRUE, paste0(
    # Here's the stuff for the progress feedback bar:
    'document.getElementById("progressBar").setAttribute("max", totalItems);','\n',
    'document.getElementById("progressBar").setAttribute("value", to+1);','\n',
    'document.getElementById("textProgress").innerHTML = (to)+" ',progress_text,' "+(totalItems-1);','\n',
    "});",'\n','\n'),
    # Alternative (no progress bar)
    paste0("});",'\n','\n'))]

  Text_Question_List <- Text_Question_List[, EmployerSpecificsSubmit_Click := ifelse(set_mandatory == TRUE, paste0(
    # This is the document.ready end brackets:
    '});','\n',
    # This is the function to click on the submit button when the last card slides
    "function isVisible(){",'\n',
    'document.getElementById("ls-button-submit").disabled = false;','\n',
    'document.getElementById("ls-button-submit").click();','\n',
    "}",'\n',
    '</script>','\n'),
    paste0(
      # This is the document.ready end brackets:
      '});','\n',
      # This is the function to click on the submit button when the last card slides
      "function isVisible(){",'\n',
      'document.getElementById("ls-button-submit").click();','\n',
      "}",'\n',
      '</script>','\n'))]

  Text_Question_List <- Text_Question_List[, EmployerSpecificsEnd := paste0(
    # This is just for style- but the template trumps this anyway, so it won't show
    '<style type="text/css">html, body { height: 100%; }','\n',
    'body {','\n',
    'background: rgba(241,231,103,1);','\n',
    'background: -moz-linear-gradient(-45deg, rgba(241,231,103,1) 0%, rgba(252,70,104,1) 100%);','\n',
    'background: -webkit-gradient(left top, right bottom, color-stop(0%, rgba(241,231,103,1)), color-stop(100%, rgba(252,70,104,1)));','\n',
    'background: -webkit-linear-gradient(-45deg, rgba(241,231,103,1) 0%, rgba(252,70,104,1) 100%);','\n',
    'background: -o-linear-gradient(-45deg, rgba(241,231,103,1) 0%, rgba(252,70,104,1) 100%);','\n',
    'background: -ms-linear-gradient(-45deg, rgba(241,231,103,1) 0%, rgba(252,70,104,1) 100%);','\n',
    'background: linear-gradient(135deg, rgba(241,231,103,1) 0%, rgba(252,70,104,1) 100%);','\n',
    "filter: progid:DXImageTransform.Microsoft.gradient( startColorstr='#f1e767', endColorstr='#fc4668', GradientType=1 );}",'\n',
    '</style>','\n',
    '</div>','\n')]


  #-------------------------------------------------------
  # Per Parent_QID you take all of the entries, cat them, then upload them to the parent
  # Upload to LS
  options(lime_api = 'https://survey.statista-research.com/admin/remotecontrol')
  options(lime_username = Sys.getenv("Statista_LS_Username"))
  options(lime_password = Sys.getenv("Statista_LS_Password"))

  get_session_key()  # Log in

  # This is to keep track of progress
  Unique_Text_Questions <- Text_Question_List
  Unique_Text_Questions[, language.update := character()]
  Unique_Text_Questions[, question.update := character()]


  for(i in 1:nrow(Unique_Text_Questions)){

    # This part is only if you want to store the results in a data.table:
    # Finished_Questions[j]$parent_qid <- paste0(i)
    # Finished_Questions[j]$question <- paste(EmployerSpecificsTop, paste(Questions[parent_qid == paste0(i)]$carouseldiv1, collapse = ""), EmployerSpecificsMiddle, paste(Answers_Melted[parent_qid == paste0(i)]$value, collapse = ""), EmployerSpecificsEnd, sep = "\n\n", collapse = "")

    # This part puts the results straight into the appropriate questions:
    get_question_properties_current <-  call_limer(method = "get_question_properties",
                                                   params = list(iQuestionID = Unique_Text_Questions[i]$Text_qid
                                                   ))
    # Injects the html/javascript into the question
    if("language" %in% names(Questions)){
      get_question_properties_current["question"] <-  paste(Unique_Text_Questions[i]$EmployerSpecificsTop,
                                                            paste0(Questions[Text_qid == Unique_Text_Questions[i]$Text_qid & language == Unique_Text_Questions[i]$language]$carouseldiv1, collapse = ""),
                                                            Unique_Text_Questions[i]$EmployerSpecificsMiddle,
                                                            Unique_Text_Questions[i]$EmployerSpecificsProgressBar_HTML,
                                                            Unique_Text_Questions[i]$EmployerSpecificsRandomizer,
                                                            paste(Answers_Melted[Text_qid == Unique_Text_Questions[i]$Text_qid & language == Unique_Text_Questions[i]$language]$value, collapse = ""),
                                                            Unique_Text_Questions[i]$EmployerSpecificsSubmitButton_disable,
                                                            Unique_Text_Questions[i]$EmployerSpecificsCarouselCounter,
                                                            Unique_Text_Questions[i]$EmployerSpecificsProgressBar_JS,
                                                            Unique_Text_Questions[i]$EmployerSpecificsSubmit_Click,
                                                            Unique_Text_Questions[i]$EmployerSpecificsEnd, sep = "\n\n", collapse = "")
    }else{
      get_question_properties_current["question"] <-  paste(Unique_Text_Questions[i]$EmployerSpecificsTop,
                                                            paste0(Questions[Text_qid == Unique_Text_Questions[i]$Text_qid]$carouseldiv1, collapse = ""),
                                                            Unique_Text_Questions[i]$EmployerSpecificsMiddle,
                                                            Unique_Text_Questions[i]$EmployerSpecificsProgressBar_HTML,
                                                            Unique_Text_Questions[i]$EmployerSpecificsRandomizer,
                                                            paste(Answers_Melted[Text_qid == Unique_Text_Questions[i]$Text_qid]$value, collapse = ""),
                                                            Unique_Text_Questions[i]$EmployerSpecificsSubmitButton_disable,
                                                            Unique_Text_Questions[i]$EmployerSpecificsCarouselCounter,
                                                            Unique_Text_Questions[i]$EmployerSpecificsProgressBar_JS,
                                                            Unique_Text_Questions[i]$EmployerSpecificsSubmit_Click,
                                                            Unique_Text_Questions[i]$EmployerSpecificsEnd, sep = "\n\n", collapse = "")
    }

    # Use the base language if there's either no language column, or if there's an NA in it
    if("language" %in% names(Text_Question_List)){
      target_language <- ifelse(!is.na(Unique_Text_Questions[i]$language), Unique_Text_Questions[i]$language, get_question_properties_current[["language"]])
    }else{
      target_language <- get_question_properties_current[["language"]]
    }

    # Just to track progress
    Unique_Text_Questions[i]$language.update <- target_language

    get_question_properties_current <- get_question_properties_current["question"]
    # uploads the question
    Unique_Text_Questions[i]$question.update <-  call_limer(method = "set_question_properties",
                                                            params = list(iQuestionID = Unique_Text_Questions[i]$Text_qid,
                                                                          aQuestionData = get_question_properties_current,
                                                                          sLanguage = target_language

                                                            ))

  }

  return(Unique_Text_Questions)

} # end Apply_Carousel Function
bpresentati/surveyR documentation built on March 19, 2022, 3:40 a.m.