/**
  * Define the common setting that any restore type will have
  */
 protected function define_settings()
 {
     // Load all the root settings found in backup file from controller
     $rootsettings = $this->get_info()->root_settings;
     // Define users setting (keeping it on hand to define dependencies)
     $defaultvalue = false;
     // Safer default
     $changeable = false;
     if (isset($rootsettings['users']) && $rootsettings['users']) {
         // Only enabled when available
         $defaultvalue = true;
         $changeable = true;
     }
     $users = new restore_users_setting('users', base_setting::IS_BOOLEAN, $defaultvalue);
     $users->set_ui(new backup_setting_ui_checkbox($users, get_string('rootsettingusers', 'backup')));
     $users->get_ui()->set_changeable($changeable);
     $this->add_setting($users);
     // Define role_assignments (dependent of users)
     $defaultvalue = false;
     // Safer default
     $changeable = false;
     if (isset($rootsettings['role_assignments']) && $rootsettings['role_assignments']) {
         // Only enabled when available
         $defaultvalue = true;
         $changeable = true;
     }
     $roleassignments = new restore_role_assignments_setting('role_assignments', base_setting::IS_BOOLEAN, $defaultvalue);
     $roleassignments->set_ui(new backup_setting_ui_checkbox($roleassignments, get_string('rootsettingroleassignments', 'backup')));
     $roleassignments->get_ui()->set_changeable($changeable);
     $this->add_setting($roleassignments);
     $users->add_dependency($roleassignments);
     // Define user_files (dependent of users)
     $defaultvalue = false;
     // Safer default
     $changeable = false;
     if (isset($rootsettings['user_files']) && $rootsettings['user_files']) {
         // Only enabled when available
         $defaultvalue = true;
         $changeable = true;
     }
     $userfiles = new restore_user_files_setting('user_files', base_setting::IS_BOOLEAN, $defaultvalue);
     $userfiles->set_ui(new backup_setting_ui_checkbox($userfiles, get_string('rootsettinguserfiles', 'backup')));
     $userfiles->get_ui()->set_changeable($changeable);
     $this->add_setting($userfiles);
     $users->add_dependency($userfiles);
     // Define activitites
     $defaultvalue = false;
     // Safer default
     $changeable = false;
     if (isset($rootsettings['activities']) && $rootsettings['activities']) {
         // Only enabled when available
         $defaultvalue = true;
         $changeable = true;
     }
     $activities = new restore_activities_setting('activities', base_setting::IS_BOOLEAN, $defaultvalue);
     $activities->set_ui(new backup_setting_ui_checkbox($activities, get_string('rootsettingactivities', 'backup')));
     $activities->get_ui()->set_changeable($changeable);
     $this->add_setting($activities);
     // Define blocks
     $defaultvalue = false;
     // Safer default
     $changeable = false;
     if (isset($rootsettings['blocks']) && $rootsettings['blocks']) {
         // Only enabled when available
         $defaultvalue = true;
         $changeable = true;
     }
     $blocks = new restore_generic_setting('blocks', base_setting::IS_BOOLEAN, $defaultvalue);
     $blocks->set_ui(new backup_setting_ui_checkbox($blocks, get_string('rootsettingblocks', 'backup')));
     $blocks->get_ui()->set_changeable($changeable);
     $this->add_setting($blocks);
     // Define filters
     $defaultvalue = false;
     // Safer default
     $changeable = false;
     if (isset($rootsettings['filters']) && $rootsettings['filters']) {
         // Only enabled when available
         $defaultvalue = true;
         $changeable = true;
     }
     $filters = new restore_generic_setting('filters', base_setting::IS_BOOLEAN, $defaultvalue);
     $filters->set_ui(new backup_setting_ui_checkbox($filters, get_string('rootsettingfilters', 'backup')));
     $filters->get_ui()->set_changeable($changeable);
     $this->add_setting($filters);
     // Define comments (dependent of users)
     $defaultvalue = false;
     // Safer default
     $changeable = false;
     if (isset($rootsettings['comments']) && $rootsettings['comments']) {
         // Only enabled when available
         $defaultvalue = true;
         $changeable = true;
     }
     $comments = new restore_comments_setting('comments', base_setting::IS_BOOLEAN, $defaultvalue);
     $comments->set_ui(new backup_setting_ui_checkbox($comments, get_string('rootsettingcomments', 'backup')));
     $comments->get_ui()->set_changeable($changeable);
     $this->add_setting($comments);
     $users->add_dependency($comments);
     // Define completion (dependent of users)
     $defaultvalue = false;
     // Safer default
     $changeable = false;
     if (isset($rootsettings['userscompletion']) && $rootsettings['userscompletion']) {
         // Only enabled when available
         $defaultvalue = true;
         $changeable = true;
     }
     $completion = new restore_userscompletion_setting('userscompletion', base_setting::IS_BOOLEAN, $defaultvalue);
     $completion->set_ui(new backup_setting_ui_checkbox($completion, get_string('rootsettinguserscompletion', 'backup')));
     $completion->get_ui()->set_changeable($changeable);
     $this->add_setting($completion);
     $users->add_dependency($completion);
     // Define logs (dependent of users)
     $defaultvalue = false;
     // Safer default
     $changeable = false;
     if (isset($rootsettings['logs']) && $rootsettings['logs']) {
         // Only enabled when available
         $defaultvalue = true;
         $changeable = true;
     }
     $logs = new restore_logs_setting('logs', base_setting::IS_BOOLEAN, $defaultvalue);
     $logs->set_ui(new backup_setting_ui_checkbox($logs, get_string('rootsettinglogs', 'backup')));
     $logs->get_ui()->set_changeable($changeable);
     $this->add_setting($logs);
     $users->add_dependency($logs);
     // Define grade_histories (dependent of users)
     $defaultvalue = false;
     // Safer default
     $changeable = false;
     if (isset($rootsettings['grade_histories']) && $rootsettings['grade_histories']) {
         // Only enabled when available
         $defaultvalue = true;
         $changeable = true;
     }
     $gradehistories = new restore_grade_histories_setting('grade_histories', base_setting::IS_BOOLEAN, $defaultvalue);
     $gradehistories->set_ui(new backup_setting_ui_checkbox($gradehistories, get_string('rootsettinggradehistories', 'backup')));
     $gradehistories->get_ui()->set_changeable($changeable);
     $this->add_setting($gradehistories);
     $users->add_dependency($gradehistories);
 }
 /**
  * Define the common setting that any restore type will have
  */
 protected function define_settings()
 {
     // Load all the root settings found in backup file from controller
     $rootsettings = $this->get_info()->root_settings;
     // Define users setting (keeping it on hand to define dependencies)
     $defaultvalue = false;
     // Safer default
     $changeable = false;
     if (isset($rootsettings['users']) && $rootsettings['users']) {
         // Only enabled when available
         $defaultvalue = true;
         $changeable = true;
     }
     $users = new restore_users_setting('users', base_setting::IS_BOOLEAN, $defaultvalue);
     $users->set_ui(new backup_setting_ui_checkbox($users, get_string('rootsettingusers', 'backup')));
     $users->get_ui()->set_changeable($changeable);
     $this->add_setting($users);
     $rootenrolmanual = new restore_users_setting('enrol_migratetomanual', base_setting::IS_BOOLEAN, false);
     $rootenrolmanual->set_ui(new backup_setting_ui_checkbox($rootenrolmanual, get_string('rootenrolmanual', 'backup')));
     $rootenrolmanual->get_ui()->set_changeable(enrol_is_enabled('manual'));
     $rootenrolmanual->get_ui()->set_changeable($changeable);
     $this->add_setting($rootenrolmanual);
     $users->add_dependency($rootenrolmanual);
     // Define role_assignments (dependent of users)
     $defaultvalue = false;
     // Safer default
     $changeable = false;
     if (isset($rootsettings['role_assignments']) && $rootsettings['role_assignments']) {
         // Only enabled when available
         $defaultvalue = true;
         $changeable = true;
     }
     $roleassignments = new restore_role_assignments_setting('role_assignments', base_setting::IS_BOOLEAN, $defaultvalue);
     $roleassignments->set_ui(new backup_setting_ui_checkbox($roleassignments, get_string('rootsettingroleassignments', 'backup')));
     $roleassignments->get_ui()->set_changeable($changeable);
     $this->add_setting($roleassignments);
     $users->add_dependency($roleassignments);
     // Define activitites
     $defaultvalue = false;
     // Safer default
     $changeable = false;
     if (isset($rootsettings['activities']) && $rootsettings['activities']) {
         // Only enabled when available
         $defaultvalue = true;
         $changeable = true;
     }
     $activities = new restore_activities_setting('activities', base_setting::IS_BOOLEAN, $defaultvalue);
     $activities->set_ui(new backup_setting_ui_checkbox($activities, get_string('rootsettingactivities', 'backup')));
     $activities->get_ui()->set_changeable($changeable);
     $this->add_setting($activities);
     // Define blocks
     $defaultvalue = false;
     // Safer default
     $changeable = false;
     if (isset($rootsettings['blocks']) && $rootsettings['blocks']) {
         // Only enabled when available
         $defaultvalue = true;
         $changeable = true;
     }
     $blocks = new restore_generic_setting('blocks', base_setting::IS_BOOLEAN, $defaultvalue);
     $blocks->set_ui(new backup_setting_ui_checkbox($blocks, get_string('rootsettingblocks', 'backup')));
     $blocks->get_ui()->set_changeable($changeable);
     $this->add_setting($blocks);
     // Define filters
     $defaultvalue = false;
     // Safer default
     $changeable = false;
     if (isset($rootsettings['filters']) && $rootsettings['filters']) {
         // Only enabled when available
         $defaultvalue = true;
         $changeable = true;
     }
     $filters = new restore_generic_setting('filters', base_setting::IS_BOOLEAN, $defaultvalue);
     $filters->set_ui(new backup_setting_ui_checkbox($filters, get_string('rootsettingfilters', 'backup')));
     $filters->get_ui()->set_changeable($changeable);
     $this->add_setting($filters);
     // Define comments (dependent of users)
     $defaultvalue = false;
     // Safer default
     $changeable = false;
     if (isset($rootsettings['comments']) && $rootsettings['comments']) {
         // Only enabled when available
         $defaultvalue = true;
         $changeable = true;
     }
     $comments = new restore_comments_setting('comments', base_setting::IS_BOOLEAN, $defaultvalue);
     $comments->set_ui(new backup_setting_ui_checkbox($comments, get_string('rootsettingcomments', 'backup')));
     $comments->get_ui()->set_changeable($changeable);
     $this->add_setting($comments);
     $users->add_dependency($comments);
     // Define badges (dependent of activities).
     $defaultvalue = false;
     // Safer default.
     $changeable = false;
     if (isset($rootsettings['badges']) && $rootsettings['badges']) {
         // Only enabled when available.
         $defaultvalue = true;
         $changeable = true;
     }
     $badges = new restore_badges_setting('badges', base_setting::IS_BOOLEAN, $defaultvalue);
     $badges->set_ui(new backup_setting_ui_checkbox($badges, get_string('rootsettingbadges', 'backup')));
     $badges->get_ui()->set_changeable($changeable);
     $this->add_setting($badges);
     $activities->add_dependency($badges);
     $users->add_dependency($badges);
     // Define Calendar events.
     $defaultvalue = false;
     // Safer default
     $changeable = false;
     if (isset($rootsettings['calendarevents']) && $rootsettings['calendarevents']) {
         // Only enabled when available
         $defaultvalue = true;
         $changeable = true;
     }
     $events = new restore_calendarevents_setting('calendarevents', base_setting::IS_BOOLEAN, $defaultvalue);
     $events->set_ui(new backup_setting_ui_checkbox($events, get_string('rootsettingcalendarevents', 'backup')));
     $events->get_ui()->set_changeable($changeable);
     $this->add_setting($events);
     // Define completion (dependent of users)
     $defaultvalue = false;
     // Safer default
     $changeable = false;
     if (isset($rootsettings['userscompletion']) && $rootsettings['userscompletion']) {
         // Only enabled when available
         $defaultvalue = true;
         $changeable = true;
     }
     $completion = new restore_userscompletion_setting('userscompletion', base_setting::IS_BOOLEAN, $defaultvalue);
     $completion->set_ui(new backup_setting_ui_checkbox($completion, get_string('rootsettinguserscompletion', 'backup')));
     $completion->get_ui()->set_changeable($changeable);
     $this->add_setting($completion);
     $users->add_dependency($completion);
     // Define logs (dependent of users)
     $defaultvalue = false;
     // Safer default
     $changeable = false;
     if (isset($rootsettings['logs']) && $rootsettings['logs']) {
         // Only enabled when available
         $defaultvalue = true;
         $changeable = true;
     }
     $logs = new restore_logs_setting('logs', base_setting::IS_BOOLEAN, $defaultvalue);
     $logs->set_ui(new backup_setting_ui_checkbox($logs, get_string('rootsettinglogs', 'backup')));
     $logs->get_ui()->set_changeable($changeable);
     $this->add_setting($logs);
     $users->add_dependency($logs);
     // Define grade_histories (dependent of users)
     $defaultvalue = false;
     // Safer default
     $changeable = false;
     if (isset($rootsettings['grade_histories']) && $rootsettings['grade_histories']) {
         // Only enabled when available
         $defaultvalue = true;
         $changeable = true;
     }
     $gradehistories = new restore_grade_histories_setting('grade_histories', base_setting::IS_BOOLEAN, $defaultvalue);
     $gradehistories->set_ui(new backup_setting_ui_checkbox($gradehistories, get_string('rootsettinggradehistories', 'backup')));
     $gradehistories->get_ui()->set_changeable($changeable);
     $this->add_setting($gradehistories);
     $users->add_dependency($gradehistories);
     // The restore does not process the grade histories when some activities are ignored.
     // So let's define a dependency to prevent false expectations from our users.
     $activities->add_dependency($gradehistories);
 }