public function data_preprocessing($question)
 {
     $question = parent::data_preprocessing($question);
     $question = $this->data_preprocessing_combined_feedback($question, true);
     $question = $this->data_preprocessing_hints($question, true, true);
     $dragids = array();
     // drag no -> dragid
     if (!empty($question->options)) {
         $question->shuffleanswers = $question->options->shuffleanswers;
         $question->drags = array();
         foreach ($question->options->drags as $drag) {
             $dragindex = $drag->no - 1;
             $question->drags[$dragindex] = array();
             $question->drags[$dragindex]['draglabel'] = $drag->label;
             $question->drags[$dragindex]['infinite'] = $drag->infinite;
             $question->drags[$dragindex]['draggroup'] = $drag->draggroup;
             $dragids[$dragindex] = $drag->id;
         }
         $question->drops = array();
         foreach ($question->options->drops as $drop) {
             $question->drops[$drop->no - 1] = array();
             $question->drops[$drop->no - 1]['choice'] = $drop->choice;
             $question->drops[$drop->no - 1]['droplabel'] = $drop->label;
             $question->drops[$drop->no - 1]['xleft'] = $drop->xleft;
             $question->drops[$drop->no - 1]['ytop'] = $drop->ytop;
         }
     }
     //initialise file picker for bgimage
     $draftitemid = file_get_submitted_draft_itemid('bgimage');
     file_prepare_draft_area($draftitemid, $this->context->id, 'qtype_ddimageortext', 'bgimage', !empty($question->id) ? (int) $question->id : null, self::file_picker_options());
     $question->bgimage = $draftitemid;
     //initialise file picker for dragimages
     list(, $imagerepeats) = $this->get_drag_item_repeats();
     $draftitemids = optional_param_array('dragitem', array(), PARAM_INT);
     for ($imageindex = 0; $imageindex < $imagerepeats; $imageindex++) {
         $draftitemid = isset($draftitemids[$imageindex]) ? $draftitemids[$imageindex] : 0;
         //numbers not allowed in filearea name
         $itemid = isset($dragids[$imageindex]) ? $dragids[$imageindex] : null;
         file_prepare_draft_area($draftitemid, $this->context->id, 'qtype_ddimageortext', 'dragimage', $itemid, self::file_picker_options());
         $question->dragitem[$imageindex] = $draftitemid;
     }
     if (!empty($question->options)) {
         foreach ($question->options->drags as $drag) {
             $dragindex = $drag->no - 1;
             if (!isset($question->dragitem[$dragindex])) {
                 $fileexists = false;
             } else {
                 $fileexists = self::file_uploaded($question->dragitem[$dragindex]);
             }
             $labelexists = trim($question->drags[$dragindex]['draglabel']) != '';
             if ($labelexists && !$fileexists) {
                 $question->dragitemtype[$dragindex] = 'word';
             } else {
                 $question->dragitemtype[$dragindex] = 'image';
             }
         }
     }
     $this->js_call();
     return $question;
 }
 public function data_preprocessing($question)
 {
     $question = parent::data_preprocessing($question);
     $question = $this->data_preprocessing_combined_feedback($question, true);
     $question = $this->data_preprocessing_hints($question, true, true);
     $dragids = array();
     // drag no -> dragid
     if (!empty($question->options)) {
         $question->shuffleanswers = $question->options->shuffleanswers;
         $question->showmisplaced = $question->options->showmisplaced;
         $question->drags = array();
         foreach ($question->options->drags as $drag) {
             $dragindex = $drag->no - 1;
             $question->drags[$dragindex] = array();
             $question->drags[$dragindex]['label'] = $drag->label;
             $question->drags[$dragindex]['infinite'] = $drag->infinite;
             $dragids[$dragindex] = $drag->id;
         }
         $question->drops = array();
         foreach ($question->options->drops as $drop) {
             $droparray = (array) $drop;
             unset($droparray['id']);
             unset($droparray['no']);
             unset($droparray['questionid']);
             $question->drops[$drop->no - 1] = $droparray;
         }
     }
     //initialise file picker for bgimage
     $draftitemid = file_get_submitted_draft_itemid('bgimage');
     file_prepare_draft_area($draftitemid, $this->context->id, 'qtype_ddmarker', 'bgimage', !empty($question->id) ? (int) $question->id : null, self::file_picker_options());
     $question->bgimage = $draftitemid;
     $this->js_call();
     return $question;
 }