Translations of this page:
 

multiLevelPrepare()

int multiLevelPrepare(string questionnaire, [array data])

The multiLevelPrepare() function creates a subordinate case in the data set (Multi-Level Structure). Variables in the new case can be pre-assigned. This function is particularly useful in conjunction with a Multi-Level Listing.

  • questionnaire – The identifier of the questionnaire to be used to process the subordinate case.
  • data – An associative Array of variable names and values, which values are to be pre-assigned in the new case.

Only one case with the specified data is created at a time, even if the function is called several times.

  • It is therefore unproblematic if the page is executed several times with the call.
  • If several cases are to be created, the transferred data must vary.

Return Value

The function returns the case number (CASE) of the newly created case in the data record.

Example

Usually, when using multiLevelPrepare(), you want to store some information (here, e.g., a name) for each subordinate case right away. For this, you use an internal variable that you create separately in the list of questions.

The following PHP code creates a subordinate case for each name in the list $names in the data record for the questionnaire personaldata and saves the name in the internal variable TX01_01.

foreach ($names as $name) {
    multiLevelPrepare('personaldata', ['TX01_01' => $name]);
}

Below the PHP code, a question of the type Multi-Level Listing could be placed here, which allows the respective cases to be called up to enter the personal details. In the multi-level overview, you would again enter TX01_01 as the Variable for the title, so that the list shows all names.

In the subordinate questionnaire, the name can then be read via value('TX01_01') and, e.g., displayed with html().

// Display directly
html('<h1>'.value('TX01_01').'</h1>');
 
// Display via placeholder, for example for further questions
replace('%name%', 'TX01_01', 'response');
html('<h1>%name%</h1>');
en/create/functions/multilevelprepare.txt · Last modified: by 127.0.0.1
 
Except where otherwise noted, content on this wiki is licensed under the following license: CC Attribution-Share Alike 4.0 International
Driven by DokuWiki