Proyectos de Subversion Moodle

Rev

Rev 1 | | Comparar con el anterior | Ultima modificación | Ver Log |

Rev Autor Línea Nro. Línea
1 efrain 1
/**
2
 * A collection of utility classes for use with course modules.
3
 *
1441 ariadna 4
 * TODO: remove this module as part of MDL-83627.
5
 *
1 efrain 6
 * @module moodle-course-util
7
 * @submodule moodle-course-util-cm
8
 */
9
 
10
Y.namespace('Moodle.core_course.util.cm');
11
 
1441 ariadna 12
Y.log(
13
    'YUI Moodle.core_course.util.cm is deprecated. Please, add support_components to your course format.',
14
    'warn',
15
    'moodle-course-coursebase'
16
);
17
 
1 efrain 18
/**
19
 * A collection of utility classes for use with course modules.
20
 *
21
 * @class Moodle.core_course.util.cm
22
 * @static
23
 */
24
Y.Moodle.core_course.util.cm = {
25
    CONSTANTS: {
26
        MODULEIDPREFIX: 'module-'
27
    },
28
    SELECTORS: {
29
        COURSEMODULE: '.activity',
30
        INSTANCENAME: '.instancename'
31
    },
32
 
33
    /**
34
     * Retrieve the course module item from one of it's child Nodes.
35
     *
36
     * @method getCourseModuleNodeFromComponent
37
     * @param coursemodulecomponent {Node} The component Node.
38
     * @return {Node|null} The Course Module Node.
39
     */
40
    getCourseModuleFromComponent: function(coursemodulecomponent) {
41
        return Y.one(coursemodulecomponent).ancestor(this.SELECTORS.COURSEMODULE, true);
42
    },
43
 
44
    /**
45
     * Determines the section ID for the provided section.
46
     *
47
     * @method getId
48
     * @param coursemodule {Node} The course module to find an ID for.
49
     * @return {Number|false} The ID of the course module in question or false if no ID was found.
50
     */
51
    getId: function(coursemodule) {
52
        // We perform a simple substitution operation to get the ID.
53
        var id = coursemodule.get('id').replace(
54
                this.CONSTANTS.MODULEIDPREFIX, '');
55
 
56
        // Attempt to validate the ID.
57
        id = parseInt(id, 10);
58
        if (typeof id === 'number' && isFinite(id)) {
59
            return id;
60
        }
61
        return false;
62
    },
63
 
64
    /**
65
     * Determines the section ID for the provided section.
66
     *
67
     * @method getName
68
     * @param coursemodule {Node} The course module to find an ID for.
69
     * @return {Number|false} The ID of the course module in question or false if no ID was found.
70
     */
71
    getName: function(coursemodule) {
72
        var instance = coursemodule.one(this.SELECTORS.INSTANCENAME);
73
        if (instance) {
74
            return instance.get('firstChild').get('data');
75
        }
76
        return null;
77
    }
78
};