Channelgroup.php 6.8 KB

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