Search moodle.org's
Developer Documentation

See Release Notes

  • Bug fixes for general core bugs in 3.10.x will end 8 November 2021 (12 months).
  • Bug fixes for security issues in 3.10.x will end 9 May 2022 (18 months).
  • PHP version: minimum PHP 7.2.0 Note: minimum PHP version has increased since Moodle 3.8. PHP 7.3.x and 7.4.x are supported too.

Differences Between: [Versions 310 and 401] [Versions 310 and 402] [Versions 310 and 403]

Applies the same callback to all recorset records.

Copyright: 2015 David Monllao
License: http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
File Size: 161 lines (4 kb)
Included or required:0 times
Referenced: 0 times
Includes or requires: 0 files

Defines 1 class

recordset_walk:: (8 methods):
  __construct()
  __destruct()
  current()
  next()
  key()
  valid()
  rewind()
  close()


Class: recordset_walk  - X-Ref

Iterator that walks through a moodle_recordset applying the provided function.

The internal recordset can be closed using the close() function.

Note that consumers of this class are responsible of closing the recordset,
although there are some implicit closes under some ciscumstances:
- Once all recordset records have been iterated
- The object is destroyed

__construct(\moodle_recordset $recordset, callable $callback, $callbackextra = null)   X-Ref
Create a new iterator applying the callback to each record.

param: \moodle_recordset $recordset Recordset to iterate.
param: callable $callback Apply this function to each record. If using a method, it should be public.
param: mixed $callbackextra An extra single parameter to pass to the callback. Use a container to pass multiple values.

__destruct()   X-Ref
Closes the recordset.

return: void

current()   X-Ref
Returns the current element after applying the callback.

return: mixed|bool The returned value type will depend on the callback.

next()   X-Ref
Moves the internal pointer to the next record.

return: void

key()   X-Ref
Returns current record key.

return: int

valid()   X-Ref
Returns whether the current position is valid or not.

If we reached the end of the recordset we close as we
don't allow rewinds. Doing do so we reduce the chance
of unclosed recordsets.

return: bool

rewind()   X-Ref
Rewind is not supported.

return: void

close()   X-Ref
Closes the recordset.

return: void