ILIAS  release_5-4 Revision v5.4.26-12-gabc799a52e6
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 194 of file class.ilECSAppEventListener.php.

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

195  {
196  if (!count($server->getUserRecipients())) {
197  return true;
198  }
199  // If sub id is set => mail was send
200  include_once './Services/WebServices/ECS/classes/class.ilECSImport.php';
201  $import = new ilECSImport($server->getServerId(), $user_obj->getId());
202  if ($import->getSubId()) {
203  return false;
204  }
205 
206  include_once('./Services/Language/classes/class.ilLanguageFactory.php');
208  $lang->loadLanguageModule('ecs');
209 
210  include_once('./Services/Mail/classes/class.ilMail.php');
211  $mail = new ilMail(6);
212  $mail->enableSoap(false);
213  $subject = $lang->txt('ecs_new_user_subject');
214 
215  // build body
216  $body = $lang->txt('ecs_new_user_body') . "\n\n";
217  $body .= $lang->txt('ecs_new_user_profile') . "\n\n";
218  $body .= $user_obj->getProfileAsString($lang) . "\n\n";
220 
221  $mail->sendMail($server->getUserRecipientsAsString(), "", "", $subject, $body, array(), array("normal"));
222 
223  // Store sub_id = 1 in ecs import which means mail is send
224  $import->setSubId(1);
225  $import->save();
226 
227  return true;
228  }
getServerId()
Get current server id.
static _getLanguage($a_lang_key='')
Get langauge object.
getId()
get object id public
getUserRecipientsAsString()
Get new user recipients.
Storage of ECS imported objects.
static _getAutoGeneratedMessageString(ilLanguage $lang=null)
Get auto generated info string.
for($i=1; $i<=count($kw_cases_sel); $i+=1) $lang
Definition: langwiz.php:349
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 281 of file class.ilECSAppEventListener.php.

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

282  {
283  $end = new ilDateTime(time(), IL_CAL_UNIX);
284  $end->increment(IL_CAL_MONTH, $settings->getDuration());
285 
286  $GLOBALS['DIC']['ilLog']->write(__METHOD__ . ': account extension ' . (string) $end);
287 
288  if ($user->getTimeLimitUntil() < $end->get(IL_CAL_UNIX)) {
289  $user->setTimeLimitUntil($end->get(IL_CAL_UNIX));
290  $user->update();
291  }
292  }
const IL_CAL_MONTH
const IL_CAL_UNIX
setTimeLimitUntil($a_until)
Date and time handling
getDuration()
get duration
update()
update object in db
$GLOBALS['JPEG_Segment_Names']
Global Variable: XMP_tag_captions.
+ 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 $DIC, $GLOBALS, $ilLog, $log, $user, ilObjUser\_lookupAuthMode(), ilObjectFactory\getInstanceByObjId(), ilECSEnrolmentStatus\STATUS_ACTIVE, ilECSEnrolmentStatus\STATUS_PENDING, and ilECSEnrolmentStatus\STATUS_UNSUBSCRIBED.

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

References $GLOBALS, $log, ilObject\_getAllReferences(), ilObject\_lookupType(), ilCourseConstants\CRS_MEMBER, ilLogLevel\ERROR, ilObjUser\getAuthMode(), ilObjUser\getExternalAccount(), ilObject\getId(), ilParticipants\getInstance(), ilECSNodeMappingSettings\getInstanceByServerMid(), IL_GRP_MEMBER, and ilECSCourseMemberAssignment\lookupMissingAssignmentsOfUser().

235  {
236  $log = $GLOBALS['DIC']->logger()->wsrv();
237  $log->debug('Handling ECS assignments ');
238 
239  include_once './Services/WebServices/ECS/classes/Course/class.ilECSCourseMemberAssignment.php';
241  foreach ($assignments as $assignment) {
242  include_once './Services/WebServices/ECS/classes/Mapping/class.ilECSNodeMappingSettings.php';
244  $assignment->getServer(),
245  $assignment->getMid()
246  );
247  if ($user->getAuthMode() == $msettings->getAuthMode()) {
248  $log->info('Adding user ' . $assignment->getUid() . ' to course/group: ' . $assignment->getObjId());
249  $obj_type = ilObject::_lookupType($assignment->getObjId());
250  if ($obj_type !== 'crs' && $obj_type !== 'grp') {
251  $log->error('Invalid assignment type: ' . $obj_type);
252  $log->logStack(ilLogLevel::ERROR);
253  continue;
254  }
255  $refs = ilObject::_getAllReferences($assignment->getObjId());
256  $ref_id = end($refs);
257 
258  try {
259  $part = ilParticipants::getInstance((int) $ref_id);
260  if ($obj_type === 'crs') {
261  $part->add($user->getId(), ilCourseConstants::CRS_MEMBER);
262  } elseif ($obj_type === 'grp') {
263  $part->add($user->getId(), IL_GRP_MEMBER);
264  }
265  } catch (InvalidArgumentException $e) {
266  $log->error('Invalid ref_id given: ' . (int) $ref_id);
267  $log->logStack(ilLogLevel::ERROR);
268  continue;
269  }
270  } else {
271  $log->notice('Auth mode of user: ' . $user->getAuthMode() . ' conflicts ' . $msettings->getAuthMode());
272  }
273  }
274  }
getAuthMode($a_auth_key=false)
get auth mode public
static getInstanceByServerMid($a_server_id, $a_mid)
Get instance.
$log
Definition: sabredav.php:21
const IL_GRP_MEMBER
static lookupMissingAssignmentsOfUser($a_usr_id)
Lookup missing assignments; type $ilDB.
static _getAllReferences($a_id)
get all reference ids of object
static getInstance($a_ref_id)
Get instance by ref_id.
getExternalAccount()
get external account
getId()
get object id public
static _lookupType($a_id, $a_reference=false)
lookup object type
$GLOBALS['JPEG_Segment_Names']
Global Variable: XMP_tag_captions.
+ 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 178 of file class.ilECSAppEventListener.php.

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

179  {
180  include_once './Services/WebServices/ECS/classes/class.ilECSImport.php';
181  $server_id = ilECSImport::lookupServerId($a_usr_id);
182 
183  include_once('Services/WebServices/ECS/classes/class.ilECSSetting.php');
184  $settings = ilECSSetting::getInstanceByServerId($server_id);
185 
186  return $settings;
187  }
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 301 of file class.ilECSAppEventListener.php.

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

302  {
303  include_once './Services/WebServices/ECS/classes/class.ilECSRemoteUser.php';
304  $remote = ilECSRemoteUser::factory($user->getId());
305  if (!$remote instanceof ilECSRemoteUser) {
306  return false;
307  }
308 
309  include_once './Services/WebServices/ECS/classes/Connectors/class.ilECSEnrolmentStatus.php';
310  $enrol = new ilECSEnrolmentStatus();
311  $enrol->setId('il_' . $GLOBALS['DIC']['ilSetting']->get('inst_id', 0) . '_' . ilObject::_lookupType($a_obj_id) . '_' . $a_obj_id);
312  $enrol->setPersonId($remote->getRemoteUserId());
313  $enrol->setPersonIdType(ilECSEnrolmentStatus::ID_UID);
314  $enrol->setStatus($a_status);
315 
316  try {
317  include_once './Services/WebServices/ECS/classes/Connectors/class.ilECSEnrolmentStatusConnector.php';
319  $con->addEnrolmentStatus($enrol, $remote->getMid());
320  } catch (ilECSConnectorException $e) {
321  $GLOBALS['DIC']['ilLog']->write(__METHOD__ . ': update enrolment status faild with message: ' . $e->getMessage());
322  return false;
323  }
324  }
static getInstanceByServerId($a_server_id)
Get singleton instance per server.
Storage of ecs remote user.
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.
$GLOBALS['JPEG_Segment_Names']
Global Variable: XMP_tag_captions.
+ Here is the call graph for this function:

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