$nick,"group"=>$group); if ($this->roster) { $this->roster = $this->roster += $new_item; } else { $this->roster = $new_item; } } public function get_roster() { return $this->roster; } public function get_nick($jid) { $roster = $this->roster; $nick = $roster[$jid][nick]; return htmlspecialchars($nick); } public function get_group($jid) { $roster = $this->roster; $group = $roster[$jid][group]; return htmlspecialchars($group); } public function get_nick_group($jid) { $roster = $this->roster; $result = array($roster[$jid][nick],$roster[$jid][group]); return $result; } public function sort_by_jid($dir) { $arr = $this->roster; if ($dir==="az") { ksort($arr); } elseif($dir==="za") { krsort($arr); } else{ return false; } $this->roster = $arr; } public function sort_by_nick($dir) { $this->sort_roster($dir,"nick"); } public function sort_by_group($dir) { $this->sort_roster($dir,"group"); } public function sort_by_nick_group() { $arr = $this->roster; array_multisort($this->prepare_multisort("group"),SORT_ASC, $this->prepare_multisort("nick"),SORT_ASC,$arr); $this->roster = $arr; } protected function sort_roster($dir,$field) { $arr = $this->roster; if ($dir ==="az") { array_multisort($this->prepare_multisort("$field"),SORT_ASC,$arr); } elseif($dir==="za") { array_multisort($this->prepare_multisort("$field"),SORT_DESC,$arr); } else{ return false; } $this->roster = $arr; } protected function prepare_multisort($val) { $arr = $this->roster; foreach ($arr as $key => $row) { $field[$key] = $row[$val]; } $ret = array_map('strtolower', $field); return $ret; } } ?>