78 private $results = [];
85 private $getter = null;
92 private $options = [];
99 private $chunkSize = 25;
106 private $callback = null;
127 private $retrievedResults = 0;
134 private $resultIndex = 0;
141 private $chunkIndex = 0;
148 private $processedResults = 0;
155 private $validGetter = null;
169 private $incrementOffset =
true;
176 private $reportedFailures = 0;
200 public function __construct(callable $getter, array $options, $callback = null,
int $chunk_size = 25,
bool $inc_offset =
true) {
202 $this->getter = $getter;
203 $this->options = $options;
204 $this->callback = $callback;
205 $this->chunkSize = $chunk_size;
208 if ($this->chunkSize <= 0) {
209 $this->chunkSize = 25;
218 if ($callback && is_callable($callback)) {
219 $batch = new \ElggBatch($getter, $options, null, $chunk_size, $inc_offset);
224 $result = call_user_func($callback, $result, $getter, $options);
226 if (!isset($all_results)) {
227 if ($result ===
true || $result ===
false || $result === null) {
234 if (($result ===
true || $result ===
false || $result === null) && !is_array($all_results)) {
235 $all_results = $result && $all_results;
241 $this->callbackResult = $all_results;
250 private function getNextResultsChunk():
bool {
255 if (!isset($this->validGetter)) {
256 $this->validGetter = is_callable($this->getter);
259 if (!$this->validGetter) {
263 $limit = $this->chunkSize;
266 if ($this->limit != 0) {
267 if ($this->retrievedResults >= $this->limit) {
273 if ($this->limit < $this->chunkSize) {
274 $limit = $this->limit;
275 }
elseif ($this->retrievedResults + $this->chunkSize > $this->limit) {
277 $limit = $this->limit - $this->retrievedResults;
281 if ($this->incrementOffset) {
282 $offset = $this->offset + $this->retrievedResults;
284 $offset = $this->offset + $this->reportedFailures;
290 '__ElggBatch' => $this,
293 $options = array_merge($this->options, $current_options);
298 $this->results = call_user_func($this->getter, $options);
300 $num_results =
count($this->results);
302 if ($this->results) {
304 $this->resultIndex = 0;
306 $this->retrievedResults += $num_results;
307 if ($num_results === 0) {
310 return $this->getNextResultsChunk();
330 $this->incrementOffset = $increment;
339 $this->chunkSize =
$size;
351 $this->reportedFailures += $num;
361 #[\ReturnTypeWillChange] 363 $this->resultIndex = 0;
364 $this->retrievedResults = 0;
365 $this->processedResults = 0;
366 $this->reportedFailures = 0;
369 if ($this->chunkIndex == 0 || $this->limit > $this->chunkSize) {
370 $this->chunkIndex = 0;
371 $this->getNextResultsChunk();
378 #[\ReturnTypeWillChange] 380 return current($this->results);
386 #[\ReturnTypeWillChange] 388 return $this->processedResults;
394 #[\ReturnTypeWillChange] 397 if (($this->processedResults + 1) >= $this->limit && $this->limit > 0) {
403 if (($this->resultIndex + 1) >= $this->chunkSize) {
404 if (!$this->getNextResultsChunk()) {
413 $this->resultIndex++;
417 $this->processedResults++;
424 #[\ReturnTypeWillChange] 426 if (!is_array($this->results)) {
431 return (
$key !== null &&
$key !==
false);
444 #[\ReturnTypeWillChange] 446 if (!is_callable($this->getter)) {
447 $inspector = new \Elgg\Debug\Inspector();
448 throw new ElggRuntimeException(
'Getter is not callable: ' . $inspector->describeCallable($this->getter));
451 $options = array_merge($this->options, [
'count' =>
true]);
453 return call_user_func($this->getter, $options);
__construct(callable $getter, array $options, $callback=null, int $chunk_size=25, bool $inc_offset=true)
Batches operations on any elgg_get_*() or compatible function that supports an options array...
c Accompany it with the information you received as to the offer to distribute corresponding source complete source code means all the source code for all modules it plus any associated interface definition plus the scripts used to control compilation and installation of the executable as a special the source code distributed need not include anything that is normally and so on of the operating system on which the executable unless that component itself accompanies the executable If distribution of executable or object code is made by offering access to copy from a designated then offering equivalent access to copy the source code from the same place counts as distribution of the source even though third parties are not compelled to copy the source along with the object code You may not or distribute the Program except as expressly provided under this License Any attempt otherwise to sublicense or distribute the Program is void
if($item instanceof\ElggEntity) elseif($item instanceof\ElggRiverItem) elseif($item instanceof\ElggRelationship) elseif(is_callable([$item, 'getType']))
elgg_extract($key, $array, $default=null, bool $strict=true)
Checks for $array[$key] and returns its value if it exists, else returns $default.
rewind()
Implements Iterator.
setIncrementOffset(bool $increment=true)
Increment the offset from the original options array? Setting to false is required for callbacks that...
reportFailure(int $num=1)
Report a number of failures during the batch execution, this will increase the internal offset by $nu...
setChunkSize(int $size=25)
Set chunk size.
count()
Count the total results available at this moment.
if($container instanceof ElggGroup &&$container->guid!=elgg_get_page_owner_guid()) $key
_elgg_services()
Get the global service provider.