TeamSpeak 3 PHP Framework  1.1.16
Copyright © Planet TeamSpeak. All rights reserved.
 All Classes Namespaces Files Functions Variables Pages
Channelgroup.php
Go to the documentation of this file.
1 <?php
2 
3 /**
4  * @file
5  * TeamSpeak 3 PHP Framework
6  *
7  * $Id: Channelgroup.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_Channelgroup
30  * @brief Class describing a TeamSpeak 3 channel group and all it's parameters.
31  */
33 {
34  /**
35  * The TeamSpeak3_Node_Channelgroup constructor.
36  *
37  * @param TeamSpeak3_Node_Server $server
38  * @param array $info
39  * @param string $index
40  * @throws TeamSpeak3_Adapter_ServerQuery_Exception
41  * @return TeamSpeak3_Node_Channelgroup
42  */
43  public function __construct(TeamSpeak3_Node_Server $server, array $info, $index = "cgid")
44  {
45  $this->parent = $server;
46  $this->nodeInfo = $info;
47 
48  if(!array_key_exists($index, $this->nodeInfo))
49  {
50  throw new TeamSpeak3_Adapter_ServerQuery_Exception("invalid groupID", 0xA00);
51  }
52 
53  $this->nodeId = $this->nodeInfo[$index];
54  }
55 
56  /**
57  * Renames the channel group specified.
58  *
59  * @param string $name
60  * @return void
61  */
62  public function rename($name)
63  {
64  return $this->getParent()->channelGroupRename($this->getId(), $name);
65  }
66 
67  /**
68  * Deletes the channel group. If $force is set to TRUE, the channel 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()->channelGroupDelete($this->getId(), $force);
77 
78  unset($this);
79  }
80 
81  /**
82  * Creates a copy of the channel group and returns the new groups ID.
83  *
84  * @param string $name
85  * @param integer $tcgid
86  * @param integer $type
87  * @return integer
88  */
89  public function copy($name = null, $tcgid = 0, $type = TeamSpeak3::GROUP_DBTYPE_REGULAR)
90  {
91  return $this->getParent()->channelGroupCopy($this->getId(), $name, $tcgid, $type);
92  }
93 
94  /**
95  * Returns a list of permissions assigned to the channel group.
96  *
97  * @param boolean $permsid
98  * @return array
99  */
100  public function permList($permsid = FALSE)
101  {
102  return $this->getParent()->channelGroupPermList($this->getId(), $permsid);
103  }
104 
105  /**
106  * Adds a set of specified permissions to the channel group. Multiple permissions
107  * can be added by providing the two parameters of each permission in separate arrays.
108  *
109  * @param integer $permid
110  * @param integer $permvalue
111  * @return void
112  */
113  public function permAssign($permid, $permvalue)
114  {
115  return $this->getParent()->channelGroupPermAssign($this->getId(), $permid, $permvalue);
116  }
117 
118  /**
119  * Alias for permAssign().
120  *
121  * @deprecated
122  */
123  public function permAssignByName($permname, $permvalue)
124  {
125  return $this->permAssign($permname, $permvalue);
126  }
127 
128  /**
129  * Removes a set of specified permissions from the channel group. Multiple
130  * permissions can be removed at once.
131  *
132  * @param integer $permid
133  * @return void
134  */
135  public function permRemove($permid)
136  {
137  return $this->getParent()->channelGroupPermRemove($this->getId(), $permid);
138  }
139 
140  /**
141  * Alias for permAssign().
142  *
143  * @deprecated
144  */
145  public function permRemoveByName($permname)
146  {
147  return $this->permRemove($permname);
148  }
149 
150  /**
151  * Returns a list of clients assigned to the server group specified.
152  *
153  * @return array
154  */
155  public function clientList()
156  {
157  return $this->getParent()->channelGroupClientList($this->getId());
158  }
159 
160  /**
161  * Alias for privilegeKeyCreate().
162  *
163  * @deprecated
164  */
165  public function tokenCreate($cid, $description = null, $customset = null)
166  {
167  return $this->privilegeKeyCreate($cid, $description, $customset);
168  }
169 
170  /**
171  * Creates a new privilege key (token) for the channel group and returns the key.
172  *
173  * @param integer $cid
174  * @param string $description
175  * @param string $customset
176  * @return TeamSpeak3_Helper_String
177  */
178  public function privilegeKeyCreate($cid, $description = null, $customset = null)
179  {
180  return $this->getParent()->privilegeKeyCreate(TeamSpeak3::TOKEN_CHANNELGROUP, $this->getId(), $cid, $description, $customset);
181  }
182 
183  /**
184  * Sends a text message to all clients residing in the channel group on the virtual server.
185  *
186  * @param string $msg
187  * @return void
188  */
189  public function message($msg)
190  {
191  foreach($this as $client)
192  {
193  try
194  {
195  $this->execute("sendtextmessage", array("msg" => $msg, "target" => $client, "targetmode" => TeamSpeak3::TEXTMSG_CLIENT));
196  }
198  {
199  /* ERROR_client_invalid_id */
200  if($e->getCode() != 0x0200) throw $e;
201  }
202  }
203  }
204 
205  /**
206  * Downloads and returns the channel groups icon file content.
207  *
208  * @return TeamSpeak3_Helper_String
209  */
210  public function iconDownload()
211  {
212  if($this->iconIsLocal("iconid") || $this["iconid"] == 0) return;
213 
214  $download = $this->getParent()->transferInitDownload(rand(0x0000, 0xFFFF), 0, $this->iconGetName("iconid"));
215  $transfer = TeamSpeak3::factory("filetransfer://" . $download["host"] . ":" . $download["port"]);
216 
217  return $transfer->download($download["ftkey"], $download["size"]);
218  }
219 
220  /**
221  * @ignore
222  */
223  protected function fetchNodeList()
224  {
225  $this->nodeList = array();
226 
227  foreach($this->getParent()->clientList() as $client)
228  {
229  if($client["client_channel_group_id"] == $this->getId())
230  {
231  $this->nodeList[] = $client;
232  }
233  }
234  }
235 
236  /**
237  * Returns a unique identifier for the node which can be used as a HTML property.
238  *
239  * @return string
240  */
241  public function getUniqueId()
242  {
243  return $this->getParent()->getUniqueId() . "_cg" . $this->getId();
244  }
245 
246  /**
247  * Returns the name of a possible icon to display the node object.
248  *
249  * @return string
250  */
251  public function getIcon()
252  {
253  return "group_channel";
254  }
255 
256  /**
257  * Returns a symbol representing the node.
258  *
259  * @return string
260  */
261  public function getSymbol()
262  {
263  return "%";
264  }
265 
266  /**
267  * Returns a string representation of this node.
268  *
269  * @return string
270  */
271  public function __toString()
272  {
273  return (string) $this["name"];
274  }
275 }
276