ILIAS  release_5-2 Revision v5.2.25-18-g3f80b828510
class.ilChatroomGUIHandler.php
Go to the documentation of this file.
1 <?php
2 /* Copyright (c) 1998-2013 ILIAS open source, Extended GPL, see docs/LICENSE */
3 
4 require_once 'Modules/Chatroom/classes/class.ilChatroom.php';
5 
12 abstract class ilChatroomGUIHandler
13 {
17  protected $gui;
18 
22  protected $ilUser;
23 
27  protected $ilCtrl;
28 
32  protected $ilLng;
33 
37  protected $rbacsystem;
38 
43  {
44  global $ilUser, $ilCtrl, $lng, $rbacsystem;
45 
46  $this->gui = $gui;
47  $this->ilUser = $ilUser;
48  $this->ilCtrl = $ilCtrl;
49  $this->ilLng = $lng;
50  $this->rbacsystem = $rbacsystem;
51  }
52 
57  protected function getRoomByObjectId($objectId)
58  {
59  return ilChatroom::byObjectId($objectId);
60  }
61 
66  protected function exitIfNoRoomExists($room)
67  {
68  if(!$room)
69  {
70  $this->sendResponse(
71  array(
72  'success' => false,
73  'reason' => 'unkown room',
74  )
75  );
76  }
77  }
78 
83  public function sendResponse($response)
84  {
85  echo json_encode($response);
86  exit;
87  }
88 
95  protected function exitIfNoRoomPermission($room, $subRoom, $chat_user)
96  {
97  if(!$this->canModerate($room, $subRoom, $chat_user->getUserId()))
98  {
99  $this->sendResponse(
100  array(
101  'success' => false,
102  'reason' => 'not owner of private room',
103  )
104  );
105  }
106  }
107 
115  protected function canModerate($room, $subRoom, $user_id)
116  {
117  return $this->isMainRoom($subRoom) || $room->isOwnerOfPrivateRoom($user_id, $subRoom) || $this->hasPermission('moderate');
118  }
119 
124  protected function isMainRoom($subRoomId)
125  {
126  return $subRoomId == 0;
127  }
128 
134  public function hasPermission($permission)
135  {
136  return $this->rbacsystem->checkAccess($permission, $this->gui->ref_id);
137  }
138 
145  public function execute($method)
146  {
147  $this->ilLng->loadLanguageModule('chatroom');
148 
149  if(method_exists($this, $method))
150  {
151  return $this->$method();
152  }
153  else
154  {
155  return $this->executeDefault($method);
156  }
157  }
158 
163  abstract public function executeDefault($requestedMethod);
164 
169  public function redirectIfNoPermission($permission)
170  {
171  if(!ilChatroom::checkUserPermissions($permission, $this->gui->ref_id))
172  {
173  $this->ilCtrl->setParameterByClass("ilrepositorygui", "ref_id", ROOT_FOLDER_ID);
174  $this->ilCtrl->redirectByClass("ilrepositorygui", "");
175  }
176  }
177 
183  public function isSuccessful($response)
184  {
185  $response = json_decode($response, true);
186 
187  return $response !== null && array_key_exists('success', $response) && $response['success'];
188  }
189 }
This class provides processing control methods.
redirectIfNoPermission($permission)
Checks for requested permissions and redirects if the permission check failed.
sendResponse($response)
Sends a json encoded response and exits the php process.
executeDefault($requestedMethod)
exitIfNoRoomExists($room)
Checks if a ilChatroom exists.
hasPermission($permission)
Checks for access with ilRbacSystem.
execute($method)
Executes given $method if existing, otherwise executes executeDefault() method.
canModerate($room, $subRoom, $user_id)
Checks if the user has permission to moderate a ilChatroom.
static checkUserPermissions($permissions, $ref_id, $send_info=true)
Checks user permissions by given array and ref_id.
redirectByClass($a_class, $a_cmd="", $a_anchor="", $a_asynch=false)
Redirect to other gui class using class name.
Class ilChatroomGUIHandler.
isSuccessful($response)
Checks for success param in an json decoded response.
Create styles array
The data for the language used.
setParameterByClass($a_class, $a_parameter, $a_value)
Same as setParameterByClass, except that a class name is passed.
exitIfNoRoomPermission($room, $subRoom, $chat_user)
Check if user can moderate a chatroom.
__construct(ilChatroomObjectGUI $gui)
global $lng
Definition: privfeed.php:17
static byObjectId($object_id)
Returns ilChatroom object by given $object_id.