ILIAS  Release_4_4_x_branch Revision 61816
 All Data Structures Namespaces Files Functions Variables Groups Pages
class.ilChatroomInviteUsersToPrivateRoomTask.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 require_once 'Modules/Chatroom/classes/class.ilChatroomUser.php';
6 
14 {
18  private $gui;
19 
24  {
25  $this->gui = $gui;
26  }
27 
34  public function executeDefault($method)
35  {
36  $this->byLogin();
37  }
38 
42  public function byLogin()
43  {
44  $this->inviteById(ilObjUser::_lookupId($_REQUEST['users']));
45  }
46 
50  public function byId()
51  {
52  $this->inviteById($_REQUEST['users']);
53  }
54 
58  private function inviteById($invited_id)
59  {
64  global $ilUser, $ilCtrl;
65 
66  if(!ilChatroom::checkUserPermissions('read', $this->gui->ref_id))
67  {
68  $ilCtrl->setParameterByClass('ilrepositorygui', 'ref_id', ROOT_FOLDER_ID);
69  $ilCtrl->redirectByClass('ilrepositorygui', '');
70  }
71 
72  $room = ilChatroom::byObjectId($this->gui->object->getId());
73 
74  $chat_user = new ilChatroomUser($ilUser, $room);
75  $user_id = $chat_user->getUserId();
76 
77  if(!$room)
78  {
79  $response = json_encode(array(
80  'success' => false,
81  'reason' => 'unkown room'
82  ));
83  echo json_encode($response);
84  exit;
85  }
86  else if($_REQUEST['sub'] && !$room->isOwnerOfPrivateRoom($user_id, $_REQUEST['sub']))
87  {
88  $response = json_encode(array(
89  'success' => false,
90  'reason' => 'not owner of private room'
91  ));
92  echo json_encode($response);
93  exit;
94  }
95 
96  $connector = $this->gui->getConnector();
97 
98  $result = $connector->inviteToPrivateRoom($room, $_REQUEST['sub'], $ilUser, $invited_id);
99 
100  $room->sendInvitationNotification($this->gui, $chat_user, $invited_id, (int)$_REQUEST['sub']);
101 
102  echo json_encode($result);
103  exit;
104  }
105 
106  public function getUserList()
107  {
111  global $ilUser;
112 
113  require_once 'Services/User/classes/class.ilUserAutoComplete.php';
114  $auto = new ilUserAutoComplete();
115  $auto->setUser($ilUser);
117  if($ilUser->isAnonymous())
118  {
119  $auto->setSearchType(ilUserAutoComplete::SEARCH_TYPE_EQUALS);
120  }
121  $auto->setSearchFields(array('firstname', 'lastname'));
122  $auto->setResultField('login');
123  $auto->enableFieldSearchableCheck(true);
124  echo $auto->getList($_REQUEST['q']);
125  exit;
126  }
127 }