EGOCMS  24.0
EGOTEC Content-Managament-System
Page_Iterator.php
gehe zur Dokumentation dieser Datei
1 <?php
9 require_once('base/Page.php');
10 
21 class Page_Iterator implements Iterator, Countable
22 {
23  private $_db;
24  private $_site;
25  private $_firstRun = true;
26  private $_haltId = 0;
28  public $page;
37  public function __construct($site='', $db='')
38  {
39  $this->_site = $site;
40  $this->_db = $db;
41  }
42 
58  public function nextPage()
59  {
60  $this->_firstRun = false;
61  if ($this->_db && $this->_db->nextRecord())
62  { // Wenn noch ein Eintrag existiert, wird ein Page Objekt erzeugt.
63  while ($this->_haltId) {
64  if ($this->_db->Record['id'] == $this->_haltId) {
65  $this->_haltId = 0;
66  }
67  if (!$this->_db->nextRecord()) {
68  return false;
69  }
70  }
71  $class = $this->_site->getPageClass($this->_db->Record['type']);
72  $this->page = new $class($this->_site, $this->_db->Record);
73 
74  // Sicherstellen, dass für Archiveinträge die richtige Page Klasse verwendet wird
75  if (
76  $this->page->archiveOnly
77  && $this->page->originalType != $this->page->field['type']
78  && ($new_class = $this->_site->getPageClass($this->page->field['type'])) != $class
79  ) {
80  $this->page = new $new_class($this->_site, $this->page->field, true);
81  }
82 
83  return $this->page;
84  }
85  unset($this->page); // Die Funktion valid() testet auf isset($this->page).
86  return null;
87  }
88 
105  public function numRecords()
106  {
107  return $this->_db?$this->_db->numRecords():0;
108  }
109 
115  function current()
116  {
117  return $this->page;
118  }
119 
125  function next()
126  {
127  return $this->nextPage();
128  }
129 
135  function key()
136  {
137  return $this->_db->key();
138  }
139 
143  function valid()
144  {
145  return isset($this->page) && (
146  $GLOBALS['admin_area']
147  || !$this->page->extra['quarantine']
148  );
149  }
150 
154  function rewind()
155  {
156  if ($this->_firstRun) {
157  return $this->nextPage();
158  }
159  $this->_db->rewind();
160  if ($this->_db->Record !== null) {
161  $class = $this->_site->getPageClass($this->_db->Record['type']);
162  return $this->page = new $class($this->_site, $this->_db->Record);
163  }
164  unset($this->page); // Die Funktion valid() testet auf isset($this->page).
165  return null;
166  }
167 
173  function getDb()
174  {
175  return $this->_db;
176  }
177 
184  public function setHaltId($id) {
185  $this->_haltId = $id;
186  }
187 
193  public function __toString()
194  {
195  return 'Page_Iterator('.$this->page.')';
196  }
197 
198  public function count() {
199  return $this->numRecords();
200  }
201 }
__construct($site='', $db='')