Proyectos de Subversion Moodle

Rev

| Ultima modificación | Ver Log |

Rev Autor Línea Nro. Línea
1 efrain 1
<?php
2
// This file is part of Moodle - http://moodle.org/
3
//
4
// Moodle is free software: you can redistribute it and/or modify
5
// it under the terms of the GNU General Public License as published by
6
// the Free Software Foundation, either version 3 of the License, or
7
// (at your option) any later version.
8
//
9
// Moodle is distributed in the hope that it will be useful,
10
// but WITHOUT ANY WARRANTY; without even the implied warranty of
11
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
12
// GNU General Public License for more details.
13
//
14
// You should have received a copy of the GNU General Public License
15
// along with Moodle.  If not, see <http://www.gnu.org/licenses/>.
16
 
17
/**
18
 * IMS Enterprise enrol plugin implementation.
19
 *
20
 * @package    enrol_imsenterprise
21
 * @copyright  2010 Eugene Venter
22
 * @license    http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
23
 */
24
 
25
defined('MOODLE_INTERNAL') || die();
26
 
27
 
28
/**
29
 * Class for dealing with role mappings in IMS Enterprise.
30
 *
31
 * @copyright  2010 Eugene Venter
32
 * @license    http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
33
 */
34
class imsenterprise_roles {
35
    /** @var imscode => ims role name. Role name mapping. */
36
    private $imsroles;
37
 
38
    /**
39
     * Constructor.
40
     */
41
    public function __construct() {
42
        $this->imsroles = array(
43
            '01' => 'Learner',
44
            '02' => 'Instructor',
45
            '03' => 'Content Developer',
46
            '04' => 'Member',
47
            '05' => 'Manager',
48
            '06' => 'Mentor',
49
            '07' => 'Administrator',
50
            '08' => 'TeachingAssistant',
51
        );
52
        // PLEASE NOTE: It may seem odd that "Content Developer" has a space in it
53
        // but "TeachingAssistant" doesn't. That's what the spec says though!!!
54
    }
55
 
56
    /**
57
     * Returns the mapped roles
58
     *
59
     * @return array of IMS roles indexed by IMS code.
60
     */
61
    public function get_imsroles() {
62
        return $this->imsroles;
63
    }
64
 
65
    /**
66
     * This function is only used when first setting up the plugin, to
67
     * decide which role assignments to recommend by default.
68
     * For example, IMS role '01' is 'Learner', so may map to 'student' in Moodle.
69
     *
70
     * @param string $imscode
71
     */
72
    public function determine_default_rolemapping($imscode) {
73
        global $DB;
74
 
75
        switch($imscode) {
76
            case '01':
77
            case '04':
78
                $shortname = 'student';
79
                break;
80
            case '06':
81
            case '08':
82
                $shortname = 'teacher';
83
                break;
84
            case '02':
85
            case '03':
86
                $shortname = 'editingteacher';
87
                break;
88
            case '05':
89
            case '07':
90
                $shortname = 'admin';
91
                break;
92
            default:
93
                return 0; // Zero for no match.
94
        }
95
        return (string)$DB->get_field('role', 'id', array('shortname' => $shortname));
96
    }
97
 
98
 
99
}
100
 
101
 
102
/**
103
 * Mapping between Moodle course attributes and IMS enterprise group description tags
104
 *
105
 * @package   enrol_imsenterprise
106
 * @copyright 2011 Aaron C Spike
107
 * @license   http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
108
 */
109
class imsenterprise_courses {
110
    /** @var array IMS group description names */
111
    private $imsnames;
112
    /** @var array moodle course field names */
113
    private $courseattrs;
114
 
115
    /**
116
     * Loads default
117
     */
118
    public function __construct() {
119
        $this->imsnames = array(
120
            'short' => 'short',
121
            'long' => 'long',
122
            'full' => 'full',
123
            'coursecode' => 'coursecode');
124
        $this->courseattrs = array('shortname', 'fullname', 'summary');
125
    }
126
 
127
    /**
128
     * Returns the assignable values for the course attribute
129
     * @param string $courseattr The course attribute (shortname, fullname...)
130
     * @return array Array of assignable values
131
     */
132
    public function get_imsnames($courseattr) {
133
 
134
        $values = $this->imsnames;
135
        if ($courseattr == 'summary') {
136
            $values = array_merge(array('ignore' => get_string('emptyattribute', 'enrol_imsenterprise')), $values);
137
        }
138
        return $values;
139
    }
140
 
141
    /**
142
     * courseattrs getter
143
     * @return array
144
     */
145
    public function get_courseattrs() {
146
        return $this->courseattrs;
147
    }
148
 
149
    /**
150
     * This function is only used when first setting up the plugin, to
151
     * decide which name assignments to recommend by default.
152
     *
153
     * @param string $courseattr
154
     * @return string
155
     */
156
    public function determine_default_coursemapping($courseattr) {
157
        switch($courseattr) {
158
            case 'fullname':
159
                $imsname = 'short';
160
                break;
161
            case 'shortname':
162
                $imsname = 'coursecode';
163
                break;
164
            default:
165
                $imsname = 'ignore';
166
        }
167
 
168
        return $imsname;
169
    }
170
}