Commit | Line | Data |
---|---|---|
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 | */ | |
30 | abstract 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 | ||
44 | public function add_dependency($obj) { | |
45 | if (! $obj instanceof backup_setting) { | |
46 | throw new backup_setting_exception('dependency_is_not_backkup_setting'); | |
47 | } | |
48 | // Check the dependency level is >= current level | |
49 | if ($obj->get_level() < $this->level) { | |
50 | throw new backup_setting_exception('cannot_add_upper_level_dependency'); | |
51 | } | |
52 | parent::add_dependency($obj); | |
53 | } | |
54 | ||
55 | // checksumable interface methods | |
56 | ||
57 | public function calculate_checksum() { | |
58 | // Checksum is a simple md5 hash of name, value, level | |
59 | // Not following dependencies at all. Each setting will | |
60 | // calculate its own checksum | |
61 | return md5($this->name . '-' . $this->value . '-' . $this->level); | |
62 | } | |
63 | ||
64 | public function is_checksum_correct($checksum) { | |
65 | return $this->calculate_checksum() === $checksum; | |
66 | } | |
67 | } | |
68 | ||
69 | /* | |
70 | * Exception class used by all the @backup_setting stuff | |
71 | */ | |
72 | class backup_setting_exception extends base_setting_exception { | |
73 | } |