@@ -135,19 +135,58 @@ public function returnArray($arr)
135
135
return $ this ->getResponse ()->setBody (json_encode ($ arr ));
136
136
}
137
137
138
+
138
139
/**
139
140
* Convert a provided DataList to a PaginatedList and return the source.
140
141
*
141
142
* @param SS_List $list
142
143
* @param callable $keyFunc
143
144
* @param callabale $dataFunc
145
+ * @param int $pageLength
146
+ *
147
+ * @return array
148
+ */
149
+ public function prepList (SS_List $ list , $ keyFunc = null , $ dataFunc = null ): array
150
+ {
151
+ $ output = [];
152
+
153
+ foreach ($ list as $ item ) {
154
+ if ($ dataFunc ) {
155
+ $ record = $ dataFunc ($ item );
156
+ } else if (is_array ($ item )) {
157
+ $ record = $ item ;
158
+ } else {
159
+ $ record = $ item ->toApi ();
160
+ }
161
+
162
+ if ($ keyFunc ) {
163
+ $ output [$ keyFunc ($ item )] = $ record ;
164
+ } else {
165
+ $ output [] = $ record ;
166
+ }
167
+ }
168
+
169
+ return [
170
+ $ list ,
171
+ $ output
172
+ ];
173
+ }
174
+
175
+
176
+ /**
177
+ * Convert a provided List to a PaginatedList and return the source.
178
+ *
179
+ * @param SS_List $list
180
+ * @param callable $keyFunc
181
+ * @param callabale $dataFunc
182
+ * @param int $pageLength
144
183
*
145
184
* @return array
146
185
*/
147
- public function prepPaginatedOutput (SS_List $ list , $ keyFunc = null , $ dataFunc = null ): array
186
+ public function prepPaginatedOutput (SS_List $ list , $ keyFunc = null , $ dataFunc = null , $ pageLength = 100 ): array
148
187
{
149
188
$ list = new PaginatedList ($ list , $ this ->request );
150
- $ list ->setPageLength (100 );
189
+ $ list ->setPageLength ($ pageLength );
151
190
$ output = [];
152
191
153
192
foreach ($ list as $ item ) {
0 commit comments