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 override permission information by roles
49 class restore_permissions_setting
extends restore_generic_setting
{
53 * root setting to control if restore will create groups/grouping information. Depends on @restore_users_setting
55 * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
56 * @copyright 2014 Matt Sammarco
58 class restore_groups_setting
extends restore_generic_setting
{
62 * root setting to control if restore will include custom field information
64 * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
65 * @copyright 2018 Daniel Neis Araujo
67 class restore_customfield_setting
extends restore_generic_setting
{
71 * root setting to control if restore will create role assignments
72 * or no (any level), depends of @restore_users_setting
74 class restore_role_assignments_setting
extends root_backup_setting
{}
77 * root setting to control if restore will create activities
78 * A lot of other settings (_included at activity levels)
79 * are dependent of this setting
81 class restore_activities_setting
extends restore_generic_setting
{}
84 * root setting to control if restore will create
85 * comments or no, depends of @restore_users_setting
86 * exactly in the same way than @restore_role_assignments_setting so we extend from it
88 class restore_comments_setting
extends restore_role_assignments_setting
{}
91 * root setting to control if restore will create badges or not,
92 * depends on @restore_activities_setting
94 class restore_badges_setting
extends restore_generic_setting
{}
97 * root setting to control if competencies will also be restored.
99 class restore_competencies_setting
extends restore_generic_setting
{
102 * restore_competencies_setting constructor.
103 * @param bool $hascompetencies Flag whether to set the restore setting as checked and unlocked.
105 public function __construct($hascompetencies) {
106 $defaultvalue = false;
107 $visibility = base_setting
::HIDDEN
;
108 $status = base_setting
::LOCKED_BY_CONFIG
;
109 if (\core_competency\api
::is_enabled()) {
110 $visibility = base_setting
::VISIBLE
;
111 if ($hascompetencies) {
112 $defaultvalue = true;
113 $status = base_setting
::NOT_LOCKED
;
116 parent
::__construct('competencies', base_setting
::IS_BOOLEAN
, $defaultvalue, $visibility, $status);
121 * root setting to control if restore will create
122 * events or no, depends of @restore_users_setting
123 * exactly in the same way than @restore_role_assignments_setting so we extend from it
125 class restore_calendarevents_setting
extends restore_role_assignments_setting
{}
128 * root setting to control if restore will create
129 * completion info or no, depends of @restore_users_setting
130 * exactly in the same way than @restore_role_assignments_setting so we extend from it
132 class restore_userscompletion_setting
extends restore_role_assignments_setting
{}
135 * root setting to control if restore will create
136 * logs or no, depends of @restore_users_setting
137 * exactly in the same way than @restore_role_assignments_setting so we extend from it
139 class restore_logs_setting
extends restore_role_assignments_setting
{}
142 * root setting to control if restore will create
143 * grade_histories or no, depends of @restore_users_setting
144 * exactly in the same way than @restore_role_assignments_setting so we extend from it
146 class restore_grade_histories_setting
extends restore_role_assignments_setting
{}
149 // Course restore settings
152 * generic course setting to pass various settings between tasks and steps
154 class restore_course_generic_setting
extends course_backup_setting
{}
157 * Setting to define is we are going to overwrite course configuration
159 class restore_course_overwrite_conf_setting
extends restore_course_generic_setting
{}
162 * Setting to switch between current and new course name/startdate
164 * @copyright 2017 Marina Glancy
165 * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
167 class restore_course_defaultcustom_setting
extends restore_course_generic_setting
{
169 * Validates that the value $value has type $vtype
171 * @param mixed $value
174 public function validate_value($vtype, $value) {
175 if ($value === false) {
176 // Value "false" means default and is allowed for this setting type even if it does not match $vtype.
179 return parent
::validate_value($vtype, $value);
183 * Special method for this element only. When value is "false" returns the default value.
186 public function get_normalized_value() {
187 $value = $this->get_value();
188 if ($value === false && $this->get_ui() instanceof backup_setting_ui_defaultcustom
) {
189 $attributes = $this->get_ui()->get_attributes();
190 return $attributes['defaultvalue'];
197 class restore_course_generic_text_setting
extends restore_course_generic_setting
{
199 public function __construct($name, $vtype, $value = null, $visibility = self
::VISIBLE
, $status = self
::NOT_LOCKED
) {
200 parent
::__construct($name, $vtype, $value, $visibility, $status);
201 $this->set_ui(new backup_setting_ui_text($this, $name));
206 // Section restore settings
209 * generic section setting to pass various settings between tasks and steps
211 class restore_section_generic_setting
extends section_backup_setting
{}
214 * Setting to define if one section is included or no. Activities _included
215 * settings depend of them if available
217 class restore_section_included_setting
extends restore_section_generic_setting
{}
220 * section backup setting to control if section will include
221 * user information or no, depends of @restore_users_setting
223 class restore_section_userinfo_setting
extends restore_section_generic_setting
{}
226 // Activity backup settings
229 * generic activity setting to pass various settings between tasks and steps
231 class restore_activity_generic_setting
extends activity_backup_setting
{}
234 * activity backup setting to control if activity will
235 * be included or no, depends of @restore_activities_setting and
236 * optionally parent section included setting
238 class restore_activity_included_setting
extends restore_activity_generic_setting
{}
241 * activity backup setting to control if activity will include
242 * user information or no, depends of @restore_users_setting
244 class restore_activity_userinfo_setting
extends restore_activity_generic_setting
{}
247 * root setting to control if restore will create content bank content or no
249 class restore_contentbankcontent_setting
extends restore_generic_setting
{
253 * Root setting to control if restore will create xAPI states or not.
255 class restore_xapistate_setting
extends restore_generic_setting
{