| 1 | 
           efrain | 
           1 | 
           <?php
  | 
        
        
            | 
            | 
           2 | 
           // This file is part of Moodle - http://moodle.org/
  | 
        
        
            | 
            | 
           3 | 
           //
  | 
        
        
            | 
            | 
           4 | 
           // Moodle is free software: you can redistribute it and/or modify
  | 
        
        
            | 
            | 
           5 | 
           // it under the terms of the GNU General Public License as published by
  | 
        
        
            | 
            | 
           6 | 
           // the Free Software Foundation, either version 3 of the License, or
  | 
        
        
            | 
            | 
           7 | 
           // (at your option) any later version.
  | 
        
        
            | 
            | 
           8 | 
           //
  | 
        
        
            | 
            | 
           9 | 
           // Moodle is distributed in the hope that it will be useful,
  | 
        
        
            | 
            | 
           10 | 
           // but WITHOUT ANY WARRANTY; without even the implied warranty of
  | 
        
        
            | 
            | 
           11 | 
           // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  | 
        
        
            | 
            | 
           12 | 
           // GNU General Public License for more details.
  | 
        
        
            | 
            | 
           13 | 
           //
  | 
        
        
            | 
            | 
           14 | 
           // You should have received a copy of the GNU General Public License
  | 
        
        
            | 
            | 
           15 | 
           // along with Moodle.  If not, see <http://www.gnu.org/licenses/>.
  | 
        
        
            | 
            | 
           16 | 
              | 
        
        
            | 
            | 
           17 | 
           /**
  | 
        
        
            | 
            | 
           18 | 
            * Serve question type files
  | 
        
        
            | 
            | 
           19 | 
            *
  | 
        
        
            | 
            | 
           20 | 
            * @package    qtype_randomsamatch
  | 
        
        
            | 
            | 
           21 | 
            * @copyright  2013 Jean-Michel Vedrine
  | 
        
        
            | 
            | 
           22 | 
            * @license    http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
  | 
        
        
            | 
            | 
           23 | 
            */
  | 
        
        
            | 
            | 
           24 | 
              | 
        
        
            | 
            | 
           25 | 
           defined('MOODLE_INTERNAL') || die();
  | 
        
        
            | 
            | 
           26 | 
              | 
        
        
            | 
            | 
           27 | 
           /**
  | 
        
        
            | 
            | 
           28 | 
            * Random shortanswer matching question type conversion handler.
  | 
        
        
            | 
            | 
           29 | 
            *
  | 
        
        
            | 
            | 
           30 | 
            * @copyright  2013 Jean-Michel Vedrine
  | 
        
        
            | 
            | 
           31 | 
            * @license    http://www.gnu.org/copyleft/gpl.html GNU Public License
  | 
        
        
            | 
            | 
           32 | 
            */
  | 
        
        
            | 
            | 
           33 | 
           class moodle1_qtype_randomsamatch_handler extends moodle1_qtype_handler {
  | 
        
        
            | 
            | 
           34 | 
              | 
        
        
            | 
            | 
           35 | 
               /**
  | 
        
        
            | 
            | 
           36 | 
                * Returns the list of paths within one <QUESTION> that this qtype needs to have included
  | 
        
        
            | 
            | 
           37 | 
                * in the grouped question structure
  | 
        
        
            | 
            | 
           38 | 
                *
  | 
        
        
            | 
            | 
           39 | 
                * @return array of strings
  | 
        
        
            | 
            | 
           40 | 
                */
  | 
        
        
            | 
            | 
           41 | 
               public function get_question_subpaths() {
  | 
        
        
            | 
            | 
           42 | 
                   return array(
  | 
        
        
            | 
            | 
           43 | 
                       'RANDOMSAMATCH',
  | 
        
        
            | 
            | 
           44 | 
                   );
  | 
        
        
            | 
            | 
           45 | 
               }
  | 
        
        
            | 
            | 
           46 | 
              | 
        
        
            | 
            | 
           47 | 
               /**
  | 
        
        
            | 
            | 
           48 | 
                * Appends the randomsamatch specific information to the question.
  | 
        
        
            | 
            | 
           49 | 
                *
  | 
        
        
            | 
            | 
           50 | 
                * @param array $data grouped question data
  | 
        
        
            | 
            | 
           51 | 
                * @param array $raw grouped raw QUESTION data
  | 
        
        
            | 
            | 
           52 | 
                */
  | 
        
        
            | 
            | 
           53 | 
               public function process_question(array $data, array $raw) {
  | 
        
        
            | 
            | 
           54 | 
              | 
        
        
            | 
            | 
           55 | 
                   // Convert match options.
  | 
        
        
            | 
            | 
           56 | 
                   if (isset($data['randomsamatch'])) {
  | 
        
        
            | 
            | 
           57 | 
                       $randomsamatch = $data['randomsamatch'][0];
  | 
        
        
            | 
            | 
           58 | 
                   } else {
  | 
        
        
            | 
            | 
           59 | 
                       $randomsamatch = array('choose' => 4);
  | 
        
        
            | 
            | 
           60 | 
                   }
  | 
        
        
            | 
            | 
           61 | 
                   $randomsamatch['id'] = $this->converter->get_nextid();
  | 
        
        
            | 
            | 
           62 | 
                   $randomsamatch['subcats'] = 1;
  | 
        
        
            | 
            | 
           63 | 
                   $randomsamatch['correctfeedback'] = '';
  | 
        
        
            | 
            | 
           64 | 
                   $randomsamatch['correctfeedbackformat'] = FORMAT_HTML;
  | 
        
        
            | 
            | 
           65 | 
                   $randomsamatch['partiallycorrectfeedback'] = '';
  | 
        
        
            | 
            | 
           66 | 
                   $randomsamatch['partiallycorrectfeedbackformat'] = FORMAT_HTML;
  | 
        
        
            | 
            | 
           67 | 
                   $randomsamatch['incorrectfeedback'] = '';
  | 
        
        
            | 
            | 
           68 | 
                   $randomsamatch['incorrectfeedbackformat'] = FORMAT_HTML;
  | 
        
        
            | 
            | 
           69 | 
                   $this->write_xml('randomsamatch', $randomsamatch, array('/randomsamatch/id'));
  | 
        
        
            | 
            | 
           70 | 
               }
  | 
        
        
            | 
            | 
           71 | 
           }
  |