ILIAS  release_8 Revision v8.19
All Data Structures Namespaces Files Functions Variables Modules Pages
ilECSAppEventListener Class Reference

ECS Event Handler. More...

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

Public Member Functions

 __construct (\ilLogger $logger, ilSetting $settings, ilRbacAdmin $rbac_admin)
 

Static Public Member Functions

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

Protected Member Functions

 handleNewAccountCreation (string $username)
 

Private Member Functions

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

Private Attributes

ilLogger $logger
 
ilSetting $settings
 
ilRbacAdmin $rbac_admin
 

Detailed Description

ECS Event Handler.

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

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

Constructor & Destructor Documentation

◆ __construct()

ilECSAppEventListener::__construct ( \ilLogger  $logger,
ilSetting  $settings,
ilRbacAdmin  $rbac_admin 
)

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

References $logger, $rbac_admin, $settings, ILIAS\Repository\logger(), and ILIAS\Repository\settings().

+ Here is the call graph for this function:

Member Function Documentation

◆ extendAccount()

ilECSAppEventListener::extendAccount ( ilECSSetting  $settings,
ilObjUser  $user 
)
private

Extend account.

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

References ilECSSetting\getDuration(), ilObjUser\getTimeLimitUntil(), IL_CAL_MONTH, IL_CAL_UNIX, ILIAS\Repository\logger(), ilObjUser\setTimeLimitUntil(), and ilObjUser\update().

Referenced by handleEvent().

313  : void
314  {
315  $end = new ilDateTime(time(), IL_CAL_UNIX);
316  $end->increment(IL_CAL_MONTH, $settings->getDuration());
317 
318  $this->logger->info(__METHOD__ . ': account extension ' . $end);
319 
320  if ($user->getTimeLimitUntil() < $end->get(IL_CAL_UNIX)) {
321  $user->setTimeLimitUntil($end->get(IL_CAL_UNIX));
322  $user->update();
323  }
324  }
const IL_CAL_MONTH
const IL_CAL_UNIX
setTimeLimitUntil(?int $a_until)
getDuration()
get duration
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ handleEvent()

static ilECSAppEventListener::handleEvent ( string  $a_component,
string  $a_event,
array  $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 46 of file class.ilECSAppEventListener.php.

References $DIC, ilObjUser\_lookupAuthMode(), extendAccount(), ilObjectFactory\getInstanceByObjId(), handleMembership(), handleNewAccountCreation(), initServer(), ILIAS\Repository\logger(), sendNotification(), ilECSEnrolmentStatus\STATUS_ACTIVE, ilECSEnrolmentStatus\STATUS_PENDING, ilECSEnrolmentStatus\STATUS_UNSUBSCRIBED, and updateEnrolmentStatus().

46  : void
47  {
48  global $DIC;
49 
50  $eventHandler = new static(
51  $DIC->logger()->wsrv(),
52  $DIC->settings(),
53  $DIC->rbac()->admin(),
54  );
55  $eventHandler->handle($a_component, $a_event, $a_parameter);
56  }
global $DIC
Definition: feed.php:28
+ Here is the call graph for this function:

◆ handleMembership()

ilECSAppEventListener::handleMembership ( ilObjUser  $user)
private

Assign missing course/groups to new user accounts.

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

References Vendor\Package\$e, $ref_id, ilObject\_getAllReferences(), ilObject\_lookupType(), ilCourseConstants\CRS_MEMBER, ilLogLevel\ERROR, ilObjUser\getAuthMode(), ilObjUser\getExternalAccount(), ilObject\getId(), ilParticipants\getInstance(), ilECSNodeMappingSettings\getInstanceByServerMid(), ilParticipants\IL_GRP_MEMBER, ILIAS\Repository\logger(), and ilECSCourseMemberAssignment\lookupMissingAssignmentsOfUser().

Referenced by handleEvent().

271  : void
272  {
273  $this->logger->debug('Handling ECS assignments ');
274 
276  foreach ($assignments as $assignment) {
278  $assignment->getServer(),
279  $assignment->getMid()
280  );
281  if ($user->getAuthMode() === $msettings->getAuthMode()) {
282  $this->logger->info('Adding user ' . $assignment->getUid() . ' to course/group: ' . $assignment->getObjId());
283  $obj_type = ilObject::_lookupType($assignment->getObjId());
284  if ($obj_type !== 'crs' && $obj_type !== 'grp') {
285  $this->logger->error('Invalid assignment type: ' . $obj_type);
286  $this->logger->logStack(ilLogLevel::ERROR);
287  continue;
288  }
289  $refs = ilObject::_getAllReferences($assignment->getObjId());
290  $ref_id = end($refs);
291 
292  try {
293  $part = ilParticipants::getInstance((int) $ref_id);
294  if ($obj_type === 'crs') {
295  $part->add($user->getId(), ilCourseConstants::CRS_MEMBER);
296  } elseif ($obj_type === 'grp') {
297  $part->add($user->getId(), ilParticipants::IL_GRP_MEMBER);
298  }
299  } catch (InvalidArgumentException $e) {
300  $this->logger->error('Invalid ref_id given: ' . (int) $ref_id);
301  $this->logger->logStack(ilLogLevel::ERROR);
302  continue;
303  }
304  } else {
305  $this->logger->notice('Auth mode of user: ' . $user->getAuthMode() . ' conflicts ' . $msettings->getAuthMode());
306  }
307  }
308  }
static getInstanceByServerMid(int $a_server_id, int $a_mid)
Get instance.
static getInstance(int $a_ref_id)
static _getAllReferences(int $id)
get all reference ids for object ID
getAuthMode(bool $a_auth_key=false)
$ref_id
Definition: ltiauth.php:67
static lookupMissingAssignmentsOfUser(string $a_usr_id)
Lookup missing assignments;.
static _lookupType(int $id, bool $reference=false)
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ handleNewAccountCreation()

ilECSAppEventListener::handleNewAccountCreation ( string  $username)
protected

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

References $server, ilObjUser\_loginExists(), ilObjUser\_lookupExternalAccount(), ilECSParticipantSetting\getInstance(), ilECSSetting\getInstanceByServerId(), ilECSParticipantSetting\INCOMING_AUTH_TYPE_LOGIN_PAGE, ilECSParticipantSetting\INCOMING_AUTH_TYPE_SHIBBOLETH, and ILIAS\Repository\logger().

Referenced by handleEvent().

230  : void
231  {
232  $user_id = ilObjUser::_loginExists($username);
233  if (!$user_id) {
234  $this->logger->warning('Invalid username given: ' . $username);
235  }
236 
237  $external_account = ilObjUser::_lookupExternalAccount($user_id);
238  if ($external_account == '') {
239  return;
240  }
241  $remote_user_repo = new ilECSRemoteUserRepository();
242  $remote_user = $remote_user_repo->getECSRemoteUserByRemoteId($external_account);
243  if ($remote_user === null) {
244  return;
245  }
246  if ($remote_user->getServerId() === 0) {
247  $this->logger->warning('Found remote user without server id: ' . $external_account);
248  return;
249  }
250  if ($remote_user->getMid() === 0) {
251  $this->logger->warning('Found remote user without mid id: ' . $external_account);
252  return;
253  }
255  $remote_user->getServerId(),
256  $remote_user->getMid()
257  );
258  $server = ilECSSetting::getInstanceByServerId($remote_user->getServerId());
259  if (
260  $part->getIncomingAuthType() === ilECSParticipantSetting::INCOMING_AUTH_TYPE_LOGIN_PAGE ||
261  $part->getIncomingAuthType() === ilECSParticipantSetting::INCOMING_AUTH_TYPE_SHIBBOLETH
262  ) {
263  $this->logger->info('Assigning ' . $username . ' to global ecs role');
264  $this->rbac_admin->assignUser($server->getGlobalRole(), $user_id);
265  }
266  }
static getInstance(int $a_server_id, int $mid)
Get instance by server id and mid.
static _lookupExternalAccount(int $a_user_id)
static _loginExists(string $a_login, int $a_user_id=0)
check if a login name already exists You may exclude a user from the check by giving his user id as 2...
static getInstanceByServerId(int $a_server_id)
Get singleton instance per server.
$server
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ initServer()

ilECSAppEventListener::initServer ( int  $a_usr_id)
private

Init server settings.

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

References ilECSImportManager\getInstance(), and ilECSSetting\getInstanceByServerId().

Referenced by handleEvent().

190  : ilECSSetting
191  {
192  $server_id = ilECSImportManager::getInstance()->lookupServerId($a_usr_id);
193 
194  return ilECSSetting::getInstanceByServerId($server_id);
195  }
static getInstance()
Get the singleton instance of this ilECSImportManager.
static getInstanceByServerId(int $a_server_id)
Get singleton instance per server.
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ sendNotification()

ilECSAppEventListener::sendNotification ( ilECSSetting  $server,
ilObjUser  $user_obj 
)
private

send notification about new user accounts

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

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

Referenced by handleEvent().

200  : void
201  {
202  if (!count($server->getUserRecipients())) {
203  return;
204  }
205  // If sub id is set => mail was send
206  $import = new ilECSImport($server->getServerId(), $user_obj->getId());
207  if ($import->getSubId()) {
208  return;
209  }
210 
212  $lang->loadLanguageModule('ecs');
213 
214  $mail = new ilMail(ANONYMOUS_USER_ID);
215  $subject = $lang->txt('ecs_new_user_subject');
216 
217  // build body
218  $body = $lang->txt('ecs_new_user_body') . "\n\n";
219  $body .= $lang->txt('ecs_new_user_profile') . "\n\n";
220  $body .= $user_obj->getProfileAsString($lang) . "\n\n";
222 
223  $mail->enqueue($server->getUserRecipientsAsString(), "", "", $subject, $body, array());
224 
225  // Store sub_id = 1 in ecs import which means mail is send
226  $import->setSubId("1");
227  $import->save();
228  }
const ANONYMOUS_USER_ID
Definition: constants.php:27
getServerId()
Get current server id.
getUserRecipientsAsString()
Get new user recipients.
Storage of ECS imported objects.
static _getLanguage(string $a_lang_key='')
Get language object.
$lang
Definition: xapiexit.php:26
static _getAutoGeneratedMessageString(ilLanguage $lang=null)
getUserRecipients()
Get new user recipients.
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ updateEnrolmentStatus()

ilECSAppEventListener::updateEnrolmentStatus ( int  $a_obj_id,
ilObjUser  $user,
string  $a_status 
)
private

Update enrolment status.

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

References Vendor\Package\$e, ilObject\_lookupType(), ilObject\getId(), ilECSSetting\getInstanceByServerId(), ilECSEnrolmentStatus\ID_UID, ILIAS\Repository\logger(), and ILIAS\Repository\settings().

Referenced by handleEvent().

329  : void
330  {
331  $remote = (new ilECSRemoteUserRepository())->getECSRemoteUserByUsrId($user->getId());
332  if (!$remote instanceof ilECSRemoteUser) {
333  return;
334  }
335 
336  $enrol = new ilECSEnrolmentStatus();
337  $enrol->setId('il_' . $this->settings->get('inst_id', "0") . '_' . ilObject::_lookupType($a_obj_id) . '_' . $a_obj_id);
338  $enrol->setPersonId($remote->getRemoteUserId());
339  $enrol->setPersonIdType(ilECSEnrolmentStatus::ID_UID);
340  $enrol->setStatus($a_status);
341 
342  try {
344  $con->addEnrolmentStatus($enrol, $remote->getMid());
345  } catch (ilECSConnectorException $e) {
346  $this->logger->info(__METHOD__ . ': update enrolment status faild with message: ' . $e->getMessage());
347  }
348  }
Storage of ecs remote user.
Presentation of ecs enrolment status.
static getInstanceByServerId(int $a_server_id)
Get singleton instance per server.
Connector for course member ressource.
static _lookupType(int $id, bool $reference=false)
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

Field Documentation

◆ $logger

ilLogger ilECSAppEventListener::$logger
private

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

Referenced by __construct().

◆ $rbac_admin

ilRbacAdmin ilECSAppEventListener::$rbac_admin
private

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

Referenced by __construct().

◆ $settings

ilSetting ilECSAppEventListener::$settings
private

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

Referenced by __construct().


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