| @@ -197,18 +197,31 @@ | ||
| 197 | 197 | /** |
| 198 | 198 | * Save changes directly to current document |
| 199 | 199 | * |
| 200 | 200 | * @param array $fields |
| 201 | + * @param array $args | |
| 201 | 202 | * |
| 202 | 203 | * @return array |
| 203 | 204 | * @throws Exception |
| 204 | 205 | */ |
| 205 | - public function getList( array $fields = [] ) | |
| 206 | + public function getList( array $fields = [], $args = [] ) | |
| 206 | 207 | { |
| 207 | 208 | $columnsName = !empty( $fields ) ? $fields : ['id', 'name', 'slug', 'author', 'sections_count', 'created_at', 'modified_at', 'thumbnail', 'status']; |
| 208 | - $documents = $this->select( $fields )->findAll()->get(); | |
| 209 | + $numberOfPages = ''; | |
| 210 | + if ( !empty( $args['page'] ) && !empty( $args['perPage'] ) ) { | |
| 211 | + $pager = $this->select( $fields )->paginate( $args['perPage'], $args['page'] ); | |
| 212 | + if ( $pager ) { | |
| 213 | + $numberOfPages = $pager->getNumberOfPages(); | |
| 214 | + $documents = $pager->getResults(); | |
| 215 | + } else { | |
| 216 | + $documents = []; | |
| 217 | + } | |
| 209 | 218 | |
| 219 | + } else { | |
| 220 | + $documents = $this->select( $fields )->findAll()->get(); | |
| 221 | + } | |
| 210 | 222 | |
| 223 | + | |
| 211 | 224 | $documents = $documents ? $documents->toArray() : []; |
| 212 | 225 | |
| 213 | 226 | if ( $documents && empty( $fields ) ) { |
| 214 | 227 | $uploadDir = wp_upload_dir(); |
| @@ -220,8 +233,17 @@ | ||
| 220 | 233 | } else { |
| 221 | 234 | $documents[ $key ]['previewImage'] = ''; |
| 222 | 235 | } |
| 223 | 236 | } |
| 237 | + } | |
| 238 | + | |
| 239 | + if ( !empty( $numberOfPages ) ) { | |
| 240 | + return [ | |
| 241 | + 'page' => $args['page'], | |
| 242 | + 'perPage' => $args['perPage'], | |
| 243 | + 'numberOfPages' => $numberOfPages, | |
| 244 | + 'documents' => $documents | |
| 245 | + ]; | |
| 224 | 246 | } |
| 225 | 247 | |
| 226 | 248 | return $documents; |
| 227 | 249 | } |