FusionDirectory
class_EntrySortIterator.inc
1 <?php
2 /*
3  This code is part of FusionDirectory (http://www.fusiondirectory.org/)
4  Copyright (C) 2003-2010 Cajus Pollmeier
5  Copyright (C) 2011-2018 FusionDirectory
6 
7  This program is free software; you can redistribute it and/or modify
8  it under the terms of the GNU General Public License as published by
9  the Free Software Foundation; either version 2 of the License, or
10  (at your option) any later version.
11 
12  This program is distributed in the hope that it will be useful,
13  but WITHOUT ANY WARRANTY; without even the implied warranty of
14  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15  GNU General Public License for more details.
16 
17  You should have received a copy of the GNU General Public License
18  along with this program; if not, write to the Free Software
19  Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA.
20 */
21 
26 class EntrySortIterator implements Iterator
27 {
28  protected $data;
29 
39  public function __construct (array $entries, Column $column = NULL, bool $direction = FALSE)
40  {
41  // Sort for attribute
42  if (is_object($column)) {
43  uasort(
44  $entries,
45  function ($ao, $bo) use ($column)
46  {
47  return $column->compare($ao, $bo);
48  }
49  );
50  }
51 
52  // Invert if direction is set
53  if ($direction) {
54  $this->data = array_reverse($entries, TRUE);
55  } else {
56  $this->data = $entries;
57  }
58  }
59 
63  function rewind ()
64  {
65  reset($this->data);
66  }
67 
73  function current ()
74  {
75  return current($this->data);
76  }
77 
83  function key ()
84  {
85  return key($this->data);
86  }
87 
91  function next ()
92  {
93  next($this->data);
94  }
95 
101  function valid ()
102  {
103  return (key($this->data) !== NULL);
104  }
105 }
This class contains all the function needed to sort list go up, go down , back , next. etc...
valid()
Check if the data array is valid.
rewind()
Put the array pointer to the first element.
next()
Get the next data element.
Column base class.
__construct(array $entries, Column $column=NULL, bool $direction=FALSE)
EntrySortIterator constructor.
current()
Get the current data element.
key()
Get the key element.