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
class backup_section_task extends backup_task {
36
class backup_section_task extends backup_task {
Línea 37... Línea 37...
37
 
37
 
Línea 38... Línea 38...
38
    protected $sectionid;
38
    protected $sectionid;
-
 
39
 
-
 
40
    /**
-
 
41
     * @var stdClass $section The database section object.
-
 
42
     */
-
 
43
    protected stdClass $section;
-
 
44
 
-
 
45
    /**
-
 
46
     * @var int|null $delegatedcmid the course module that is delegating this section (if any)
-
 
47
     */
-
 
48
    protected ?int $delegatedcmid = null;
39
 
49
 
40
    /**
50
    /**
41
     * Constructor - instantiates one object of this class
51
     * Constructor - instantiates one object of this class
42
     */
52
     */
Línea 43... Línea 53...
43
    public function __construct($name, $sectionid, $plan = null) {
53
    public function __construct($name, $sectionid, $plan = null) {
44
        global $DB;
54
        global $DB;
45
 
55
 
46
        // Check section exists
56
        // Check section exists
Línea -... Línea 57...
-
 
57
        if (!$section = $DB->get_record('course_sections', array('id' => $sectionid))) {
47
        if (!$section = $DB->get_record('course_sections', array('id' => $sectionid))) {
58
            throw new backup_task_exception('section_task_section_not_found', $sectionid);
Línea 48... Línea 59...
48
            throw new backup_task_exception('section_task_section_not_found', $sectionid);
59
        }
49
        }
60
 
Línea -... Línea 61...
-
 
61
        $this->section = $section;
-
 
62
        $this->sectionid  = $sectionid;
-
 
63
 
-
 
64
        parent::__construct($name, $plan);
-
 
65
    }
-
 
66
 
-
 
67
    /**
-
 
68
     * Set the course module that is delegating this section.
-
 
69
     *
-
 
70
     * Delegated section can belong to any kind of plugin. However, when a delegated
-
 
71
     * section belongs to a course module, the UI will present all settings according.
-
 
72
     *
-
 
73
     * @param int $cmid the course module id that is delegating this section
-
 
74
     */
-
 
75
    public function set_delegated_cm(int $cmid) {
-
 
76
        $this->delegatedcmid = $cmid;
-
 
77
    }
-
 
78
 
-
 
79
    /**
-
 
80
     * Get the course module that is delegating this section.
-
 
81
     *
-
 
82
     * @return int|null the course module id that is delegating this section
-
 
83
     */
-
 
84
    public function get_delegated_cm(): ?int {
-
 
85
        return $this->delegatedcmid;
-
 
86
    }
-
 
87
 
-
 
88
    /**
-
 
89
     * Get the delegate activity modname (if any).
-
 
90
     *
-
 
91
     * @return string|null the modname of the delegated activity
-
 
92
     */
-
 
93
    public function get_modname(): ?string {
50
 
94
        if (empty($this->section->component)) {
51
        $this->sectionid  = $sectionid;
95
            return null;
52
 
96
        }
Línea 53... Línea 97...
53
        parent::__construct($name, $plan);
97
        return core_component::normalize_component($this->section->component)[1];
Línea 70... Línea 114...
70
     */
114
     */
71
    public function build() {
115
    public function build() {
Línea 72... Línea 116...
72
 
116
 
73
        // Set the backup::VAR_CONTEXTID setting to course context as far as next steps require that
117
        // Set the backup::VAR_CONTEXTID setting to course context as far as next steps require that
74
        $coursectxid = context_course::instance($this->get_courseid())->id;
118
        $coursectxid = context_course::instance($this->get_courseid())->id;
Línea 75... Línea 119...
75
        $this->add_setting(new backup_activity_generic_setting(backup::VAR_CONTEXTID, base_setting::IS_INTEGER, $coursectxid));
119
        $this->add_section_setting(backup::VAR_CONTEXTID, base_setting::IS_INTEGER, $coursectxid);
76
 
120
 
77
        // Add some extra settings that related processors are going to need
121
        // Add some extra settings that related processors are going to need
Línea 78... Línea 122...
78
        $this->add_setting(new backup_activity_generic_setting(backup::VAR_SECTIONID, base_setting::IS_INTEGER, $this->sectionid));
122
        $this->add_section_setting(backup::VAR_SECTIONID, base_setting::IS_INTEGER, $this->sectionid);
79
        $this->add_setting(new backup_activity_generic_setting(backup::VAR_COURSEID, base_setting::IS_INTEGER, $this->get_courseid()));
123
        $this->add_section_setting(backup::VAR_COURSEID, base_setting::IS_INTEGER, $this->get_courseid());
Línea 80... Línea 124...
80
 
124
 
Línea 135... Línea 179...
135
    }
179
    }
Línea 136... Línea 180...
136
 
180
 
Línea 137... Línea 181...
137
// Protected API starts here
181
// Protected API starts here
138
 
182
 
139
    /**
183
    /**
140
     * Define the common setting that any backup section will have
184
     * Define the common setting that any backup section will have.
141
     */
185
     */
Línea 142... Línea 186...
142
    protected function define_settings() {
186
    protected function define_settings() {
143
        global $DB;
187
        global $DB;
Línea -... Línea 188...
-
 
188
 
144
 
189
        // All the settings related to this activity will include this prefix.
-
 
190
        $settingprefix = 'section_' . $this->sectionid . '_';
Línea -... Línea 191...
-
 
191
 
-
 
192
        $incudefield = $this->add_section_included_setting($settingprefix);
-
 
193
        $this->add_section_userinfo_setting($settingprefix, $incudefield);
-
 
194
    }
-
 
195
 
-
 
196
    /**
-
 
197
     * Add a setting to the task. This method is used to add a setting to the task
-
 
198
     *
-
 
199
     * @param int|string $identifier the identifier of the setting
-
 
200
     * @param string $type the type of the setting
145
        // All the settings related to this activity will include this prefix
201
     * @param string|int $value the value of the setting
-
 
202
     * @return section_backup_setting the setting added
-
 
203
     */
-
 
204
    protected function add_section_setting(int|string $identifier, string $type, string|int $value): section_backup_setting {
-
 
205
        if ($this->get_delegated_cm()) {
-
 
206
            $setting = new backup_subsection_generic_setting($identifier, $type, $value);
-
 
207
        } else {
-
 
208
            $setting = new backup_section_generic_setting($identifier, $type, $value);
-
 
209
        }
-
 
210
        $this->add_setting($setting);
-
 
211
        return $setting;
-
 
212
    }
-
 
213
 
-
 
214
    /**
-
 
215
     * Add the section included setting to the task.
-
 
216
     *
146
        $settingprefix = 'section_' . $this->sectionid . '_';
217
     * @param string $settingprefix the identifier of the setting
Línea 147... Línea 218...
147
 
218
     * @return section_backup_setting the setting added
148
        // All these are common settings to be shared by all sections
219
     */
-
 
220
    protected function add_section_included_setting(string $settingprefix): section_backup_setting {
-
 
221
        global $DB;
-
 
222
        $course = $DB->get_record('course', ['id' => $this->section->course], '*', MUST_EXIST);
-
 
223
 
-
 
224
        // Define sectionincluded (to decide if the whole task must be really executed).
-
 
225
        $settingname = $settingprefix . 'included';
-
 
226
 
-
 
227
        $delegatedcmid = $this->get_delegated_cm();
-
 
228
        if ($delegatedcmid) {
-
 
229
            $sectionincluded = new backup_subsection_included_setting($settingname, base_setting::IS_BOOLEAN, true);
-
 
230
            // Subsections depends on the parent activity included setting.
-
 
231
            $settingname = $this->get_modname() . '_' . $delegatedcmid . '_included';
-
 
232
            if ($this->plan->setting_exists($settingname)) {
-
 
233
                $cmincluded = $this->plan->get_setting($settingname);
149
 
234
                $cmincluded->add_dependency(
150
        $section = $DB->get_record('course_sections', array('id' => $this->sectionid), '*', MUST_EXIST);
235
                    $sectionincluded,
-
 
236
                );
-
 
237
            }
151
        $course = $DB->get_record('course', array('id' => $section->course), '*', MUST_EXIST);
238
            $sectionincluded->get_ui()->set_label(get_string('subsectioncontent', 'backup'));
-
 
239
        } else {
-
 
240
            $sectionincluded = new backup_section_included_setting($settingname, base_setting::IS_BOOLEAN, true);
-
 
241
            $sectionincluded->get_ui()->set_label(get_section_name($course, $this->section));
152
 
242
        }
-
 
243
 
-
 
244
        $this->add_setting($sectionincluded);
-
 
245
 
-
 
246
        return $sectionincluded;
-
 
247
    }
-
 
248
 
-
 
249
    /**
-
 
250
     * Add the section userinfo setting to the task.
-
 
251
     *
-
 
252
     * @param string $settingprefix the identifier of the setting
-
 
253
     * @param section_backup_setting $includefield the setting to depend on
153
        // Define section_included (to decide if the whole task must be really executed)
254
     * @return section_backup_setting the setting added
154
        $settingname = $settingprefix . 'included';
255
     */
155
        $section_included = new backup_section_included_setting($settingname, base_setting::IS_BOOLEAN, true);
256
    protected function add_section_userinfo_setting(
156
        $section_included->get_ui()->set_label(get_section_name($course, $section));
257
        string $settingprefix,
-
 
258
        section_backup_setting $includefield
-
 
259
    ): section_backup_setting {
-
 
260
        // Define sectionuserinfo. Dependent of:
-
 
261
        // - users root setting.
-
 
262
        // - section_included setting.
-
 
263
        $settingname = $settingprefix . 'userinfo';
-
 
264
 
-
 
265
        $delegatedcmid = $this->get_delegated_cm();
-
 
266
        if ($delegatedcmid) {
-
 
267
            $sectionuserinfo = new backup_subsection_userinfo_setting($settingname, base_setting::IS_BOOLEAN, true);
-
 
268
            // Subsections depends on the parent activity included setting.
-
 
269
            $settingname = $this->get_modname() . '_' . $delegatedcmid . '_userinfo';
-
 
270
            if ($this->plan->setting_exists($settingname)) {
157
        $this->add_setting($section_included);
271
                $cmincluded = $this->plan->get_setting($settingname);
-
 
272
                $cmincluded->add_dependency(
-
 
273
                    $sectionuserinfo,
158
 
274
                );
-
 
275
            }
-
 
276
        } else {
-
 
277
            $sectionuserinfo = new backup_section_userinfo_setting($settingname, base_setting::IS_BOOLEAN, true);
159
        // Define section_userinfo. Dependent of:
278
        }
160
        // - users root setting
279
 
161
        // - section_included setting
280
        $sectionuserinfo->get_ui()->set_label(get_string('includeuserinfo', 'backup'));
162
        $settingname = $settingprefix . 'userinfo';
281
        $sectionuserinfo->get_ui()->set_visually_hidden_label(
163
        $section_userinfo = new backup_section_userinfo_setting($settingname, base_setting::IS_BOOLEAN, true);
282
            get_string('section_prefix', 'core_backup', $this->section->name ?: $this->section->section)
164
        $section_userinfo->get_ui()->set_label(get_string('includeuserinfo','backup'));
283
        );
-
 
284
        $this->add_setting($sectionuserinfo);
-
 
285
        // Look for "users" root setting.
165
        $this->add_setting($section_userinfo);
286
        $users = $this->plan->get_setting('users');
166
        // Look for "users" root setting
287
        $users->add_dependency($sectionuserinfo);