ILIAS  release_5-2 Revision v5.2.25-18-g3f80b828510
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 208 of file class.ilECSAppEventListener.php.

209 {
210 if(!count($server->getUserRecipients()))
211 {
212 return true;
213 }
214 // If sub id is set => mail was send
215 include_once './Services/WebServices/ECS/classes/class.ilECSImport.php';
216 $import = new ilECSImport($server->getServerId(),$user_obj->getId());
217 if($import->getSubId())
218 {
219 return false;
220 }
221
222 include_once('./Services/Language/classes/class.ilLanguageFactory.php');
224 $lang->loadLanguageModule('ecs');
225
226 include_once('./Services/Mail/classes/class.ilMail.php');
227 $mail = new ilMail(6);
228 $mail->enableSoap(false);
229 $subject = $lang->txt('ecs_new_user_subject');
230
231 // build body
232 $body = $lang->txt('ecs_new_user_body')."\n\n";
233 $body .= $lang->txt('ecs_new_user_profile')."\n\n";
234 $body .= $user_obj->getProfileAsString($lang)."\n\n";
235 $body .= ilMail::_getAutoGeneratedMessageString($lang);
236
237 $mail->sendMail($server->getUserRecipientsAsString(),"","",$subject,$body,array(),array("normal"));
238
239 // Store sub_id = 1 in ecs import which means mail is send
240 $import->setSubId(1);
241 $import->save();
242
243 return true;
244 }
Storage of ECS imported objects.
static _getLanguage($a_lang_key='')
Get langauge object.
This class handles base functions for mail handling.
getId()
get object id @access public
$server
for($i=1; $i<=count($kw_cases_sel); $i+=1) $lang
Definition: langwiz.php:349

References $lang, $server, 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 291 of file class.ilECSAppEventListener.php.

292 {
293 $end = new ilDateTime(time(),IL_CAL_UNIX);
294 $end->increment(IL_CAL_MONTH,$settings->getDuration());
295
296 $GLOBALS['ilLog']->write(__METHOD__.': account extension '.(string) $end);
297
298 if($user->getTimeLimitUntil() < $end->get(IL_CAL_UNIX))
299 {
300 $user->setTimeLimitUntil($end->get(IL_CAL_UNIX));
301 $user->update();
302 }
303 }
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.

References $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 {
54 case 'Services/User':
55 switch($a_event)
56 {
57 case 'afterCreate':
58 $user = $a_parameter['user_obj'];
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 {
69 case 'addSubscriber':
70 case 'addToWaitingList':
71 if(ilObjUser::_lookupAuthMode($a_parameter['usr_id']) == 'ecs')
72 {
73 if(!$user = ilObjectFactory::getInstanceByObjId($a_parameter['usr_id']))
74 {
75 $log->info('No valid user found for usr_id '.$a_parameter['usr_id']);
76 return true;
77 }
78
79 $settings = self::initServer($a_parameter['usr_id']);
80 self::extendAccount($settings, $user);
81
82 include_once './Services/WebServices/ECS/classes/Connectors/class.ilECSEnrolmentStatus.php';
84 }
85 break;
86
87 case 'deleteParticipant':
88 if(ilObjUser::_lookupAuthMode($a_parameter['usr_id']) == 'ecs')
89 {
90 if(!$user = ilObjectFactory::getInstanceByObjId($a_parameter['usr_id']))
91 {
92 $log->info('No valid user found for usr_id '.$a_parameter['usr_id']);
93 return true;
94 }
95 include_once './Services/WebServices/ECS/classes/Connectors/class.ilECSEnrolmentStatus.php';
97 }
98 break;
99
100 case 'addParticipant':
101 if((ilObjUser::_lookupAuthMode($a_parameter['usr_id']) == 'ecs'))
102 {
103 if(!$user = ilObjectFactory::getInstanceByObjId($a_parameter['usr_id']))
104 {
105 $log->info('No valid user found for usr_id '.$a_parameter['usr_id']);
106 return true;
107 }
108
109 $settings = self::initServer($user->getId());
110
111 self::extendAccount($settings, $user);
112 #self::_sendNotification($settings,$user);
113
114 include_once './Services/WebServices/ECS/classes/Connectors/class.ilECSEnrolmentStatus.php';
116 unset($user);
117 }
118 break;
119
120
121
122 }
123 break;
124
125 case 'Modules/Course':
126
127 $GLOBALS['ilLog']->write(__METHOD__.': New event from course: '.$a_event);
128 switch($a_event)
129 {
130
131 case 'addSubscriber':
132 case 'addToWaitingList':
133 if(ilObjUser::_lookupAuthMode($a_parameter['usr_id']) == 'ecs')
134 {
135 if(!$user = ilObjectFactory::getInstanceByObjId($a_parameter['usr_id']))
136 {
137 $log->info('No valid user found for usr_id '.$a_parameter['usr_id']);
138 return true;
139 }
140
141 $settings = self::initServer($a_parameter['usr_id']);
142 self::extendAccount($settings, $user);
143
144 include_once './Services/WebServices/ECS/classes/Connectors/class.ilECSEnrolmentStatus.php';
146 }
147 break;
148
149
150 case 'deleteParticipant':
151 if(ilObjUser::_lookupAuthMode($a_parameter['usr_id']) == 'ecs')
152 {
153 if(!$user = ilObjectFactory::getInstanceByObjId($a_parameter['usr_id']))
154 {
155 $log->info('No valid user found for usr_id '.$a_parameter['usr_id']);
156 return true;
157 }
158 include_once './Services/WebServices/ECS/classes/Connectors/class.ilECSEnrolmentStatus.php';
160 }
161 break;
162
163 case 'addParticipant':
164
165 if((ilObjUser::_lookupAuthMode($a_parameter['usr_id']) == 'ecs'))
166 {
167 if(!$user = ilObjectFactory::getInstanceByObjId($a_parameter['usr_id']))
168 {
169 $log->info('No valid user found for usr_id '.$a_parameter['usr_id']);
170 return true;
171 }
172
173 $settings = self::initServer($user->getId());
174
175 self::extendAccount($settings, $user);
176 self::_sendNotification($settings,$user);
177
178 include_once './Services/WebServices/ECS/classes/Connectors/class.ilECSEnrolmentStatus.php';
180 unset($user);
181 }
182 break;
183 }
184 break;
185 }
186 }
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 250 of file class.ilECSAppEventListener.php.

251 {
252 $log = $GLOBALS['DIC']->logger()->wsrv();
253 $log->debug('Handling ECS assignments ');
254
255 include_once './Services/WebServices/ECS/classes/Course/class.ilECSCourseMemberAssignment.php';
257 foreach($assignments as $assignment)
258 {
259 include_once './Services/WebServices/ECS/classes/Mapping/class.ilECSNodeMappingSettings.php';
261 $assignment->getServer(),
262 $assignment->getMid()
263 );
264 if($user->getAuthMode() == $msettings->getAuthMode())
265 {
266 $log->info('Adding user ' . $assignment->getUid() . ' to course/group: ' . $assignment->getObjId());
267 include_once './Services/Membership/classes/class.ilParticipants.php';
268
269 if(
270 ilObject::_lookupType($assignment->getObjId()) == 'crs' ||
271 ilObject::_lookupType($assignment->getObjId()) == 'grp'
272 )
273 {
274 include_once './Modules/Course/classes/class.ilCourseConstants.php';
275 $part = ilParticipants::getInstanceByObjId($assignment->getObjId());
276 $part->add($user->getId(), ilCourseConstants::CRS_MEMBER);
277 }
278 }
279 else
280 {
281 $log->notice('Auth mode of user: ' . $user->getAuthMode() .' conflicts ' . $msettings->getAuthMode());
282 }
283 }
284 }
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 192 of file class.ilECSAppEventListener.php.

193 {
194 include_once './Services/WebServices/ECS/classes/class.ilECSImport.php';
195 $server_id = ilECSImport::lookupServerId($a_usr_id);
196
197 include_once('Services/WebServices/ECS/classes/class.ilECSSetting.php');
198 $settings = ilECSSetting::getInstanceByServerId($server_id);
199
200 return $settings;
201 }
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 312 of file class.ilECSAppEventListener.php.

313 {
314 include_once './Services/WebServices/ECS/classes/class.ilECSRemoteUser.php';
315 $remote = ilECSRemoteUser::factory($user->getId());
316 if(!$remote instanceof ilECSRemoteUser)
317 {
318 return FALSE;
319 }
320
321 include_once './Services/WebServices/ECS/classes/Connectors/class.ilECSEnrolmentStatus.php';
322 $enrol = new ilECSEnrolmentStatus();
323 $enrol->setId('il_'.$GLOBALS['ilSetting']->get('inst_id',0).'_'.ilObject::_lookupType($a_obj_id).'_'.$a_obj_id);
324 $enrol->setPersonId($remote->getRemoteUserId());
325 $enrol->setPersonIdType(ilECSEnrolmentStatus::ID_UID);
326 $enrol->setStatus($a_status);
327
328 try {
329 include_once './Services/WebServices/ECS/classes/Connectors/class.ilECSEnrolmentStatusConnector.php';
331 $con->addEnrolmentStatus($enrol,$remote->getMid());
332 }
334 {
335 $GLOBALS['ilLog']->write(__METHOD__.': update enrolment status faild with message: '. $e->getMessage());
336 return false;
337 }
338 }
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: