Merge branch 'MDL-68614-master' of git://github.com/aanabit/moodle
[moodle.git] / enrol / imsenterprise / locallib.php
blobacaaa12ba1ce5ab0669ba7f9bc97f0e120df87f7
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.
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/>.
17 /**
18 * IMS Enterprise enrol plugin implementation.
20 * @package enrol_imsenterprise
21 * @copyright 2010 Eugene Venter
22 * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
25 defined('MOODLE_INTERNAL') || die();
28 /**
29 * Class for dealing with role mappings in IMS Enterprise.
31 * @copyright 2010 Eugene Venter
32 * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
34 class imsenterprise_roles {
35 /** @var imscode => ims role name. Role name mapping. */
36 private $imsroles;
38 /**
39 * Constructor.
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',
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!!!
56 /**
57 * Returns the mapped roles
59 * @return array of IMS roles indexed by IMS code.
61 public function get_imsroles() {
62 return $this->imsroles;
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.
70 * @param string $imscode
72 public function determine_default_rolemapping($imscode) {
73 global $DB;
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.
95 return (string)$DB->get_field('role', 'id', array('shortname' => $shortname));
103 * Mapping between Moodle course attributes and IMS enterprise group description tags
105 * @package enrol_imsenterprise
106 * @copyright 2011 Aaron C Spike
107 * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
109 class imsenterprise_courses {
110 /** @var array IMS group description names */
111 private $imsnames;
112 /** @var array moodle course field names */
113 private $courseattrs;
116 * Loads default
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');
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
132 public function get_imsnames($courseattr) {
134 $values = $this->imsnames;
135 if ($courseattr == 'summary') {
136 $values = array_merge(array('ignore' => get_string('emptyattribute', 'enrol_imsenterprise')), $values);
138 return $values;
142 * courseattrs getter
143 * @return array
145 public function get_courseattrs() {
146 return $this->courseattrs;
150 * This function is only used when first setting up the plugin, to
151 * decide which name assignments to recommend by default.
153 * @param string $courseattr
154 * @return string
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';
168 return $imsname;