ILIAS  trunk Revision v12.0_alpha-377-g3641b37b9db
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
 
ilECSAuthFactory $auth_factory
 

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 49 of file class.ilECSAppEventListener.php.

49 : void
50 {
51 global $DIC;
52
53 $eventHandler = new static(
54 $DIC->logger()->wsrv(),
55 $DIC->settings(),
56 $DIC->rbac()->admin(),
58 );
59 $eventHandler->handle($a_component, $a_event, $a_parameter);
60 }
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 230 of file class.ilECSAppEventListener.php.

230 : void
231 {
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 (in_array($part->getIncomingAuthType(), $this->auth_factory->getAuthTypes(), true)) {
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(), 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 190 of file class.ilECSAppEventListener.php.

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.

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 200 of file class.ilECSAppEventListener.php.

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 }
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

References $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

◆ $auth_factory

ilECSAuthFactory ilECSAppEventListener::$auth_factory
private

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

◆ $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: