ILIAS  release_9 Revision v9.13-25-g2c18ec4c24f
class.ilECSMappingUtils.php
Go to the documentation of this file.
1 <?php
2 
18 declare(strict_types=1);
19 
26 {
27  public const MAPPED_WHOLE_TREE = 1;
28  public const MAPPED_MANUAL = 2;
29  public const MAPPED_UNMAPPED = 3;
30 
31  public const PARALLEL_ONE_COURSE = 0;
32  public const PARALLEL_GROUPS_IN_COURSE = 1;
33  public const PARALLEL_ALL_COURSES = 2;
35 
39  public static function lookupMappingStatus(int $a_server_id, int $a_mid, int $a_tree_id): int
40  {
41  if (ilECSNodeMappingAssignments::hasAssignments($a_server_id, $a_mid, $a_tree_id)) {
42  if (ilECSNodeMappingAssignments::isWholeTreeMapped($a_server_id, $a_mid, $a_tree_id)) {
43  return self::MAPPED_WHOLE_TREE;
44  }
45  return self::MAPPED_MANUAL;
46  }
47  return self::MAPPED_UNMAPPED;
48  }
49 
53  public static function mappingStatusToString(int $a_status): string
54  {
55  global $DIC;
56 
57  return $DIC->language()->txt('ecs_node_mapping_status_' . $a_status);
58  }
59 
60 
61  public static function getCourseMappingFieldInfo(): array
62  {
63  global $DIC;
64 
65  $lng = $DIC['lng'];
66 
67  $field_info = array();
68  $counter = 0;
69  foreach (
70  array(
71  'organisation',
72  'orgunit',
73  'term',
74  'title',
75  'lecturer',
76  'courseType',
77  'degreeProgramme',
78  'module',
79  'venue'
80  ) as $field) {
81  $field_info[$counter]['name'] = $field;
82  $field_info[$counter]['translation'] = $lng->txt('ecs_cmap_att_' . $field);
83  $counter++;
84  }
85  return $field_info;
86  }
87 
88  public static function getCourseMappingFieldSelectOptions(): array
89  {
90  global $DIC;
91 
92  $lng = $DIC['lng'];
93 
94  $options[''] = $lng->txt('select_one');
95  foreach (self::getCourseMappingFieldInfo() as $info) {
96  $options[$info['name']] = $info['translation'];
97  }
98  return $options;
99  }
100 
104  public static function getCourseValueByMappingAttribute($course, $a_field): array
105  {
106  switch ($a_field) {
107  case 'organisation':
108  return array((string) $course->organisation);
109 
110  case 'term':
111  if (property_exists($course, "term")) {
112  return array((string) $course->term);
113  }
114  return [];
115 
116  case 'title':
117  return array((string) $course->title);
118 
119  case 'orgunit':
120  $units = array();
121  foreach ((array) $course->organisationalUnits as $unit) {
122  $units[] = (string) $unit->title;
123  }
124  return $units;
125 
126  case 'lecturer':
127  $lecturers = array();
128  foreach ((array) $course->groups as $group) {
129  foreach ((array) $group->lecturers as $lecturer) {
130  $lecturers[] = $lecturer->lastName . ', ' . $lecturer->firstName;
131  }
132  }
133  return $lecturers;
134 
135  case 'courseType':
136  return array((string) $course->lectureType);
137 
138  case 'degreeProgramme':
139  $degree_programmes = array();
140  foreach ((array) $course->degreeProgrammes as $prog) {
141  $degree_programmes[] = (string) $prog->title;
142  }
143  return $degree_programmes;
144 
145  case 'module':
146  $modules = array();
147  foreach ((array) $course->modules as $mod) {
148  $modules[] = (string) $mod->title;
149  }
150  return $modules;
151 
152  case 'venue':
153  $venues = [];
154  foreach ((array) $course->groups as $group) {
155  foreach ((array) $group->datesAndVenues as $venue) {
156  $venues[] = (string) $venue->venue;
157  }
158  }
159  return $venues;
160  }
161  return array();
162  }
163 
164 
168  public static function getRoleMappingInfo($a_role_type_info = 0): array
169  {
170  //KEEP!!! until the defines are turned into proper constants
171  include_once './Services/Membership/classes/class.ilParticipants.php';
172  $roles = array(
175  'lang' => 'il_crs_admin',
176  'create' => true,
177  'required' => true,
178  'type' => 'crs'),
181  'lang' => 'il_crs_tutor',
182  'create' => true,
183  'required' => false,
184  'type' => 'crs'),
187  'lang' => 'il_crs_member',
188  'create' => false,
189  'required' => true,
190  'type' => 'crs'),
193  'lang' => 'il_grp_admin',
194  'create' => true,
195  'required' => false,
196  'type' => 'grp'),
199  'lang' => 'il_grp_member',
200  'create' => false,
201  'required' => false,
202  'type' => 'grp')
203  );
204  if (!$a_role_type_info) {
205  return $roles;
206  }
207  return $roles[$a_role_type_info];
208  }
209 
214  public static function getAuthModeSelection(): array
215  {
216  global $DIC;
217 
218  $lng = $DIC->language();
219  $active_auth_modes = ilAuthUtils::_getActiveAuthModes();
220  $options = [];
221  $options["0"] = $lng->txt('select_one');
222  foreach ($active_auth_modes as $auth_string => $auth_int) {
223  if (
224  $auth_string === 'default' ||
225  $auth_string === 'ecs' ||
226  substr($auth_string, 0, 3) === 'lti'
227  ) {
228  continue;
229  }
230  $options[$auth_string] = ilAuthUtils::getAuthModeTranslation((string) $auth_int);
231  }
232  return $options;
233  }
234 }
static getRoleMappingInfo($a_role_type_info=0)
Get role mapping info.
static getAuthModeTranslation(string $a_auth_key, string $auth_name='')
static getCourseValueByMappingAttribute($course, $a_field)
Get course value by mapping.
static _getActiveAuthModes()
static isWholeTreeMapped(int $a_server_id, int $a_mid, int $a_tree_id)
Check if whole tree is mapped.
static lookupMappingStatus(int $a_server_id, int $a_mid, int $a_tree_id)
Lookup mapping status.
static getCourseMappingFieldSelectOptions()
static mappingStatusToString(int $a_status)
Get mapping status as string.
global $DIC
Definition: feed.php:28
$lng
static getAuthModeSelection()
Get auth mode selection with active authentication modes.