Proyectos de Subversion Moodle

Rev

| Ultima modificación | Ver Log |

Rev Autor Línea Nro. Línea
1 efrain 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 final element atom (name/value/parent) piece of information on backup
29
 */
30
class backup_final_element extends base_final_element 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_final_element($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('element_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('element_has_not_value', $this->get_name());
57
        }
58
        backup_structure_dbops::insert_backup_ids_record($backupid, $this->annotationitem, $this->get_value());
59
    }
60
 
61
// Protected API starts here
62
 
63
    /**
64
     * Returns one instace of the @base_attribute class to work with
65
     * when attributes are added simply by name
66
     */
67
    protected function get_new_attribute($name) {
68
        return new backup_attribute($name);
69
    }
70
}