Search moodle.org's
Developer Documentation

See Release Notes
Long Term Support Release

  • Bug fixes for general core bugs in 4.1.x will end 13 November 2023 (12 months).
  • Bug fixes for security issues in 4.1.x will end 10 November 2025 (36 months).
  • PHP version: minimum PHP 7.4.0 Note: minimum PHP version has increased since Moodle 4.0. PHP 8.0.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   * @package    moodlecore
  20   * @subpackage backup-structure
  21   * @copyright  2010 onwards Eloy Lafuente (stronk7) {@link http://stronk7.com}
  22   * @license    http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
  23   *
  24   * TODO: Finish phpdocs
  25   */
  26  
  27  /**
  28   * Instantiable class representing one attribute atom (name/value) piece of information on backup
  29   */
  30  class backup_attribute extends base_attribute implements processable, annotable {
  31  
  32      protected $annotationitem; // To store the item this element will be responsible to annotate
  33  
  34      public function process($processor) {
  35          if (!$processor instanceof base_processor) { // No correct processor, throw exception
  36              throw new base_element_struct_exception('incorrect_processor');
  37          }
  38          $processor->process_attribute($this);
  39      }
  40  
  41      public function set_annotation_item($itemname) {
  42          if (!empty($this->annotationitem)) {
  43              $a = new stdclass();
  44              $a->attribute = $this->get_name();
  45              $a->annotating= $this->annotationitem;
  46              throw new base_element_struct_exception('attribute_already_used_for_annotation', $a);
  47          }
  48          $this->annotationitem = $itemname;
  49      }
  50  
  51      public function annotate($backupid) {
  52          if (empty($this->annotationitem)) { // We aren't annotating this item
  53              return;
  54          }
  55          if (!$this->is_set()) {
  56              throw new base_element_struct_exception('attribute_has_not_value', $this->get_name());
  57          }
  58          backup_structure_dbops::insert_backup_ids_record($backupid, $this->annotationitem, $this->get_value());
  59      }
  60  
  61  }