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

@ilCtrl_Calls

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

@access protected

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

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 }
Storage of ECS imported objects.
static _getLanguage($a_lang_key='')
Get langauge object.
This class handles base functions for mail handling.
static _getAutoGeneratedMessageString(ilLanguage $lang=null)
Get auto generated info string.
getId()
get object id @access public
$lang
Definition: consent.php:3
$server
Definition: getUserInfo.php:12

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

Referenced by handleEvent().

+ Here is the call graph for this function:
+ Here is the caller 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.

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 }
const IL_CAL_UNIX
const IL_CAL_MONTH
@classDescription Date and time handling
getDuration()
get duration
setTimeLimitUntil($a_until)
update()
update object in db
$GLOBALS['loaded']
Global hash that tracks already loaded includes.
$end
Definition: saml1-acs.php:18

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

Referenced by handleEvent().

+ Here is the call graph for this function:
+ Here is the caller 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.

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'];
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';
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';
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';
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';
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';
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';
164 unset($user);
165 }
166 break;
167 }
168 break;
169 }
170 }
static extendAccount(ilECSSetting $settings, ilObjUser $user)
Extend account.
static updateEnrolmentStatus($a_obj_id, ilObjUser $user, $a_status)
Update enrolment status.
static handleMembership(ilObjUser $user)
Assign missing course/groups to new user accounts.
static _sendNotification(ilECSSetting $server, ilObjUser $user_obj)
send notification about new user accounts
static initServer($a_usr_id)
Init server settings.
static _lookupAuthMode($a_usr_id)
lookup auth mode
static getInstanceByObjId($a_obj_id, $stop_on_error=true)
get an instance of an Ilias object by object id

References $GLOBALS, $ilLog, $log, ilObjUser\_lookupAuthMode(), _sendNotification(), extendAccount(), ilObjectFactory\getInstanceByObjId(), handleMembership(), initServer(), ilECSEnrolmentStatus\STATUS_ACTIVE, ilECSEnrolmentStatus\STATUS_PENDING, ilECSEnrolmentStatus\STATUS_UNSUBSCRIBED, and updateEnrolmentStatus().

+ 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.

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 }
static lookupMissingAssignmentsOfUser($a_usr_id)
Lookup missing assignments; @global type $ilDB.
static getInstanceByServerMid($a_server_id, $a_mid)
Get instance.
getAuthMode($a_auth_key=false)
get auth mode @access public
getExternalAccount()
get external account
static _lookupType($a_id, $a_reference=false)
lookup object type
static getInstanceByObjId($a_obj_id)
Get instance by obj type.

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

Referenced by handleEvent().

+ Here is the call graph for this function:
+ Here is the caller 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.

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 lookupServerId($a_obj_id)
Lookup server id of imported content @global <type> $ilDB.
static getInstanceByServerId($a_server_id)
Get singleton instance per server.

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

Referenced by handleEvent().

+ Here is the call graph for this function:
+ Here is the caller 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.

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 }
Connector for course member ressource.
Storage of ecs remote user.
static factory($a_usr_id)
Get instance for usr_id.

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

Referenced by handleEvent().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

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