ILIAS  release_5-1 Revision 5.0.0-5477-g43f3e3fab5f
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{
17 private $server = null;
18 private $mid = 0;
19
20 private $mapping = null;
21
26 {
27 $this->server = $server;
28 }
29
34 public function getServer()
35 {
36 return $this->server;
37 }
38
43 public function getMid()
44 {
45 return $this->mid;
46 }
47
48
53 public function getMappingSettings()
54 {
55 return $this->mapping;
56 }
57
63 public function checkAllocationActivation(ilECSSetting $server, $a_content_id)
64 {
65 try
66 {
67 include_once './Services/WebServices/ECS/classes/Course/class.ilECSCourseMemberConnector.php';
68 $crsm_reader = new ilECSCourseMemberConnector($server);
69 $details = $crsm_reader->getCourseMember($a_content_id,true);
70 $this->mid = $details->getMySender();
71
72 // Check if import is enabled
73 include_once './Services/WebServices/ECS/classes/class.ilECSParticipantSetting.php';
74 $part = ilECSParticipantSetting::getInstance($this->getServer()->getServerId(), $this->getMid());
75 if(!$part->isImportEnabled())
76 {
77 $GLOBALS['ilLog']->write(__METHOD__.': Import disabled for mid '.$this->getMid());
78 return false;
79 }
80 // Check course allocation setting
81 include_once './Services/WebServices/ECS/classes/Mapping/class.ilECSNodeMappingSettings.php';
83 $this->getServer()->getServerId(),
84 $this->getMid()
85 );
86 return $this->getMappingSettings()->isCourseAllocationEnabled();
87 }
89 {
90 $GLOBALS['ilLog']->write(__METHOD__.': Reading course member details failed with message '. $e->getMessage());
91 return false;
92 }
93 }
94
95
101 public function handleCreate(ilECSSetting $server, $a_content_id)
102 {
103 include_once './Services/WebServices/ECS/classes/Tree/class.ilECSCmsData.php';
104 include_once './Services/WebServices/ECS/classes/Tree/class.ilECSCmsTree.php';
105 include_once './Services/WebServices/ECS/classes/Course/class.ilECSCourseConnector.php';
106
107 if(!$this->checkAllocationActivation($server, $a_content_id))
108 {
109 return true;
110 }
111 try
112 {
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 }
118 catch(ilECSConnectorException $e)
119 {
120 $GLOBALS['ilLog']->write(__METHOD__.': Course member creation failed with mesage ' . $e->getMessage());
121 return false;
122 }
123 return true;
124 }
125
131 public function handleDelete(ilECSSetting $server, $a_content_id)
132 {
133 // nothing todo
134 return true;
135 }
136
142 public function handleUpdate(ilECSSetting $server, $a_content_id)
143 {
144 if(!$this->checkAllocationActivation($server, $a_content_id))
145 {
146 return true;
147 }
148
149 try
150 {
151 $course_member = $this->readCourseMember($server,$a_content_id);
152 $this->doUpdate($a_content_id, $course_member);
153 return true;
154 }
155 catch(ilECSConnectorException $e)
156 {
157 $GLOBALS['ilLog']->write(__METHOD__.': Course member update failed with mesage ' . $e->getMessage());
158 return false;
159 }
160 return true;
161 }
162
163
168 protected function doUpdate($a_content_id, $course_member)
169 {
170 $GLOBALS['ilLog']->write(__METHOD__.': Starting ecs member update');
171
172 $course_id = (int) $course_member->lectureID;
173 if(!$course_id)
174 {
175 $GLOBALS['ilLog']->write(__METHOD__.': Missing course id');
176 return false;
177 }
178 include_once './Services/WebServices/ECS/classes/class.ilECSImport.php';
179 $GLOBALS['ilLog']->write(__METHOD__.': sid: '.$this->getServer()->getServerId().' course_id: '.$course_id.' mid: '.$this->mid);
180 //$crs_obj_id = ilECSImport::_lookupObjId($this->getServer()->getServerId(), $course_id, $this->mid);
181 $crs_obj_id = ilECSImport::lookupObjIdByContentId($this->getServer()->getServerId(), $this->mid, $course_id);
182
183 if(!$crs_obj_id)
184 {
185 // check for parallel scenario iv and create courses
186 $GLOBALS['ilLog']->write(__METHOD__.': Missing assigned course with id '. $course_id);
187 return false;
188 }
189
190 $course = $this->readCourse($course_member);
191 // Lookup already imported users and update their status
192 $assignments = $this->readAssignments($course,$course_member);
193
194 // iterate through all parallel groups
195 foreach((array) $assignments as $cms_id => $assigned)
196 {
197 $sub_id = ($cms_id == $course_id) ? 0 : $cms_id;
198
199 include_once './Services/WebServices/ECS/classes/class.ilECSImport.php';
201 $this->getServer()->getServerId(),
202 $this->getMid(),
203 $course_id,
204 $sub_id);
205
206 $this->refreshAssignmentStatus($course_member, $obj_id, $sub_id, $assigned);
207 }
208 return true;
209 }
210
216 protected function readAssignments($course,$course_member)
217 {
218 $put_in_course = true;
219
220 include_once './Services/WebServices/ECS/classes/Mapping/class.ilECSMappingUtils.php';
221 switch((int) $course->groupScenario)
222 {
224 $GLOBALS['ilLog']->write(__METHOD__.': No parallel group scenario defined.');
225 $put_in_course = true;
226 break;
227
229 $GLOBALS['ilLog']->write(__METHOD__.': Parallel group scenario one course.');
230 $put_in_course = true;
231 break;
232
234 $GLOBALS['ilLog']->write(__METHOD__.': Parallel group scenario groups in courses.');
235 $put_in_course = false;
236 break;
237
239 $GLOBALS['ilLog']->write(__METHOD__.': Parallel group scenario only courses.');
240 $put_in_course = false;
241 break;
242
243 default:
244 $GLOBALS['ilLog']->write(__METHOD__.': Parallel group scenario undefined.');
245 $put_in_course = true;
246 break;
247 }
248
249 $course_id = $course_member->lectureID;
250 $assigned = array();
251 foreach((array) $course_member->members as $member)
252 {
253 $assigned[$course_id][$member->personID] = array(
254 'id' => $member->personID,
255 'role' => $member->role
256 );
257
258 foreach((array) $member->groups as $pgroup)
259 {
260 if(!$put_in_course)
261 {
262 // @todo check hierarchy of roles
263 $assigned[$pgroup->num][$member->personID] = array(
264 'id' => $member->personID,
265 'role' => $pgroup->role
266 );
267 }
268 }
269 }
270 $GLOBALS['ilLog']->write(__METHOD__.': ECS member assignments '.print_r($assigned,true));
271 return $assigned;
272 }
273
274
275
281 protected function refreshAssignmentStatus($course_member, $obj_id, $sub_id, $assigned)
282 {
283 include_once './Services/WebServices/ECS/classes/Course/class.ilECSCourseMemberAssignment.php';
284
285 $type = ilObject::_lookupType($obj_id);
286 if($type == 'crs')
287 {
288 include_once './Modules/Course/classes/class.ilCourseParticipants.php';
290 }
291 else
292 {
293 include_once './Modules/Group/classes/class.ilGroupParticipants.php';
295 }
296
297
298
299 $course_id = (int) $course_member->lectureID;
301 $course_id,
302 $sub_id,
303 $obj_id);
304
305 // Delete remote deleted
306 foreach((array) $usr_ids as $usr_id)
307 {
308 if(!isset($assigned[$usr_id]))
309 {
310 $ass = ilECSCourseMemberAssignment::lookupAssignment($course_id, $sub_id,$obj_id, $usr_id);
311 if($ass instanceof ilECSCourseMemberAssignment)
312 {
315 (string) $usr_id);
316 if($il_usr_id = ilObjUser::_lookupId($acc))
317 {
318 // this removes also admin, tutor roles
319 $part->delete($il_usr_id);
320 $GLOBALS['ilLog']->write(__METHOD__.': Deassigning user ' . $usr_id. ' '. 'from course '. ilObject::_lookupTitle($obj_id));
321 }
322 else
323 {
324 $GLOBALS['ilLog']->write(__METHOD__.': Deassigning unknown ILIAS user ' . $usr_id. ' '. 'from course '. ilObject::_lookupTitle($obj_id));
325 }
326
327 $ass->delete();
328 }
329 }
330 }
331
332 // Assign new participants
333 foreach((array) $assigned as $person_id => $person)
334 {
335 $role = $this->lookupRole($person['role']);
336 $role_info = ilECSMappingUtils::getRoleMappingInfo($role);
337
340 (string) $person_id);
341 $GLOBALS['ilLog']->write(__METHOD__.': Handling user '. (string) $person_id);
342
343 if(in_array($person_id, $usr_ids))
344 {
345 if($il_usr_id = ilObjUser::_lookupId($acc))
346 {
347 $GLOBALS['ilLog']->write(__METHOD__.': '. print_r($role,true));
348 $part->updateRoleAssignments($il_usr_id, array($role));
349 // Nothing to do, user is member or is locally deleted
350 }
351 }
352 else
353 {
354 if($il_usr_id = ilObjUser::_lookupId($acc))
355 {
356 if($role)
357 {
358 // Add user
359 $GLOBALS['ilLog']->write(__METHOD__.': Assigning new user ' . $person_id. ' '. 'to '. ilObject::_lookupTitle($obj_id));
360 $part->add($il_usr_id,$role);
361 }
362
363 }
364 else
365 {
366 if($role_info['create'])
367 {
368 $this->createMember($person_id);
369 $GLOBALS['ilLog']->write(__METHOD__.': Added new user '. $person_id);
370 }
371 // Assign to role
372 if($role)
373 {
376 (string) $person_id);
377
378 if($il_usr_id = ilObjUser::_lookupId($acc))
379 {
380 $part->add($il_usr_id,$role);
381 }
382 }
383 }
384
385 $assignment = new ilECSCourseMemberAssignment();
386 $assignment->setServer($this->getServer()->getServerId());
387 $assignment->setMid($this->mid);
388 $assignment->setCmsId($course_id);
389 $assignment->setCmsSubId($sub_id);
390 $assignment->setObjId($obj_id);
391 $assignment->setUid($person_id);
392 $assignment->save();
393 }
394 }
395 return true;
396 }
397
398 protected function lookupRole($role_value)
399 {
400 $role_mappings = $this->getMappingSettings()->getRoleMappings();
401
402 /* Zero is an allowed value */
403 if(!$role_value)
404 {
405 //$GLOBALS['ilLog']->write(__METHOD__.': No role assignment missing attribute: role');
406 //return 0;
407 }
408 foreach($role_mappings as $name => $map)
409 {
410 if($role_value == $map)
411 {
412 return $name;
413 }
414 }
415 $GLOBALS['ilLog']->write(__METHOD__.': No role assignment mapping for role ' . $role_value);
416 return 0;
417 }
418
423 private function createMember($a_person_id)
424 {
425 try
426 {
427 include_once './Services/LDAP/classes/class.ilLDAPServer.php';
429 $server->doConnectionCheck();
430
431 include_once './Services/LDAP/classes/class.ilLDAPQuery.php';
434
435 $users = $query->fetchUser($a_person_id);
436 if($users)
437 {
438 include_once './Services/LDAP/classes/class.ilLDAPAttributeToUser.php';
439 $xml = new ilLDAPAttributeToUser($server);
440 $xml->setNewUserAuthMode($server->getAuthenticationMappingKey());
441 $xml->setUserData($users);
442 $xml->refresh();
443 }
444
445 }
446 catch (ilLDAPQueryException $exc)
447 {
448 $this->log->write($exc->getMessage());
449 }
450 }
451
452
457 private function readCourseMember(ilECSSetting $server, $a_content_id)
458 {
459 try
460 {
461 include_once './Services/WebServices/ECS/classes/Course/class.ilECSCourseMemberConnector.php';
462 $crs_member_reader = new ilECSCourseMemberConnector($server);
463
464 $member = $crs_member_reader->getCourseMember($a_content_id);
465 //$GLOBALS['ilLog']->write(__METHOD__.': ??????????? crs member:' . print_r($member,true));
466 //$GLOBALS['ilLog']->write(__METHOD__.': ??????????? content id :' . $a_content_id);
467 return $member;
468 }
469 catch(ilECSConnectorException $e)
470 {
471 throw $e;
472 }
473 }
474
479 private function readCourse($course_member)
480 {
481 try
482 {
483 include_once './Services/WebServices/ECS/classes/class.ilECSImport.php';
485 $this->getServer()->getServerId(),
486 $this->getMid(),
487 $course_member->lectureID
488 );
489
490 include_once './Services/WebServices/ECS/classes/Course/class.ilECSCourseConnector.php';
491 $crs_reader = new ilECSCourseConnector($this->getServer());
492 return $crs_reader->getCourse($ecs_id);
493 }
494 catch(ilECSConnectorException $e)
495 {
496 throw $e;
497 }
498 }
499
500}
501?>
const IL_LDAP_BIND_DEFAULT
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.
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='')
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 lookupAuthMode()
Lookup auth mode.
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 _lookupId($a_user_str)
Lookup id by login.
static _checkExternalAuthAccount($a_auth, $a_account)
check whether external account and authentication method matches with a user
static _lookupTitle($a_id)
lookup object title
static _lookupType($a_id, $a_reference=false)
lookup object type
$GLOBALS['PHPCAS_CLIENT']
This global variable is used by the interface class phpCAS.
Definition: CAS.php:276
Interface for all command queue handler classes.