ILIAS  release_6 Revision v6.24-5-g0c8bfefb3b8
class.ilECSCmsCourseMemberCommandQueueHandler.php
Go to the documentation of this file.
1<?php
2
3/* Copyright (c) 1998-2009 ILIAS open source, Extended GPL, see docs/LICENSE */
4
5include_once './Services/WebServices/ECS/classes/Mapping/class.ilECSNodeMappingSettings.php';
6include_once './Services/WebServices/ECS/interfaces/interface.ilECSCommandQueueHandler.php';
7include_once './Services/WebServices/ECS/classes/class.ilECSParticipantSettings.php';
8include_once './Services/WebServices/ECS/classes/class.ilECSParticipantSetting.php';
9
16{
20 protected $log;
21
22 private $server = null;
23 private $mid = 0;
24
25 private $mapping = null;
26
31 {
32 $this->log = $GLOBALS['DIC']->logger()->wsrv();
33 $this->server = $server;
34 }
35
40 public function getServer()
41 {
42 return $this->server;
43 }
44
49 public function getMid()
50 {
51 return $this->mid;
52 }
53
54
59 public function getMappingSettings()
60 {
61 return $this->mapping;
62 }
63
69 public function checkAllocationActivation(ilECSSetting $server, $a_content_id)
70 {
71 try {
72 include_once './Services/WebServices/ECS/classes/Course/class.ilECSCourseMemberConnector.php';
73 $crsm_reader = new ilECSCourseMemberConnector($server);
74 $details = $crsm_reader->getCourseMember($a_content_id, true);
75 $this->mid = $details->getMySender();
76
77 // Check if import is enabled
78 include_once './Services/WebServices/ECS/classes/class.ilECSParticipantSetting.php';
79 $part = ilECSParticipantSetting::getInstance($this->getServer()->getServerId(), $this->getMid());
80 if (!$part->isImportEnabled()) {
81 $this->log->warning('Import disabled for mid ' . $this->getMid());
82 return false;
83 }
84 // Check course allocation setting
85 include_once './Services/WebServices/ECS/classes/Mapping/class.ilECSNodeMappingSettings.php';
87 $this->getServer()->getServerId(),
88 $this->getMid()
89 );
90 return $this->getMappingSettings()->isCourseAllocationEnabled();
91 } catch (ilECSConnectorException $e) {
92 $this->log->error('Reading course member details failed with message ' . $e->getMessage());
93 return false;
94 }
95 }
96
97
103 public function handleCreate(ilECSSetting $server, $a_content_id)
104 {
105 include_once './Services/WebServices/ECS/classes/Tree/class.ilECSCmsData.php';
106 include_once './Services/WebServices/ECS/classes/Tree/class.ilECSCmsTree.php';
107 include_once './Services/WebServices/ECS/classes/Course/class.ilECSCourseConnector.php';
108
109 if (!$this->checkAllocationActivation($server, $a_content_id)) {
110 return true;
111 }
112 try {
113 //$course = $this->readCourse($server, $a_content_id);
114 $course_member = $this->readCourseMember($server, $a_content_id);
115 $this->doUpdate($a_content_id, $course_member);
116 return true;
117 } catch (ilECSConnectorException $e) {
118 $this->log->error('Course member creation failed with mesage ' . $e->getMessage());
119 return false;
120 }
121 return true;
122 }
123
129 public function handleDelete(ilECSSetting $server, $a_content_id)
130 {
131 // nothing todo
132 return true;
133 }
134
140 public function handleUpdate(ilECSSetting $server, $a_content_id)
141 {
142 if (!$this->checkAllocationActivation($server, $a_content_id)) {
143 return true;
144 }
145
146 try {
147 $course_member = $this->readCourseMember($server, $a_content_id);
148 $this->doUpdate($a_content_id, $course_member);
149 return true;
150 } catch (ilECSConnectorException $e) {
151 $this->log->error('Course member update failed with mesage ' . $e->getMessage());
152 return false;
153 }
154 return true;
155 }
156
157
162 protected function doUpdate($a_content_id, $course_member)
163 {
164 $this->log->debug('Starting ecs member update');
165
166 $course_id = (int) $course_member->lectureID;
167 if (!$course_id) {
168 $this->log->warning('Missing course id');
169 return false;
170 }
171 include_once './Services/WebServices/ECS/classes/class.ilECSImport.php';
172 $this->log->debug('sid: ' . $this->getServer()->getServerId() . ' course_id: ' . $course_id . ' mid: ' . $this->mid);
173 //$crs_obj_id = ilECSImport::_lookupObjId($this->getServer()->getServerId(), $course_id, $this->mid);
174 $crs_obj_id = ilECSImport::lookupObjIdByContentId($this->getServer()->getServerId(), $this->mid, $course_id);
175
176 if (!$crs_obj_id) {
177 $this->log->info('No main course created. Group scenario >= 3 ?');
178 }
179
180 $course = $this->readCourse($course_member);
181 // Lookup already imported users and update their status
182 $assignments = $this->readAssignments($course, $course_member);
183
184 $this->log->debug('Parallel group assignments');
185 $this->log->dump($assignments, ilLogLevel::DEBUG);
186 $this->log->debug('------------------ End assignemtns');
187
188 // iterate through all parallel groups
189 foreach ((array) $assignments as $cms_id => $assigned) {
190 $sub_id = ($cms_id == $course_id) ? null : $cms_id;
191
192 $this->log->debug('sub id is ' . $sub_id . ' for ' . $cms_id);
193
194 include_once './Services/WebServices/ECS/classes/class.ilECSImport.php';
196 $this->getServer()->getServerId(),
197 $this->getMid(),
198 $course_id,
199 $sub_id
200 );
201
202 $this->refreshAssignmentStatus($course_member, $obj_id, $sub_id, $assigned);
203 }
204 return true;
205 }
206
212 protected function readAssignments($course, $course_member)
213 {
214 $put_in_course = true;
215
216 include_once './Services/WebServices/ECS/classes/Mapping/class.ilECSMappingUtils.php';
217 switch ((int) $course->groupScenario) {
219 $this->log->debug('Parallel group scenario one course.');
220 $put_in_course = true;
221 break;
222
224 $this->log->debug('Parallel group scenario groups in courses.');
225 $put_in_course = false;
226 break;
227
229 $this->log->debug('Parallel group scenario only courses.');
230 $put_in_course = false;
231 break;
232
233 default:
234 $this->log->debug('Parallel group scenario undefined.');
235 $put_in_course = true;
236 break;
237 }
238
239 $course_id = $course_member->lectureID;
240 $assigned = array();
241 foreach ((array) $course_member->members as $member) {
242 $assigned[$course_id][$member->personID] = array(
243 'id' => $member->personID,
244 'role' => $member->role
245 );
246 if ((int) $course->groupScenario == ilECSMappingUtils::PARALLEL_ONE_COURSE) {
247 $this->log->debug('Group scenarion "one course". Ignoring group assignments');
248 continue;
249 }
250
251 foreach ((array) $member->groups as $pgroup) {
252 // the sequence number in the course ressource
253 $sequence_number = (int) $pgroup->num;
254 // find parallel group with by sequence number
255 $tmp_pgroup = $course->groups[$sequence_number];
256 if (is_object($tmp_pgroup)) {
257 $pgroup_id = $tmp_pgroup->id;
258 }
259 if (strlen($pgroup_id)) {
260 $this->log->debug('Found parallel group with id: ' . $pgroup_id . ': for sequence number: ' . $sequence_number);
261
262 // @todo check hierarchy of roles
263 $assigned[$pgroup_id][$member->personID] = array(
264 'id' => $member->personID,
265 'role' => $pgroup->role
266 );
267 } else {
268 $this->log->warning('Cannot find parallel group with sequence id: ' . $sequence_number);
269 }
270 }
271 }
272 $this->log->debug('ECS member assignments ' . print_r($assigned, true));
273 return $assigned;
274 }
275
276
277
283 protected function refreshAssignmentStatus($course_member, $obj_id, $sub_id, $assigned)
284 {
285 include_once './Services/WebServices/ECS/classes/Course/class.ilECSCourseMemberAssignment.php';
286
287 $this->log->debug('Currrent sub_id = ' . $sub_id . ', obj_id = ' . $obj_id);
288
289 $type = ilObject::_lookupType($obj_id);
290 if ($type == 'crs') {
291 include_once './Modules/Course/classes/class.ilCourseParticipants.php';
293 } elseif ($type == 'grp') {
294 include_once './Modules/Group/classes/class.ilGroupParticipants.php';
296 } else {
297 $this->log->warning('Invalid object type given for obj_id: ' . $obj_id);
298 return false;
299 }
300
301 $course_id = (int) $course_member->lectureID;
303 $course_id,
304 $sub_id,
305 $obj_id
306 );
307
308 // Delete remote deleted
309 foreach ((array) $usr_ids as $usr_id) {
310 if (!isset($assigned[$usr_id])) {
311 $ass = ilECSCourseMemberAssignment::lookupAssignment($course_id, $sub_id, $obj_id, $usr_id);
312 if ($ass instanceof ilECSCourseMemberAssignment) {
314 $this->getMappingSettings()->getAuthMode(),
315 (string) $usr_id
316 );
317
318 $this->log->debug('Local user assignment: ' . (string) $usr_id . ' <-> ' . $login);
319
320 if ($il_usr_id = ilObjUser::_lookupId($login)) {
321 // this removes also admin, tutor roles
322 $part->delete($il_usr_id);
323 $this->log->info('Deassigning user ' . $usr_id . ' ' . 'from course ' . ilObject::_lookupTitle($obj_id));
324 } else {
325 $this->log->notice('Deassigning unknown ILIAS user ' . $usr_id . ' ' . 'from course ' . ilObject::_lookupTitle($obj_id));
326 }
327
328 $ass->delete();
329 }
330 }
331 }
332
333 $this->log->debug('Handled assignmnent...');
334
335 // Assign new participants
336 foreach ((array) $assigned as $person_id => $person) {
337 $role = $this->lookupRole($person['role'], $type);
338 $role_info = ilECSMappingUtils::getRoleMappingInfo($role);
339
340 $this->log->debug('Using role info...');
342 $this->getMappingSettings()->getAuthMode(),
343 (string) $person_id
344 );
345 $this->log->info('Handling user ' . (string) $person_id);
346
347 if (in_array($person_id, $usr_ids)) {
348 if ($il_usr_id = ilObjUser::_lookupId($login)) {
349 $part->updateRoleAssignments($il_usr_id, array($part->getAutoGeneratedRoleId($role)));
350 } elseif ($role_info['create']) {
351 $this->createMember($person_id);
352 $this->log->info('Added new user ' . $person_id);
354 $this->getMappingSettings()->getAuthMode(),
355 (string) $person_id
356 );
357 if ($role) {
358 if ($il_usr_id = ilObjUser::_lookupId($login)) {
359 $part->add($il_usr_id, $role);
360 $part->sendNotification($part->NOTIFY_ACCEPT_USER, $il_usr_id);
361 }
362 }
363 }
364 } else {
365 if ($il_usr_id = ilObjUser::_lookupId($login)) {
366 // user exists => assign to course/group
367 if ($role) {
368 // Assign user
369 $this->log->info('Assigning new user ' . $person_id . ' ' . 'to ' . ilObject::_lookupTitle($obj_id) . ' using role: ' . $role);
370 $part->add($il_usr_id, $role);
371 $part->sendNotification($part->NOTIFY_ACCEPT_USER, $il_usr_id);
372 }
373 } else {
374 // no local user exists
375 if ($role_info['create']) {
376 $this->createMember($person_id);
377 $this->log->info('Added new user ' . $person_id);
379 $this->getMappingSettings()->getAuthMode(),
380 (string) $person_id
381 );
382 }
383 // Assign to role
384 if ($role) {
385 if ($il_usr_id = ilObjUser::_lookupId($login)) {
386 $part->add($il_usr_id, $role);
387 $part->sendNotification($part->NOTIFY_ACCEPT_USER, $il_usr_id);
388 }
389 }
390 }
391
392 $assignment = new ilECSCourseMemberAssignment();
393 $assignment->setServer($this->getServer()->getServerId());
394 $assignment->setMid($this->mid);
395 $assignment->setCmsId($course_id);
396 $assignment->setCmsSubId($sub_id);
397 $assignment->setObjId($obj_id);
398 $assignment->setUid($person_id);
399 $assignment->save();
400 }
401 }
402 return true;
403 }
404
410 protected function lookupRole($role_value, $a_obj_type)
411 {
412 $role_mappings = $this->getMappingSettings()->getRoleMappings();
413
414 /* Zero is an allowed value */
415 if (!$role_value) {
416 $this->log->debug('No role assignment attribute: role');
417 }
418 foreach ($role_mappings as $name => $map) {
419 $this->log->debug('Role "name" is ' . $name);
420
421 // map is a string of ids seperated by ","
422 $exploded_map = (array) explode(',', $map);
423 if (in_array($role_value, $exploded_map)) {
424 switch ($name) {
425 case IL_CRS_ADMIN:
426 case IL_CRS_TUTOR:
427 case IL_CRS_MEMBER:
428 if ($a_obj_type == 'crs') {
429 $this->log->debug('Role: ' . $role_value . ' maps: ' . $exploded_map);
430 return $name;
431 }
432 break;
433
434 case IL_GRP_ADMIN:
435 case IL_GRP_MEMBER:
436 if ($a_obj_type == 'grp') {
437 $this->log->debug('Role: ' . $role_value . ' maps: ' . $exploded_map);
438 return $name;
439 }
440 break;
441 }
442 }
443 }
444 $this->log->info('No role assignment mapping for role ' . $role_value);
445 return 0;
446 }
447
452 private function createMember($a_person_id)
453 {
454 if (!$this->getMappingSettings() instanceof ilECSNodeMappingSettings) {
455 $this->log->warning('Node mapping settings not initialized.');
456 }
457 $auth_mode = $this->getMappingSettings()->getAuthMode();
458
459 if (
460 $this->getMappingSettings()->getAuthMode() ==
462 ) {
463 $this->log->info('Not handling direct user creation for auth mode: ' . $auth_mode);
464 return false;
465 }
466 if (substr($auth_mode, 0, 4) !== 'ldap') {
467 $this->log->info('Not handling direct user creation for auth mode: ' . $auth_mode);
468 return false;
469 }
470
471 try {
472 include_once './Services/LDAP/classes/class.ilLDAPServer.php';
474 $server->doConnectionCheck();
475
476 include_once './Services/LDAP/classes/class.ilLDAPQuery.php';
479
480 $users = $query->fetchUser($a_person_id, true);
481 if ($users) {
482 include_once './Services/User/classes/class.ilUserCreationContext.php';
484
485 include_once './Services/LDAP/classes/class.ilLDAPAttributeToUser.php';
487 $xml->setNewUserAuthMode($server->getAuthenticationMappingKey());
488 $xml->setUserData($users);
489 $xml->refresh();
490 }
491 } catch (ilLDAPQueryException $exc) {
492 $this->log->error($exc->getMessage());
493 }
494 }
495
496
501 private function readCourseMember(ilECSSetting $server, $a_content_id)
502 {
503 try {
504 include_once './Services/WebServices/ECS/classes/Course/class.ilECSCourseMemberConnector.php';
505 $crs_member_reader = new ilECSCourseMemberConnector($server);
506
507 $member = $crs_member_reader->getCourseMember($a_content_id);
508 return $member;
509 } catch (ilECSConnectorException $e) {
510 throw $e;
511 }
512 }
513
518 private function readCourse($course_member)
519 {
520 try {
521 include_once './Services/WebServices/ECS/classes/class.ilECSImport.php';
523 $this->getServer()->getServerId(),
524 $this->getMid(),
525 $course_member->lectureID
526 );
527
528 include_once './Services/WebServices/ECS/classes/Course/class.ilECSCourseConnector.php';
529 $crs_reader = new ilECSCourseConnector($this->getServer());
530 return $crs_reader->getCourse($ecs_id);
531 } catch (ilECSConnectorException $e) {
532 throw $e;
533 }
534 }
535}
if(!defined('PATH_SEPARATOR')) $GLOBALS['_PEAR_default_error_mode']
Definition: PEAR.php:64
An exception for terminatinating execution or to throw for unit testing.
const AUTH_SHIBBOLETH
const IL_LDAP_BIND_DEFAULT
const IL_CRS_ADMIN
Base class for course and group participants.
const IL_CRS_MEMBER
const IL_GRP_MEMBER
const IL_CRS_TUTOR
const IL_GRP_ADMIN
static _getAuthModeName($a_auth_key)
static _getInstanceByObjId($a_obj_id)
Get singleton instance.
handleCreate(ilECSSetting $server, $a_content_id)
Handle create.
readCourseMember(ilECSSetting $server, $a_content_id)
Read course from ecs.
readAssignments($course, $course_member)
Read assignments for all parallel groups.
refreshAssignmentStatus($course_member, $obj_id, $sub_id, $assigned)
Refresh status of course member assignments.
lookupRole($role_value, $a_obj_type)
Lookup local role by assignment.
checkAllocationActivation(ilECSSetting $server, $a_content_id)
Check if course allocation is activated for one recipient of the.
handleUpdate(ilECSSetting $server, $a_content_id)
Handle update.
handleDelete(ilECSSetting $server, $a_content_id)
Handle delete.
Storage of ecs course assignments.
static lookupAssignment($a_cms_id, $a_cms_sub_id, $a_obj_id, $a_usr_id)
Lookup assignment of user @global type $ilDB.
static lookupUserIds($a_cms_id, $a_cms_sub_id, $a_obj_id)
Lookup user ids @global type $ilDB.
Connector for course member ressource.
static lookupEContentIdByContentId($a_server_id, $a_mid, $a_content_id)
Lookup econtent id The econtent id is the unique id from ecs.
static lookupObjIdByContentId($a_server_id, $a_mid, $a_content_id, $a_sub_id=null)
Lookup obj_id by content id.
static getRoleMappingInfo($a_role_type_info=0)
Get role mapping info.
static getInstanceByServerMid($a_server_id, $a_mid)
Get instance.
static getInstance($a_server_id, $mid)
Get instance by server id and mid.
static _getInstanceByObjId($a_obj_id)
Get singleton instance.
Update/create ILIAS user account by given LDAP attributes according to user attribute mapping setting...
static getInstanceByServerId($a_server_id)
Get instance by server id.
static _getFirstActiveServer()
Get first active server.
static _checkExternalAuthAccount($a_auth, $a_account, $tryFallback=true)
check whether external account and authentication method matches with a user
static _lookupId($a_user_str)
Lookup id by login.
static _lookupTitle($a_id)
lookup object title
static _lookupType($a_id, $a_reference=false)
lookup object type
static getInstance()
Get instance.
if(!file_exists(getcwd() . '/ilias.ini.php'))
registration confirmation script for ilias
Definition: confirmReg.php:12
$login
Definition: cron.php:13
Interface for all command queue handler classes.
if($format !==null) $name
Definition: metadata.php:230
$xml
Definition: metadata.php:332
$query
$type