ILIAS  release_5-1 Revision 5.0.0-5477-g43f3e3fab5f
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...
 

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 {
40 $this->read();
41 }
42 }

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 300 of file class.ilMembershipNotifications.php.

301 {
302 return $this->toggleUser(true, $a_user_id);
303 }
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 525 of file class.ilMembershipNotifications.php.

526 {
527 global $lng;
528
529 if(self::isActive() &&
530 $a_ref_id)
531 {
532 $lng->loadLanguageModule("membership");
533 $noti = new self($a_ref_id);
534
535 $force_noti = new ilRadioGroupInputGUI($lng->txt("mem_force_notification"), "force_noti");
536 $force_noti->setRequired(true);
537 if($a_form)
538 {
539 $a_form->addItem($force_noti);
540 }
541 else
542 {
543 $a_input->addSubItem($force_noti);
544 }
545
546 if($noti->isValidMode(self::MODE_SELF))
547 {
548 $option = new ilRadioOption($lng->txt("mem_force_notification_mode_self"), self::MODE_SELF);
549 $force_noti->addOption($option);
550 }
551 if($noti->isValidMode(self::MODE_ALL_BLOCKED))
552 {
553 $option = new ilRadioOption($lng->txt("mem_force_notification_mode_blocked"), self::MODE_ALL_BLOCKED);
554 $force_noti->addOption($option);
555
556 if($noti->isValidMode(self::MODE_ALL))
557 {
558 $changeable = new ilCheckboxInputGUI($lng->txt("mem_force_notification_mode_all_sub_blocked"), "force_noti_allblk");
559 $option->addSubItem($changeable);
560 }
561 }
562 else if($noti->isValidMode(self::MODE_ALL))
563 {
564 $option = new ilRadioOption($lng->txt("mem_force_notification_mode_all"), self::MODE_ALL);
565 $force_noti->addOption($option);
566 }
567 /* not supported in GUI
568 if($noti->isValidMode(self::MODE_CUSTOM))
569 {
570 $option = new ilRadioOption($lng->txt("mem_force_notification_mode_custom"), self::MODE_CUSTOM);
571 $option->setInfo($lng->txt("mem_force_notification_mode_custom_info"));
572 $force_noti->addOption($option);
573 }
574 */
575
576 // set current mode
577 $current_mode = $noti->getMode();
578 $has_changeable_cb = ($noti->isValidMode(self::MODE_ALL_BLOCKED) &&
579 $noti->isValidMode(self::MODE_ALL));
580 if(!$has_changeable_cb)
581 {
582 $force_noti->setValue($current_mode);
583 }
584 else
585 {
586 switch($current_mode)
587 {
588 case self::MODE_SELF:
589 $force_noti->setValue($current_mode);
590 $changeable->setChecked(true); // checked as "default" on selection of parent
591 break;
592
594 $force_noti->setValue($current_mode);
595 break;
596
597 case self::MODE_ALL:
598 $force_noti->setValue(self::MODE_ALL_BLOCKED);
599 $changeable->setChecked(true);
600 break;
601 }
602 }
603 }
604 }
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:40

References $lng, MODE_ALL, MODE_ALL_BLOCKED, and MODE_SELF.

Referenced by ilObjectServiceSettingsGUI\initServiceSettingsForm().

+ Here is the caller graph for this function:

◆ canCurrentUserEdit()

ilMembershipNotifications::canCurrentUserEdit ( )

Can user change notification status?

Returns
boolean

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

431 {
432 global $ilUser;
433
434 $user_id = $ilUser->getId();
435 if($user_id == ANONYMOUS_USER_ID)
436 {
437 return false;
438 }
439
440 switch($this->getMode())
441 {
442 case self::MODE_SELF:
443 case self::MODE_ALL:
444 return true;
445
447 return false;
448
450 return !(array_key_exists($user_id, $this->custom) &&
451 $this->custom[$user_id] == self::VALUE_BLOCKED);
452 }
453 }
global $ilUser
Definition: imgupload.php:15

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

+ Here is the call graph for this function:

◆ deactivateUser()

ilMembershipNotifications::deactivateUser (   $a_user_id = null)

Deactivate notification for user.

Parameters
int$a_user_id
Returns
bool

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

312 {
313 return $this->toggleUser(false, $a_user_id);
314 }

References toggleUser().

+ Here is the call graph for this function:

◆ getActiveUsers()

ilMembershipNotifications::getActiveUsers ( )

Get active notifications for current object.

Returns
array

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

224 {
225 global $ilDB;
226
227 $users = $all = array();
228
229 $part_obj = $this->getParticipants();
230 if($part_obj)
231 {
232 $all = $part_obj->getParticipants();
233 }
234 if(!sizeof($all))
235 {
236 return array();
237 }
238
239 switch($this->getMode())
240 {
241 // users decide themselves
242 case self::MODE_SELF:
243 $set = $ilDB->query("SELECT usr_id".
244 " FROM usr_pref".
245 " WHERE ".$ilDB->like("keyword", "text", "grpcrs_ntf_".$this->ref_id).
246 " AND value = ".$ilDB->quote(self::VALUE_ON, "text"));
247 while($row = $ilDB->fetchAssoc($set))
248 {
249 $users[] = $row["usr_id"];
250 }
251 break;
252
253 // all members, mind opt-out
254 case self::MODE_ALL:
255 // users who did opt-out
256 $inactive = array();
257 $set = $ilDB->query("SELECT usr_id".
258 " FROM usr_pref".
259 " WHERE ".$ilDB->like("keyword", "text", "grpcrs_ntf_".$this->ref_id).
260 " AND value = ".$ilDB->quote(self::VALUE_OFF, "text"));
261 while($row = $ilDB->fetchAssoc($set))
262 {
263 $inactive[] = $row["usr_id"];
264 }
265 $users = array_diff($all, $inactive);
266 break;
267
268 // all members, no opt-out
270 $users = $all;
271 break;
272
273 // custom settings
274 case self::MODE_CUSTOM:
275 foreach($this->custom as $user_id => $status)
276 {
277 if($status != self::VALUE_OFF)
278 {
279 $users[] = $user_id;
280 }
281 }
282 break;
283 }
284
285 // only valid participants
286 return array_intersect($all, $users);
287 }
getParticipants()
Init participants for current object.
global $ilDB

References $ilDB, $row, 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 465 of file class.ilMembershipNotifications.php.

466 {
467 global $ilDB, $tree;
468
469 $res = array();
470
471 if(self::isActive())
472 {
473 $objects = array();
474
475 // user-preference data (MODE_SELF)
476 $set = $ilDB->query("SELECT DISTINCT(keyword) keyword".
477 " FROM usr_pref".
478 " WHERE ".$ilDB->like("keyword", "text", "grpcrs_ntf_%").
479 " AND value = ".$ilDB->quote("1", "text"));
480 while($row = $ilDB->fetchAssoc($set))
481 {
482 $ref_id = substr($row["keyword"], 11);
483 $objects[] = (int)$ref_id;
484 }
485
486 // all other modes
487 $set = $ilDB->query("SELECT ref_id".
488 " FROM member_noti");
489 while($row = $ilDB->fetchAssoc($set))
490 {
491 $objects[] = (int)$row["ref_id"];
492 }
493
494 // this might be slow but it is to be used in CRON JOB ONLY!
495 foreach(array_unique($objects) as $ref_id)
496 {
497 // :TODO: enough checking?
498 if(!$tree->isDeleted($ref_id))
499 {
500 $noti = new self($ref_id);
501 $active = $noti->getActiveUsers();
502 if(sizeof($active))
503 {
504 $res[$ref_id] = $active;
505 }
506 }
507 }
508 }
509
510 return $res;
511 }

References $ilDB, $ref_id, $res, and $row.

Referenced by ilMembershipCronNotifications\run().

+ Here is the caller graph for this function:

◆ getMode()

ilMembershipNotifications::getMode ( )

Get mode.

Returns
int

Definition at line 95 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 189 of file class.ilMembershipNotifications.php.

190 {
191 global $tree;
192
193 if($this->participants === null)
194 {
195 $this->participants = false;
196
197 $grp_ref_id = $tree->checkForParentType($this->ref_id, "grp");
198 if($grp_ref_id)
199 {
200 include_once "Modules/Group/classes/class.ilGroupParticipants.php";
201 $this->participants = ilGroupParticipants::_getInstanceByObjId(ilObject::_lookupObjId($grp_ref_id));
202 }
203
204 if(!$this->participants)
205 {
206 $crs_ref_id = $tree->checkForParentType($this->ref_id, "crs");
207 if($crs_ref_id)
208 {
209 include_once "Modules/Course/classes/class.ilCourseParticipants.php";
210 $this->participants = ilCourseParticipants::_getInstanceByObjId(ilObject::_lookupObjId($crs_ref_id));
211 }
212 }
213 }
214
215 return $this->participants;
216 }
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 322 of file class.ilMembershipNotifications.php.

323 {
324 global $ilUser;
325
326 if($a_user_id === null ||
327 $a_user_id == $ilUser->getId())
328 {
329 $user = $ilUser;
330 }
331 else
332 {
333 $user = new ilUser($a_user_id);
334 }
335
336 if($user->getId() &&
337 $user->getId() != ANONYMOUS_USER_ID)
338 {
339 return $user;
340 }
341 }

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 612 of file class.ilMembershipNotifications.php.

613 {
614 if(self::isActive() &&
615 $a_ref_id)
616 {
617 $noti = new self($a_ref_id);
618 $has_changeable_cb = ($noti->isValidMode(self::MODE_ALL_BLOCKED) &&
619 $noti->isValidMode(self::MODE_ALL));
620 $changeable = null;
621 if(!$a_form)
622 {
623 $mode = (int)$_POST["force_noti"];
624 if($has_changeable_cb)
625 {
626 $changeable = (int)$_POST["force_noti_allblk"];
627 }
628 }
629 else
630 {
631 $mode = $a_form->getInput("force_noti");
632 if($has_changeable_cb)
633 {
634 $changeable = $a_form->getInput("force_noti_allblk");
635 }
636 }
637 // checkbox (all) is subitem of all_blocked
638 if($changeable &&
639 $mode == self::MODE_ALL_BLOCKED)
640 {
642 }
643 $noti->switchMode($mode);
644 }
645 }
getInput($a_post_var, $ensureValidation=true)
Returns the value of a HTTP-POST variable, identified by the passed id.
$_POST['username']
Definition: cron.php:12

References $_POST, $mode, and MODE_ALL.

Referenced by ilObjectServiceSettingsGUI\updateServiceSettingsForm().

+ Here is the caller graph for this function:

◆ isActive()

static ilMembershipNotifications::isActive ( )
static

Is feature active?

Returns
bool

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

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

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 418 of file class.ilMembershipNotifications.php.

419 {
420 global $ilUser;
421
422 return in_array($ilUser->getId(), $this->getActiveUsers());
423 }

References $ilUser.

◆ isValidMode()

ilMembershipNotifications::isValidMode (   $a_value)
protected

Is given mode valid?

Parameters
int$a_value
Returns
bool

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

120 {
121 $valid = array(
122 self::MODE_SELF
123 ,self::MODE_ALL
124 ,self::MODE_ALL_BLOCKED
125 // ,self::MODE_CUSTOM currently used in forum
126 );
127 return in_array($a_value, $valid);
128 }
$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 60 of file class.ilMembershipNotifications.php.

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

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 105 of file class.ilMembershipNotifications.php.

106 {
107 if($this->isValidMode($a_value))
108 {
109 $this->mode = $a_value;
110 }
111 }
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 136 of file class.ilMembershipNotifications.php.

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

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 350 of file class.ilMembershipNotifications.php.

351 {
352 global $ilDB;
353
354 if(!self::isActive())
355 {
356 return;
357 }
358
359 switch($this->getMode())
360 {
361 case self::MODE_ALL:
362 case self::MODE_SELF:
363 // current user!
364 $user = $this->getUser();
365 if($user)
366 {
367 // blocked value not supported in user pref!
368 $user->setPref("grpcrs_ntf_".$this->ref_id, (int)(bool)$a_status);
369 $user->writePrefs();
370 return true;
371 }
372 break;
373
375 $user = $this->getUser($a_user_id);
376 if($user)
377 {
378 $user_id = $user->getId();
379
380 // did status change at all?
381 if(!array_key_exists($user_id, $this->custom) ||
382 $this->custom[$user_id != $a_status])
383 {
384 $this->custom[$user_id] = $a_status;
385
386 $ilDB->replace("member_noti_user",
387 array(
388 "ref_id" => array("integer", $this->ref_id),
389 "user_id" => array("integer", $user_id),
390 ),
391 array(
392 "status" => array("integer", $a_status)
393 )
394 );
395 }
396 return true;
397 }
398 break;
399
401 // no individual settings
402 break;
403 }
404
405 return false;
406 }
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: