ILIAS  release_5-3 Revision v5.3.23-19-g915713cf615
ilECSAppEventListener Class Reference

ECS Event Handler. More...

+ Inheritance diagram for ilECSAppEventListener:
+ Collaboration diagram for ilECSAppEventListener:

Static Public Member Functions

static handleEvent ($a_component, $a_event, $a_parameter)
 Handle an event in a listener. More...
 

Static Protected Member Functions

static initServer ($a_usr_id)
 Init server settings. More...
 
static _sendNotification (ilECSSetting $server, ilObjUser $user_obj)
 send notification about new user accounts More...
 
static handleMembership (ilObjUser $user)
 Assign missing course/groups to new user accounts. More...
 
static extendAccount (ilECSSetting $settings, ilObjUser $user)
 Extend account. More...
 
static updateEnrolmentStatus ($a_obj_id, ilObjUser $user, $a_status)
 Update enrolment status. More...
 

Detailed Description

ECS Event Handler.

Author
Stefan Meyer meyer.nosp@m.@lei.nosp@m.fos.c.nosp@m.om
Version
$Id$

Definition at line 35 of file class.ilECSAppEventListener.php.

Member Function Documentation

◆ _sendNotification()

static ilECSAppEventListener::_sendNotification ( ilECSSetting  $server,
ilObjUser  $user_obj 
)
staticprotected

send notification about new user accounts

protected

Definition at line 192 of file class.ilECSAppEventListener.php.

References $lang, ilMail\_getAutoGeneratedMessageString(), ilLanguageFactory\_getLanguage(), array, ilObject\getId(), ilECSSetting\getServerId(), ilECSSetting\getUserRecipients(), and ilECSSetting\getUserRecipientsAsString().

193  {
194  if (!count($server->getUserRecipients())) {
195  return true;
196  }
197  // If sub id is set => mail was send
198  include_once './Services/WebServices/ECS/classes/class.ilECSImport.php';
199  $import = new ilECSImport($server->getServerId(), $user_obj->getId());
200  if ($import->getSubId()) {
201  return false;
202  }
203 
204  include_once('./Services/Language/classes/class.ilLanguageFactory.php');
206  $lang->loadLanguageModule('ecs');
207 
208  include_once('./Services/Mail/classes/class.ilMail.php');
209  $mail = new ilMail(6);
210  $mail->enableSoap(false);
211  $subject = $lang->txt('ecs_new_user_subject');
212 
213  // build body
214  $body = $lang->txt('ecs_new_user_body') . "\n\n";
215  $body .= $lang->txt('ecs_new_user_profile') . "\n\n";
216  $body .= $user_obj->getProfileAsString($lang) . "\n\n";
218 
219  $mail->sendMail($server->getUserRecipientsAsString(), "", "", $subject, $body, array(), array("normal"));
220 
221  // Store sub_id = 1 in ecs import which means mail is send
222  $import->setSubId(1);
223  $import->save();
224 
225  return true;
226  }
getServerId()
Get current server id.
static _getLanguage($a_lang_key='')
Get langauge object.
getId()
get object id public
getUserRecipientsAsString()
Get new user recipients.
This class handles base functions for mail handling.
Storage of ECS imported objects.
Create styles array
The data for the language used.
static _getAutoGeneratedMessageString(ilLanguage $lang=null)
Get auto generated info string.
getUserRecipients()
Get new user recipients.
+ Here is the call graph for this function:

◆ extendAccount()

static ilECSAppEventListener::extendAccount ( ilECSSetting  $settings,
ilObjUser  $user 
)
staticprotected

Extend account.

Parameters
ilECSSetting$server
ilObjUser$user

Definition at line 268 of file class.ilECSAppEventListener.php.

References $end, $GLOBALS, ilECSSetting\getDuration(), ilObjUser\getTimeLimitUntil(), IL_CAL_MONTH, IL_CAL_UNIX, ilObjUser\setTimeLimitUntil(), time, and ilObject\update().

269  {
270  $end = new ilDateTime(time(), IL_CAL_UNIX);
271  $end->increment(IL_CAL_MONTH, $settings->getDuration());
272 
273  $GLOBALS['ilLog']->write(__METHOD__ . ': account extension ' . (string) $end);
274 
275  if ($user->getTimeLimitUntil() < $end->get(IL_CAL_UNIX)) {
276  $user->setTimeLimitUntil($end->get(IL_CAL_UNIX));
277  $user->update();
278  }
279  }
$end
Definition: saml1-acs.php:18
$GLOBALS['loaded']
Global hash that tracks already loaded includes.
const IL_CAL_MONTH
const IL_CAL_UNIX
setTimeLimitUntil($a_until)
Date and time handling
getDuration()
get duration
Add data(end) time
Method that wraps PHPs time in order to allow simulations with the workflow.
update()
update object in db
+ Here is the call graph for this function:

◆ handleEvent()

static ilECSAppEventListener::handleEvent (   $a_component,
  $a_event,
  $a_parameter 
)
static

Handle an event in a listener.

Parameters
string$a_componentcomponent, e.g. "Modules/Forum" or "Services/User"
string$a_eventevent e.g. "createUser", "updateUser", "deleteUser", ...
array$a_parameterparameter array (assoc), array("name" => ..., "phone_office" => ...)

Implements ilAppEventListener.

Definition at line 44 of file class.ilECSAppEventListener.php.

References $GLOBALS, $ilLog, $log, ilObjUser\_lookupAuthMode(), ilObjectFactory\getInstanceByObjId(), ilECSEnrolmentStatus\STATUS_ACTIVE, ilECSEnrolmentStatus\STATUS_PENDING, and ilECSEnrolmentStatus\STATUS_UNSUBSCRIBED.

45  {
46  global $ilLog;
47 
48  $log = $GLOBALS['DIC']->logger()->wsrv();
49 
50  $log->debug('Listening to event from: ' . $a_component . ' ' . $a_event);
51 
52  switch ($a_component) {
53  case 'Services/User':
54  switch ($a_event) {
55  case 'afterCreate':
56  $user = $a_parameter['user_obj'];
57  self::handleMembership($user);
58  break;
59  }
60  break;
61 
62  case 'Modules/Group':
63 
64  $log->debug('New event from group: ' . $a_event);
65  switch ($a_event) {
66  case 'addSubscriber':
67  case 'addToWaitingList':
68  if (ilObjUser::_lookupAuthMode($a_parameter['usr_id']) == 'ecs') {
69  if (!$user = ilObjectFactory::getInstanceByObjId($a_parameter['usr_id'])) {
70  $log->info('No valid user found for usr_id ' . $a_parameter['usr_id']);
71  return true;
72  }
73 
74  $settings = self::initServer($a_parameter['usr_id']);
75  self::extendAccount($settings, $user);
76 
77  include_once './Services/WebServices/ECS/classes/Connectors/class.ilECSEnrolmentStatus.php';
78  self::updateEnrolmentStatus($a_parameter['obj_id'], $user, ilECSEnrolmentStatus::STATUS_PENDING);
79  }
80  break;
81 
82  case 'deleteParticipant':
83  if (ilObjUser::_lookupAuthMode($a_parameter['usr_id']) == 'ecs') {
84  if (!$user = ilObjectFactory::getInstanceByObjId($a_parameter['usr_id'])) {
85  $log->info('No valid user found for usr_id ' . $a_parameter['usr_id']);
86  return true;
87  }
88  include_once './Services/WebServices/ECS/classes/Connectors/class.ilECSEnrolmentStatus.php';
89  self::updateEnrolmentStatus($a_parameter['obj_id'], $user, ilECSEnrolmentStatus::STATUS_UNSUBSCRIBED);
90  }
91  break;
92 
93  case 'addParticipant':
94  if ((ilObjUser::_lookupAuthMode($a_parameter['usr_id']) == 'ecs')) {
95  if (!$user = ilObjectFactory::getInstanceByObjId($a_parameter['usr_id'])) {
96  $log->info('No valid user found for usr_id ' . $a_parameter['usr_id']);
97  return true;
98  }
99 
100  $settings = self::initServer($user->getId());
101 
102  self::extendAccount($settings, $user);
103  #self::_sendNotification($settings,$user);
104 
105  include_once './Services/WebServices/ECS/classes/Connectors/class.ilECSEnrolmentStatus.php';
106  self::updateEnrolmentStatus($a_parameter['obj_id'], $user, ilECSEnrolmentStatus::STATUS_ACTIVE);
107  unset($user);
108  }
109  break;
110 
111 
112 
113  }
114  break;
115 
116  case 'Modules/Course':
117 
118  $GLOBALS['ilLog']->write(__METHOD__ . ': New event from course: ' . $a_event);
119  switch ($a_event) {
120 
121  case 'addSubscriber':
122  case 'addToWaitingList':
123  if (ilObjUser::_lookupAuthMode($a_parameter['usr_id']) == 'ecs') {
124  if (!$user = ilObjectFactory::getInstanceByObjId($a_parameter['usr_id'])) {
125  $log->info('No valid user found for usr_id ' . $a_parameter['usr_id']);
126  return true;
127  }
128 
129  $settings = self::initServer($a_parameter['usr_id']);
130  self::extendAccount($settings, $user);
131 
132  include_once './Services/WebServices/ECS/classes/Connectors/class.ilECSEnrolmentStatus.php';
133  self::updateEnrolmentStatus($a_parameter['obj_id'], $user, ilECSEnrolmentStatus::STATUS_PENDING);
134  }
135  break;
136 
137 
138  case 'deleteParticipant':
139  if (ilObjUser::_lookupAuthMode($a_parameter['usr_id']) == 'ecs') {
140  if (!$user = ilObjectFactory::getInstanceByObjId($a_parameter['usr_id'])) {
141  $log->info('No valid user found for usr_id ' . $a_parameter['usr_id']);
142  return true;
143  }
144  include_once './Services/WebServices/ECS/classes/Connectors/class.ilECSEnrolmentStatus.php';
145  self::updateEnrolmentStatus($a_parameter['obj_id'], $user, ilECSEnrolmentStatus::STATUS_UNSUBSCRIBED);
146  }
147  break;
148 
149  case 'addParticipant':
150 
151  if ((ilObjUser::_lookupAuthMode($a_parameter['usr_id']) == 'ecs')) {
152  if (!$user = ilObjectFactory::getInstanceByObjId($a_parameter['usr_id'])) {
153  $log->info('No valid user found for usr_id ' . $a_parameter['usr_id']);
154  return true;
155  }
156 
157  $settings = self::initServer($user->getId());
158 
159  self::extendAccount($settings, $user);
160  self::_sendNotification($settings, $user);
161 
162  include_once './Services/WebServices/ECS/classes/Connectors/class.ilECSEnrolmentStatus.php';
163  self::updateEnrolmentStatus($a_parameter['obj_id'], $user, ilECSEnrolmentStatus::STATUS_ACTIVE);
164  unset($user);
165  }
166  break;
167  }
168  break;
169  }
170  }
$GLOBALS['loaded']
Global hash that tracks already loaded includes.
static getInstanceByObjId($a_obj_id, $stop_on_error=true)
get an instance of an Ilias object by object id
static _lookupAuthMode($a_usr_id)
lookup auth mode
+ Here is the call graph for this function:

◆ handleMembership()

static ilECSAppEventListener::handleMembership ( ilObjUser  $user)
staticprotected

Assign missing course/groups to new user accounts.

Parameters
ilObjUser$user

Definition at line 232 of file class.ilECSAppEventListener.php.

References $GLOBALS, $log, ilObject\_lookupType(), ilCourseConstants\CRS_MEMBER, ilObjUser\getAuthMode(), ilObjUser\getExternalAccount(), ilObject\getId(), ilParticipants\getInstanceByObjId(), ilECSNodeMappingSettings\getInstanceByServerMid(), and ilECSCourseMemberAssignment\lookupMissingAssignmentsOfUser().

233  {
234  $log = $GLOBALS['DIC']->logger()->wsrv();
235  $log->debug('Handling ECS assignments ');
236 
237  include_once './Services/WebServices/ECS/classes/Course/class.ilECSCourseMemberAssignment.php';
239  foreach ($assignments as $assignment) {
240  include_once './Services/WebServices/ECS/classes/Mapping/class.ilECSNodeMappingSettings.php';
242  $assignment->getServer(),
243  $assignment->getMid()
244  );
245  if ($user->getAuthMode() == $msettings->getAuthMode()) {
246  $log->info('Adding user ' . $assignment->getUid() . ' to course/group: ' . $assignment->getObjId());
247  include_once './Services/Membership/classes/class.ilParticipants.php';
248 
249  if (
250  ilObject::_lookupType($assignment->getObjId()) == 'crs' ||
251  ilObject::_lookupType($assignment->getObjId()) == 'grp'
252  ) {
253  include_once './Modules/Course/classes/class.ilCourseConstants.php';
254  $part = ilParticipants::getInstanceByObjId($assignment->getObjId());
255  $part->add($user->getId(), ilCourseConstants::CRS_MEMBER);
256  }
257  } else {
258  $log->notice('Auth mode of user: ' . $user->getAuthMode() . ' conflicts ' . $msettings->getAuthMode());
259  }
260  }
261  }
getAuthMode($a_auth_key=false)
get auth mode public
$GLOBALS['loaded']
Global hash that tracks already loaded includes.
static getInstanceByServerMid($a_server_id, $a_mid)
Get instance.
static lookupMissingAssignmentsOfUser($a_usr_id)
Lookup missing assignments; type $ilDB.
getExternalAccount()
get external account
getId()
get object id public
static _lookupType($a_id, $a_reference=false)
lookup object type
static getInstanceByObjId($a_obj_id)
Get instance by obj type.
+ Here is the call graph for this function:

◆ initServer()

static ilECSAppEventListener::initServer (   $a_usr_id)
staticprotected

Init server settings.

Parameters
type$a_usr_id

Definition at line 176 of file class.ilECSAppEventListener.php.

References ilECSSetting\getInstanceByServerId(), and ilECSImport\lookupServerId().

177  {
178  include_once './Services/WebServices/ECS/classes/class.ilECSImport.php';
179  $server_id = ilECSImport::lookupServerId($a_usr_id);
180 
181  include_once('Services/WebServices/ECS/classes/class.ilECSSetting.php');
182  $settings = ilECSSetting::getInstanceByServerId($server_id);
183 
184  return $settings;
185  }
static getInstanceByServerId($a_server_id)
Get singleton instance per server.
static lookupServerId($a_obj_id)
Lookup server id of imported content <type> $ilDB.
+ Here is the call graph for this function:

◆ updateEnrolmentStatus()

static ilECSAppEventListener::updateEnrolmentStatus (   $a_obj_id,
ilObjUser  $user,
  $a_status 
)
staticprotected

Update enrolment status.

Parameters
type$a_obj_id
ilObjUser$user
type$a_status
Returns
boolean

Definition at line 288 of file class.ilECSAppEventListener.php.

References $GLOBALS, ilObject\_lookupType(), ilECSRemoteUser\factory(), ilObject\getId(), ilECSSetting\getInstanceByServerId(), and ilECSEnrolmentStatus\ID_UID.

289  {
290  include_once './Services/WebServices/ECS/classes/class.ilECSRemoteUser.php';
291  $remote = ilECSRemoteUser::factory($user->getId());
292  if (!$remote instanceof ilECSRemoteUser) {
293  return false;
294  }
295 
296  include_once './Services/WebServices/ECS/classes/Connectors/class.ilECSEnrolmentStatus.php';
297  $enrol = new ilECSEnrolmentStatus();
298  $enrol->setId('il_' . $GLOBALS['ilSetting']->get('inst_id', 0) . '_' . ilObject::_lookupType($a_obj_id) . '_' . $a_obj_id);
299  $enrol->setPersonId($remote->getRemoteUserId());
300  $enrol->setPersonIdType(ilECSEnrolmentStatus::ID_UID);
301  $enrol->setStatus($a_status);
302 
303  try {
304  include_once './Services/WebServices/ECS/classes/Connectors/class.ilECSEnrolmentStatusConnector.php';
306  $con->addEnrolmentStatus($enrol, $remote->getMid());
307  } catch (ilECSConnectorException $e) {
308  $GLOBALS['ilLog']->write(__METHOD__ . ': update enrolment status faild with message: ' . $e->getMessage());
309  return false;
310  }
311  }
static getInstanceByServerId($a_server_id)
Get singleton instance per server.
Storage of ecs remote user.
$GLOBALS['loaded']
Global hash that tracks already loaded includes.
getId()
get object id public
static _lookupType($a_id, $a_reference=false)
lookup object type
Connector for course member ressource.
static factory($a_usr_id)
Get instance for usr_id.
+ Here is the call graph for this function:

The documentation for this class was generated from the following file: