Updated the HEAD build version to 20100615
[moodle.git] / backup / util / settings / backup_setting.class.php
CommitLineData
69dd0c8c
EL
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-settings
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
25/**
26 * This abstract class defines one backup_setting
27 *
28 * TODO: Finish phpdocs
29 */
30abstract class backup_setting extends base_setting implements checksumable {
31
32 // Some constants defining levels of setting
33 const ROOT_LEVEL = 1;
34 const COURSE_LEVEL = 5;
35 const SECTION_LEVEL = 9;
36 const ACTIVITY_LEVEL = 13;
37
38 protected $level; // level of the setting
39
40 public function get_level() {
41 return $this->level;
42 }
43
1904e9b3 44 public function add_dependency(backup_setting $dependentsetting, $type=setting_dependency::DISABLED_VALUE, $options=array()) {
69dd0c8c 45 // Check the dependency level is >= current level
1904e9b3 46 if ($dependentsetting->get_level() < $this->level) {
69dd0c8c
EL
47 throw new backup_setting_exception('cannot_add_upper_level_dependency');
48 }
1904e9b3 49 parent::add_dependency($dependentsetting, $type, $options);
69dd0c8c
EL
50 }
51
52// checksumable interface methods
53
54 public function calculate_checksum() {
55 // Checksum is a simple md5 hash of name, value, level
56 // Not following dependencies at all. Each setting will
57 // calculate its own checksum
58 return md5($this->name . '-' . $this->value . '-' . $this->level);
59 }
60
61 public function is_checksum_correct($checksum) {
62 return $this->calculate_checksum() === $checksum;
63 }
64}
65
66/*
67 * Exception class used by all the @backup_setting stuff
68 */
69class backup_setting_exception extends base_setting_exception {
70}