Ejemplo n.º 1
0
 /**
  * Parses external Structure YAML file and assigns to object property
  * 
  * The Questions YAML file is first parsed and stored in the SC Survey Constructor object
  * If the YAML file could not be found, a default structure is created, else the program ends and an error is thrown
  * 
  * @param string $surveyID 'SC Survey ID'
  * @param string $folder directory path where YAML file is stored
  */
 public function __construct($surveyID, $folder, $langCode = NULL)
 {
     $langCode === !is_null($langCode) ? $langCode : 'en';
     $folder = Misc::add_slash($folder);
     $survey_folder = $folder . $surveyID . '/';
     $language_folder = $survey_folder . $langCode . '/';
     ## Load structure
     $sc_survey_constructor = new SC_Survey_Constructor($surveyID, $folder);
     $this->arr_yaml_questions = $sc_survey_constructor->get_questions();
     if (!isset($_SESSION[TOOLKIT_TAG]['data'][$surveyID][$langCode]['structure'])) {
         // If structure isn't already cached in session### Default to language-specific questions YAML
         $filepath = $language_folder . 'structure.yaml';
         ### Fallback to root structure.yaml
         if (!file_exists($filepath)) {
             $filepath = $survey_folder . 'structure.yaml';
         }
         $arr_yaml = Misc::parse_yaml($filepath);
         $_SESSION[TOOLKIT_TAG]['data'][$surveyID][$langCode]['structure'] = isset($arr_yaml) ? $arr_yaml : $this->create_default_structure($surveyID, $folder, $langCode);
     }
     $this->arr_yaml_structure = $this->standardise($_SESSION[TOOLKIT_TAG]['data'][$surveyID][$langCode]['structure']);
 }
Ejemplo n.º 2
0
        pg_address:
            title: Address
            questions:
                - q_address
cat_primary:
    title: Primary Questions
    pages:
        pg_fft:
            title:
                content: The **FFT** Question
                type: markdown
            questions:
                -
                    content: q_fft
                -
                    type: html
                    content: And now: the <span>follow-up</span> question
                - q_fft_why
cat_secondary:
    title:
        title: Secondary questions
    pages:
        pg_last:
            questions:
                - q_last
EOT;
$yaml_parser = new Parser();
$arr_questions = $yaml_parser->parse($questions);
$arr_structure = $yaml_parser->parse($structure);
var_dump(SC_Survey_Constructor::standardise($arr_questions), SC_Page_Generator::standardise($arr_structure));