Proyectos de Subversion Moodle

Rev

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

Rev 1 Rev 1441
Línea 65... Línea 65...
65
        }])[0];
65
        }])[0];
66
        return JSON.parse(ajaxresult);
66
        return JSON.parse(ajaxresult);
67
    }
67
    }
Línea 68... Línea 68...
68
 
68
 
-
 
69
    /**
-
 
70
     * Private method to call core_courseformat_create_module webservice.
-
 
71
     *
-
 
72
     * @deprecated since Moodle 5.0 MDL-83469.
-
 
73
     * @todo MDL-83851 This will be deleted in Moodle 6.0.
-
 
74
     * @method _callEditWebservice
-
 
75
     * @param {number} courseId
-
 
76
     * @param {string} modName module name
-
 
77
     * @param {number} targetSectionNum target section number
-
 
78
     * @param {number} targetCmId optional target cm id
-
 
79
     */
-
 
80
    async _callAddModuleWebservice(courseId, modName, targetSectionNum, targetCmId) {
-
 
81
        log.debug('_callAddModuleWebservice() is deprecated. Use _callNewModuleWebservice() instead');
-
 
82
        const args = {
-
 
83
            courseid: courseId,
-
 
84
            modname: modName,
-
 
85
            targetsectionnum: targetSectionNum,
-
 
86
        };
-
 
87
        if (targetCmId) {
-
 
88
            args.targetcmid = targetCmId;
-
 
89
        }
-
 
90
        let ajaxresult = await ajax.call([{
-
 
91
            methodname: 'core_courseformat_create_module',
-
 
92
            args,
-
 
93
        }])[0];
-
 
94
        return JSON.parse(ajaxresult);
-
 
95
    }
-
 
96
 
-
 
97
    /**
-
 
98
     * Private method to call core_courseformat_new_module webservice.
-
 
99
     *
-
 
100
     * @method _callEditWebservice
-
 
101
     * @param {number} courseId
-
 
102
     * @param {string} modName module name
-
 
103
     * @param {number} targetSectionId target section number
-
 
104
     * @param {number} targetCmId optional target cm id
-
 
105
     */
-
 
106
    async _callNewModuleWebservice(courseId, modName, targetSectionId, targetCmId) {
-
 
107
        const args = {
-
 
108
            courseid: courseId,
-
 
109
            modname: modName,
-
 
110
            targetsectionid: targetSectionId,
-
 
111
        };
-
 
112
        if (targetCmId) {
-
 
113
            args.targetcmid = targetCmId;
-
 
114
        }
-
 
115
        let ajaxresult = await ajax.call([{
-
 
116
            methodname: 'core_courseformat_new_module',
-
 
117
            args,
-
 
118
        }])[0];
-
 
119
        return JSON.parse(ajaxresult);
-
 
120
    }
-
 
121
 
69
    /**
122
    /**
70
     * Execute a basic section state action.
123
     * Execute a basic section state action.
71
     * @param {StateManager} stateManager the current state manager
124
     * @param {StateManager} stateManager the current state manager
72
     * @param {string} action the action name
125
     * @param {string} action the action name
73
     * @param {array} sectionIds the section ids
126
     * @param {array} sectionIds the section ids
Línea 132... Línea 185...
132
     * @param {Object|undefined} data extra params for the log entry
185
     * @param {Object|undefined} data extra params for the log entry
133
     * @param {string|undefined} data.itemType the element type (will be taken from action if none)
186
     * @param {string|undefined} data.itemType the element type (will be taken from action if none)
134
     * @param {int|null|undefined} data.targetSectionId the target section id
187
     * @param {int|null|undefined} data.targetSectionId the target section id
135
     * @param {int|null|undefined} data.targetCmId the target cm id
188
     * @param {int|null|undefined} data.targetCmId the target cm id
136
     * @param {String|null|undefined} data.component optional component (for format plugins)
189
     * @param {String|null|undefined} data.component optional component (for format plugins)
-
 
190
     * @param {Object|undefined} [data.feedbackParams] the params to build the feedback message
137
     * @return {Object} the log entry
191
     * @return {Object} the log entry
138
     */
192
     */
139
    async _getLoggerEntry(stateManager, action, itemIds, data = {}) {
193
    async _getLoggerEntry(stateManager, action, itemIds, data = {}) {
140
        if (!isLoggerSet) {
194
        if (!isLoggerSet) {
141
            // In case the logger has not been set from init(), ensure we set the logger.
195
            // In case the logger has not been set from init(), ensure we set the logger.
142
            stateManager.setLogger(new SRLogger());
196
            stateManager.setLogger(new SRLogger());
143
            isLoggerSet = true;
197
            isLoggerSet = true;
144
        }
198
        }
145
        const feedbackParams = {
199
        let feedbackParams = {
146
            action,
200
            action,
147
            itemType: data.itemType ?? action.split('_')[0],
201
            itemType: data.itemType ?? action.split('_')[0],
148
        };
202
        };
149
        let batch = '';
203
        let batch = '';
150
        if (itemIds.length > 1) {
204
        if (itemIds.length > 1) {
Línea 159... Línea 213...
159
            feedbackParams.targetSectionName = stateManager.get('section', data.targetSectionId).title;
213
            feedbackParams.targetSectionName = stateManager.get('section', data.targetSectionId).title;
160
        }
214
        }
161
        if (data.targetCmId) {
215
        if (data.targetCmId) {
162
            feedbackParams.targetCmName = stateManager.get('cm', data.targetCmId).name;
216
            feedbackParams.targetCmName = stateManager.get('cm', data.targetCmId).name;
163
        }
217
        }
-
 
218
        if (data.feedbackParams) {
-
 
219
            feedbackParams = {...feedbackParams, ...data.feedbackParams};
-
 
220
        }
Línea 164... Línea 221...
164
 
221
 
165
        const message = await getString(
222
        const message = await getString(
166
            `${action.toLowerCase()}_feedback${batch}`,
223
            `${action.toLowerCase()}_feedback${batch}`,
167
            data.component ?? 'core_courseformat',
224
            data.component ?? 'core_courseformat',
Línea 307... Línea 364...
307
        stateManager.processUpdates(updates);
364
        stateManager.processUpdates(updates);
308
        this.cmLock(stateManager, cmids, false);
365
        this.cmLock(stateManager, cmids, false);
309
    }
366
    }
Línea 310... Línea 367...
310
 
367
 
311
    /**
-
 
312
     * Move course modules to specific course location.
-
 
313
     *
-
 
314
     * @deprecated since Moodle 4.4 MDL-77038.
-
 
315
     * @todo MDL-80116 This will be deleted in Moodle 4.8.
-
 
316
     * @param {StateManager} stateManager the current state manager
-
 
317
     * @param {array} sectionIds the list of section ids to move
-
 
318
     * @param {number} targetSectionId the target section id
-
 
319
     */
-
 
320
    async sectionMove(stateManager, sectionIds, targetSectionId) {
-
 
321
        log.debug('sectionMove() is deprecated. Use sectionMoveAfter() instead');
-
 
322
        if (!targetSectionId) {
-
 
323
            throw new Error(`Mutation sectionMove requires targetSectionId`);
-
 
324
        }
-
 
325
        const course = stateManager.get('course');
-
 
326
        this.sectionLock(stateManager, sectionIds, true);
-
 
327
        const updates = await this._callEditWebservice('section_move', course.id, sectionIds, targetSectionId);
-
 
328
        this.bulkReset(stateManager);
-
 
329
        stateManager.processUpdates(updates);
-
 
330
        this.sectionLock(stateManager, sectionIds, false);
-
 
331
    }
-
 
332
 
-
 
333
    /**
368
    /**
334
     * Move course modules after a specific course location.
369
     * Move course modules after a specific course location.
335
     *
370
     *
336
     * @param {StateManager} stateManager the current state manager
371
     * @param {StateManager} stateManager the current state manager
337
     * @param {array} sectionIds the list of section ids to move
372
     * @param {array} sectionIds the list of section ids to move
Línea 360... Línea 395...
360
            targetSectionId = 0;
395
            targetSectionId = 0;
361
        }
396
        }
362
        const course = stateManager.get('course');
397
        const course = stateManager.get('course');
363
        const updates = await this._callEditWebservice('section_add', course.id, [], targetSectionId);
398
        const updates = await this._callEditWebservice('section_add', course.id, [], targetSectionId);
364
        stateManager.processUpdates(updates);
399
        stateManager.processUpdates(updates);
-
 
400
        const logEntry = this._getLoggerEntry(stateManager, 'section_add', []);
-
 
401
        stateManager.addLoggerEntry(await logEntry);
365
    }
402
    }
Línea 366... Línea 403...
366
 
403
 
367
    /**
404
    /**
368
     * Delete sections.
405
     * Delete sections.
369
     *
406
     *
370
     * @param {StateManager} stateManager the current state manager
407
     * @param {StateManager} stateManager the current state manager
371
     * @param {array} sectionIds the list of course modules ids
408
     * @param {array} sectionIds the list of course modules ids
372
     */
409
     */
373
    async sectionDelete(stateManager, sectionIds) {
410
    async sectionDelete(stateManager, sectionIds) {
-
 
411
        const course = stateManager.get('course');
374
        const course = stateManager.get('course');
412
        const logEntry = this._getLoggerEntry(stateManager, 'section_delete', sectionIds);
375
        const updates = await this._callEditWebservice('section_delete', course.id, sectionIds);
413
        const updates = await this._callEditWebservice('section_delete', course.id, sectionIds);
376
        this.bulkReset(stateManager);
414
        this.bulkReset(stateManager);
-
 
415
        stateManager.processUpdates(updates);
377
        stateManager.processUpdates(updates);
416
        stateManager.addLoggerEntry(await logEntry);
Línea 378... Línea 417...
378
    }
417
    }
379
 
418
 
380
    /**
419
    /**
381
     * Delete cms.
420
     * Delete cms.
382
     * @param {StateManager} stateManager the current state manager
421
     * @param {StateManager} stateManager the current state manager
383
     * @param {array} cmIds the list of section ids
422
     * @param {array} cmIds the list of section ids
384
     */
423
     */
-
 
424
    async cmDelete(stateManager, cmIds) {
385
    async cmDelete(stateManager, cmIds) {
425
        const course = stateManager.get('course');
386
        const course = stateManager.get('course');
426
        const logEntry = this._getLoggerEntry(stateManager, 'cm_delete', cmIds);
387
        this.cmLock(stateManager, cmIds, true);
427
        this.cmLock(stateManager, cmIds, true);
388
        const updates = await this._callEditWebservice('cm_delete', course.id, cmIds);
428
        const updates = await this._callEditWebservice('cm_delete', course.id, cmIds);
389
        this.bulkReset(stateManager);
429
        this.bulkReset(stateManager);
-
 
430
        this.cmLock(stateManager, cmIds, false);
-
 
431
        stateManager.processUpdates(updates);
-
 
432
        stateManager.addLoggerEntry(await logEntry);
-
 
433
    }
-
 
434
 
-
 
435
    /**
-
 
436
     * Add a new module to a specific course section.
-
 
437
     *
-
 
438
     * @deprecated since Moodle 5.0 MDL-83469.
-
 
439
     * @todo MDL-83851 This will be deleted in Moodle 6.0.
-
 
440
     * @param {StateManager} stateManager the current state manager
-
 
441
     * @param {string} modName the modulename to add
-
 
442
     * @param {number} targetSectionNum the target section number
-
 
443
     * @param {number} targetCmId optional the target cm id
-
 
444
     */
-
 
445
    async addModule(stateManager, modName, targetSectionNum, targetCmId) {
-
 
446
        log.debug('addModule() is deprecated. Use newModule() instead');
-
 
447
        if (!modName) {
-
 
448
            throw new Error(`Mutation addModule requires moduleName`);
-
 
449
        }
-
 
450
        if (!targetSectionNum) {
-
 
451
            throw new Error(`Mutation addModule requires targetSectionNum`);
-
 
452
        }
-
 
453
        if (!targetCmId) {
-
 
454
            targetCmId = 0;
-
 
455
        }
-
 
456
        const course = stateManager.get('course');
-
 
457
        const updates = await this._callAddModuleWebservice(course.id, modName, targetSectionNum, targetCmId);
-
 
458
        stateManager.processUpdates(updates);
-
 
459
    }
-
 
460
 
-
 
461
    /**
-
 
462
     * Add a new module to a specific course section.
-
 
463
     *
-
 
464
     * @param {StateManager} stateManager the current state manager
-
 
465
     * @param {string} modName the modulename to add
-
 
466
     * @param {number} targetSectionId the target section id
-
 
467
     * @param {number} targetCmId optional the target cm id
-
 
468
     */
-
 
469
    async newModule(stateManager, modName, targetSectionId, targetCmId) {
-
 
470
        if (!modName) {
-
 
471
            throw new Error(`Mutation newModule requires moduleName`);
-
 
472
        }
-
 
473
        if (!targetSectionId) {
-
 
474
            throw new Error(`Mutation newModule requires targetSectionId`);
-
 
475
        }
-
 
476
        if (!targetCmId) {
-
 
477
            targetCmId = 0;
-
 
478
        }
-
 
479
        const course = stateManager.get('course');
-
 
480
        const pluginname = await getString(
-
 
481
            'pluginname',
-
 
482
            `${modName.toLowerCase()}`,
-
 
483
        );
-
 
484
        const logEntry = this._getLoggerEntry(stateManager, 'cm_add', [], {
-
 
485
            feedbackParams: {
-
 
486
                'modname': pluginname,
-
 
487
            },
-
 
488
        });
-
 
489
        const updates = await this._callNewModuleWebservice(course.id, modName, targetSectionId, targetCmId);
390
        this.cmLock(stateManager, cmIds, false);
490
        stateManager.processUpdates(updates);
Línea 391... Línea 491...
391
        stateManager.processUpdates(updates);
491
        stateManager.addLoggerEntry(await logEntry);
392
    }
492
    }
393
 
493
 
Línea 420... Línea 520...
420
     *
520
     *
421
     * @param {StateManager} stateManager the current state manager
521
     * @param {StateManager} stateManager the current state manager
422
     * @param {array} cmIds the list of course modules ids
522
     * @param {array} cmIds the list of course modules ids
423
     * @param {bool} complete the new completion value
523
     * @param {bool} complete the new completion value
424
     */
524
     */
425
    cmCompletion(stateManager, cmIds, complete) {
525
    async cmCompletion(stateManager, cmIds, complete) {
426
        const newValue = (complete) ? 1 : 0;
526
        const newState = (complete) ? 1 : 0;
427
        this._setElementsValue(stateManager, 'cm', cmIds, 'completionstate', newValue);
527
        const action = (newState == 1) ? 'cm_complete' : 'cm_uncomplete';
-
 
528
        const logEntry = this._getLoggerEntry(stateManager, action, cmIds);
-
 
529
        stateManager.setReadOnly(false);
-
 
530
        cmIds.forEach((id) => {
-
 
531
            const element = stateManager.get('cm', id);
-
 
532
            if (element) {
-
 
533
                element.isoverallcomplete = complete;
-
 
534
                element.completionstate = newState;
-
 
535
            }
-
 
536
        });
-
 
537
        stateManager.setReadOnly(true);
-
 
538
        stateManager.addLoggerEntry(await logEntry);
428
    }
539
    }
Línea 429... Línea 540...
429
 
540
 
430
    /**
541
    /**
431
     * Move cms to the right: indent = 1.
542
     * Move cms to the right: indent = 1.
Línea 529... Línea 640...
529
            newPageItem = stateManager.get(type, id);
640
            newPageItem = stateManager.get(type, id);
530
            if (!newPageItem) {
641
            if (!newPageItem) {
531
                return;
642
                return;
532
            }
643
            }
533
        }
644
        }
-
 
645
        const course = stateManager.get('course');
-
 
646
        if (course.pageItem && course.pageItem.type === type && course.pageItem.id === id) {
-
 
647
            return;
-
 
648
        }
534
        stateManager.setReadOnly(false);
649
        stateManager.setReadOnly(false);
535
        // Remove the current page item.
650
        // Remove the current page item.
536
        const course = stateManager.get('course');
-
 
537
        course.pageItem = null;
651
        course.pageItem = null;
538
        // Save the new page item.
652
        // Save the new page item.
539
        if (newPageItem) {
653
        if (newPageItem) {
540
            course.pageItem = {
654
            course.pageItem = {
541
                id,
655
                id,