Class ElggBatch
Efficiently run operations on batches of results for any function that supports an options array.
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. 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 no entities are processed, callbackResults will be null.
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.
- ElggBatch implements Iterator
Since: 1.8
Link: http://docs.elgg.org/DataModel/ElggBatch
Example: <code> // using foreach $batch = new ElggBatch('elgg_get_entities', array()); $batch->setIncrementOffset(false); foreach ($batch as $entity) { $entity->disable(); } // using both a callback $callback = function($result, $getter, $options) { var_dump("Looking at annotation id: $result->id"); return true; } $batch = new ElggBatch('elgg_get_annotations', array('guid' => 2), $callback); </code>
Warning: If your callback or foreach loop deletes or disable entities you MUST call setIncrementOffset(false) or set that when instantiating. This forces the offset to stay what it was in the $options array.
Located at ElggBatch.php
public
|
#
__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. |
public
|
#
reportIncompleteEntity(
Tell the process that an entity was incomplete during a fetch |
public
|
#
setIncrementOffset( boolean $increment = true )
Increment the offset from the original options array? Setting to false is required for callbacks that delete rows. |
public
|
|
public
mixed
|
|
public
integer
|
|
public
mixed
|
|
public
boolean
|
public
mixed
|
$callbackResult | null |
#
The result of running all entities through the callback function. |