Search moodle.org's
Developer Documentation

See Release Notes

  • Bug fixes for general core bugs in 3.11.x will end 14 Nov 2022 (12 months plus 6 months extension).
  • Bug fixes for security issues in 3.11.x will end 13 Nov 2023 (18 months plus 12 months extension).
  • PHP version: minimum PHP 7.3.0 Note: minimum PHP version has increased since Moodle 3.10. PHP 7.4.x is supported too.
   1  <?php
   2  
   3  // This file is part of Moodle - http://moodle.org/
   4  //
   5  // Moodle is free software: you can redistribute it and/or modify
   6  // it under the terms of the GNU General Public License as published by
   7  // the Free Software Foundation, either version 3 of the License, or
   8  // (at your option) any later version.
   9  //
  10  // Moodle is distributed in the hope that it will be useful,
  11  // but WITHOUT ANY WARRANTY; without even the implied warranty of
  12  // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  13  // GNU General Public License for more details.
  14  //
  15  // You should have received a copy of the GNU General Public License
  16  // along with Moodle.  If not, see <http://www.gnu.org/licenses/>.
  17  
  18  /**
  19   * Provides support for the conversion of moodle1 backup to the moodle2 format
  20   *
  21   * @package    workshopform_comments
  22   * @copyright  2011 David Mudrak <david@moodle.com>
  23   * @license    http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
  24   */
  25  
  26  defined('MOODLE_INTERNAL') || die();
  27  
  28  /**
  29   * Conversion handler for the comments grading strategy data
  30   */
  31  class moodle1_workshopform_comments_handler extends moodle1_workshopform_handler {
  32  
  33      /**
  34       * Converts <ELEMENT> into <workshopform_comments_dimension>
  35       *
  36       * @param array $data legacy element data
  37       * @param array $raw raw element data
  38       *
  39       * @return array converted
  40       */
  41      public function process_legacy_element(array $data, array $raw) {
  42          // prepare a fake record and re-use the upgrade logic
  43          $fakerecord = (object)$data;
  44          $converted = (array)workshopform_comments_upgrade_element($fakerecord, 12345678);
  45          unset($converted['workshopid']);
  46  
  47          $converted['id'] = $data['id'];
  48          $this->write_xml('workshopform_comments_dimension', $converted, array('/workshopform_comments_dimension/id'));
  49  
  50          return $converted;
  51      }
  52  }
  53  
  54  /**
  55   * Transforms a given record from workshop_elements_old into an object to be saved into workshopform_comments
  56   *
  57   * @param stdClass $old legacy record from workshop_elements_old
  58   * @param int $newworkshopid id of the new workshop instance that replaced the previous one
  59   * @return stdclass to be saved in workshopform_comments
  60   */
  61  function workshopform_comments_upgrade_element(stdclass $old, $newworkshopid) {
  62      $new                    = new stdclass();
  63      $new->workshopid        = $newworkshopid;
  64      $new->sort              = $old->elementno;
  65      $new->description       = $old->description;
  66      $new->descriptionformat = FORMAT_HTML;
  67      return $new;
  68  }