planetteamspeak / ts3phpframework

Modern use-at-will framework that provides individual components to manage TeamSpeak 3 Server instances
https://www.planetteamspeak.com
GNU General Public License v3.0
211 stars 59 forks source link

Server Group List bug ? #86

Closed ph1823 closed 6 years ago

ph1823 commented 6 years ago

Hi ! I want to filter my server group list, and i insert the array("Guest Server Query", "Admin Server Query") or juste array("Query") in parametre of serverGroupList , and dont work. Why? And when I take the list of groups, non query groups appear in duplicate, is this normal? How to solve this .. Thank you for your answer!

ronindesign commented 6 years ago

Please see the documentation regarding the correct usage of $filter parameter. Here is an example of $filter being used in Example #2 (see part about filter by platform):

// query clientlist from virtual server and filter by platform
$arr_ClientList = $ts3_VirtualServer->clientList(array("client_platform" => "Android"));

So maybe you want something like this (untested):

serverGroupList(['name' => 'Guest']) // or whatever the correct "key" for group name is...

Here is how the framework processes a filter: Ref: TeamSpeak3/Node/Abstract::filterList()

/**
   * Filters given node list array using specified filter rules.
   *
   * @param  array $nodes
   * @param  array $rules
   * @return array
   */
  protected function filterList(array $nodes = array(), array $rules = array())
  {
    if(!empty($rules))
    {
      foreach($nodes as $node)
      {
        if(!$node instanceof TeamSpeak3_Node_Abstract) continue;
        $props = $node->getInfo(FALSE);
        $props = array_intersect_key($props, $rules);
        foreach($props as $key => $val)
        {
          if($val instanceof TeamSpeak3_Helper_String)
          {
            $match = $val->contains($rules[$key], TRUE);
          }
          else
          {
            $match = $val == $rules[$key];
          }
          if($match === FALSE)
          {
            unset($nodes[$node->getId()]);
          }
        }
      }
    }
    return $nodes;
  }

EDIT: Regarding the duplicates groups, you'll have to provide the code you're using. I've never had duplicate groups appear, nor have I heard issues from anyone else regarding this. I think think if this were broken, the HTML Viewer and more would not work correctly. Please provide you're code and we can help with troubleshooting.

ph1823 commented 6 years ago

Hello! Thank four your reply ! I did not understand the doc, thank you for your explain filter!

And for the duplicate entry after appliced the correct filter, this dont duplicate,I do not know what he knows, but important it's this fix!

ronindesign commented 6 years ago

Great, glad it's working now. Please feel free to comment if you need further assistance on this.