Пример #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']);
 }