ILIAS  release_5-2 Revision v5.2.25-18-g3f80b828510
ilChatroomPostMessageGUI Class Reference

Class ilChatroomPostMessageGUI. More...

+ Inheritance diagram for ilChatroomPostMessageGUI:
+ Collaboration diagram for ilChatroomPostMessageGUI:

Public Member Functions

 executeDefault ($method)
 Prepares and posts message fetched from $_REQUEST['message'] to recipients fetched from $_REQUEST['recipient'] and adds an entry to history if successful. More...
 
- Public Member Functions inherited from ilChatroomGUIHandler
 __construct (ilChatroomObjectGUI $gui)
 
 sendResponse ($response)
 Sends a json encoded response and exits the php process. More...
 
 hasPermission ($permission)
 Checks for access with ilRbacSystem. More...
 
 execute ($method)
 Executes given $method if existing, otherwise executes executeDefault() method. More...
 
 executeDefault ($requestedMethod)
 
 redirectIfNoPermission ($permission)
 Checks for requested permissions and redirects if the permission check failed. More...
 
 isSuccessful ($response)
 Checks for success param in an json decoded response. More...
 

Private Member Functions

 buildMessage ($messageString, $params, ilChatroomUser $chat_user)
 Instantiates stdClass, sets $data->user, $data->message, $data->public and $data->recipients using given $chat_user, $messageString and $params and returns $data. More...
 

Additional Inherited Members

- Protected Member Functions inherited from ilChatroomGUIHandler
 getRoomByObjectId ($objectId)
 
 exitIfNoRoomExists ($room)
 Checks if a ilChatroom exists. More...
 
 exitIfNoRoomPermission ($room, $subRoom, $chat_user)
 Check if user can moderate a chatroom. More...
 
 canModerate ($room, $subRoom, $user_id)
 Checks if the user has permission to moderate a ilChatroom. More...
 
 isMainRoom ($subRoomId)
 
- Protected Attributes inherited from ilChatroomGUIHandler
 $gui
 
 $ilUser
 
 $ilCtrl
 
 $ilLng
 
 $rbacsystem
 

Detailed Description

Class ilChatroomPostMessageGUI.

Author
Jan Posselt jposs.nosp@m.elt@.nosp@m.datab.nosp@m.ay.d.nosp@m.e
Version
$Id$

DELETE THIS

Definition at line 11 of file class.ilChatroomPostMessageGUI.php.

Member Function Documentation

◆ buildMessage()

ilChatroomPostMessageGUI::buildMessage (   $messageString,
  $params,
ilChatroomUser  $chat_user 
)
private

Instantiates stdClass, sets $data->user, $data->message, $data->public and $data->recipients using given $chat_user, $messageString and $params and returns $data.

Parameters
string$messageString
array$params
ilChatroomUser$chat_user
Returns
stdClass

Definition at line 108 of file class.ilChatroomPostMessageGUI.php.

References $data, $params, and time.

Referenced by executeDefault().

109  {
110  $data = new stdClass();
111 
112  $data->user = $this->gui->object->getPersonalInformation($chat_user);
113  $data->message = $messageString;
114  $data->timestamp = time() * 1000;//date( 'c' );
115  $data->type = 'message';
116  isset($params['sub']) ? ($data->sub = $params['sub']) : false;
117  $data->public = (int)$params['public'];
118  $data->recipients = $params['recipients']; // ? explode(",", $params['recipients']) : array();
119  $data->recipient_names = $params['recipient_names'];
120 
121  return $data;
122  }
Add data(end) time
Method that wraps PHPs time in order to allow simulations with the workflow.
$params
Definition: example_049.php:96
+ Here is the caller graph for this function:

◆ executeDefault()

ilChatroomPostMessageGUI::executeDefault (   $method)

Prepares and posts message fetched from $_REQUEST['message'] to recipients fetched from $_REQUEST['recipient'] and adds an entry to history if successful.

ilObjUser $ilUser

Parameters
string$method

Definition at line 20 of file class.ilChatroomPostMessageGUI.php.

References ilChatroomGUIHandler\$ilCtrl, ilChatroomGUIHandler\$ilUser, $params, $query, array, buildMessage(), ilChatroom\byObjectId(), ilChatroom\checkUserPermissions(), exit, and ilUtil\stripSlashes().

21  {
22  throw new Exception('METHOD_NOT_IN_USE', 1456435027);
23  global $ilUser, $ilCtrl;
24 
25  require_once 'Modules/Chatroom/classes/class.ilChatroom.php';
26  require_once 'Modules/Chatroom/classes/class.ilChatroomUser.php';
27 
28  if(!ilChatroom::checkUserPermissions('read', $this->gui->ref_id))
29  {
30  $ilCtrl->setParameterByClass("ilrepositorygui", "ref_id", ROOT_FOLDER_ID);
31  $ilCtrl->redirectByClass("ilrepositorygui", "");
32  }
33 
34  $room = ilChatroom::byObjectId($this->gui->object->getId());
35 
36  $chat_user = new ilChatroomUser($ilUser, $room);
37  $user_id = $chat_user->getUserId();
38 
39  if(!$room)
40  {
41  throw new Exception('unkown room');
42  }
43  else if(!$room->isSubscribed($chat_user->getUserId()))
44  {
45  throw new Exception('not subscribed');
46  }
47  else if(isset($_REQUEST['sub']) && !$room->userIsInPrivateRoom($_REQUEST['sub'], $chat_user->getUserId()))
48  {
49  $response = json_encode(array(
50  'success' => false,
51  'reason' => 'not subscribed to private room'
52  ));
53  echo json_encode($response);
54  exit;
55  }
56 
57  $scope = $room->getRoomId();
58  $params = array();
59 
60  if(($recipient = $_REQUEST['recipient']))
61  {
62  $params['recipients'] = join(',', array_unique(array($user_id, $recipient)));
63  $params['recipient_names'] = implode(',', array($chat_user->getUsername(), $_REQUEST['recipient_name']));
64  $params['public'] = isset($_REQUEST['public']) ? (int)$_REQUEST['public'] : 0;
65  }
66  else
67  {
68  $params['public'] = 1;
69  }
70 
71  if($_REQUEST['sub'])
72  $params['sub'] = (int)$_REQUEST['sub'];
73 
74  $messageObject = $this->buildMessage(
75  ilUtil::stripSlashes($_REQUEST['message']),
76  $params,
77  $chat_user
78  );
79 
80  $message = json_encode($messageObject);
81 
82  $params = array_merge($params, array('message' => $message));
83  //print_r($params);exit;
84  $query = http_build_query($params);
85  $connector = $this->gui->getConnector();
86  $response = $connector->post($scope, $query);
87 
88  $responseObject = json_decode($response);
89 
90  if($responseObject->success == true /*&& $room->getSetting( 'enable_history' )*/)
91  {
92  $room->addHistoryEntry($messageObject, $recipient, $publicMessage);
93  }
94 
95  echo $response;
96  exit;
97  }
static checkUserPermissions($permissions, $ref_id, $send_info=true)
Checks user permissions by given array and ref_id.
buildMessage($messageString, $params, ilChatroomUser $chat_user)
Instantiates stdClass, sets $data->user, $data->message, $data->public and $data->recipients using gi...
static stripSlashes($a_str, $a_strip_html=true, $a_allow="")
strip slashes if magic qoutes is enabled
Create styles array
The data for the language used.
Class ilChatroomUser.
static byObjectId($object_id)
Returns ilChatroom object by given $object_id.
$params
Definition: example_049.php:96
+ Here is the call graph for this function:

The documentation for this class was generated from the following file: