ILIAS  release_5-3 Revision v5.3.23-19-g915713cf615
class.ilChatroomPostMessageGUI.php
Go to the documentation of this file.
1<?php
2/* Copyright (c) 1998-2009 ILIAS open source, Extended GPL, see docs/LICENSE */
3
12{
20 public function executeDefault($method)
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 $this->redirectIfNoPermission('read');
29
30 $room = ilChatroom::byObjectId($this->gui->object->getId());
31
32 $chat_user = new ilChatroomUser($ilUser, $room);
33 $user_id = $chat_user->getUserId();
34
35 if (!$room) {
36 throw new Exception('unkown room');
37 } elseif (!$room->isSubscribed($chat_user->getUserId())) {
38 throw new Exception('not subscribed');
39 } elseif (isset($_REQUEST['sub']) && !$room->userIsInPrivateRoom($_REQUEST['sub'], $chat_user->getUserId())) {
40 $response = json_encode(array(
41 'success' => false,
42 'reason' => 'not subscribed to private room'
43 ));
44 echo json_encode($response);
45 exit;
46 }
47
48 $scope = $room->getRoomId();
49 $params = array();
50
51 if (($recipient = $_REQUEST['recipient'])) {
52 $params['recipients'] = join(',', array_unique(array($user_id, $recipient)));
53 $params['recipient_names'] = implode(',', array($chat_user->getUsername(), $_REQUEST['recipient_name']));
54 $params['public'] = isset($_REQUEST['public']) ? (int) $_REQUEST['public'] : 0;
55 } else {
56 $params['public'] = 1;
57 }
58
59 if ($_REQUEST['sub']) {
60 $params['sub'] = (int) $_REQUEST['sub'];
61 }
62
63 $messageObject = $this->buildMessage(
64 ilUtil::stripSlashes($_REQUEST['message']),
65 $params,
66 $chat_user
67 );
68
69 $message = json_encode($messageObject);
70
71 $params = array_merge($params, array('message' => $message));
72 //print_r($params);exit;
73 $query = http_build_query($params);
74 $connector = $this->gui->getConnector();
75 $response = $connector->post($scope, $query);
76
77 $responseObject = json_decode($response);
78
79 if ($responseObject->success == true /*&& $room->getSetting( 'enable_history' )*/) {
80 $room->addHistoryEntry($messageObject, $recipient, $publicMessage);
81 }
82
83 echo $response;
84 exit;
85 }
86
96 private function buildMessage($messageString, $params, ilChatroomUser $chat_user)
97 {
98 $data = new stdClass();
99
100 $data->user = $this->gui->object->getPersonalInformation($chat_user);
101 $data->message = $messageString;
102 $data->timestamp = time() * 1000;//date( 'c' );
103 $data->type = 'message';
104 isset($params['sub']) ? ($data->sub = $params['sub']) : false;
105 $data->public = (int) $params['public'];
106 $data->recipients = $params['recipients']; // ? explode(",", $params['recipients']) : array();
107 $data->recipient_names = $params['recipient_names'];
108
109 return $data;
110 }
111}
An exception for terminatinating execution or to throw for unit testing.
Class ilChatroomGUIHandler.
redirectIfNoPermission($permission)
Checks for requested permissions and redirects if the permission check failed.
Class ilChatroomPostMessageGUI.
executeDefault($method)
Prepares and posts message fetched from $_REQUEST['message'] to recipients fetched from $_REQUEST['re...
buildMessage($messageString, $params, ilChatroomUser $chat_user)
Instantiates stdClass, sets $data->user, $data->message, $data->public and $data->recipients using gi...
Class ilChatroomUser.
static byObjectId($object_id)
Returns ilChatroom object by given $object_id.
static stripSlashes($a_str, $a_strip_html=true, $a_allow="")
strip slashes if magic qoutes is enabled
catch(Exception $e) $message
$query
$response
$params
Definition: disable.php:11