Note:

If you want to create a new page for developers, you should create it on the Moodle Developer Resource site.

Calculated question function find all question dataset names

From MoodleDocs
Revision as of 14:13, 24 June 2022 by Andrew Nicols (talk | contribs) (Note about plan not to migrate this page to the new developer resources. See template for more info.)
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)


Warning: This page is no longer in use. The information contained on the page should NOT be seen as relevant or reliable.


Description of the function find_all_question_dataset_names() This is an adaptation of the actual code in datasetdependent/datasetdefinition.php

 function find_all_question_dataset_names(&$question, &$mandatorydatasets, &$possibledatasets) {
   // Returns the possible dataset names found in the text and answers
   $possibledatasets = $this->find_dataset_names($question->questiontext);
   foreach ($question->options->answers as $answer) {
              $mandatorydatasets += $this
               ->find_dataset_names($answer->answer);
       }
   }
  // construct the complete list with a single entry for each dataset name
    $allpossibledatasets=array();
    foreach ($mandatorydatasets as $datasetname) {
        if (!isset($allpossibledatasets[$datasetname])) {
           $allpossibledatasets[$datasetname]=$datasetname;
        }
    }    
        foreach ($possibledatasets as $datasetname) {
           if (!isset($allpossibledatasets[$datasetname])) {
               $allpossibledatasets[$datasetname]=$datasetname;
           }
       } 
       return fullclone($allpossibledatasets);   //fullclone() necessary; array of objects
   }