3 // This file is part of Moodle - http://moodle.org/
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.
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.
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/>.
19 * Defines classes used to handle restore settings
21 * @package core_backup
24 * @copyright 2010 onwards Eloy Lafuente (stronk7) {@link http://stronk7.com}
25 * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
28 defined('MOODLE_INTERNAL') ||
die();
30 // TODO: Reduce these to the minimum because ui/dependencies are 100% separated
32 // Root restore settings
35 * root generic setting to store different things without dependencies
37 class restore_generic_setting
extends root_backup_setting
{}
40 * root setting to control if restore will create user information
41 * A lot of other settings are dependent of this (module's user info,
42 * grades user info, messages, blogs...
44 class restore_users_setting
extends restore_generic_setting
{}
47 * root setting to control if restore will create groups/grouping information. Depends on @restore_users_setting
49 * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
50 * @copyright 2014 Matt Sammarco
52 class restore_groups_setting
extends restore_generic_setting
{
56 * root setting to control if restore will include custom field information
58 * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
59 * @copyright 2018 Daniel Neis Araujo
61 class restore_customfield_setting
extends restore_generic_setting
{
65 * root setting to control if restore will create role assignments
66 * or no (any level), depends of @restore_users_setting
68 class restore_role_assignments_setting
extends root_backup_setting
{}
71 * root setting to control if restore will create activities
72 * A lot of other settings (_included at activity levels)
73 * are dependent of this setting
75 class restore_activities_setting
extends restore_generic_setting
{}
78 * root setting to control if restore will create
79 * comments or no, depends of @restore_users_setting
80 * exactly in the same way than @restore_role_assignments_setting so we extend from it
82 class restore_comments_setting
extends restore_role_assignments_setting
{}
85 * root setting to control if restore will create badges or not,
86 * depends on @restore_activities_setting
88 class restore_badges_setting
extends restore_generic_setting
{}
91 * root setting to control if competencies will also be restored.
93 class restore_competencies_setting
extends restore_generic_setting
{
96 * restore_competencies_setting constructor.
97 * @param bool $hascompetencies Flag whether to set the restore setting as checked and unlocked.
99 public function __construct($hascompetencies) {
100 $defaultvalue = false;
101 $visibility = base_setting
::HIDDEN
;
102 $status = base_setting
::LOCKED_BY_CONFIG
;
103 if (\core_competency\api
::is_enabled()) {
104 $visibility = base_setting
::VISIBLE
;
105 if ($hascompetencies) {
106 $defaultvalue = true;
107 $status = base_setting
::NOT_LOCKED
;
110 parent
::__construct('competencies', base_setting
::IS_BOOLEAN
, $defaultvalue, $visibility, $status);
115 * root setting to control if restore will create
116 * events or no, depends of @restore_users_setting
117 * exactly in the same way than @restore_role_assignments_setting so we extend from it
119 class restore_calendarevents_setting
extends restore_role_assignments_setting
{}
122 * root setting to control if restore will create
123 * completion info or no, depends of @restore_users_setting
124 * exactly in the same way than @restore_role_assignments_setting so we extend from it
126 class restore_userscompletion_setting
extends restore_role_assignments_setting
{}
129 * root setting to control if restore will create
130 * logs or no, depends of @restore_users_setting
131 * exactly in the same way than @restore_role_assignments_setting so we extend from it
133 class restore_logs_setting
extends restore_role_assignments_setting
{}
136 * root setting to control if restore will create
137 * grade_histories or no, depends of @restore_users_setting
138 * exactly in the same way than @restore_role_assignments_setting so we extend from it
140 class restore_grade_histories_setting
extends restore_role_assignments_setting
{}
143 // Course restore settings
146 * generic course setting to pass various settings between tasks and steps
148 class restore_course_generic_setting
extends course_backup_setting
{}
151 * Setting to define is we are going to overwrite course configuration
153 class restore_course_overwrite_conf_setting
extends restore_course_generic_setting
{}
156 * Setting to switch between current and new course name/startdate
158 * @copyright 2017 Marina Glancy
159 * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
161 class restore_course_defaultcustom_setting
extends restore_course_generic_setting
{
163 * Validates that the value $value has type $vtype
165 * @param mixed $value
168 public function validate_value($vtype, $value) {
169 if ($value === false) {
170 // Value "false" means default and is allowed for this setting type even if it does not match $vtype.
173 return parent
::validate_value($vtype, $value);
177 * Special method for this element only. When value is "false" returns the default value.
180 public function get_normalized_value() {
181 $value = $this->get_value();
182 if ($value === false && $this->get_ui() instanceof backup_setting_ui_defaultcustom
) {
183 $attributes = $this->get_ui()->get_attributes();
184 return $attributes['defaultvalue'];
191 class restore_course_generic_text_setting
extends restore_course_generic_setting
{
193 public function __construct($name, $vtype, $value = null, $visibility = self
::VISIBLE
, $status = self
::NOT_LOCKED
) {
194 parent
::__construct($name, $vtype, $value, $visibility, $status);
195 $this->set_ui(new backup_setting_ui_text($this, $name));
200 // Section restore settings
203 * generic section setting to pass various settings between tasks and steps
205 class restore_section_generic_setting
extends section_backup_setting
{}
208 * Setting to define if one section is included or no. Activities _included
209 * settings depend of them if available
211 class restore_section_included_setting
extends restore_section_generic_setting
{}
214 * section backup setting to control if section will include
215 * user information or no, depends of @restore_users_setting
217 class restore_section_userinfo_setting
extends restore_section_generic_setting
{}
220 // Activity backup settings
223 * generic activity setting to pass various settings between tasks and steps
225 class restore_activity_generic_setting
extends activity_backup_setting
{}
228 * activity backup setting to control if activity will
229 * be included or no, depends of @restore_activities_setting and
230 * optionally parent section included setting
232 class restore_activity_included_setting
extends restore_activity_generic_setting
{}
235 * activity backup setting to control if activity will include
236 * user information or no, depends of @restore_users_setting
238 class restore_activity_userinfo_setting
extends restore_activity_generic_setting
{}