PHP Class ElggBatch, Elgg

This is usually used with elgg_get_entities() and friends, elgg_get_annotations(), and elgg_get_metadata(). If you pass a valid PHP callback, all results will be run through that callback. You can still foreach() through the result set after. Valid PHP callbacks can be a string, an array, or a closure. {@link http://php.net/manual/en/language.pseudo-types.php} The callback function must accept 3 arguments: an entity, the getter used, and the options used. Results from the callback are stored in callbackResult. If the callback returns only booleans, callbackResults will be the combined result of all calls. If the callback returns anything else, callbackresult will be an indexed array of whatever the callback returns. If returning error handling information, you should include enough information to determine which result you're referring to. Don't combine returning bools and returning something else. Note that returning false will not stop the foreach.
Inheritance: implements Iterator
Mostra file Open project: elgg/elgg Class Usage Examples

Public Properties

Property Type Description
$callbackResult mixed The result of running all entities through the callback function.

Public Methods

Method Description
__construct ( string $getter, array $options, mixed $callback = null, integer $chunk_size = 25, boolean $inc_offset = true ) Batches operations on any elgg_get_*() or compatible function that supports an options array.
count ( ) : integer Count the total results available at this moment.
current ( )
key ( )
next ( )
reportIncompleteEntity ( stdClass $row ) Tell the process that an entity was incomplete during a fetch
rewind ( )
setIncrementOffset ( boolean $increment = true ) : void Increment the offset from the original options array? Setting to false is required for callbacks that delete rows.
valid ( )

Private Methods

Method Description
getNextResultsChunk ( ) : boolean Fetches the next chunk of results

Method Details

__construct() public method

Instead of returning all objects in memory, it goes through $chunk_size objects, then requests more from the server. This avoids OOM errors.
public __construct ( string $getter, array $options, mixed $callback = null, integer $chunk_size = 25, boolean $inc_offset = true )
$getter string The function used to get objects. Usually an elgg_get_*() function, but can be any valid PHP callback.
$options array The options array to pass to the getter function. If limit is not set, 10 is used as the default. In most cases that is not what you want.
$callback mixed An optional callback function that all results will be passed to upon load. The callback needs to accept $result, $getter, $options.
$chunk_size integer The number of entities to pull in before requesting more. You have to balance this between running out of memory in PHP and hitting the db server too often.
$inc_offset boolean Increment the offset on each fetch. This must be false for callbacks that delete rows. You can set this after the object is created with {@link \ElggBatch::setIncrementOffset()}.

count() public method

As this performs a separate query, the count returned may not match the number of results you can fetch via iteration on a very active DB.
See also: Countable::count()
public count ( ) : integer
return integer

current() public method

public current ( )

key() public method

public key ( )

next() public method

public next ( )

reportIncompleteEntity() public method

Tell the process that an entity was incomplete during a fetch
public reportIncompleteEntity ( stdClass $row )
$row stdClass

rewind() public method

public rewind ( )

setIncrementOffset() public method

Increment the offset from the original options array? Setting to false is required for callbacks that delete rows.
public setIncrementOffset ( boolean $increment = true ) : void
$increment boolean Set to false when deleting data
return void

valid() public method

public valid ( )

Property Details

$callbackResult public_oe property

The result of running all entities through the callback function.
public mixed $callbackResult
return mixed