Overview

Packages

  • ClipIt
    • clipit
      • api
    • urjc
      • backend
  • Elgg
    • Core
      • Access
      • Authentication
      • Cache
      • Caches
      • Core
      • DataMode
        • Site
      • DataModel
        • Annotations
        • Entities
        • Extender
        • File
        • Importable
        • Loggable
        • Notable
        • Object
        • User
      • DataStorage
      • Exception
      • Exceptions
        • Stub
      • FileStore
        • Disk
      • Groups
      • Helpers
      • HMAC
      • Memcache
      • Metadata
      • Navigation
      • ODD
      • Output
      • Plugins
        • Settings
      • Sessions
      • SocialModel
        • Friendable
        • Locatable
      • WebServicesAPI
      • Widgets
      • XML
      • XMLRPC
    • Exceptions
      • Stub
  • None
  • PHP

Classes

  • ElggAttributeLoader
  • ElggBatch
  • ElggData
  • Overview
  • Package
  • Class
  • Tree

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
Package: Elgg\Core\DataModel
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
Methods summary
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.

Batches operations on any elgg_get_*() or compatible function that supports an options array.

Instead of returning all objects in memory, it goes through $chunk_size objects, then requests more from the server. This avoids OOM errors.

Parameters

$getter
string
$getter The function used to get objects. Usually an elgg_get_*() function, but can be any valid PHP callback.
$options
array
$options 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
$callback An optional callback function that all results will be passed to upon load. The callback needs to accept $result, $getter, $options.
$chunk_size
integer
$chunk_size 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
$inc_offset 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 ElggBatch::setIncrementOffset().
public
# reportIncompleteEntity( stdClass $row )

Tell the process that an entity was incomplete during a fetch

Tell the process that an entity was incomplete during a fetch

Parameters

$row
stdClass
$row
public
# setIncrementOffset( boolean $increment = true )

Increment the offset from the original options array? Setting to false is required for callbacks that delete rows.

Increment the offset from the original options array? Setting to false is required for callbacks that delete rows.

Parameters

$increment
boolean
$increment Set to false when deleting data
public
# rewind( )

PHP Iterator Interface

PHP Iterator Interface

See

Iterator::rewind()

Implementation of

Iterator::rewind()
public mixed
# current( )

PHP Iterator Interface

PHP Iterator Interface

Returns

mixed

See

Iterator::current()

Implementation of

Iterator::current()
public integer
# key( )

PHP Iterator Interface

PHP Iterator Interface

Returns

integer

See

Iterator::key()

Implementation of

Iterator::key()
public mixed
# next( )

PHP Iterator Interface

PHP Iterator Interface

Returns

mixed

See

Iterator::next()

Implementation of

Iterator::next()
public boolean
# valid( )

PHP Iterator Interface

PHP Iterator Interface

Returns

boolean

See

Iterator::valid()

Implementation of

Iterator::valid()
Properties summary
public mixed $callbackResult null
#

The result of running all entities through the callback function.

The result of running all entities through the callback function.

API documentation generated by ApiGen 2.8.0