Open Journal Systems  3.3.0
DBRowIterator.inc.php
1 <?php
2 
18 import('lib.pkp.classes.core.ItemIterator');
19 
20 class DBRowIterator extends ItemIterator {
22  var $records;
23 
28  var $idFields;
29 
31  var $wasEmpty;
32 
33  var $isFirst;
34  var $isLast;
35  var $page;
36  var $count;
38 
46  function __construct($records, $idFields = array()) {
47  parent::__construct();
48  $this->idFields = $idFields;
49 
50  if (!$records || $records->EOF) {
51  if ($records) $records->Close();
52  $this->records = null;
53  $this->wasEmpty = true;
54  $this->page = 1;
55  $this->isFirst = true;
56  $this->isLast = true;
57  $this->count = 0;
58  $this->pageCount = 1;
59  }
60  else {
61  $this->records = $records;
62  $this->wasEmpty = false;
63  $this->page = $records->AbsolutePage();
64  $this->isFirst = $records->atFirstPage();
65  $this->isLast = $records->atLastPage();
66  $this->count = $records->MaxRecordCount();
67  $this->pageCount = $records->LastPageNo();
68  }
69  }
70 
75  function next() {
76  if ($this->records == null) return $this->records;
77  if (!$this->records->EOF) {
78  $row = $this->records->getRowAssoc(false);
79  if (!$this->records->MoveNext()) $this->close();
80  return $row;
81  } else {
82  $this->close();
83  $nullVar = null;
84  return $nullVar;
85  }
86  }
87 
92  function nextWithKey() {
93  $result = $this->next();
94  if (empty($this->idFields)) {
95  $key = null;
96  } else {
97  assert(is_array($result) && is_array($this->idFields));
98  $key = '';
99  foreach($this->idFields as $idField) {
100  assert(isset($result[$idField]));
101  if (!empty($key)) $key .= '-';
102  $key .= (string)$result[$idField];
103  }
104  }
105  return array($key, $result);
106  }
107 
112  function atFirstPage() {
113  return $this->isFirst;
114  }
115 
120  function atLastPage() {
121  return $this->isLast;
122  }
123 
128  function getPage() {
129  return $this->page;
130  }
131 
136  function getCount() {
137  return $this->count;
138  }
139 
144  function getPageCount() {
145  return $this->pageCount;
146  }
147 
152  function eof() {
153  if ($this->records == null) return true;
154  if ($this->records->EOF) {
155  $this->close();
156  return true;
157  }
158  return false;
159  }
160 
165  function wasEmpty() {
166  return $this->wasEmpty;
167  }
168 
173  function close() {
174  $this->records->close();
175  unset($this->records);
176  $this->records = null;
177  }
178 
183  function toArray() {
184  $returner = array();
185  while (!$this->eof()) {
186  $returner[] = $this->next();
187  }
188  return $returner;
189  }
190 }
DBRowIterator\$page
$page
Definition: DBRowIterator.inc.php:38
DBRowIterator\$isLast
$isLast
Definition: DBRowIterator.inc.php:37
DBRowIterator\getPageCount
getPageCount()
Definition: DBRowIterator.inc.php:147
DBRowIterator\next
next()
Definition: DBRowIterator.inc.php:78
DBRowIterator\atFirstPage
atFirstPage()
Definition: DBRowIterator.inc.php:115
DBRowIterator\$count
$count
Definition: DBRowIterator.inc.php:39
DBRowIterator\$pageCount
$pageCount
Definition: DBRowIterator.inc.php:40
DBRowIterator\close
close()
Definition: DBRowIterator.inc.php:176
DBRowIterator\toArray
toArray()
Definition: DBRowIterator.inc.php:186
DBRowIterator\$wasEmpty
$wasEmpty
Definition: DBRowIterator.inc.php:34
DBRowIterator\$idFields
$idFields
Definition: DBRowIterator.inc.php:31
ItemIterator\__construct
__construct()
Definition: ItemIterator.inc.php:22
DBRowIterator\nextWithKey
nextWithKey()
Definition: DBRowIterator.inc.php:95
DBRowIterator\wasEmpty
wasEmpty()
Definition: DBRowIterator.inc.php:168
DBRowIterator
Wrapper around ADORecordSet providing "factory" features for generating objects from DAOs.
Definition: DBRowIterator.inc.php:20
DBRowIterator\eof
eof()
Definition: DBRowIterator.inc.php:155
DBRowIterator\$records
$records
Definition: DBRowIterator.inc.php:22
DBRowIterator\__construct
__construct($records, $idFields=array())
Definition: DBRowIterator.inc.php:49
DBRowIterator\getCount
getCount()
Definition: DBRowIterator.inc.php:139
ItemIterator
Generic iterator class; needs to be overloaded by subclasses providing specific implementations.
Definition: ItemIterator.inc.php:18
DBRowIterator\getPage
getPage()
Definition: DBRowIterator.inc.php:131
DBRowIterator\atLastPage
atLastPage()
Definition: DBRowIterator.inc.php:123
DBRowIterator\$isFirst
$isFirst
Definition: DBRowIterator.inc.php:36