예제 #1
0
 /**
  * Prepares and returns $userInfo using given $user object.
  *
  * @param ilChatroomUser $user
  * @return stdClass
  */
 public function getPersonalInformation(ilChatroomUser $user)
 {
     $userInfo = new stdClass();
     $userInfo->username = $user->getUsername();
     $userInfo->id = $user->getUserId();
     return $userInfo;
 }
 /**
  * Prepares and posts message fetched from $_REQUEST['message']
  * to recipients fetched from $_REQUEST['recipient']
  * and adds an entry to history if successful.
  *
  * @global ilObjUser $ilUser
  * @param string $method
  */
 public function executeDefault($method)
 {
     global $ilUser, $ilCtrl;
     require_once 'Modules/Chatroom/classes/class.ilChatroom.php';
     require_once 'Modules/Chatroom/classes/class.ilChatroomUser.php';
     if (!ilChatroom::checkUserPermissions('read', $this->gui->ref_id)) {
         $ilCtrl->setParameterByClass("ilrepositorygui", "ref_id", ROOT_FOLDER_ID);
         $ilCtrl->redirectByClass("ilrepositorygui", "");
     }
     $room = ilChatroom::byObjectId($this->gui->object->getId());
     $chat_user = new ilChatroomUser($ilUser, $room);
     $user_id = $chat_user->getUserId();
     if (!$room) {
         throw new Exception('unkown room');
     } else {
         if (!$room->isSubscribed($chat_user->getUserId())) {
             throw new Exception('not subscribed');
         } else {
             if (isset($_REQUEST['sub']) && !$room->userIsInPrivateRoom($_REQUEST['sub'], $chat_user->getUserId())) {
                 $response = json_encode(array('success' => false, 'reason' => 'not subscribed to private room'));
                 echo json_encode($response);
                 exit;
             }
         }
     }
     $scope = $room->getRoomId();
     $params = array();
     if ($recipient = $_REQUEST['recipient']) {
         $params['recipients'] = join(',', array_unique(array($user_id, $recipient)));
         $params['recipient_names'] = implode(',', array($chat_user->getUsername(), $_REQUEST['recipient_name']));
         $params['public'] = isset($_REQUEST['public']) ? (int) $_REQUEST['public'] : 0;
     } else {
         $params['public'] = 1;
     }
     if ($_REQUEST['sub']) {
         $params['sub'] = (int) $_REQUEST['sub'];
     }
     $messageObject = $this->buildMessage(ilUtil::stripSlashes($_REQUEST['message']), $params, $chat_user);
     $message = json_encode($messageObject);
     $params = array_merge($params, array('message' => $message));
     //print_r($params);exit;
     $query = http_build_query($params);
     $connector = $this->gui->getConnector();
     $response = $connector->post($scope, $query);
     $responseObject = json_decode($response);
     if ($responseObject->success == true) {
         $room->addHistoryEntry($messageObject, $recipient, $publicMessage);
     }
     echo $response;
     exit;
 }
예제 #3
0
 /**
  * Connects user by inserting userdata into userTable.
  *
  * Checks if user is already connected by using the given $user object
  * for selecting the userId from userTable. If no entry is found, matching
  * userId and roomId, the userdata is inserted into the userTable to
  * connect the user.
  *
  * @global ilDBMySQL $ilDB
  * @param ilChatroomUser $user
  * @return boolean
  */
 public function connectUser(ilChatroomUser $user)
 {
     /**
      * @var $ilDB ilDB
      */
     global $ilDB;
     $userdata = array('login' => $user->getUsername(), 'id' => $user->getUserId());
     $query = 'SELECT user_id FROM ' . self::$userTable . ' WHERE room_id = %s AND user_id = %s';
     $types = array('integer', 'integer');
     $values = array($this->roomId, $user->getUserId());
     if (!$ilDB->fetchAssoc($ilDB->queryF($query, $types, $values))) {
         // Notice: Using replace instead of insert looks strange, because we actually know whether the selected data exists or not
         // But we occasionally found some duplicate key errors although the data set should not exist when the following code is reached
         $ilDB->replace(self::$userTable, array('room_id' => array('integer', $this->roomId), 'user_id' => array('integer', $user->getUserId())), array('userdata' => array('text', json_encode($userdata)), 'connected' => array('integer', time())));
         return true;
     }
     return false;
 }
예제 #4
0
 /**
  *
  */
 public function invitePD()
 {
     /**
      * @var $ilUser ilObjUser
      * @var $ilCtrl ilCtrl
      */
     global $ilUser, $ilCtrl;
     $chatSettings = new ilSetting('chatroom');
     if (!$chatSettings->get('chat_enabled')) {
         $ilCtrl->redirect($this->gui, 'settings-general');
     }
     $room = ilChatroom::byObjectId($this->gui->object->getId());
     $chat_user = new ilChatroomUser($ilUser, $room);
     $user_id = $_REQUEST['usr_id'];
     $connector = $this->gui->getConnector();
     $title = $room->getUniquePrivateRoomTitle($chat_user->getUsername());
     $response = $connector->createPrivateRoom($room, $title, $chat_user);
     $connector->inviteToPrivateRoom($room, $response->id, $ilUser, $user_id);
     $room->sendInvitationNotification($this->gui, $chat_user, $user_id, $response->id);
     $_REQUEST['sub'] = $response->id;
     $_SESSION['show_invitation_message'] = $user_id;
     $ilCtrl->setParameter($this->gui, 'sub', $response->id);
     $ilCtrl->redirect($this->gui, 'view');
 }
 /**
  * Connects user by inserting userdata into userTable.
  *
  * Checks if user is already connected by using the given $user object
  * for selecting the userId from userTable. If no entry is found, matching
  * userId and roomId, the userdata is inserted into the userTable to
  * connect the user.
  *
  * @global ilDBMySQL $ilDB
  * @param ilChatroomUser $user
  * @return boolean
  */
 public function connectUser(ilChatroomUser $user)
 {
     /**
      * @var $ilDB ilDB
      */
     global $ilDB;
     $userdata = array('login' => $user->getUsername(), 'id' => $user->getUserId());
     $query = 'SELECT user_id FROM ' . self::$userTable . ' WHERE room_id = %s AND user_id = %s';
     $types = array('integer', 'integer');
     $values = array($this->roomId, $user->getUserId());
     if (!$ilDB->fetchAssoc($ilDB->queryF($query, $types, $values))) {
         $ilDB->insert(self::$userTable, array('room_id' => array('integer', $this->roomId), 'user_id' => array('integer', $user->getUserId()), 'userdata' => array('text', json_encode($userdata)), 'connected' => array('integer', time())));
         return true;
     }
     return false;
 }