ILIAS  release_5-1 Revision 5.0.0-5477-g43f3e3fab5f
class.ilObjChatroom.php
Go to the documentation of this file.
1 <?php
2 
3 /* Copyright (c) 1998-2009 ILIAS open source, Extended GPL, see docs/LICENSE */
4 
5 require_once "./Services/Object/classes/class.ilObject.php";
6 
15 class ilObjChatroom extends ilObject
16 {
17 
24  public function __construct($a_id = 0, $a_call_by_reference = true)
25  {
26  $this->type = 'chtr';
27  $this->ilObject($a_id, $a_call_by_reference);
28  }
29 
36  public function getPersonalInformation(ilChatroomUser $user)
37  {
38  $userInfo = new stdClass();
39  $userInfo->username = $user->getUsername();
40  $userInfo->id = $user->getUserId();
41 
42  return $userInfo;
43  }
44 
45 
46  public static function _getPublicRefId() {
47  $settings = new ilSetting('chatroom');
48  return $settings->get('public_room_ref', 0);
49  }
50 
51  public static function _getPublicObjId() {
52  global $ilDB;
53 
54  $rset = $ilDB->query('SELECT object_id FROM chatroom_settings WHERE room_type=' . $ilDB->quote( 'default' ,'text'));
55  if ($row = $ilDB->fetchAssoc($rset)) {
56  return $row['object_id'];
57  }
58  return 0;
59  }
67  function initDefaultRoles()
68  {
69  include_once './Services/AccessControl/classes/class.ilObjRole.php';
71  'il_chat_moderator_'.$this->getRefId(),
72  "Moderator of chat obj_no.".$this->getId(),
73  'il_chat_moderator',
74  $this->getRefId()
75  );
76  return array();
77  }
78 
79  public function cloneObject($a_target_id,$a_copy_id = 0,$a_omit_tree = false) {
80  global $rbacreview;
81  require_once 'Modules/Chatroom/classes/class.ilChatroom.php';
82  $original_room = ilChatroom::byObjectId($this->getId());
83 
84  $newObj = parent::cloneObject($a_target_id, $a_copy_id, $a_omit_tree);
85 
86 
87 
88  $objId = $newObj->getId();
89 
90 
91 
92  $original_settings = $original_room->getSettings();
93  $room = new ilChatroom();
94 
95  $original_settings['object_id'] = $objId;
96 
97  $room->saveSettings($original_settings);
98 
99  // rbac log
100  include_once "Services/AccessControl/classes/class.ilRbacLog.php";
101  $rbac_log_roles = $rbacreview->getParentRoleIds( $newObj->getRefId(), false );
102  $rbac_log = ilRbacLog::gatherFaPa( $newObj->getRefId(), array_keys( $rbac_log_roles ), true );
103  ilRbacLog::add( ilRbacLog::CREATE_OBJECT, $newObj->getRefId(), $rbac_log );
104 
105  return $newObj;
106  }
107 
111  public function delete()
112  {
116  global $ilDB;
117 
118  $ilDB->manipulateF(
119  'DELETE FROM chatroom_users WHERE chatroom_users.room_id IN (SELECT chatroom_settings.room_id FROM chatroom_settings WHERE chatroom_settings.object_id = %s)',
120  array('integer'),
121  array($this->getId())
122  );
123 
124  $ilDB->manipulateF(
125  'DELETE FROM chatroom_history WHERE chatroom_history.room_id IN (SELECT chatroom_settings.room_id FROM chatroom_settings WHERE chatroom_settings.object_id = %s)',
126  array('integer'),
127  array($this->getId())
128  );
129 
130  $ilDB->manipulateF(
131  'DELETE FROM chatroom_bans WHERE chatroom_bans.room_id IN (SELECT chatroom_settings.room_id FROM chatroom_settings WHERE chatroom_settings.object_id = %s)',
132  array('integer'),
133  array($this->getId())
134  );
135 
136  $ilDB->manipulateF(
137  'DELETE FROM chatroom_sessions WHERE chatroom_sessions.room_id IN (SELECT chatroom_settings.room_id FROM chatroom_settings WHERE chatroom_settings.object_id = %s)',
138  array('integer'),
139  array($this->getId())
140  );
141 
142  $ilDB->manipulateF('
143  DELETE FROM chatroom_proomaccess
144  WHERE chatroom_proomaccess.proom_id IN (
145  SELECT chatroom_prooms.proom_id
146  FROM chatroom_prooms WHERE chatroom_prooms.parent_id IN (
147  SELECT chatroom_settings.room_id
148  FROM chatroom_settings
149  WHERE chatroom_settings.object_id = %s
150  )
151  )',
152  array('integer'),
153  array($this->getId())
154  );
155 
156  $ilDB->manipulateF('
157  DELETE FROM chatroom_psessions
158  WHERE chatroom_psessions.proom_id IN (
159  SELECT chatroom_prooms.proom_id
160  FROM chatroom_prooms WHERE chatroom_prooms.parent_id IN (
161  SELECT chatroom_settings.room_id
162  FROM chatroom_settings
163  WHERE chatroom_settings.object_id = %s
164  )
165  )',
166  array('integer'),
167  array($this->getId())
168  );
169 
170  $ilDB->manipulateF(
171  'DELETE FROM chatroom_prooms WHERE chatroom_prooms.parent_id IN (SELECT chatroom_settings.room_id FROM chatroom_settings WHERE chatroom_settings.object_id = %s)',
172  array('integer'),
173  array($this->getId())
174  );
175 
176  // Finally delete rooms
177  $ilDB->manipulateF(
178  'DELETE FROM chatroom_settings WHERE object_id = %s',
179  array('integer'),
180  array($this->getId())
181  );
182 
183  return parent::delete();
184  }
185 }
ILIAS Setting Class.
getUserId()
Returns Ilias User ID.
cloneObject($a_target_id, $a_copy_id=0, $a_omit_tree=false)
Class ilObject Basic functions for all objects.
__construct($a_id=0, $a_call_by_reference=true)
Constructor.
static gatherFaPa($a_ref_id, array $a_role_ids, $a_add_action=false)
ilObject($a_id=0, $a_reference=true)
Constructor public.
static createDefaultRole($a_title, $a_description, $a_tpl_name, $a_ref_id)
Class ilObjChatroom.
const CREATE_OBJECT
getId()
get object id public
Class ilChatroom.
Class ilChatroomUser.
static add($a_action, $a_ref_id, array $a_diff, $a_source_ref_id=false)
global $ilDB
getRefId()
get reference id public
static byObjectId($object_id)
Returns ilChatroom object by given $object_id.
getUsername()
Returns username from Object or SESSION.
getPersonalInformation(ilChatroomUser $user)
Prepares and returns $userInfo using given $user object.
initDefaultRoles()
type $rbacadmin type $rbacreview ilDB $ilDB