ILIAS  trunk Revision v11.0_alpha-3011-gc6b235a2e85
class.ilSessionParticipants.php
Go to the documentation of this file.
1<?php
2
19declare(strict_types=1);
20
30{
31 public const COMPONENT_NAME = 'components/ILIAS/Session';
32
33 protected static array $instances = [];
34
36
37 public function __construct(int $a_ref_id)
38 {
39 $this->event_part = new ilEventParticipants(ilObject::_lookupObjId($a_ref_id));
40 parent::__construct(self::COMPONENT_NAME, $a_ref_id);
41 }
42
43 public static function _getInstanceByObjId(int $a_obj_id): ilSessionParticipants
44 {
45 $refs = ilObject::_getAllReferences($a_obj_id);
46 return self::getInstance(array_pop($refs));
47 }
48
49 public static function getInstance(int $a_ref_id): ilSessionParticipants
50 {
51 if (isset(self::$instances[$a_ref_id]) && self::$instances[$a_ref_id] instanceof self) {
52 return self::$instances[$a_ref_id];
53 }
54 return self::$instances[$a_ref_id] = new self($a_ref_id);
55 }
56
58 {
59 return $this->event_part;
60 }
61
66 public function checkLastAdmin(array $a_usr_ids): bool
67 {
68 return false;
69 }
70
71 public static function _isParticipant(int $a_ref_id, int $a_usr_id): bool
72 {
75 }
76
77 protected function readParticipantsStatus(): void
78 {
79 $this->participants_status = [];
80 foreach ($this->getEventParticipants()->getParticipants() as $mem_uid => $info) {
81 $this->participants_status[$mem_uid]['blocked'] = false;
82 $this->participants_status[$mem_uid]['notification_enabled'] = (bool) $info['notification_enabled'];
83 $this->participants_status[$mem_uid]['passed'] = false;
84 $this->participants_status[$mem_uid]['contact'] = (bool) $info['contact'];
85 }
86 }
87
91 public function add(int $a_usr_id, int $a_role = 0): bool
92 {
93 if (parent::add($a_usr_id, $a_role)) {
94 return true;
95 }
96 return false;
97 }
98
99 public function register(int $a_usr_id): bool
100 {
101 $this->logger->debug('Registering user: ' . $a_usr_id . ' for session: ' . $this->getObjId());
102 $this->add($a_usr_id, ilParticipants::IL_SESS_MEMBER);
103 // in any (already participant since status attended) case register user.
104 $this->getEventParticipants()->register($a_usr_id);
105 return true;
106 }
107
108 public function unregister(int $a_usr_id): bool
109 {
110 // participated users are not dropped from role
111 if (!$this->getEventParticipants()->hasParticipated($a_usr_id)) {
112 $this->delete($a_usr_id);
113 }
114 $this->getEventParticipants()->unregister($a_usr_id);
115 return true;
116 }
117
118 public function sendNotification(int $a_type, int $a_usr_id, bool $a_force_email = false): void
119 {
121
122 switch ($a_type) {
125 $mail->setRefId($this->ref_id);
126 $mail->setRecipients([$a_usr_id]);
127 $mail->send();
128 break;
129
130 default:
131 $this->logger->warning('Invalid notfication type given: ' . $a_type);
132 $this->logger->logStack(ilLogLevel::WARNING);
133 break;
134 }
135 }
136}
class ilEventParticipants
static _isRegistered(int $a_usr_id, int $a_event_id)
static _getAllReferences(int $id)
get all reference ids for object ID
static _lookupObjId(int $ref_id)
Base class for course and group participants.
getParticipants()
Get all participants ids.
Session participation handling.
checkLastAdmin(array $a_usr_ids)
no last admin restrictions for sessions
add(int $a_usr_id, int $a_role=0)
Add user to session member role.
static getInstance(int $a_ref_id)
static _isParticipant(int $a_ref_id, int $a_usr_id)
Static function to check if a user is a participant of the container object.
static _getInstanceByObjId(int $a_obj_id)
readParticipantsStatus()
Read status of participants (blocked, notification, passed)
sendNotification(int $a_type, int $a_usr_id, bool $a_force_email=false)
$info
Definition: entry_point.php:21
__construct(Container $dic, ilPlugin $plugin)
@inheritDoc