1<?php
2/* Copyright (c) 1998-2013 ILIAS open source, Extended GPL, see docs/LICENSE */
3
4require_once 'Modules/Chatroom/classes/class.ilChatroom.php';
5require_once 'Modules/Chatroom/classes/class.ilChatroomUser.php';
6
7/**
8 * Class ilChatroomInviteUsersToPrivateRoomGUI
9 * @author  Jan Posselt <jposselt@databay.de>
10 * @version $Id$
11 * @ingroup ModulesChatroom
12 */
13class ilChatroomInviteUsersToPrivateRoomGUI extends ilChatroomGUIHandler
14{
15
16    /**
17     * @param string $method
18     * @return mixed
19     */
20    public function executeDefault($method)
21    {
22        $this->byLogin();
23    }
24
25    /**
26     *
27     */
28    public function byLogin()
29    {
30        $this->inviteById(ilObjUser::_lookupId($_REQUEST['user']));
31    }
32
33    /**
34     * @param int $invited_id
35     */
36    private function inviteById($invited_id)
37    {
38        $this->redirectIfNoPermission('read');
39
40        $room = ilChatroom::byObjectId($this->gui->object->getId());
41        $subRoomId = (int) $_REQUEST['sub'];
42        $chat_user = new ilChatroomUser($this->ilUser, $room);
43
44        $this->exitIfNoRoomExists($room);
45        $this->exitIfNoRoomPermission($room, $subRoomId, $chat_user);
46
47        if (!$this->isMainRoom($subRoomId)) {
48            $room->inviteUserToPrivateRoom($invited_id, $subRoomId);
49        }
50
51        $connector = $this->gui->getConnector();
52        $response = $connector->sendInviteToPrivateRoom($room->getRoomId(), $subRoomId, $chat_user->getUserId(), $invited_id);
53
54        $room->sendInvitationNotification($this->gui, $chat_user, $invited_id, $subRoomId);
55
56        $this->sendResponse($response);
57    }
58
59    /**
60     *
61     */
62    public function byId()
63    {
64        $this->inviteById($_REQUEST['user']);
65    }
66
67    /**
68     *
69     */
70    public function getUserList()
71    {
72        require_once 'Services/User/classes/class.ilUserAutoComplete.php';
73        $auto = new ilUserAutoComplete();
74        $auto->setUser($this->ilUser);
75        $auto->setPrivacyMode(ilUserAutoComplete::PRIVACY_MODE_RESPECT_USER_SETTING);
76        if ($this->ilUser->isAnonymous()) {
77            $auto->setSearchType(ilUserAutoComplete::SEARCH_TYPE_EQUALS);
78        }
79
80        if (($_REQUEST['fetchall'])) {
81            $auto->setLimit(ilUserAutoComplete::MAX_ENTRIES);
82        }
83        $auto->setMoreLinkAvailable(true);
84        $auto->setSearchFields(array('firstname', 'lastname'));
85        $auto->setResultField('login');
86        $auto->enableFieldSearchableCheck(true);
87        echo $auto->getList($_REQUEST['q']);
88        exit;
89    }
90}
91