ILIAS  trunk Revision v11.0_alpha-1753-gb21ca8c4367
All Data Structures Namespaces Files Functions Variables Enumerations Enumerator Modules Pages
class.ilSessionParticipants.php
Go to the documentation of this file.
1 <?php
2 
19 declare(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  {
73  $obj_id = ilObject::_lookupObjId($a_ref_id);
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 }
Session participation handling.
add()
description: > Example for rendring an add glyph.
Definition: add.php:41
static _getAllReferences(int $id)
get all reference ids for object ID
static _isParticipant(int $a_ref_id, int $a_usr_id)
sendNotification(int $a_type, int $a_usr_id, bool $a_force_email=false)
static _lookupObjId(int $ref_id)
checkLastAdmin(array $a_usr_ids)
no last admin restrictions for sessions
static _isRegistered(int $a_usr_id, int $a_event_id)
static getInstance(int $a_ref_id)
getParticipants()
Get all participants ids.
add(int $a_usr_id, int $a_role=0)
Add user to session member role.
class ilEventParticipants
Base class for course and group participants.
__construct(Container $dic, ilPlugin $plugin)
static _getInstanceByObjId(int $a_obj_id)