TeamSpeak 3 PHP Framework  1.1.16
Copyright © Planet TeamSpeak. All rights reserved.
 All Classes Namespaces Files Functions Variables Pages
Servergroup.php
Go to the documentation of this file.
1 <?php
2 
3 /**
4  * @file
5  * TeamSpeak 3 PHP Framework
6  *
7  * $Id: Servergroup.php 8/31/2012 11:06:09 scp@orilla $
8  *
9  * This program is free software: you can redistribute it and/or modify
10  * it under the terms of the GNU General Public License as published by
11  * the Free Software Foundation, either version 3 of the License, or
12  * (at your option) any later version.
13  *
14  * This program is distributed in the hope that it will be useful,
15  * but WITHOUT ANY WARRANTY; without even the implied warranty of
16  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17  * GNU General Public License for more details.
18  *
19  * You should have received a copy of the GNU General Public License
20  * along with this program. If not, see <http://www.gnu.org/licenses/>.
21  *
22  * @package TeamSpeak3
23  * @version 1.1.16
24  * @author Sven 'ScP' Paulsen
25  * @copyright Copyright (c) 2010 by Planet TeamSpeak. All rights reserved.
26  */
27 
28 /**
29  * @class TeamSpeak3_Node_Servergroup
30  * @brief Class describing a TeamSpeak 3 server group and all it's parameters.
31  */
33 {
34  /**
35  * The TeamSpeak3_Node_Servergroup constructor.
36  *
37  * @param TeamSpeak3_Node_Server $server
38  * @param array $info
39  * @param string $index
40  * @throws TeamSpeak3_Node_Exception
41  * @return TeamSpeak3_Node_Servergroup
42  */
43  public function __construct(TeamSpeak3_Node_Server $server, array $info, $index = "sgid")
44  {
45  $this->parent = $server;
46  $this->nodeInfo = $info;
47 
48  if(!array_key_exists($index, $this->nodeInfo))
49  {
50  throw new TeamSpeak3_Node_Exception("invalid groupID", 0xA00);
51  }
52 
53  $this->nodeId = $this->nodeInfo[$index];
54  }
55 
56  /**
57  * Renames the server group specified.
58  *
59  * @param string $name
60  * @return void
61  */
62  public function rename($name)
63  {
64  return $this->getParent()->serverGroupRename($this->getId(), $name);
65  }
66 
67  /**
68  * Deletes the server group. If $force is set to 1, the server group will be
69  * deleted even if there are clients within.
70  *
71  * @param boolean $force
72  * @return void
73  */
74  public function delete($force = FALSE)
75  {
76  $this->getParent()->serverGroupDelete($this->getId(), $force);
77 
78  unset($this);
79  }
80 
81  /**
82  * Creates a copy of the server group and returns the new groups ID.
83  *
84  * @param string $name
85  * @param integer $tsgid
86  * @param integer $type
87  * @return integer
88  */
89  public function copy($name = null, $tsgid = 0, $type = TeamSpeak3::GROUP_DBTYPE_REGULAR)
90  {
91  return $this->getParent()->serverGroupCopy($this->getId(), $name, $tsgid, $type);
92  }
93 
94  /**
95  * Returns a list of permissions assigned to the server group.
96  *
97  * @param boolean $permsid
98  * @return array
99  */
100  public function permList($permsid = FALSE)
101  {
102  return $this->getParent()->serverGroupPermList($this->getId(), $permsid);
103  }
104 
105  /**
106  * Adds a set of specified permissions to the server group. Multiple permissions
107  * can be added by providing the four parameters of each permission in separate arrays.
108  *
109  * @param integer $permid
110  * @param integer $permvalue
111  * @param integer $permnegated
112  * @param integer $permskip
113  * @return void
114  */
115  public function permAssign($permid, $permvalue, $permnegated = FALSE, $permskip = FALSE)
116  {
117  return $this->getParent()->serverGroupPermAssign($this->getId(), $permid, $permvalue, $permnegated, $permskip);
118  }
119 
120  /**
121  * Alias for permAssign().
122  *
123  * @deprecated
124  */
125  public function permAssignByName($permname, $permvalue, $permnegated = FALSE, $permskip = FALSE)
126  {
127  return $this->permAssign($permname, $permvalue, $permnegated, $permskip);
128  }
129 
130  /**
131  * Removes a set of specified permissions from the server group. Multiple
132  * permissions can be removed at once.
133  *
134  * @param integer $permid
135  * @return void
136  */
137  public function permRemove($permid)
138  {
139  return $this->getParent()->serverGroupPermRemove($this->getId(), $permid);
140  }
141 
142  /**
143  * Alias for permRemove().
144  *
145  * @deprecated
146  */
147  public function permRemoveByName($permname)
148  {
149  return $this->permRemove($permname);
150  }
151 
152  /**
153  * Returns a list of clients assigned to the server group specified.
154  *
155  * @return array
156  */
157  public function clientList()
158  {
159  return $this->getParent()->serverGroupClientList($this->getId());
160  }
161 
162  /**
163  * Adds a client to the server group specified. Please note that a client cannot be
164  * added to default groups or template groups.
165  *
166  * @param integer $cldbid
167  * @return void
168  */
169  public function clientAdd($cldbid)
170  {
171  return $this->getParent()->serverGroupClientAdd($this->getId(), $cldbid);
172  }
173 
174  /**
175  * Removes a client from the server group.
176  *
177  * @param integer $cldbid
178  * @return void
179  */
180  public function clientDel($cldbid)
181  {
182  return $this->getParent()->serverGroupClientDel($this->getId(), $cldbid);
183  }
184 
185  /**
186  * Alias for privilegeKeyCreate().
187  *
188  * @deprecated
189  */
190  public function tokenCreate($description = null, $customset = null)
191  {
192  return $this->privilegeKeyCreate($description, $customset);
193  }
194 
195  /**
196  * Creates a new privilege key (token) for the server group and returns the key.
197  *
198  * @param string $description
199  * @param string $customset
200  * @return TeamSpeak3_Helper_String
201  */
202  public function privilegeKeyCreate($description = null, $customset = null)
203  {
204  return $this->getParent()->privilegeKeyCreate(TeamSpeak3::TOKEN_SERVERGROUP, $this->getId(), 0, $description, $customset);
205  }
206 
207  /**
208  * Sends a text message to all clients residing in the server group on the virtual server.
209  *
210  * @param string $msg
211  * @return void
212  */
213  public function message($msg)
214  {
215  foreach($this as $client)
216  {
217  try
218  {
219  $this->execute("sendtextmessage", array("msg" => $msg, "target" => $client, "targetmode" => TeamSpeak3::TEXTMSG_CLIENT));
220  }
222  {
223  /* ERROR_client_invalid_id */
224  if($e->getCode() != 0x0200) throw $e;
225  }
226  }
227  }
228 
229  /**
230  * Downloads and returns the server groups icon file content.
231  *
232  * @return TeamSpeak3_Helper_String
233  */
234  public function iconDownload()
235  {
236  if($this->iconIsLocal("iconid") || $this["iconid"] == 0) return;
237 
238  $download = $this->getParent()->transferInitDownload(rand(0x0000, 0xFFFF), 0, $this->iconGetName("iconid"));
239  $transfer = TeamSpeak3::factory("filetransfer://" . $download["host"] . ":" . $download["port"]);
240 
241  return $transfer->download($download["ftkey"], $download["size"]);
242  }
243 
244  /**
245  * @ignore
246  */
247  protected function fetchNodeList()
248  {
249  $this->nodeList = array();
250 
251  foreach($this->getParent()->clientList() as $client)
252  {
253  if(in_array($this->getId(), explode(",", $client["client_servergroups"])))
254  {
255  $this->nodeList[] = $client;
256  }
257  }
258  }
259 
260  /**
261  * Returns a unique identifier for the node which can be used as a HTML property.
262  *
263  * @return string
264  */
265  public function getUniqueId()
266  {
267  return $this->getParent()->getUniqueId() . "_sg" . $this->getId();
268  }
269 
270  /**
271  * Returns the name of a possible icon to display the node object.
272  *
273  * @return string
274  */
275  public function getIcon()
276  {
277  return "group_server";
278  }
279 
280  /**
281  * Returns a symbol representing the node.
282  *
283  * @return string
284  */
285  public function getSymbol()
286  {
287  return "%";
288  }
289 
290  /**
291  * Returns a string representation of this node.
292  *
293  * @return string
294  */
295  public function __toString()
296  {
297  return (string) $this["name"];
298  }
299 }
300