ILIAS  release_8 Revision v8.19-1-g4e8f2f9140c
All Data Structures Namespaces Files Functions Variables Modules Pages
class.ilObjChatroom.php
Go to the documentation of this file.
1 <?php
2 
19 declare(strict_types=1);
20 
21 require_once 'Services/Object/classes/class.ilObject.php';
22 require_once 'Services/Object/classes/class.ilObjectActivation.php';
23 
30 class ilObjChatroom extends ilObject
31 {
32  protected ?int $access_type = null;
33  protected ?int $access_begin = null;
34  protected ?int $access_end = null;
35  protected ?int $access_visibility = null;
36 
37  public function __construct(int $a_id = 0, bool $a_call_by_reference = true)
38  {
40 
41  $this->type = 'chtr';
42  parent::__construct($a_id, $a_call_by_reference);
43  }
44 
45  public function setAccessVisibility(int $a_value): void
46  {
47  $this->access_visibility = $a_value;
48  }
49 
50  public function getAccessVisibility(): ?int
51  {
53  }
54 
55  public function getAccessType(): ?int
56  {
57  return $this->access_type;
58  }
59 
60  public function setAccessType(int $access_type): void
61  {
62  $this->access_type = $access_type;
63  }
64 
65  public function getAccessBegin(): ?int
66  {
67  return $this->access_begin;
68  }
69 
70  public function setAccessBegin(?int $access_begin): void
71  {
72  $this->access_begin = $access_begin;
73  }
74 
75  public function getAccessEnd(): ?int
76  {
77  return $this->access_end;
78  }
79 
80  public function setAccessEnd(?int $access_end): void
81  {
82  $this->access_end = $access_end;
83  }
84 
85  public function update(): bool
86  {
87  if ($this->referenced && $this->ref_id) {
88  $activation = new ilObjectActivation();
89  $activation->setTimingType($this->getAccessType());
90  $activation->setTimingStart($this->getAccessBegin());
91  $activation->setTimingEnd($this->getAccessEnd());
92  $activation->toggleVisible((bool) $this->getAccessVisibility());
93  $activation->toggleChangeable(true);
94  $activation->update($this->ref_id);
95  }
96 
97  return parent::update();
98  }
99 
100  public function read(): void
101  {
102  if ($this->referenced && $this->ref_id) {
103  $activation = ilObjectActivation::getItem($this->ref_id);
104  $this->setAccessType((int) $activation['timing_type']);
106  $this->setAccessBegin((int) $activation['timing_start']);
107  $this->setAccessEnd((int) $activation['timing_end']);
108  $this->setAccessVisibility((int) $activation['visible']);
109  }
110  }
111 
112  parent::read();
113  }
114 
115  public static function _getPublicRefId(): int
116  {
117  $settings = new ilSetting('chatroom');
118 
119  return (int) $settings->get('public_room_ref', '0');
120  }
121 
122  public static function _getPublicObjId(): int
123  {
124  global $DIC;
125 
126  $rset = $DIC->database()->query(
127  'SELECT object_id FROM chatroom_settings WHERE room_type = ' . $DIC->database()->quote('default', 'text')
128  );
129  if ($row = $DIC->database()->fetchAssoc($rset)) {
130  return (int) $row['object_id'];
131  }
132 
133  return 0;
134  }
135 
137  {
138  $userInfo = new stdClass();
139  $userInfo->username = $user->getUsername();
140  $userInfo->id = $user->getUserId();
141 
142  return $userInfo;
143  }
144 
145  public function initDefaultRoles(): void
146  {
147  $this->createDefaultRole();
148  }
149 
150  protected function createDefaultRole(): ilObjRole
151  {
153  'il_chat_moderator_' . $this->getRefId(),
154  'Moderator of chat obj_no.' . $this->getId(),
155  'il_chat_moderator',
156  $this->getRefId()
157  );
158  }
159 
160  public function cloneObject(int $target_id, int $copy_id = 0, bool $omit_tree = false): ?ilObject
161  {
162  $original_room = ilChatroom::byObjectId($this->getId());
163 
164  $newObj = parent::cloneObject($target_id, $copy_id, $omit_tree);
165 
166  $objId = $newObj->getId();
167 
168  $original_settings = $original_room->getSettings();
169  $room = new ilChatroom();
170 
171  $original_settings['object_id'] = $objId;
172 
173  $room->saveSettings($original_settings);
174 
175  $rbac_log_roles = $this->rbac_review->getParentRoleIds($newObj->getRefId(), false);
176  $rbac_log = ilRbacLog::gatherFaPa($newObj->getRefId(), array_keys($rbac_log_roles), true);
177  ilRbacLog::add(ilRbacLog::CREATE_OBJECT, $newObj->getRefId(), $rbac_log);
178 
179  $settings = ilChatroomAdmin::getDefaultConfiguration()->getServerSettings();
180  $connector = new ilChatroomServerConnector($settings);
181 
182  $connector->sendCreatePrivateRoom($room->getRoomId(), 0, $newObj->getOwner(), $newObj->getTitle());
183 
184  return $newObj;
185  }
186 
187  public function delete(): bool
188  {
189  $this->db->manipulateF(
190  'DELETE FROM chatroom_users WHERE chatroom_users.room_id IN (SELECT chatroom_settings.room_id FROM chatroom_settings WHERE chatroom_settings.object_id = %s)',
191  ['integer'],
192  [$this->getId()]
193  );
194 
195  $this->db->manipulateF(
196  'DELETE FROM chatroom_history WHERE chatroom_history.room_id IN (SELECT chatroom_settings.room_id FROM chatroom_settings WHERE chatroom_settings.object_id = %s)',
197  ['integer'],
198  [$this->getId()]
199  );
200 
201  $this->db->manipulateF(
202  'DELETE FROM chatroom_bans WHERE chatroom_bans.room_id IN (SELECT chatroom_settings.room_id FROM chatroom_settings WHERE chatroom_settings.object_id = %s)',
203  ['integer'],
204  [$this->getId()]
205  );
206 
207  $this->db->manipulateF(
208  'DELETE FROM chatroom_sessions WHERE chatroom_sessions.room_id IN (SELECT chatroom_settings.room_id FROM chatroom_settings WHERE chatroom_settings.object_id = %s)',
209  ['integer'],
210  [$this->getId()]
211  );
212 
213  $this->db->manipulateF(
214  '
215  DELETE FROM chatroom_proomaccess
216  WHERE chatroom_proomaccess.proom_id IN (
217  SELECT chatroom_prooms.proom_id
218  FROM chatroom_prooms WHERE chatroom_prooms.parent_id IN (
219  SELECT chatroom_settings.room_id
220  FROM chatroom_settings
221  WHERE chatroom_settings.object_id = %s
222  )
223  )',
224  ['integer'],
225  [$this->getId()]
226  );
227 
228  $this->db->manipulateF(
229  '
230  DELETE FROM chatroom_psessions
231  WHERE chatroom_psessions.proom_id IN (
232  SELECT chatroom_prooms.proom_id
233  FROM chatroom_prooms WHERE chatroom_prooms.parent_id IN (
234  SELECT chatroom_settings.room_id
235  FROM chatroom_settings
236  WHERE chatroom_settings.object_id = %s
237  )
238  )',
239  ['integer'],
240  [$this->getId()]
241  );
242 
243  $this->db->manipulateF(
244  'DELETE FROM chatroom_prooms WHERE chatroom_prooms.parent_id IN (SELECT chatroom_settings.room_id FROM chatroom_settings WHERE chatroom_settings.object_id = %s)',
245  ['integer'],
246  [$this->getId()]
247  );
248 
249  // Finally delete rooms
250  $this->db->manipulateF(
251  'DELETE FROM chatroom_settings WHERE object_id = %s',
252  ['integer'],
253  [$this->getId()]
254  );
255 
256  if ($this->ref_id && $this->getId()) {
258  }
259 
260  return parent::delete();
261  }
262 }
Class ilObjRole.
static deleteAllEntries(int $ref_id)
Delete all db entries for ref id.
static gatherFaPa(int $a_ref_id, array $a_role_ids, bool $a_add_action=false)
setAccessBegin(?int $access_begin)
array $settings
Setting values (LTI parameters, custom parameters and local parameters).
Definition: System.php:200
getUserId()
Returns Ilias User ID.
static getDefaultConfiguration()
Instantiates and returns ilChatroomAdmin object using instance_id and settings from settingsTable...
$objId
Definition: xapitoken.php:57
$target_id
Definition: goto.php:52
__construct(int $a_id=0, bool $a_call_by_reference=true)
static createDefaultRole(string $a_title, string $a_description, string $a_tpl_name, int $a_ref_id)
setAccessVisibility(int $a_value)
setAccessType(int $access_type)
global $DIC
Definition: feed.php:28
setAccessEnd(?int $access_end)
const CREATE_OBJECT
static add(int $a_action, int $a_ref_id, array $a_diff, bool $a_source_ref_id=false)
Class ilChatroomServerConnector.
cloneObject(int $target_id, int $copy_id=0, bool $omit_tree=false)
Class ilChatroom.
static getItem(int $ref_id)
__construct(Container $dic, ilPlugin $plugin)
Class ilChatroomUser.
static byObjectId(int $object_id)
getUsername()
Returns username from Object or SESSION.
getPersonalInformation(ilChatroomUser $user)
Class ilObjectActivation.
ilObjUser $user