ILIAS  release_5-1 Revision 5.0.0-5477-g43f3e3fab5f
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 mmissing 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 206 of file class.ilECSAppEventListener.php.

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

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

275 {
276 $end = new ilDateTime(time(),IL_CAL_UNIX);
277 $end->increment(IL_CAL_MONTH,$settings->getDuration());
278
279 $GLOBALS['ilLog']->write(__METHOD__.': account extension '.(string) $end);
280
281 if($user->getTimeLimitUntil() < $end->get(IL_CAL_UNIX))
282 {
283 $user->setTimeLimitUntil($end->get(IL_CAL_UNIX));
284 $user->update();
285 }
286 }
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['PHPCAS_CLIENT']
This global variable is used by the interface class phpCAS.
Definition: CAS.php:276

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 $ilLog->write(__METHOD__.': Listening to event from: '.$a_component.' '.$a_event);
49
50 switch($a_component)
51 {
52 case 'Services/User':
53 switch($a_event)
54 {
55 case 'afterCreate':
56 $user = $a_parameter['user_obj'];
58 break;
59 }
60 break;
61
62 case 'Modules/Group':
63
64 $GLOBALS['ilLog']->write(__METHOD__.': New event from group: '.$a_event);
65 switch($a_event)
66 {
67 case 'addSubscriber':
68 case 'addToWaitingList':
69 if(ilObjUser::_lookupAuthMode($a_parameter['usr_id']) == 'ecs')
70 {
71 if(!$user = ilObjectFactory::getInstanceByObjId($a_parameter['usr_id']))
72 {
73 $GLOBALS['ilLog']->write(__METHOD__.': No valid user found for usr_id '.$a_parameter['usr_id']);
74 return true;
75 }
76
77 $settings = self::initServer($a_parameter['usr_id']);
78 self::extendAccount($settings, $user);
79
80 include_once './Services/WebServices/ECS/classes/Connectors/class.ilECSEnrolmentStatus.php';
82 }
83 break;
84
85 case 'deleteParticipant':
86 if(ilObjUser::_lookupAuthMode($a_parameter['usr_id']) == 'ecs')
87 {
88 if(!$user = ilObjectFactory::getInstanceByObjId($a_parameter['usr_id']))
89 {
90 $GLOBALS['ilLog']->write(__METHOD__.': No valid user found for usr_id '.$a_parameter['usr_id']);
91 return true;
92 }
93 include_once './Services/WebServices/ECS/classes/Connectors/class.ilECSEnrolmentStatus.php';
95 }
96 break;
97
98 case 'addParticipant':
99 if((ilObjUser::_lookupAuthMode($a_parameter['usr_id']) == 'ecs'))
100 {
101 if(!$user = ilObjectFactory::getInstanceByObjId($a_parameter['usr_id']))
102 {
103 $GLOBALS['ilLog']->write(__METHOD__.': No valid user found for usr_id '.$a_parameter['usr_id']);
104 return true;
105 }
106
107 $settings = self::initServer($user->getId());
108
109 self::extendAccount($settings, $user);
110 #self::_sendNotification($settings,$user);
111
112 include_once './Services/WebServices/ECS/classes/Connectors/class.ilECSEnrolmentStatus.php';
114 unset($user);
115 }
116 break;
117
118
119
120 }
121 break;
122
123 case 'Modules/Course':
124
125 $GLOBALS['ilLog']->write(__METHOD__.': New event from course: '.$a_event);
126 switch($a_event)
127 {
128
129 case 'addSubscriber':
130 case 'addToWaitingList':
131 if(ilObjUser::_lookupAuthMode($a_parameter['usr_id']) == 'ecs')
132 {
133 if(!$user = ilObjectFactory::getInstanceByObjId($a_parameter['usr_id']))
134 {
135 $GLOBALS['ilLog']->write(__METHOD__.': No valid user found for usr_id '.$a_parameter['usr_id']);
136 return true;
137 }
138
139 $settings = self::initServer($a_parameter['usr_id']);
140 self::extendAccount($settings, $user);
141
142 include_once './Services/WebServices/ECS/classes/Connectors/class.ilECSEnrolmentStatus.php';
144 }
145 break;
146
147
148 case 'deleteParticipant':
149 if(ilObjUser::_lookupAuthMode($a_parameter['usr_id']) == 'ecs')
150 {
151 if(!$user = ilObjectFactory::getInstanceByObjId($a_parameter['usr_id']))
152 {
153 $GLOBALS['ilLog']->write(__METHOD__.': No valid user found for usr_id '.$a_parameter['usr_id']);
154 return true;
155 }
156 include_once './Services/WebServices/ECS/classes/Connectors/class.ilECSEnrolmentStatus.php';
158 }
159 break;
160
161 case 'addParticipant':
162
163 if((ilObjUser::_lookupAuthMode($a_parameter['usr_id']) == 'ecs'))
164 {
165 if(!$user = ilObjectFactory::getInstanceByObjId($a_parameter['usr_id']))
166 {
167 $GLOBALS['ilLog']->write(__METHOD__.': No valid user found for usr_id '.$a_parameter['usr_id']);
168 return true;
169 }
170
171 $settings = self::initServer($user->getId());
172
173 self::extendAccount($settings, $user);
174 self::_sendNotification($settings,$user);
175
176 include_once './Services/WebServices/ECS/classes/Connectors/class.ilECSEnrolmentStatus.php';
178 unset($user);
179 }
180 break;
181 }
182 break;
183 }
184 }
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 mmissing 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
getInstanceByObjId($a_obj_id, $stop_on_error=true)
get an instance of an Ilias object by object id

References $GLOBALS, $ilLog, 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 mmissing course/groups to new user accounts.

Parameters
ilObjUser$user

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

249 {
250 $GLOBALS['ilLog']->write(__METHOD__.': Handling ECS assignments ');
251
252 include_once './Services/WebServices/ECS/classes/class.ilECSSetting.php';
254 {
255 $GLOBALS['ilLog']->write(__METHOD__.': Not user with authmode ' . ilECSSetting::lookupAuthMode());
256 return TRUE;
257 }
258
259 include_once './Services/WebServices/ECS/classes/Course/class.ilECSCourseMemberAssignment.php';
261 foreach($assignment_ids as $obj_id)
262 {
263 include_once './Services/Membership/classes/class.ilParticipants.php';
264 $part = ilParticipants::getInstanceByObjId($obj_id);
265 $part->add($user->getId(), IL_CRS_MEMBER);
266 }
267 }
const IL_CRS_MEMBER
static lookupMissingAssignmentsOfUser($a_usr_id)
Lookup missing assignments; @global type $ilDB.
static lookupAuthMode()
Lookup auth mode.
getAuthMode($a_auth_key=false)
get auth mode @access public
getExternalAccount()
get external account
static getInstanceByObjId($a_obj_id)
Get instance by obj type.

References $GLOBALS, ilObjUser\getAuthMode(), ilObjUser\getExternalAccount(), ilObject\getId(), ilParticipants\getInstanceByObjId(), IL_CRS_MEMBER, ilECSSetting\lookupAuthMode(), 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 190 of file class.ilECSAppEventListener.php.

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

296 {
297 include_once './Services/WebServices/ECS/classes/class.ilECSRemoteUser.php';
298 $remote = ilECSRemoteUser::factory($user->getId());
299 if(!$remote instanceof ilECSRemoteUser)
300 {
301 return FALSE;
302 }
303
304 include_once './Services/WebServices/ECS/classes/Connectors/class.ilECSEnrolmentStatus.php';
305 $enrol = new ilECSEnrolmentStatus();
306 $enrol->setId('il_'.$GLOBALS['ilSetting']->get('inst_id',0).'_'.ilObject::_lookupType($a_obj_id).'_'.$a_obj_id);
307 $enrol->setPersonId($remote->getRemoteUserId());
308 $enrol->setPersonIdType(ilECSEnrolmentStatus::ID_UID);
309 $enrol->setStatus($a_status);
310
311 try {
312 include_once './Services/WebServices/ECS/classes/Connectors/class.ilECSEnrolmentStatusConnector.php';
314 $con->addEnrolmentStatus($enrol,$remote->getMid());
315 }
317 {
318 $GLOBALS['ilLog']->write(__METHOD__.': update enrolment status faild with message: '. $e->getMessage());
319 return false;
320 }
321 }
Connector for course member ressource.
Storage of ecs remote user.
static factory($a_usr_id)
Get instance for usr_id.
static _lookupType($a_id, $a_reference=false)
lookup object type

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: