ILIAS  trunk Revision v11.0_alpha-3011-gc6b235a2e85
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...
 
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 25 of file class.ilECSAppEventListener.php.

Constructor & Destructor Documentation

◆ __construct()

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

Member Function Documentation

◆ extendAccount()

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

Extend account.

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

310 : void
311 {
312 $end = new ilDateTime(time(), IL_CAL_UNIX);
313 $end->increment(IL_CAL_MONTH, $settings->getDuration());
314
315 $this->logger->info(__METHOD__ . ': account extension ' . $end);
316
317 if ($user->getTimeLimitUntil() < $end->get(IL_CAL_UNIX)) {
318 $user->setTimeLimitUntil($end->get(IL_CAL_UNIX));
319 $user->update();
320 }
321 }
const IL_CAL_UNIX
const IL_CAL_MONTH
@classDescription Date and time handling
setTimeLimitUntil(?int $a_until)

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

+ Here is the call 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. "components/ILIAS/Forum" or "components/ILIAS/User"
string$a_eventevent e.g. "createUser", "updateUser", "deleteUser", ...
array$a_parameterparameter array (assoc), array("name" => ..., "phone_office" => ...)

Implements ilAppEventListener.

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

47 : void
48 {
49 global $DIC;
50
51 $eventHandler = new static(
52 $DIC->logger()->wsrv(),
53 $DIC->settings(),
54 $DIC->rbac()->admin(),
55 );
56 $eventHandler->handle($a_component, $a_event, $a_parameter);
57 }
global $DIC
Definition: shib_login.php:26

References $DIC.

◆ handleMembership()

ilECSAppEventListener::handleMembership ( ilObjUser  $user)
private

Assign missing course/groups to new user accounts.

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

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

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().

+ Here is the call graph for this function:

◆ handleNewAccountCreation()

ilECSAppEventListener::handleNewAccountCreation ( string  $username)
protected

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

227 : void
228 {
230 if (!$user_id) {
231 $this->logger->warning('Invalid username given: ' . $username);
232 }
233
234 $external_account = ilObjUser::_lookupExternalAccount($user_id);
235 if ($external_account == '') {
236 return;
237 }
238 $remote_user_repo = new ilECSRemoteUserRepository();
239 $remote_user = $remote_user_repo->getECSRemoteUserByRemoteId($external_account);
240 if ($remote_user === null) {
241 return;
242 }
243 if ($remote_user->getServerId() === 0) {
244 $this->logger->warning('Found remote user without server id: ' . $external_account);
245 return;
246 }
247 if ($remote_user->getMid() === 0) {
248 $this->logger->warning('Found remote user without mid id: ' . $external_account);
249 return;
250 }
252 $remote_user->getServerId(),
253 $remote_user->getMid()
254 );
255 $server = ilECSSetting::getInstanceByServerId($remote_user->getServerId());
256 if (
257 $part->getIncomingAuthType() === ilECSParticipantSetting::INCOMING_AUTH_TYPE_LOGIN_PAGE ||
258 $part->getIncomingAuthType() === ilECSParticipantSetting::INCOMING_AUTH_TYPE_SHIBBOLETH
259 ) {
260 $this->logger->info('Assigning ' . $username . ' to global ecs role');
261 $this->rbac_admin->assignUser($server->getGlobalRole(), $user_id);
262 }
263 }
static getInstance(int $a_server_id, int $mid)
Get instance by server id and mid.
static getInstanceByServerId(int $a_server_id)
Get singleton instance per server.
static _lookupExternalAccount(int $a_user_id)
static _loginExists(string $a_login, int $a_user_id=0)
$server
Definition: shib_login.php:28

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

+ Here is the call graph for this function:

◆ initServer()

ilECSAppEventListener::initServer ( int  $a_usr_id)
private

Init server settings.

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

188 {
189 $server_id = ilECSImportManager::getInstance()->lookupServerId($a_usr_id);
190
191 return ilECSSetting::getInstanceByServerId($server_id);
192 }
static getInstance()
Get the singleton instance of this ilECSImportManager.

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

+ Here is the call graph for this function:

◆ sendNotification()

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

send notification about new user accounts

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

197 : void
198 {
199 if (!count($server->getUserRecipients())) {
200 return;
201 }
202 // If sub id is set => mail was send
203 $import = new ilECSImport($server->getServerId(), $user_obj->getId());
204 if ($import->getSubId()) {
205 return;
206 }
207
209 $lang->loadLanguageModule('ecs');
210
211 $mail = new ilMail(ANONYMOUS_USER_ID);
212 $subject = $lang->txt('ecs_new_user_subject');
213
214 // build body
215 $body = $lang->txt('ecs_new_user_body') . "\n\n";
216 $body .= $lang->txt('ecs_new_user_profile') . "\n\n";
217 $body .= $user_obj->getProfileAsString($lang) . "\n\n";
219
220 $mail->enqueue($server->getUserRecipientsAsString(), "", "", $subject, $body, array());
221
222 // Store sub_id = 1 in ecs import which means mail is send
223 $import->setSubId("1");
224 $import->save();
225 }
Storage of ECS imported objects.
static _getLanguage(string $a_lang_key='')
Get language object.
static _getAutoGeneratedMessageString(?ilLanguage $lang=null)
getProfileAsString(Language $language)
Get formatted mail body text of user profile data.
const ANONYMOUS_USER_ID
Definition: constants.php:27
$lang
Definition: xapiexit.php:25

References $lang, $server, ilMail\_getAutoGeneratedMessageString(), ilLanguageFactory\_getLanguage(), ANONYMOUS_USER_ID, ilObject\getId(), and ilObjUser\getProfileAsString().

+ Here is the call graph for this function:

◆ updateEnrolmentStatus()

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

Update enrolment status.

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

326 : void
327 {
328 $remote = (new ilECSRemoteUserRepository())->getECSRemoteUserByUsrId($user->getId());
329 if (!$remote instanceof ilECSRemoteUser) {
330 return;
331 }
332
333 $enrol = new ilECSEnrolmentStatus();
334 $enrol->setId('il_' . $this->settings->get('inst_id', "0") . '_' . ilObject::_lookupType($a_obj_id) . '_' . $a_obj_id);
335 $enrol->setPersonId($remote->getRemoteUserId());
336 $enrol->setPersonIdType(ilECSEnrolmentStatus::ID_UID);
337 $enrol->setStatus($a_status);
338
339 try {
341 $con->addEnrolmentStatus($enrol, $remote->getMid());
342 } catch (ilECSConnectorException $e) {
343 $this->logger->info(__METHOD__ . ': update enrolment status faild with message: ' . $e->getMessage());
344 }
345 }
Connector for course member ressource.
Presentation of ecs enrolment status.
Storage of ecs remote user.

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

+ Here is the call graph for this function:

Field Documentation

◆ $logger

ilLogger ilECSAppEventListener::$logger
private

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

Referenced by __construct().

◆ $rbac_admin

ilRbacAdmin ilECSAppEventListener::$rbac_admin
private

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

Referenced by __construct().

◆ $settings

ilSetting ilECSAppEventListener::$settings
private

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

Referenced by __construct(), and extendAccount().


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