ILIAS  trunk Revision v11.0_alpha-1713-gd8962da2f67
All Data Structures Namespaces Files Functions Variables Enumerations Enumerator Modules Pages
class.ilObjChatroom.php
Go to the documentation of this file.
1 <?php
2 
19 declare(strict_types=1);
20 
21 class ilObjChatroom extends ilObject
22 {
23  public function __construct(int $a_id = 0, bool $a_call_by_reference = true)
24  {
25  $this->type = 'chtr';
26  parent::__construct($a_id, $a_call_by_reference);
27  }
28 
29  public static function _getPublicRefId(): int
30  {
31  $settings = new ilSetting('chatroom');
32 
33  return (int) $settings->get('public_room_ref', '0');
34  }
35 
36  public static function _getPublicObjId(): int
37  {
38  global $DIC;
39 
40  $rset = $DIC->database()->query(
41  'SELECT object_id FROM chatroom_settings WHERE room_type = ' . $DIC->database()->quote('default', 'text')
42  );
43  if ($row = $DIC->database()->fetchAssoc($rset)) {
44  return (int) $row['object_id'];
45  }
46 
47  return 0;
48  }
49 
51  {
52  $userInfo = new stdClass();
53  $userInfo->username = $user->getUsername();
54  $userInfo->id = $user->getUserId();
55 
56  return $userInfo;
57  }
58 
59  public function initDefaultRoles(): void
60  {
61  $this->createDefaultRole();
62  }
63 
64  protected function createDefaultRole(): ilObjRole
65  {
67  'il_chat_moderator_' . $this->getRefId(),
68  'Moderator of chat obj_no.' . $this->getId(),
69  'il_chat_moderator',
70  $this->getRefId()
71  );
72  }
73 
74  public function cloneObject(int $target_id, int $copy_id = 0, bool $omit_tree = false): ?ilObject
75  {
76  $original_room = ilChatroom::byObjectId($this->getId());
77 
78  $newObj = parent::cloneObject($target_id, $copy_id, $omit_tree);
79 
80  $objId = $newObj->getId();
81 
82  $original_settings = $original_room->getSettings();
83  $room = new ilChatroom();
84 
85  $original_settings['object_id'] = $objId;
86 
87  $room->saveSettings($original_settings);
88 
89  $rbac_log_roles = $this->rbac_review->getParentRoleIds($newObj->getRefId(), false);
90  $rbac_log = ilRbacLog::gatherFaPa($newObj->getRefId(), array_keys($rbac_log_roles), true);
91  ilRbacLog::add(ilRbacLog::CREATE_OBJECT, $newObj->getRefId(), $rbac_log);
92 
93  $settings = ilChatroomAdmin::getDefaultConfiguration()->getServerSettings();
94  $connector = new ilChatroomServerConnector($settings);
95 
96  $connector->sendCreatePrivateRoom($room->getRoomId(), $newObj->getOwner(), $newObj->getTitle());
97 
98  return $newObj;
99  }
100 
101  public function delete(): bool
102  {
103  $this->db->manipulateF(
104  'DELETE FROM chatroom_users WHERE chatroom_users.room_id IN (SELECT chatroom_settings.room_id FROM chatroom_settings WHERE chatroom_settings.object_id = %s)',
105  ['integer'],
106  [$this->getId()]
107  );
108 
109  $this->db->manipulateF(
110  'DELETE FROM chatroom_history WHERE chatroom_history.room_id IN (SELECT chatroom_settings.room_id FROM chatroom_settings WHERE chatroom_settings.object_id = %s)',
111  ['integer'],
112  [$this->getId()]
113  );
114 
115  $this->db->manipulateF(
116  'DELETE FROM chatroom_bans WHERE chatroom_bans.room_id IN (SELECT chatroom_settings.room_id FROM chatroom_settings WHERE chatroom_settings.object_id = %s)',
117  ['integer'],
118  [$this->getId()]
119  );
120 
121  $this->db->manipulateF(
122  'DELETE FROM chatroom_sessions WHERE chatroom_sessions.room_id IN (SELECT chatroom_settings.room_id FROM chatroom_settings WHERE chatroom_settings.object_id = %s)',
123  ['integer'],
124  [$this->getId()]
125  );
126 
127  // Finally delete rooms
128  $this->db->manipulateF(
129  'DELETE FROM chatroom_settings WHERE object_id = %s',
130  ['integer'],
131  [$this->getId()]
132  );
133 
134  return parent::delete();
135  }
136 }
Class ilObjRole.
getUserId()
Returns Ilias User ID.
static getDefaultConfiguration()
Instantiates and returns ilChatroomAdmin object using instance_id and settings from settingsTable...
$objId
Definition: xapitoken.php:57
__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)
static gatherFaPa(int $ref_id, array $role_ids, bool $add_action=false)
const CREATE_OBJECT
Class ilChatroomServerConnector.
global $DIC
Definition: shib_login.php:22
cloneObject(int $target_id, int $copy_id=0, bool $omit_tree=false)
static add(int $action, int $ref_id, array $diff, bool $source_ref_id=false)
__construct(Container $dic, ilPlugin $plugin)
Class ilChatroomUser.
static byObjectId(int $object_id)
getUsername()
Returns username from Object or SESSION.
getPersonalInformation(ilChatroomUser $user)
ilObjUser $user