Proyectos de Subversion Moodle

Rev

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

Rev 1 Rev 1441
Línea 36... Línea 36...
36
 */
36
 */
37
abstract class backup_activity_task extends backup_task {
37
abstract class backup_activity_task extends backup_task {
Línea 38... Línea 38...
38
 
38
 
39
    protected $moduleid;
39
    protected $moduleid;
-
 
40
    protected $sectionid;
-
 
41
 
-
 
42
    /** @var stdClass the section object */
40
    protected $sectionid;
43
    protected $section;
41
    protected $modulename;
44
    protected $modulename;
42
    protected $activityid;
45
    protected $activityid;
Línea 43... Línea 46...
43
    protected $contextid;
46
    protected $contextid;
Línea 48... Línea 51...
48
     * @param string $name the task identifier
51
     * @param string $name the task identifier
49
     * @param int $moduleid course module id (id in course_modules table)
52
     * @param int $moduleid course module id (id in course_modules table)
50
     * @param backup_plan|null $plan the backup plan instance this task is part of
53
     * @param backup_plan|null $plan the backup plan instance this task is part of
51
     */
54
     */
52
    public function __construct($name, $moduleid, $plan = null) {
55
    public function __construct($name, $moduleid, $plan = null) {
-
 
56
        global $DB;
Línea 53... Línea 57...
53
 
57
 
54
        // Check moduleid exists
58
        // Check moduleid exists
55
        if (!$coursemodule = get_coursemodule_from_id(false, $moduleid)) {
59
        if (!$coursemodule = get_coursemodule_from_id(false, $moduleid)) {
56
            throw new backup_task_exception('activity_task_coursemodule_not_found', $moduleid);
60
            throw new backup_task_exception('activity_task_coursemodule_not_found', $moduleid);
Línea 63... Línea 67...
63
        $this->moduleid   = $moduleid;
67
        $this->moduleid   = $moduleid;
64
        $this->sectionid  = $coursemodule->section;
68
        $this->sectionid  = $coursemodule->section;
65
        $this->modulename = $coursemodule->modname;
69
        $this->modulename = $coursemodule->modname;
66
        $this->activityid = $coursemodule->instance;
70
        $this->activityid = $coursemodule->instance;
67
        $this->contextid  = context_module::instance($this->moduleid)->id;
71
        $this->contextid  = context_module::instance($this->moduleid)->id;
-
 
72
        $this->section = $DB->get_record('course_sections', ['id' => $this->sectionid]);
Línea 68... Línea 73...
68
 
73
 
69
        parent::__construct($name, $plan);
74
        parent::__construct($name, $plan);
Línea 70... Línea 75...
70
    }
75
    }
Línea 89... Línea 94...
89
    public function get_modulename() {
94
    public function get_modulename() {
90
        return $this->modulename;
95
        return $this->modulename;
91
    }
96
    }
Línea 92... Línea 97...
92
 
97
 
-
 
98
    /**
-
 
99
     * Return if the activity is inside a subsection.
-
 
100
     *
-
 
101
     * @return bool
-
 
102
     */
-
 
103
    public function is_in_subsection(): bool {
-
 
104
        return !empty($this->section->component);
-
 
105
    }
-
 
106
 
-
 
107
 
93
    /**
108
    /**
94
     * @return int the id of the activity instance (id in the activity's instances table)
109
     * @return int the id of the activity instance (id in the activity's instances table)
95
     */
110
     */
96
    public function get_activityid() {
111
    public function get_activityid() {
97
        return $this->activityid;
112
        return $this->activityid;
Línea 121... Línea 136...
121
            $this->built = true;
136
            $this->built = true;
122
            return;
137
            return;
123
        }
138
        }
Línea 124... Línea 139...
124
 
139
 
125
        // Add some extra settings that related processors are going to need
140
        // Add some extra settings that related processors are going to need
126
        $this->add_setting(new backup_activity_generic_setting(backup::VAR_MODID, base_setting::IS_INTEGER, $this->moduleid));
141
        $this->add_section_setting(backup::VAR_MODID, base_setting::IS_INTEGER, $this->moduleid);
127
        $this->add_setting(new backup_activity_generic_setting(backup::VAR_COURSEID, base_setting::IS_INTEGER, $this->get_courseid()));
142
        $this->add_section_setting(backup::VAR_COURSEID, base_setting::IS_INTEGER, $this->get_courseid());
128
        $this->add_setting(new backup_activity_generic_setting(backup::VAR_SECTIONID, base_setting::IS_INTEGER, $this->sectionid));
143
        $this->add_section_setting(backup::VAR_SECTIONID, base_setting::IS_INTEGER, $this->sectionid);
129
        $this->add_setting(new backup_activity_generic_setting(backup::VAR_MODNAME, base_setting::IS_FILENAME, $this->modulename));
144
        $this->add_section_setting(backup::VAR_MODNAME, base_setting::IS_FILENAME, $this->modulename);
130
        $this->add_setting(new backup_activity_generic_setting(backup::VAR_ACTIVITYID, base_setting::IS_INTEGER, $this->activityid));
145
        $this->add_section_setting(backup::VAR_ACTIVITYID, base_setting::IS_INTEGER, $this->activityid);
Línea 131... Línea 146...
131
        $this->add_setting(new backup_activity_generic_setting(backup::VAR_CONTEXTID, base_setting::IS_INTEGER, $this->contextid));
146
        $this->add_section_setting(backup::VAR_CONTEXTID, base_setting::IS_INTEGER, $this->contextid);
132
 
147
 
Línea 133... Línea 148...
133
        // Create the activity directory
148
        // Create the activity directory
Línea 257... Línea 272...
257
    }
272
    }
Línea 258... Línea 273...
258
 
273
 
Línea 259... Línea 274...
259
// Protected API starts here
274
// Protected API starts here
260
 
275
 
261
    /**
276
    /**
262
     * Defines the common setting that any backup activity will have
277
     * Defines the common setting that any backup activity will have.
263
     */
278
     */
264
    protected function define_settings() {
279
    protected function define_settings() {
Línea 265... Línea 280...
265
        global $CFG;
280
        global $CFG;
266
        require_once($CFG->libdir.'/questionlib.php');
281
        require_once($CFG->libdir.'/questionlib.php');
Línea 267... Línea 282...
267
 
282
 
-
 
283
        // All the settings related to this activity will include this prefix.
-
 
284
        $settingprefix = $this->modulename . '_' . $this->moduleid . '_';
-
 
285
 
-
 
286
        // All these are common settings to be shared by all activities.
-
 
287
        $activityincluded = $this->add_activity_included_setting($settingprefix);
-
 
288
 
-
 
289
 
-
 
290
        $this->add_activity_userinfo_setting($settingprefix, $activityincluded);
-
 
291
 
-
 
292
        // End of common activity settings, let's add the particular ones.
-
 
293
        $this->define_my_settings();
-
 
294
    }
-
 
295
 
-
 
296
    /**
-
 
297
     * Add a setting to the task. This method is used to add a setting to the task
-
 
298
     *
-
 
299
     * @param int|string $identifier the identifier of the setting
-
 
300
     * @param string $type the type of the setting
-
 
301
     * @param string|int $value the value of the setting
-
 
302
     * @return section_backup_setting the setting added
-
 
303
     */
-
 
304
    protected function add_section_setting(int|string $identifier, string $type, string|int $value): activity_backup_setting {
-
 
305
        if ($this->is_in_subsection()) {
-
 
306
            $setting = new backup_subactivity_generic_setting($identifier, $type, $value);
-
 
307
        } else {
-
 
308
            $setting = new backup_activity_generic_setting($identifier, $type, $value);
Línea -... Línea 309...
-
 
309
        }
-
 
310
        $this->add_setting($setting);
-
 
311
        return $setting;
-
 
312
    }
-
 
313
 
-
 
314
    /**
-
 
315
     * Add the section include setting to the task.
268
        // All the settings related to this activity will include this prefix
316
     *
269
        $settingprefix = $this->modulename . '_' . $this->moduleid . '_';
317
     * @param string $settingprefix the identifier of the setting
270
 
318
     * @return activity_backup_setting the setting added
271
        // All these are common settings to be shared by all activities
319
     */
272
 
320
    protected function add_activity_included_setting(string $settingprefix): activity_backup_setting {
-
 
321
        // Define activity_include (to decide if the whole task must be really executed)
273
        // Define activity_include (to decide if the whole task must be really executed)
322
        // Dependent of:
274
        // Dependent of:
-
 
275
        // - activities root setting
-
 
276
        // - section_included setting (if exists)
-
 
277
        $settingname = $settingprefix . 'included';
323
        // - activities root setting.
278
        $activity_included = new backup_activity_generic_setting($settingname, base_setting::IS_BOOLEAN, true);
-
 
279
        $activity_included->get_ui()->set_icon(new image_icon('monologo', get_string('pluginname', $this->modulename),
-
 
280
            $this->modulename, array('class' => 'iconlarge icon-post ml-1')));
-
 
281
        $this->add_setting($activity_included);
-
 
282
        // Look for "activities" root setting
324
        // - sectionincluded setting (if exists).
283
        $activities = $this->plan->get_setting('activities');
-
 
284
        $activities->add_dependency($activity_included);
325
        $settingname = $settingprefix . 'included';
-
 
326
        if ($this->is_in_subsection()) {
-
 
327
            $activityincluded = new backup_subactivity_generic_setting($settingname, base_setting::IS_BOOLEAN, true);
-
 
328
        } else {
-
 
329
            $activityincluded = new backup_activity_generic_setting($settingname, base_setting::IS_BOOLEAN, true);
-
 
330
        }
-
 
331
        $activityincluded->get_ui()->set_icon(new image_icon('monologo', get_string('pluginname', $this->modulename),
-
 
332
            $this->modulename, array('class' => 'ms-1')));
Línea 285... Línea 333...
285
 
333
        $this->add_setting($activityincluded);
286
        if (question_module_uses_questions($this->modulename)) {
334
 
287
            $questionbank = $this->plan->get_setting('questionbank');
335
        // Look for "activities" root setting.
288
            $questionbank->add_dependency($activity_included);
336
        $activities = $this->plan->get_setting('activities');
289
        }
337
        $activities->add_dependency($activityincluded);
290
 
338
 
-
 
339
        // Look for "sectionincluded" section setting (if exists).
-
 
340
        $settingname = 'section_' . $this->sectionid . '_included';
Línea -... Línea 341...
-
 
341
        if ($this->plan->setting_exists($settingname)) {
-
 
342
            $sectionincluded = $this->plan->get_setting($settingname);
-
 
343
            $sectionincluded->add_dependency($activityincluded);
-
 
344
        }
-
 
345
        return $activityincluded;
-
 
346
    }
-
 
347
 
-
 
348
    /**
-
 
349
     * Add the section userinfo setting to the task.
-
 
350
     *
-
 
351
     * @param string $settingprefix the identifier of the setting
291
        // Look for "section_included" section setting (if exists)
352
     * @param activity_backup_setting $includefield the setting to depend on
292
        $settingname = 'section_' . $this->sectionid . '_included';
353
     * @return activity_backup_setting the setting added
293
        if ($this->plan->setting_exists($settingname)) {
354
     */
294
            $section_included = $this->plan->get_setting($settingname);
355
    protected function add_activity_userinfo_setting(
295
            $section_included->add_dependency($activity_included);
356
        string $settingprefix,
-
 
357
        activity_backup_setting $includefield
296
        }
358
    ): activity_backup_setting {
-
 
359
        // Define activity_userinfo. Dependent of:
297
 
360
        // - users root setting.
-
 
361
        // - sectionuserinfo setting (if exists).
-
 
362
        // - includefield setting.
298
        // Define activity_userinfo. Dependent of:
363
        $settingname = $settingprefix . 'userinfo';
-
 
364
        if ($this->is_in_subsection()) {
-
 
365
            $activityuserinfo = new backup_subactivity_userinfo_setting($settingname, base_setting::IS_BOOLEAN, true);
-
 
366
        } else {
299
        // - users root setting
367
            $activityuserinfo = new backup_activity_userinfo_setting($settingname, base_setting::IS_BOOLEAN, true);
300
        // - section_userinfo setting (if exists)
368
        }
301
        // - activity_included setting
369
 
302
        $settingname = $settingprefix . 'userinfo';
370
        $activityuserinfo->get_ui()->set_label('-');
-
 
371
        $activityuserinfo->get_ui()->set_visually_hidden_label(
303
        $activity_userinfo = new backup_activity_userinfo_setting($settingname, base_setting::IS_BOOLEAN, true);
372
            get_string('includeuserinfo_instance', 'core_backup', $this->name)
304
        //$activity_userinfo->get_ui()->set_label(get_string('includeuserinfo','backup'));
373
        );
305
        $activity_userinfo->get_ui()->set_label('-');
374
        $this->add_setting($activityuserinfo);
306
        $this->add_setting($activity_userinfo);
375
        // Look for "users" root setting.
307
        // Look for "users" root setting
376
        $users = $this->plan->get_setting('users');
308
        $users = $this->plan->get_setting('users');
377
        $users->add_dependency($activityuserinfo);
309
        $users->add_dependency($activity_userinfo);
-
 
310
        // Look for "section_userinfo" section setting (if exists)
-
 
Línea 311... Línea 378...
311
        $settingname = 'section_' . $this->sectionid . '_userinfo';
378
 
312
        if ($this->plan->setting_exists($settingname)) {
379
        // Look for "sectionuserinfo" section setting (if exists).
313
            $section_userinfo = $this->plan->get_setting($settingname);
380
        $settingname = 'section_' . $this->sectionid . '_userinfo';
Línea 314... Línea 381...
314
            $section_userinfo->add_dependency($activity_userinfo);
381
        if ($this->plan->setting_exists($settingname)) {
315
        }
382
            $sectionuserinfo = $this->plan->get_setting($settingname);
316
        // Look for "activity_included" setting
383
            $sectionuserinfo->add_dependency($activityuserinfo);