1 | <?php |
||
19 | class DataProviderIterator implements Iterator, Countable |
||
20 | { |
||
21 | /** |
||
22 | * @var ColumnValueMapper|null |
||
23 | */ |
||
24 | protected $itemMapper; |
||
25 | /** |
||
26 | * @var \yii\data\BaseDataProvider |
||
27 | */ |
||
28 | private $dataProvider; |
||
29 | /** |
||
30 | * @var int |
||
31 | */ |
||
32 | private $currentIndex = -1; |
||
33 | /** |
||
34 | * @var int |
||
35 | */ |
||
36 | private $currentPage = 0; |
||
37 | /** |
||
38 | * @var int |
||
39 | */ |
||
40 | private $totalItemCount = -1; |
||
41 | /** |
||
42 | * @var |
||
43 | */ |
||
44 | private $items; |
||
45 | |||
46 | /** |
||
47 | * Constructor. |
||
48 | * |
||
49 | * @param BaseDataProvider $dataProvider the data provider to iterate over |
||
50 | * @param ColumnValueMapper|null $itemMapper apply column transformations to Models |
||
51 | * @param integer $pageSize pageSize to use for iteration. This is the number of objects loaded into memory at the same time. |
||
52 | */ |
||
53 | public function __construct(BaseDataProvider $dataProvider, ColumnValueMapper $itemMapper = null, $pageSize = null) |
||
65 | |||
66 | /** |
||
67 | * Returns the data provider to iterate over |
||
68 | * @return BaseDataProvider the data provider to iterate over |
||
69 | */ |
||
70 | public function getDataProvider() |
||
74 | |||
75 | /** |
||
76 | * Gets the total number of items to iterate over |
||
77 | * @return integer the total number of items to iterate over |
||
78 | */ |
||
79 | public function getTotalItemCount() |
||
83 | |||
84 | /** |
||
85 | * Gets the current item in the list. |
||
86 | * This method is required by the Iterator interface. |
||
87 | * @return mixed the current item in the list |
||
88 | */ |
||
89 | public function current() |
||
93 | |||
94 | /** |
||
95 | * @return int |
||
96 | */ |
||
97 | public function getCurrentIndex() |
||
101 | |||
102 | /** |
||
103 | * Gets the key of the current item. |
||
104 | * This method is required by the Iterator interface. |
||
105 | * @return integer the key of the current item |
||
106 | */ |
||
107 | public function key() |
||
113 | |||
114 | /** |
||
115 | * @return int |
||
116 | */ |
||
117 | public function getCurrentPage() |
||
121 | |||
122 | /** |
||
123 | * Moves the pointer to the next item in the list. |
||
124 | * This method is required by the Iterator interface. |
||
125 | */ |
||
126 | public function next() |
||
136 | |||
137 | /** |
||
138 | * Rewinds the iterator to the start of the list. |
||
139 | * This method is required by the Iterator interface. |
||
140 | */ |
||
141 | public function rewind() |
||
147 | |||
148 | /** |
||
149 | * Checks if the current position is valid or not. |
||
150 | * This method is required by the Iterator interface. |
||
151 | * @return boolean true if this index is valid |
||
152 | */ |
||
153 | public function valid() |
||
157 | |||
158 | /** |
||
159 | * Gets the total number of items in the dataProvider. |
||
160 | * This method is required by the Countable interface. |
||
161 | * @return integer the total number of items |
||
162 | */ |
||
163 | public function count() |
||
167 | |||
168 | /** |
||
169 | * Loads a page of items |
||
170 | * @return array the items from the next page of results |
||
171 | */ |
||
172 | protected function loadPage() |
||
179 | |||
180 | /** |
||
181 | * @param $index |
||
182 | * |
||
183 | * @return array |
||
184 | */ |
||
185 | protected function getItem($index) |
||
196 | } |
||
197 |