ddaf5c243818146a2cda7d5195affe11eb88d65f
1 <?php
2 /*
3 * This code is part of GOsa (http://www.gosa-project.org)
4 * Copyright (C) 2003-2008 GONICUS GmbH
5 *
6 * ID: $$Id: class_plugin.inc 13896 2009-07-07 07:06:37Z hickert $$
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 2 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, write to the Free Software
20 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
21 */
23 class listingSortIterator implements Iterator {
24 private $data;
26 public function __construct($data, $attribute, $type= "string") {
27 global $_sortAttribute;
28 global $_sortType;
29 $_sortAttribute= $attribute;
30 $_sortType= $type;
32 // Inline function to
33 function attrSort($ao, $bo) {
34 global $_sortAttribute;
35 global $_sortType;
37 // Extract values from ao and bo
38 $a= $b= "";
39 if (isset($ao[$_sortAttribute])) {
40 $a= $ao[$_sortAttribute];
41 if (is_array($a)) {
42 $a= $a[0];
43 }
44 }
45 if (isset($bo[$_sortAttribute])) {
46 $b= $bo[$_sortAttribute];
47 if (is_array($b)) {
48 $b= $b[0];
49 }
50 }
52 // Take a look at the several types
53 switch ($_sortType) {
54 case 'string':
55 return strnatcmp($a, $b);
57 default:
58 die(sprintf(_("Cannot sort entries: method '%s' is unknown!"), $_sortType));
59 }
60 }
62 // Sort for attribute
63 usort($data, "attrSort");
64 $this->data= $data;
65 }
67 function rewind() {
68 return reset($this->data);
69 }
71 function current() {
72 return current($this->data);
73 }
75 function key() {
76 return key($this->data);
77 }
79 function next() {
80 return next($this->data);
81 }
83 function valid() {
84 return key($this->data) !== null;
85 }
86 }
88 ?>