ILIAS  release_6 Revision v6.24-5-g0c8bfefb3b8
All Data Structures Namespaces Files Functions Variables Modules Pages
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 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$

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

protected

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

References $lang, ilMail\_getAutoGeneratedMessageString(), ilLanguageFactory\_getLanguage(), ilObject\getId(), ilECSSetting\getServerId(), ilECSSetting\getUserRecipients(), and ilECSSetting\getUserRecipientsAsString().

195  {
196  if (!count($server->getUserRecipients())) {
197  return true;
198  }
199  // If sub id is set => mail was send
200  include_once './Services/WebServices/ECS/classes/class.ilECSImport.php';
201  $import = new ilECSImport($server->getServerId(), $user_obj->getId());
202  if ($import->getSubId()) {
203  return false;
204  }
205 
206  include_once('./Services/Language/classes/class.ilLanguageFactory.php');
208  $lang->loadLanguageModule('ecs');
209 
210  include_once('./Services/Mail/classes/class.ilMail.php');
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 
226  return true;
227  }
getServerId()
Get current server id.
static _getLanguage($a_lang_key='')
Get langauge object.
getId()
get object id public
getUserRecipientsAsString()
Get new user recipients.
Storage of ECS imported objects.
$lang
Definition: xapiexit.php:8
static _getAutoGeneratedMessageString(ilLanguage $lang=null)
Get auto generated info string.
getUserRecipients()
Get new user recipients.
+ Here is the call graph for this function:

◆ extendAccount()

static ilECSAppEventListener::extendAccount ( ilECSSetting  $settings,
ilObjUser  $user 
)
staticprotected

Extend account.

Parameters
ilECSSetting$server
ilObjUser$user

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

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

281  {
282  $end = new ilDateTime(time(), IL_CAL_UNIX);
283  $end->increment(IL_CAL_MONTH, $settings->getDuration());
284 
285  $GLOBALS['DIC']['ilLog']->write(__METHOD__ . ': account extension ' . (string) $end);
286 
287  if ($user->getTimeLimitUntil() < $end->get(IL_CAL_UNIX)) {
288  $user->setTimeLimitUntil($end->get(IL_CAL_UNIX));
289  $user->update();
290  }
291  }
const IL_CAL_MONTH
const IL_CAL_UNIX
setTimeLimitUntil($a_until)
if(!defined('PATH_SEPARATOR')) $GLOBALS['_PEAR_default_error_mode']
Definition: PEAR.php:64
getDuration()
get duration
update()
update object in db
+ Here is the call 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.

References $DIC, $GLOBALS, $ilLog, $log, ilObjUser\_lookupAuthMode(), ilObjectFactory\getInstanceByObjId(), ilECSEnrolmentStatus\STATUS_ACTIVE, ilECSEnrolmentStatus\STATUS_PENDING, and ilECSEnrolmentStatus\STATUS_UNSUBSCRIBED.

45  {
46  global $DIC;
47 
48  $ilLog = $DIC['ilLog'];
49 
50  $log = $GLOBALS['DIC']->logger()->wsrv();
51 
52  $log->debug('Listening to event from: ' . $a_component . ' ' . $a_event);
53 
54  switch ($a_component) {
55  case 'Services/User':
56  switch ($a_event) {
57  case 'afterCreate':
58  $user = $a_parameter['user_obj'];
59  self::handleMembership($user);
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  case 'addSubscriber':
69  case 'addToWaitingList':
70  if (ilObjUser::_lookupAuthMode($a_parameter['usr_id']) == 'ecs') {
71  if (!$user = ilObjectFactory::getInstanceByObjId($a_parameter['usr_id'])) {
72  $log->info('No valid user found for usr_id ' . $a_parameter['usr_id']);
73  return true;
74  }
75 
76  $settings = self::initServer($a_parameter['usr_id']);
77  self::extendAccount($settings, $user);
78 
79  include_once './Services/WebServices/ECS/classes/Connectors/class.ilECSEnrolmentStatus.php';
80  self::updateEnrolmentStatus($a_parameter['obj_id'], $user, ilECSEnrolmentStatus::STATUS_PENDING);
81  }
82  break;
83 
84  case 'deleteParticipant':
85  if (ilObjUser::_lookupAuthMode($a_parameter['usr_id']) == 'ecs') {
86  if (!$user = ilObjectFactory::getInstanceByObjId($a_parameter['usr_id'])) {
87  $log->info('No valid user found for usr_id ' . $a_parameter['usr_id']);
88  return true;
89  }
90  include_once './Services/WebServices/ECS/classes/Connectors/class.ilECSEnrolmentStatus.php';
91  self::updateEnrolmentStatus($a_parameter['obj_id'], $user, ilECSEnrolmentStatus::STATUS_UNSUBSCRIBED);
92  }
93  break;
94 
95  case 'addParticipant':
96  if ((ilObjUser::_lookupAuthMode($a_parameter['usr_id']) == 'ecs')) {
97  if (!$user = ilObjectFactory::getInstanceByObjId($a_parameter['usr_id'])) {
98  $log->info('No valid user found for usr_id ' . $a_parameter['usr_id']);
99  return true;
100  }
101 
102  $settings = self::initServer($user->getId());
103 
104  self::extendAccount($settings, $user);
105  #self::_sendNotification($settings,$user);
106 
107  include_once './Services/WebServices/ECS/classes/Connectors/class.ilECSEnrolmentStatus.php';
108  self::updateEnrolmentStatus($a_parameter['obj_id'], $user, ilECSEnrolmentStatus::STATUS_ACTIVE);
109  unset($user);
110  }
111  break;
112 
113 
114 
115  }
116  break;
117 
118  case 'Modules/Course':
119 
120  $GLOBALS['DIC']['ilLog']->write(__METHOD__ . ': New event from course: ' . $a_event);
121  switch ($a_event) {
122 
123  case 'addSubscriber':
124  case 'addToWaitingList':
125  if (ilObjUser::_lookupAuthMode($a_parameter['usr_id']) == 'ecs') {
126  if (!$user = ilObjectFactory::getInstanceByObjId($a_parameter['usr_id'])) {
127  $log->info('No valid user found for usr_id ' . $a_parameter['usr_id']);
128  return true;
129  }
130 
131  $settings = self::initServer($a_parameter['usr_id']);
132  self::extendAccount($settings, $user);
133 
134  include_once './Services/WebServices/ECS/classes/Connectors/class.ilECSEnrolmentStatus.php';
135  self::updateEnrolmentStatus($a_parameter['obj_id'], $user, ilECSEnrolmentStatus::STATUS_PENDING);
136  }
137  break;
138 
139 
140  case 'deleteParticipant':
141  if (ilObjUser::_lookupAuthMode($a_parameter['usr_id']) == 'ecs') {
142  if (!$user = ilObjectFactory::getInstanceByObjId($a_parameter['usr_id'])) {
143  $log->info('No valid user found for usr_id ' . $a_parameter['usr_id']);
144  return true;
145  }
146  include_once './Services/WebServices/ECS/classes/Connectors/class.ilECSEnrolmentStatus.php';
147  self::updateEnrolmentStatus($a_parameter['obj_id'], $user, ilECSEnrolmentStatus::STATUS_UNSUBSCRIBED);
148  }
149  break;
150 
151  case 'addParticipant':
152 
153  if ((ilObjUser::_lookupAuthMode($a_parameter['usr_id']) == 'ecs')) {
154  if (!$user = ilObjectFactory::getInstanceByObjId($a_parameter['usr_id'])) {
155  $log->info('No valid user found for usr_id ' . $a_parameter['usr_id']);
156  return true;
157  }
158 
159  $settings = self::initServer($user->getId());
160 
161  self::extendAccount($settings, $user);
162  self::_sendNotification($settings, $user);
163 
164  include_once './Services/WebServices/ECS/classes/Connectors/class.ilECSEnrolmentStatus.php';
165  self::updateEnrolmentStatus($a_parameter['obj_id'], $user, ilECSEnrolmentStatus::STATUS_ACTIVE);
166  unset($user);
167  }
168  break;
169  }
170  break;
171  }
172  }
$log
Definition: result.php:15
if(!defined('PATH_SEPARATOR')) $GLOBALS['_PEAR_default_error_mode']
Definition: PEAR.php:64
static getInstanceByObjId($a_obj_id, $stop_on_error=true)
get an instance of an Ilias object by object id
static _lookupAuthMode($a_usr_id)
lookup auth mode
$DIC
Definition: xapitoken.php:46
+ 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 233 of file class.ilECSAppEventListener.php.

References Vendor\Package\$e, $GLOBALS, $log, ilObject\_getAllReferences(), ilObject\_lookupType(), ilCourseConstants\CRS_MEMBER, ilLogLevel\ERROR, ilObjUser\getAuthMode(), ilObjUser\getExternalAccount(), ilObject\getId(), ilParticipants\getInstance(), ilECSNodeMappingSettings\getInstanceByServerMid(), IL_GRP_MEMBER, and ilECSCourseMemberAssignment\lookupMissingAssignmentsOfUser().

234  {
235  $log = $GLOBALS['DIC']->logger()->wsrv();
236  $log->debug('Handling ECS assignments ');
237 
238  include_once './Services/WebServices/ECS/classes/Course/class.ilECSCourseMemberAssignment.php';
240  foreach ($assignments as $assignment) {
241  include_once './Services/WebServices/ECS/classes/Mapping/class.ilECSNodeMappingSettings.php';
243  $assignment->getServer(),
244  $assignment->getMid()
245  );
246  if ($user->getAuthMode() == $msettings->getAuthMode()) {
247  $log->info('Adding user ' . $assignment->getUid() . ' to course/group: ' . $assignment->getObjId());
248  $obj_type = ilObject::_lookupType($assignment->getObjId());
249  if ($obj_type !== 'crs' && $obj_type !== 'grp') {
250  $log->error('Invalid assignment type: ' . $obj_type);
251  $log->logStack(ilLogLevel::ERROR);
252  continue;
253  }
254  $refs = ilObject::_getAllReferences($assignment->getObjId());
255  $ref_id = end($refs);
256 
257  try {
258  $part = ilParticipants::getInstance((int) $ref_id);
259  if ($obj_type === 'crs') {
260  $part->add($user->getId(), ilCourseConstants::CRS_MEMBER);
261  } elseif ($obj_type === 'grp') {
262  $part->add($user->getId(), IL_GRP_MEMBER);
263  }
264  } catch (InvalidArgumentException $e) {
265  $log->error('Invalid ref_id given: ' . (int) $ref_id);
266  $log->logStack(ilLogLevel::ERROR);
267  continue;
268  }
269  } else {
270  $log->notice('Auth mode of user: ' . $user->getAuthMode() . ' conflicts ' . $msettings->getAuthMode());
271  }
272  }
273  }
getAuthMode($a_auth_key=false)
get auth mode public
static getInstanceByServerMid($a_server_id, $a_mid)
Get instance.
const IL_GRP_MEMBER
static lookupMissingAssignmentsOfUser($a_usr_id)
Lookup missing assignments; type $ilDB.
static _getAllReferences($a_id)
get all reference ids of object
static getInstance($a_ref_id)
Get instance by ref_id.
getExternalAccount()
get external account
getId()
get object id public
$log
Definition: result.php:15
if(!defined('PATH_SEPARATOR')) $GLOBALS['_PEAR_default_error_mode']
Definition: PEAR.php:64
static _lookupType($a_id, $a_reference=false)
lookup object type
+ Here is the call graph for this function:

◆ initServer()

static ilECSAppEventListener::initServer (   $a_usr_id)
staticprotected

Init server settings.

Parameters
type$a_usr_id

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

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

179  {
180  include_once './Services/WebServices/ECS/classes/class.ilECSImport.php';
181  $server_id = ilECSImport::lookupServerId($a_usr_id);
182 
183  include_once('Services/WebServices/ECS/classes/class.ilECSSetting.php');
184  $settings = ilECSSetting::getInstanceByServerId($server_id);
185 
186  return $settings;
187  }
static getInstanceByServerId($a_server_id)
Get singleton instance per server.
static lookupServerId($a_obj_id)
Lookup server id of imported content <type> $ilDB.
+ Here is the call 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 300 of file class.ilECSAppEventListener.php.

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

301  {
302  include_once './Services/WebServices/ECS/classes/class.ilECSRemoteUser.php';
303  $remote = ilECSRemoteUser::factory($user->getId());
304  if (!$remote instanceof ilECSRemoteUser) {
305  return false;
306  }
307 
308  include_once './Services/WebServices/ECS/classes/Connectors/class.ilECSEnrolmentStatus.php';
309  $enrol = new ilECSEnrolmentStatus();
310  $enrol->setId('il_' . $GLOBALS['DIC']['ilSetting']->get('inst_id', 0) . '_' . ilObject::_lookupType($a_obj_id) . '_' . $a_obj_id);
311  $enrol->setPersonId($remote->getRemoteUserId());
312  $enrol->setPersonIdType(ilECSEnrolmentStatus::ID_UID);
313  $enrol->setStatus($a_status);
314 
315  try {
316  include_once './Services/WebServices/ECS/classes/Connectors/class.ilECSEnrolmentStatusConnector.php';
318  $con->addEnrolmentStatus($enrol, $remote->getMid());
319  } catch (ilECSConnectorException $e) {
320  $GLOBALS['DIC']['ilLog']->write(__METHOD__ . ': update enrolment status faild with message: ' . $e->getMessage());
321  return false;
322  }
323  }
static getInstanceByServerId($a_server_id)
Get singleton instance per server.
Storage of ecs remote user.
getId()
get object id public
if(!defined('PATH_SEPARATOR')) $GLOBALS['_PEAR_default_error_mode']
Definition: PEAR.php:64
static _lookupType($a_id, $a_reference=false)
lookup object type
Connector for course member ressource.
static factory($a_usr_id)
Get instance for usr_id.
+ Here is the call graph for this function:

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