Proyectos de Subversion Moodle

Rev

Rev 1 | Mostrar el archivo completo | | | Autoría | Ultima modificación | Ver Log |

Rev 1 Rev 1441
Línea 54... Línea 54...
54
    public function get_taskbasepath() {
54
    public function get_taskbasepath() {
Línea 55... Línea 55...
55
 
55
 
56
        return $this->get_basepath() . '/sections/section_' . $this->info->sectionid;
56
        return $this->get_basepath() . '/sections/section_' . $this->info->sectionid;
Línea -... Línea 57...
-
 
57
    }
-
 
58
 
-
 
59
    /**
-
 
60
     * Get the course module that is delegating this section.
-
 
61
     *
-
 
62
     * @return int|null the course module id that is delegating this section
-
 
63
     */
-
 
64
    public function get_delegated_cm(): ?int {
-
 
65
        if (!isset($this->info->parentcmid) || empty($this->info->parentcmid)) {
-
 
66
            return null;
-
 
67
        }
-
 
68
        return intval($this->info->parentcmid);
-
 
69
    }
-
 
70
 
-
 
71
    /**
-
 
72
     * Get the delegated activity modname if any.
-
 
73
     *
-
 
74
     * @return string|null the modname of the delegated activity
-
 
75
     */
-
 
76
    public function get_modname(): ?string {
-
 
77
        if (!isset($this->info->modname) || empty($this->info->modname)) {
-
 
78
            return null;
-
 
79
        }
-
 
80
        return $this->info->modname;
57
    }
81
    }
58
 
82
 
59
    public function set_sectionid($sectionid) {
83
    public function set_sectionid($sectionid) {
Línea 60... Línea 84...
60
        $this->sectionid = $sectionid;
84
        $this->sectionid = $sectionid;
Línea 148... Línea 172...
148
 
172
 
149
    /**
173
    /**
150
     * Define the common setting that any restore section will have
174
     * Define the common setting that any restore section will have
151
     */
175
     */
152
    protected function define_settings() {
-
 
153
 
176
    protected function define_settings() {
154
        // All the settings related to this activity will include this prefix
177
        // All the settings related to this activity will include this prefix
Línea 155... Línea 178...
155
        $settingprefix = 'section_' . $this->info->sectionid . '_';
178
        $settingprefix = 'section_' . $this->info->sectionid . '_';
-
 
179
 
-
 
180
        // All these are common settings to be shared by all sections.
-
 
181
        $sectionincluded = $this->add_section_included_setting($settingprefix);
Línea -... Línea 182...
-
 
182
        $this->add_section_userinfo_setting($settingprefix, $sectionincluded);
-
 
183
    }
-
 
184
 
-
 
185
    /**
-
 
186
     * Add the section included setting to the task.
-
 
187
     *
-
 
188
     * @param string $settingprefix the identifier of the setting
-
 
189
     * @return section_backup_setting the setting added
156
 
190
     */
157
        // All these are common settings to be shared by all sections
191
    protected function add_section_included_setting(string $settingprefix): section_backup_setting {
-
 
192
        global $DB;
-
 
193
        // Define sectionincluded (to decide if the whole task must be really executed).
-
 
194
        $settingname = $settingprefix . 'included';
158
 
195
 
159
        // Define section_included (to decide if the whole task must be really executed)
196
        $delegatedcmid = $this->get_delegated_cm();
160
        $settingname = $settingprefix . 'included';
197
        if ($delegatedcmid) {
161
        $section_included = new restore_section_included_setting($settingname, base_setting::IS_BOOLEAN, true);
198
            $sectionincluded = new restore_subsection_included_setting($settingname, base_setting::IS_BOOLEAN, true);
162
        if (is_number($this->info->title)) {
199
            // Subsections depends on the parent activity included setting.
-
 
200
            $settingname = $this->get_modname() . '_' . $delegatedcmid . '_included';
-
 
201
            if ($this->plan->setting_exists($settingname)) {
-
 
202
                $cmincluded = $this->plan->get_setting($settingname);
-
 
203
                $cmincluded->add_dependency(
163
            $label = get_string('includesection', 'backup', $this->info->title);
204
                    $sectionincluded,
164
        } elseif (empty($this->info->title)) { // Don't throw error if title is empty, gracefully continue restore.
205
                );
-
 
206
            }
-
 
207
            $label = get_string('subsectioncontent', 'backup');
-
 
208
        } else {
-
 
209
            $sectionincluded = new restore_section_included_setting($settingname, base_setting::IS_BOOLEAN, true);
-
 
210
 
-
 
211
            if (is_number($this->info->title)) {
-
 
212
                $label = get_string('includesection', 'backup', $this->info->title);
-
 
213
            } else if (empty($this->info->title)) { // Don't throw error if title is empty, gracefully continue restore.
-
 
214
                $this->log(
-
 
215
                    'Section title missing in backup for section id ' . $this->info->sectionid,
-
 
216
                    backup::LOG_WARNING,
-
 
217
                    $this->name
165
            $this->log('Section title missing in backup for section id '.$this->info->sectionid, backup::LOG_WARNING, $this->name);
218
                );
-
 
219
                $label = get_string('unnamedsection', 'backup');
166
            $label = get_string('unnamedsection', 'backup');
220
            } else {
167
        } else {
-
 
168
            $label = $this->info->title;
-
 
Línea -... Línea 221...
-
 
221
                $label = $this->info->title;
-
 
222
            }
-
 
223
        }
-
 
224
 
-
 
225
        $sectionincluded->get_ui()->set_label($label);
-
 
226
        $this->add_setting($sectionincluded);
-
 
227
 
-
 
228
        return $sectionincluded;
-
 
229
    }
-
 
230
 
-
 
231
    /**
-
 
232
     * Add the section userinfo setting to the task.
-
 
233
     *
-
 
234
     * @param string $settingprefix the identifier of the setting
-
 
235
     * @param section_backup_setting $includefield the section included setting
-
 
236
     * @return section_backup_setting the setting added
-
 
237
     */
169
        }
238
    protected function add_section_userinfo_setting(
170
        $section_included->get_ui()->set_label($label);
239
        string $settingprefix,
171
        $this->add_setting($section_included);
240
        section_backup_setting $includefield
172
 
241
    ): section_backup_setting {
173
        // Define section_userinfo. Dependent of:
242
        // Define sectionuserinfo. Dependent of:
174
        // - users root setting
243
        // - users root setting.
175
        // - section_included setting.
244
        // - sectionincluded setting.
176
        $settingname = $settingprefix . 'userinfo';
245
        $settingname = $settingprefix . 'userinfo';
Línea -... Línea 246...
-
 
246
        $defaultvalue = false;
-
 
247
        if (isset($this->info->settings[$settingname]) && $this->info->settings[$settingname]) { // Only enabled when available
-
 
248
            $defaultvalue = true;
-
 
249
        }
-
 
250
 
-
 
251
        $delegatedcmid = $this->get_delegated_cm();
-
 
252
        if ($delegatedcmid) {
-
 
253
            $sectionuserinfo = new restore_subsection_userinfo_setting($settingname, base_setting::IS_BOOLEAN, $defaultvalue);
-
 
254
            // Subsections depends on the parent activity included setting.
-
 
255
            $settingname = $this->get_modname() . '_' . $delegatedcmid . '_userinfo';
-
 
256
            if ($this->plan->setting_exists($settingname)) {
-
 
257
                $cmincluded = $this->plan->get_setting($settingname);
177
        $defaultvalue = false;
258
                $cmincluded->add_dependency(
-
 
259
                    $sectionuserinfo,
-
 
260
                );
178
        if (isset($this->info->settings[$settingname]) && $this->info->settings[$settingname]) { // Only enabled when available
261
            }
179
            $defaultvalue = true;
262
        } else {
180
        }
263
            $sectionuserinfo = new restore_section_userinfo_setting($settingname, base_setting::IS_BOOLEAN, $defaultvalue);
181
 
264
        }
182
        $section_userinfo = new restore_section_userinfo_setting($settingname, base_setting::IS_BOOLEAN, $defaultvalue);
265
 
183
        if (!$defaultvalue) {
266
        if (!$defaultvalue) {
184
            // This is a bit hacky, but if there is no user data to restore, then
267
            // This is a bit hacky, but if there is no user data to restore, then
185
            // we replace the standard check-box with a select menu with the
268
            // we replace the standard check-box with a select menu with the
186
            // single choice 'No', and the select menu is clever enough that if
269
            // single choice 'No', and the select menu is clever enough that if
-
 
270
            // there is only one choice, it just displays a static string.
187
            // there is only one choice, it just displays a static string.
271
            //
188
            //
272
            // It would probably be better design to have a special UI class
-
 
273
            // setting_ui_checkbox_or_no, rather than this hack, but I am not
189
            // It would probably be better design to have a special UI class
274
            // going to do that today.
190
            // setting_ui_checkbox_or_no, rather than this hack, but I am not
275
            $sectionuserinfo->set_ui(
191
            // going to do that today.
276
                new backup_setting_ui_select($sectionuserinfo,
Línea 192... Línea 277...
192
            $section_userinfo->set_ui(new backup_setting_ui_select($section_userinfo, get_string('includeuserinfo','backup'),
277
                    get_string('includeuserinfo', 'backup'), [0 => get_string('no')])
Línea 193... Línea 278...
193
                    array(0 => get_string('no'))));
278
            );
194
        } else {
279
        } else {
195
            $section_userinfo->get_ui()->set_label(get_string('includeuserinfo','backup'));
280
            $sectionuserinfo->get_ui()->set_label(get_string('includeuserinfo', 'backup'));
-
 
281
        }
-
 
282
 
-
 
283
        $this->add_setting($sectionuserinfo);
Línea 196... Línea -...
196
        }
-
 
197
 
284
 
198
        $this->add_setting($section_userinfo);
285
        // Look for "users" root setting.
199
 
286
        $users = $this->plan->get_setting('users');