ILIAS  release_4-3 Revision
 All Data Structures Namespaces Files Functions Variables Groups Pages
class.ilChatroomUser.php
Go to the documentation of this file.
1 <?php
2 /* Copyright (c) 1998-2013 ILIAS open source, Extended GPL, see docs/LICENSE */
3 
13 {
18  private $user;
19 
23  private $username;
24 
28  private $room;
29 
39  public function __construct(ilObjUser $user, ilChatroom $chatroom)
40  {
41  require_once 'Services/User/classes/class.ilObjUser.php';
42 
43  $this->user = $user;
44  $this->room = $chatroom;
45  }
46 
54  public function getUserId()
55  {
56  $user_id = $this->user->getId();
57 
58  if($this->user->isAnonymous())
59  {
60  if(isset($_SESSION['chat'][$this->room->getRoomId()]['user_id']))
61  {
62  return $_SESSION['chat'][$this->room->getRoomId()]['user_id'];
63  }
64  else
65  {
66  $user_id = mt_rand(-99999, -20);
67  $_SESSION['chat'][$this->room->getRoomId()]['user_id'] = $user_id;
68  return $user_id;
69  }
70  }
71  else
72  {
73  return $user_id;
74  }
75  }
76 
82  public function setUsername($username)
83  {
84  $this->username = htmlspecialchars( $username );
85  $_SESSION['chat'][$this->room->getRoomId()]['username'] = $this->username;
86  }
87 
94  public function getUsername()
95  {
96  if($this->username)
97  {
98  return $this->username;
99  }
100  else if($_SESSION['chat'][$this->room->getRoomId()]['username'])
101  {
102  return $_SESSION['chat'][$this->room->getRoomId()]['username'];
103  }
104  else
105  {
106  return $this->user->getLogin();
107  }
108  }
109 
115  public function getChatNameSuggestions()
116  {
117  $options = array();
118 
119  if($this->user->isAnonymous())
120  {
121  $options['anonymousName'] = $this->buildAnonymousName();
122  }
123  else
124  {
125  $options['fullname'] = $this->buildFullname();
126  $options['shortname'] = $this->buildShortname();
127  $options['login'] = $this->buildLogin();
128  }
129 
130  return $options;
131  }
132 
138  public function buildAnonymousName()
139  {
140  $anonymous_name = str_replace(
141  '#', mt_rand( 0, 10000 ), $this->room->getSetting('autogen_usernames')
142  );
143 
144  return $anonymous_name;
145  }
146 
152  public function buildLogin()
153  {
154  return $this->user->getLogin();
155  }
156 
162  public function buildFullname()
163  {
164  return $this->user->getPublicName();
165  }
166 
172  public function buildShortname()
173  {
174  $firstname = $this->user->getFirstname();
175 
176  return $firstname{0} . '. ' . $this->user->getLastname();
177  }
178 }