TeamSpeak 3 PHP Framework
1.1.12
|
00001 <?php 00002 00003 /** 00004 * @file 00005 * TeamSpeak 3 PHP Framework 00006 * 00007 * $Id: Channelgroup.php 2/18/2012 12:42:46 scp@orilla $ 00008 * 00009 * This program is free software: you can redistribute it and/or modify 00010 * it under the terms of the GNU General Public License as published by 00011 * the Free Software Foundation, either version 3 of the License, or 00012 * (at your option) any later version. 00013 * 00014 * This program is distributed in the hope that it will be useful, 00015 * but WITHOUT ANY WARRANTY; without even the implied warranty of 00016 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 00017 * GNU General Public License for more details. 00018 * 00019 * You should have received a copy of the GNU General Public License 00020 * along with this program. If not, see <http://www.gnu.org/licenses/>. 00021 * 00022 * @package TeamSpeak3 00023 * @version 1.1.12 00024 * @author Sven 'ScP' Paulsen 00025 * @copyright Copyright (c) 2010 by Planet TeamSpeak. All rights reserved. 00026 */ 00027 00028 /** 00029 * @class TeamSpeak3_Node_Channelgroup 00030 * @brief Class describing a TeamSpeak 3 channel group and all it's parameters. 00031 */ 00032 class TeamSpeak3_Node_Channelgroup extends TeamSpeak3_Node_Abstract 00033 { 00034 /** 00035 * The TeamSpeak3_Node_Channelgroup constructor. 00036 * 00037 * @param TeamSpeak3_Node_Server $server 00038 * @param array $info 00039 * @param string $index 00040 * @throws TeamSpeak3_Adapter_ServerQuery_Exception 00041 * @return TeamSpeak3_Node_Channelgroup 00042 */ 00043 public function __construct(TeamSpeak3_Node_Server $server, array $info, $index = "cgid") 00044 { 00045 $this->parent = $server; 00046 $this->nodeInfo = $info; 00047 00048 if(!array_key_exists($index, $this->nodeInfo)) 00049 { 00050 throw new TeamSpeak3_Adapter_ServerQuery_Exception("invalid groupID", 0xA00); 00051 } 00052 00053 $this->nodeId = $this->nodeInfo[$index]; 00054 } 00055 00056 /** 00057 * Renames the channel group specified. 00058 * 00059 * @param string $name 00060 * @return void 00061 */ 00062 public function rename($name) 00063 { 00064 return $this->getParent()->channelGroupRename($this->getId(), $name); 00065 } 00066 00067 /** 00068 * Deletes the channel group. If $force is set to TRUE, the channel group will be 00069 * deleted even if there are clients within. 00070 * 00071 * @param boolean $force 00072 * @return void 00073 */ 00074 public function delete($force = FALSE) 00075 { 00076 $this->getParent()->channelGroupDelete($this->getId(), $force); 00077 00078 unset($this); 00079 } 00080 00081 /** 00082 * Creates a copy of the channel group and returns the new groups ID. 00083 * 00084 * @param string $name 00085 * @param integer $tcgid 00086 * @param integer $type 00087 * @return integer 00088 */ 00089 public function copy($name = null, $tcgid = 0, $type = TeamSpeak3::GROUP_DBTYPE_REGULAR) 00090 { 00091 return $this->getParent()->channelGroupCopy($this->getId(), $name, $tcgid, $type); 00092 } 00093 00094 /** 00095 * Returns a list of permissions assigned to the channel group. 00096 * 00097 * @param boolean $permsid 00098 * @return array 00099 */ 00100 public function permList($permsid = FALSE) 00101 { 00102 return $this->getParent()->channelGroupPermList($this->getId(), $permsid); 00103 } 00104 00105 /** 00106 * Adds a set of specified permissions to the channel group. Multiple permissions 00107 * can be added by providing the two parameters of each permission in separate arrays. 00108 * 00109 * @param integer $permid 00110 * @param integer $permvalue 00111 * @return void 00112 */ 00113 public function permAssign($permid, $permvalue) 00114 { 00115 return $this->getParent()->channelGroupPermAssign($this->getId(), $permid, $permvalue); 00116 } 00117 00118 /** 00119 * Alias for permAssign(). 00120 * 00121 * @deprecated 00122 */ 00123 public function permAssignByName($permname, $permvalue) 00124 { 00125 return $this->permAssign($permname, $permvalue); 00126 } 00127 00128 /** 00129 * Removes a set of specified permissions from the channel group. Multiple 00130 * permissions can be removed at once. 00131 * 00132 * @param integer $permid 00133 * @return void 00134 */ 00135 public function permRemove($permid) 00136 { 00137 return $this->getParent()->channelGroupPermRemove($this->getId(), $permid); 00138 } 00139 00140 /** 00141 * Alias for permAssign(). 00142 * 00143 * @deprecated 00144 */ 00145 public function permRemoveByName($permname) 00146 { 00147 return $this->permRemove($permname); 00148 } 00149 00150 /** 00151 * Returns a list of clients assigned to the server group specified. 00152 * 00153 * @return array 00154 */ 00155 public function clientList() 00156 { 00157 return $this->getParent()->channelGroupClientList($this->getId()); 00158 } 00159 00160 /** 00161 * Alias for privilegeKeyCreate(). 00162 * 00163 * @deprecated 00164 */ 00165 public function tokenCreate($cid, $description = null, $customset = null) 00166 { 00167 return $this->privilegeKeyCreate($cid, $description, $customset); 00168 } 00169 00170 /** 00171 * Creates a new privilege key (token) for the channel group and returns the key. 00172 * 00173 * @param integer $cid 00174 * @param string $description 00175 * @param string $customset 00176 * @return TeamSpeak3_Helper_String 00177 */ 00178 public function privilegeKeyCreate($cid, $description = null, $customset = null) 00179 { 00180 return $this->getParent()->privilegeKeyCreate(TeamSpeak3::TOKEN_CHANNELGROUP, $this->getId(), $cid, $description, $customset); 00181 } 00182 00183 /** 00184 * Sends a text message to all clients residing in the channel group on the virtual server. 00185 * 00186 * @param string $msg 00187 * @return void 00188 */ 00189 public function message($msg) 00190 { 00191 foreach($this as $client) 00192 { 00193 try 00194 { 00195 $this->execute("sendtextmessage", array("msg" => $msg, "target" => $client, "targetmode" => TeamSpeak3::TEXTMSG_CLIENT)); 00196 } 00197 catch(TeamSpeak3_Adapter_ServerQuery_Exception $e) 00198 { 00199 /* ERROR_client_invalid_id */ 00200 if($e->getCode() != 0x0200) throw $e; 00201 } 00202 } 00203 } 00204 00205 /** 00206 * Downloads and returns the channel groups icon file content. 00207 * 00208 * @return TeamSpeak3_Helper_String 00209 */ 00210 public function iconDownload() 00211 { 00212 if($this->iconIsLocal("iconid") || $this["iconid"] == 0) return; 00213 00214 $download = $this->getParent()->transferInitDownload(rand(0x0000, 0xFFFF), 0, $this->iconGetName("iconid")); 00215 $transfer = TeamSpeak3::factory("filetransfer://" . $download["host"] . ":" . $download["port"]); 00216 00217 return $transfer->download($download["ftkey"], $download["size"]); 00218 } 00219 00220 /** 00221 * @ignore 00222 */ 00223 protected function fetchNodeList() 00224 { 00225 $this->nodeList = array(); 00226 00227 foreach($this->getParent()->clientList() as $client) 00228 { 00229 if($client["client_channel_group_id"] == $this->getId()) 00230 { 00231 $this->nodeList[] = $client; 00232 } 00233 } 00234 } 00235 00236 /** 00237 * Returns a unique identifier for the node which can be used as a HTML property. 00238 * 00239 * @return string 00240 */ 00241 public function getUniqueId() 00242 { 00243 return $this->getParent()->getUniqueId() . "_cg" . $this->getId(); 00244 } 00245 00246 /** 00247 * Returns the name of a possible icon to display the node object. 00248 * 00249 * @return string 00250 */ 00251 public function getIcon() 00252 { 00253 return "group_channel"; 00254 } 00255 00256 /** 00257 * Returns a symbol representing the node. 00258 * 00259 * @return string 00260 */ 00261 public function getSymbol() 00262 { 00263 return "%"; 00264 } 00265 00266 /** 00267 * Returns a string representation of this node. 00268 * 00269 * @return string 00270 */ 00271 public function __toString() 00272 { 00273 return (string) $this["name"]; 00274 } 00275 } 00276