ILIAS  release_5-3 Revision v5.3.23-19-g915713cf615
ilMembershipNotifications Class Reference

Membership notification settings. More...

+ Collaboration diagram for ilMembershipNotifications:

Public Member Functions

 __construct ($a_ref_id)
 Constructor. More...
 
 getMode ()
 Get mode. More...
 
 switchMode ($a_new_mode)
 Switch mode for object. More...
 
 getActiveUsers ()
 Get active notifications for current object. More...
 
 activateUser ($a_user_id=null)
 Activate notification for user. More...
 
 deactivateUser ($a_user_id=null)
 Deactivate notification for user. More...
 
 isCurrentUserActive ()
 Get user notification status. More...
 
 canCurrentUserEdit ()
 Can user change notification status? More...
 
 cloneSettings ($new_ref_id)
 Clone notification object settings. More...
 

Static Public Member Functions

static isActive ()
 Is feature active? More...
 
static getActiveUsersforAllObjects ()
 Get active notifications for all objects. More...
 
static addToSettingsForm ($a_ref_id, ilPropertyFormGUI $a_form=null, ilFormPropertyGUI $a_input=null)
 Add notification settings to form. More...
 
static importFromForm ($a_ref_id, ilPropertyFormGUI $a_form=null)
 Import notification settings from form. More...
 

Data Fields

const VALUE_OFF = 0
 
const VALUE_ON = 1
 
const VALUE_BLOCKED = 2
 
const MODE_SELF = 1
 
const MODE_ALL = 2
 
const MODE_ALL_BLOCKED = 3
 
const MODE_CUSTOM = 4
 

Protected Member Functions

 read ()
 Read from DB. More...
 
 setMode ($a_value)
 Set mode. More...
 
 isValidMode ($a_value)
 Is given mode valid? More...
 
 getParticipants ()
 Init participants for current object. More...
 
 getUser ($a_user_id=null)
 Init user instance. More...
 
 toggleUser ($a_status, $a_user_id=null)
 Toggle user notification status. More...
 

Protected Attributes

 $ref_id
 
 $mode
 
 $custom
 
 $participants
 

Detailed Description

Membership notification settings.

Author
Jörg Lützenkirchen luetz.nosp@m.enki.nosp@m.rchen.nosp@m.@lei.nosp@m.fos.c.nosp@m.om

Definition at line 10 of file class.ilMembershipNotifications.php.

Constructor & Destructor Documentation

◆ __construct()

ilMembershipNotifications::__construct (   $a_ref_id)

Constructor.

Parameters
int$a_ref_id
Returns
self

Definition at line 32 of file class.ilMembershipNotifications.php.

33 {
34 $this->ref_id = (int) $a_ref_id;
35 $this->custom = array();
36 $this->setMode(self::MODE_SELF);
37
38 if ($this->ref_id) {
39 $this->read();
40 }
41 }

References read(), and setMode().

+ Here is the call graph for this function:

Member Function Documentation

◆ activateUser()

ilMembershipNotifications::activateUser (   $a_user_id = null)

Activate notification for user.

Parameters
int$a_user_id
Returns
bool

Definition at line 279 of file class.ilMembershipNotifications.php.

280 {
281 return $this->toggleUser(true, $a_user_id);
282 }
toggleUser($a_status, $a_user_id=null)
Toggle user notification status.

References toggleUser().

+ Here is the call graph for this function:

◆ addToSettingsForm()

static ilMembershipNotifications::addToSettingsForm (   $a_ref_id,
ilPropertyFormGUI  $a_form = null,
ilFormPropertyGUI  $a_input = null 
)
static

Add notification settings to form.

Parameters
int$a_ref_id
ilPropertyFormGUI$a_form
ilPropertyFormGUI$a_input

Definition at line 494 of file class.ilMembershipNotifications.php.

495 {
496 global $lng;
497
498 if (self::isActive() &&
499 $a_ref_id) {
500 $lng->loadLanguageModule("membership");
501 $noti = new self($a_ref_id);
502
503 $force_noti = new ilRadioGroupInputGUI($lng->txt("mem_force_notification"), "force_noti");
504 $force_noti->setRequired(true);
505 if ($a_form) {
506 $a_form->addItem($force_noti);
507 } else {
508 $a_input->addSubItem($force_noti);
509 }
510
511 if ($noti->isValidMode(self::MODE_SELF)) {
512 $option = new ilRadioOption($lng->txt("mem_force_notification_mode_self"), self::MODE_SELF);
513 $force_noti->addOption($option);
514 }
515 if ($noti->isValidMode(self::MODE_ALL_BLOCKED)) {
516 $option = new ilRadioOption($lng->txt("mem_force_notification_mode_blocked"), self::MODE_ALL_BLOCKED);
517 $force_noti->addOption($option);
518
519 if ($noti->isValidMode(self::MODE_ALL)) {
520 $changeable = new ilCheckboxInputGUI($lng->txt("mem_force_notification_mode_all_sub_blocked"), "force_noti_allblk");
521 $option->addSubItem($changeable);
522 }
523 } elseif ($noti->isValidMode(self::MODE_ALL)) {
524 $option = new ilRadioOption($lng->txt("mem_force_notification_mode_all"), self::MODE_ALL);
525 $force_noti->addOption($option);
526 }
527 /* not supported in GUI
528 if($noti->isValidMode(self::MODE_CUSTOM))
529 {
530 $option = new ilRadioOption($lng->txt("mem_force_notification_mode_custom"), self::MODE_CUSTOM);
531 $option->setInfo($lng->txt("mem_force_notification_mode_custom_info"));
532 $force_noti->addOption($option);
533 }
534 */
535
536 // set current mode
537 $current_mode = $noti->getMode();
538 $has_changeable_cb = ($noti->isValidMode(self::MODE_ALL_BLOCKED) &&
539 $noti->isValidMode(self::MODE_ALL));
540 if (!$has_changeable_cb) {
541 $force_noti->setValue($current_mode);
542 } else {
543 switch ($current_mode) {
544 case self::MODE_SELF:
545 $force_noti->setValue($current_mode);
546 $changeable->setChecked(true); // checked as "default" on selection of parent
547 break;
548
550 $force_noti->setValue($current_mode);
551 break;
552
553 case self::MODE_ALL:
554 $force_noti->setValue(self::MODE_ALL_BLOCKED);
555 $changeable->setChecked(true);
556 break;
557 }
558 }
559 }
560 }
This class represents a checkbox property in a property form.
addItem($a_item)
Add Item (Property, SectionHeader).
This class represents a property in a property form.
This class represents an option in a radio group.
global $lng
Definition: privfeed.php:17

References $lng, MODE_ALL, MODE_ALL_BLOCKED, and MODE_SELF.

Referenced by ilContainerNewsSettingsGUI\initForm(), and ilObjectServiceSettingsGUI\initServiceSettingsForm().

+ Here is the caller graph for this function:

◆ canCurrentUserEdit()

ilMembershipNotifications::canCurrentUserEdit ( )

Can user change notification status?

Returns
boolean

Definition at line 401 of file class.ilMembershipNotifications.php.

402 {
403 global $ilUser;
404
405 $user_id = $ilUser->getId();
406 if ($user_id == ANONYMOUS_USER_ID) {
407 return false;
408 }
409
410 switch ($this->getMode()) {
411 case self::MODE_SELF:
412 case self::MODE_ALL:
413 return true;
414
416 return false;
417
419 return !(array_key_exists($user_id, $this->custom) &&
420 $this->custom[$user_id] == self::VALUE_BLOCKED);
421 }
422 }
$ilUser
Definition: imgupload.php:18

References $ilUser, getMode(), MODE_ALL, MODE_ALL_BLOCKED, MODE_CUSTOM, MODE_SELF, and VALUE_BLOCKED.

+ Here is the call graph for this function:

◆ cloneSettings()

ilMembershipNotifications::cloneSettings (   $new_ref_id)

Clone notification object settings.

Parameters
$new_ref_id

Definition at line 601 of file class.ilMembershipNotifications.php.

602 {
603 global $ilDB;
604
605 $set = $ilDB->queryF(
606 "SELECT * FROM member_noti " .
607 " WHERE ref_id = %s ",
608 array("integer"),
609 array($this->ref_id)
610 );
611 while ($rec = $ilDB->fetchAssoc($set)) {
612 $ilDB->insert("member_noti", array(
613 "ref_id" => array("integer", $new_ref_id),
614 "nmode" => array("integer", $rec["nmode"])
615 ));
616 }
617 }
global $ilDB

References $ilDB.

◆ deactivateUser()

ilMembershipNotifications::deactivateUser (   $a_user_id = null)

Deactivate notification for user.

Parameters
int$a_user_id
Returns
bool

Definition at line 290 of file class.ilMembershipNotifications.php.

291 {
292 return $this->toggleUser(false, $a_user_id);
293 }

References toggleUser().

+ Here is the call graph for this function:

◆ getActiveUsers()

ilMembershipNotifications::getActiveUsers ( )

Get active notifications for current object.

Returns
array

Definition at line 209 of file class.ilMembershipNotifications.php.

210 {
211 global $ilDB;
212
213 $users = $all = array();
214
215 $part_obj = $this->getParticipants();
216 if ($part_obj) {
217 $all = $part_obj->getParticipants();
218 }
219 if (!sizeof($all)) {
220 return array();
221 }
222
223 switch ($this->getMode()) {
224 // users decide themselves
225 case self::MODE_SELF:
226 $set = $ilDB->query("SELECT usr_id" .
227 " FROM usr_pref" .
228 " WHERE " . $ilDB->like("keyword", "text", "grpcrs_ntf_" . $this->ref_id) .
229 " AND value = " . $ilDB->quote(self::VALUE_ON, "text"));
230 while ($row = $ilDB->fetchAssoc($set)) {
231 $users[] = $row["usr_id"];
232 }
233 break;
234
235 // all members, mind opt-out
236 case self::MODE_ALL:
237 // users who did opt-out
238 $inactive = array();
239 $set = $ilDB->query("SELECT usr_id" .
240 " FROM usr_pref" .
241 " WHERE " . $ilDB->like("keyword", "text", "grpcrs_ntf_" . $this->ref_id) .
242 " AND value = " . $ilDB->quote(self::VALUE_OFF, "text"));
243 while ($row = $ilDB->fetchAssoc($set)) {
244 $inactive[] = $row["usr_id"];
245 }
246 $users = array_diff($all, $inactive);
247 break;
248
249 // all members, no opt-out
251 $users = $all;
252 break;
253
254 // custom settings
256 foreach ($this->custom as $user_id => $status) {
257 if ($status != self::VALUE_OFF) {
258 $users[] = $user_id;
259 }
260 }
261 break;
262 }
263
264 // only valid participants
265 return array_intersect($all, $users);
266 }
$users
Definition: authpage.php:44
getParticipants()
Init participants for current object.

References $ilDB, $row, $users, getMode(), getParticipants(), MODE_ALL, MODE_ALL_BLOCKED, MODE_CUSTOM, and MODE_SELF.

+ Here is the call graph for this function:

◆ getActiveUsersforAllObjects()

static ilMembershipNotifications::getActiveUsersforAllObjects ( )
static

Get active notifications for all objects.

Returns
array

Definition at line 434 of file class.ilMembershipNotifications.php.

435 {
436 global $ilDB, $tree;
437
439
440
441 $res = array();
442
443 if (self::isActive()) {
444 $objects = array();
445
446 // user-preference data (MODE_SELF)
447 $log->debug("read usr_pref");
448 $set = $ilDB->query("SELECT DISTINCT(keyword) keyword" .
449 " FROM usr_pref" .
450 " WHERE " . $ilDB->like("keyword", "text", "grpcrs_ntf_%") .
451 " AND value = " . $ilDB->quote("1", "text"));
452 while ($row = $ilDB->fetchAssoc($set)) {
453 $ref_id = substr($row["keyword"], 11);
454 $objects[(int) $ref_id] = (int) $ref_id;
455 }
456
457 // all other modes
458 $log->debug("read member_noti");
459 $set = $ilDB->query("SELECT ref_id" .
460 " FROM member_noti");
461 while ($row = $ilDB->fetchAssoc($set)) {
462 $objects[(int) $row["ref_id"]] = (int) $row["ref_id"];
463 }
464
465 // this might be slow but it is to be used in CRON JOB ONLY!
466 foreach (array_unique($objects) as $ref_id) {
467 // :TODO: enough checking?
468 if (!$tree->isDeleted($ref_id)) {
469 $log->debug("get active users");
470 $noti = new self($ref_id);
471 $active = $noti->getActiveUsers();
472 if (sizeof($active)) {
473 $res[$ref_id] = $active;
474 }
475 }
476 }
477 }
478
479 return $res;
480 }
static getLogger($a_component_id)
Get component logger.
foreach($_POST as $key=> $value) $res

References $ilDB, $log, $ref_id, $res, $row, and ilLoggerFactory\getLogger().

Referenced by ilMembershipCronNotifications\run().

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

◆ getMode()

ilMembershipNotifications::getMode ( )

Get mode.

Returns
int

Definition at line 91 of file class.ilMembershipNotifications.php.

References $mode.

Referenced by canCurrentUserEdit(), getActiveUsers(), and toggleUser().

+ Here is the caller graph for this function:

◆ getParticipants()

ilMembershipNotifications::getParticipants ( )
protected

Init participants for current object.

Returns
ilParticipants

Definition at line 179 of file class.ilMembershipNotifications.php.

180 {
181 global $tree;
182
183 if ($this->participants === null) {
184 $this->participants = false;
185
186 $grp_ref_id = $tree->checkForParentType($this->ref_id, "grp");
187 if ($grp_ref_id) {
188 include_once "Modules/Group/classes/class.ilGroupParticipants.php";
189 $this->participants = ilGroupParticipants::_getInstanceByObjId(ilObject::_lookupObjId($grp_ref_id));
190 }
191
192 if (!$this->participants) {
193 $crs_ref_id = $tree->checkForParentType($this->ref_id, "crs");
194 if ($crs_ref_id) {
195 include_once "Modules/Course/classes/class.ilCourseParticipants.php";
196 $this->participants = ilCourseParticipants::_getInstanceByObjId(ilObject::_lookupObjId($crs_ref_id));
197 }
198 }
199 }
200
201 return $this->participants;
202 }
static _getInstanceByObjId($a_obj_id)
Get singleton instance.
static _getInstanceByObjId($a_obj_id)
Get singleton instance.
static _lookupObjId($a_id)

References $participants, ilCourseParticipants\_getInstanceByObjId(), ilGroupParticipants\_getInstanceByObjId(), and ilObject\_lookupObjId().

Referenced by getActiveUsers().

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

◆ getUser()

ilMembershipNotifications::getUser (   $a_user_id = null)
protected

Init user instance.

Parameters
int$a_user_id
Returns
ilUser

Definition at line 301 of file class.ilMembershipNotifications.php.

302 {
303 global $ilUser;
304
305 if ($a_user_id === null ||
306 $a_user_id == $ilUser->getId()) {
307 $user = $ilUser;
308 } else {
309 $user = new ilUser($a_user_id);
310 }
311
312 if ($user->getId() &&
313 $user->getId() != ANONYMOUS_USER_ID) {
314 return $user;
315 }
316 }

References $ilUser.

Referenced by toggleUser().

+ Here is the caller graph for this function:

◆ importFromForm()

static ilMembershipNotifications::importFromForm (   $a_ref_id,
ilPropertyFormGUI  $a_form = null 
)
static

Import notification settings from form.

Parameters
int$a_ref_id
ilPropertyFormGUI$a_form

Definition at line 568 of file class.ilMembershipNotifications.php.

569 {
570 if (self::isActive() &&
571 $a_ref_id) {
572 $noti = new self($a_ref_id);
573 $has_changeable_cb = ($noti->isValidMode(self::MODE_ALL_BLOCKED) &&
574 $noti->isValidMode(self::MODE_ALL));
575 $changeable = null;
576 if (!$a_form) {
577 $mode = (int) $_POST["force_noti"];
578 if ($has_changeable_cb) {
579 $changeable = (int) $_POST["force_noti_allblk"];
580 }
581 } else {
582 $mode = $a_form->getInput("force_noti");
583 if ($has_changeable_cb) {
584 $changeable = $a_form->getInput("force_noti_allblk");
585 }
586 }
587 // checkbox (all) is subitem of all_blocked
588 if ($changeable &&
589 $mode == self::MODE_ALL_BLOCKED) {
591 }
592 $noti->switchMode($mode);
593 }
594 }
$_POST["username"]
getInput($a_post_var, $ensureValidation=true)
Returns the value of a HTTP-POST variable, identified by the passed id.

References $_POST, $mode, and MODE_ALL.

Referenced by ilContainerNewsSettingsGUI\save(), and ilObjectServiceSettingsGUI\updateServiceSettingsForm().

+ Here is the caller graph for this function:

◆ isActive()

static ilMembershipNotifications::isActive ( )
static

Is feature active?

Returns
bool

Definition at line 48 of file class.ilMembershipNotifications.php.

49 {
50 global $ilSetting;
51
52 return ($ilSetting->get("block_activated_news") &&
53 $ilSetting->get("crsgrp_ntf"));
54 }
global $ilSetting
Definition: privfeed.php:17

References $ilSetting.

Referenced by ilObjCourseGUI\initHeaderAction(), and ilObjGroupGUI\initHeaderAction().

+ Here is the caller graph for this function:

◆ isCurrentUserActive()

ilMembershipNotifications::isCurrentUserActive ( )

Get user notification status.

Returns
boolean

Definition at line 389 of file class.ilMembershipNotifications.php.

390 {
391 global $ilUser;
392
393 return in_array($ilUser->getId(), $this->getActiveUsers());
394 }

References $ilUser.

◆ isValidMode()

ilMembershipNotifications::isValidMode (   $a_value)
protected

Is given mode valid?

Parameters
int$a_value
Returns
bool

Definition at line 114 of file class.ilMembershipNotifications.php.

115 {
116 $valid = array(
117 self::MODE_SELF
118 ,self::MODE_ALL
119 ,self::MODE_ALL_BLOCKED
120 // ,self::MODE_CUSTOM currently used in forum
121 );
122 return in_array($a_value, $valid);
123 }
$valid

References $valid.

Referenced by setMode(), and switchMode().

+ Here is the caller graph for this function:

◆ read()

ilMembershipNotifications::read ( )
protected

Read from DB.

Definition at line 59 of file class.ilMembershipNotifications.php.

60 {
61 global $ilDB;
62
63 $set = $ilDB->query("SELECT nmode mode" .
64 " FROM member_noti" .
65 " WHERE ref_id = " . $ilDB->quote($this->ref_id, "integer"));
66 if ($ilDB->numRows($set)) {
67 $row = $ilDB->fetchAssoc($set);
68 $this->setMode($row["mode"]);
69
70 if ($row["mode"] == self::MODE_CUSTOM) {
71 $set = $ilDB->query("SELECT *" .
72 " FROM member_noti_user" .
73 " WHERE ref_id = " . $ilDB->quote($this->ref_id, "integer"));
74 while ($row = $ilDB->fetchAssoc($set)) {
75 $this->custom[$row["user_id"]] = $row["status"];
76 }
77 }
78 }
79 }

References $ilDB, $row, and setMode().

Referenced by __construct().

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

◆ setMode()

ilMembershipNotifications::setMode (   $a_value)
protected

Set mode.

Parameters
int$a_value

Definition at line 101 of file class.ilMembershipNotifications.php.

102 {
103 if ($this->isValidMode($a_value)) {
104 $this->mode = $a_value;
105 }
106 }
isValidMode($a_value)
Is given mode valid?

References isValidMode().

Referenced by __construct(), read(), and switchMode().

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

◆ switchMode()

ilMembershipNotifications::switchMode (   $a_new_mode)

Switch mode for object.

Parameters
int$a_new_mode
Returns
bool

Definition at line 131 of file class.ilMembershipNotifications.php.

132 {
133 global $ilDB;
134
135 if (!$this->ref_id) {
136 return;
137 }
138
139 if ($this->mode &&
140 $this->mode != $a_new_mode &&
141 $this->isValidMode($a_new_mode)) {
142 $ilDB->manipulate("DELETE FROM member_noti" .
143 " WHERE ref_id = " . $ilDB->quote($this->ref_id, "integer"));
144
145 // no custom data
146 if ($a_new_mode != self::MODE_CUSTOM) {
147 $ilDB->manipulate("DELETE FROM member_noti_user" .
148 " WHERE ref_id = " . $ilDB->quote($this->ref_id, "integer"));
149 }
150
151 // mode self is default
152 if ($a_new_mode != self::MODE_SELF) {
153 $ilDB->insert("member_noti", array(
154 "ref_id" => array("integer", $this->ref_id),
155 "nmode" => array("integer", $a_new_mode)
156 ));
157 }
158
159 // remove all user settings (all active is preset, optional opt out)
160 if ($a_new_mode == self::MODE_ALL) {
161 $ilDB->manipulate("DELETE FROM usr_pref" .
162 " WHERE " . $ilDB->like("keyword", "text", "grpcrs_ntf_" . $this->ref_id));
163 }
164 }
165
166 $this->setMode($a_new_mode);
167 }

References $ilDB, isValidMode(), and setMode().

+ Here is the call graph for this function:

◆ toggleUser()

ilMembershipNotifications::toggleUser (   $a_status,
  $a_user_id = null 
)
protected

Toggle user notification status.

Parameters
bool$a_status
int$a_user_id
Returns
boolean

Definition at line 325 of file class.ilMembershipNotifications.php.

326 {
327 global $ilDB;
328
329 if (!self::isActive()) {
330 return;
331 }
332
333 switch ($this->getMode()) {
334 case self::MODE_ALL:
335 case self::MODE_SELF:
336 // current user!
337 $user = $this->getUser();
338 if ($user) {
339 // blocked value not supported in user pref!
340 $user->setPref("grpcrs_ntf_" . $this->ref_id, (int) (bool) $a_status);
341 $user->writePrefs();
342 return true;
343 }
344 break;
345
347 $user = $this->getUser($a_user_id);
348 if ($user) {
349 $user_id = $user->getId();
350
351 // did status change at all?
352 if (!array_key_exists($user_id, $this->custom) ||
353 $this->custom[$user_id != $a_status]) {
354 $this->custom[$user_id] = $a_status;
355
356 $ilDB->replace(
357 "member_noti_user",
358 array(
359 "ref_id" => array("integer", $this->ref_id),
360 "user_id" => array("integer", $user_id),
361 ),
362 array(
363 "status" => array("integer", $a_status)
364 )
365 );
366 }
367 return true;
368 }
369 break;
370
372 // no individual settings
373 break;
374 }
375
376 return false;
377 }
getUser($a_user_id=null)
Init user instance.

References $ilDB, getMode(), getUser(), MODE_ALL, MODE_ALL_BLOCKED, MODE_CUSTOM, and MODE_SELF.

Referenced by activateUser(), and deactivateUser().

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

Field Documentation

◆ $custom

ilMembershipNotifications::$custom
protected

Definition at line 14 of file class.ilMembershipNotifications.php.

◆ $mode

ilMembershipNotifications::$mode
protected

Definition at line 13 of file class.ilMembershipNotifications.php.

Referenced by getMode(), and importFromForm().

◆ $participants

ilMembershipNotifications::$participants
protected

Definition at line 15 of file class.ilMembershipNotifications.php.

Referenced by getParticipants().

◆ $ref_id

ilMembershipNotifications::$ref_id
protected

Definition at line 12 of file class.ilMembershipNotifications.php.

Referenced by getActiveUsersforAllObjects().

◆ MODE_ALL

const ilMembershipNotifications::MODE_ALL = 2

◆ MODE_ALL_BLOCKED

const ilMembershipNotifications::MODE_ALL_BLOCKED = 3

◆ MODE_CUSTOM

const ilMembershipNotifications::MODE_CUSTOM = 4

◆ MODE_SELF

const ilMembershipNotifications::MODE_SELF = 1

◆ VALUE_BLOCKED

const ilMembershipNotifications::VALUE_BLOCKED = 2

Definition at line 19 of file class.ilMembershipNotifications.php.

Referenced by canCurrentUserEdit().

◆ VALUE_OFF

const ilMembershipNotifications::VALUE_OFF = 0

Definition at line 17 of file class.ilMembershipNotifications.php.

◆ VALUE_ON

const ilMembershipNotifications::VALUE_ON = 1

Definition at line 18 of file class.ilMembershipNotifications.php.


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