Search moodle.org's
Developer Documentation

See Release Notes

  • Bug fixes for general core bugs in 4.0.x will end 8 May 2023 (12 months).
  • Bug fixes for security issues in 4.0.x will end 13 November 2023 (18 months).
  • PHP version: minimum PHP 7.3.0 Note: the minimum PHP version has increased since Moodle 3.10. PHP 7.4.x is also supported.
   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   * Provides the information to backup question custom field.
  19   *
  20   * @package    qbank_customfields
  21   * @copyright  2021 Catalyst IT Australia Pty Ltd
  22   * @author     Matt Porritt <mattp@catalyst-au.net>
  23   * @license    http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
  24   */
  25  class backup_qbank_customfields_plugin extends \backup_qbank_plugin {
  26  
  27      /**
  28       * Returns the comment information to attach to question element.
  29       *
  30       * @return backup_plugin_element The backup plugin element
  31       */
  32      protected function define_question_plugin_structure(): backup_plugin_element {
  33  
  34          // Define the virtual plugin element with the condition to fulfill.
  35          $plugin = $this->get_plugin_element();
  36  
  37          // Create one standard named plugin element (the visible container).
  38          $pluginwrapper = new backup_nested_element($this->get_recommended_name());
  39  
  40          // Connect the visible container ASAP.
  41          $plugin->add_child($pluginwrapper);
  42  
  43          $customfields = new backup_nested_element('customfields');
  44          $customfield = new backup_nested_element('customfield', ['id'], ['shortname', 'type', 'value', 'valueformat']);
  45  
  46          $pluginwrapper->add_child($customfields);
  47          $customfields->add_child($customfield);
  48  
  49          $customfield->set_source_sql("SELECT cfd.id, cff.shortname, cff.type,  cfd.value, cfd.valueformat
  50                                          FROM {customfield_data} cfd
  51                                          JOIN {customfield_field} cff ON cff.id = cfd.fieldid
  52                                          JOIN {customfield_category} cfc ON cfc.id = cff.categoryid
  53                                         WHERE cfc.component = 'qbank_customfields'
  54                                           AND cfc.area = 'question'
  55                                           AND cfd.instanceid = ?",
  56                  [
  57                          backup::VAR_PARENTID
  58                  ]);
  59  
  60          // Don't need to annotate ids nor files.
  61  
  62          return $plugin;
  63      }
  64  }