public function MemoryQueue::selectPage in Purge 8.3
Select a page of queue data with a limited number of items.
This method facilitates end-user inspection of the queue by letting it select a set of data records, without the ability to further interact with the returned data. The items returned aren't claimed and no action is taken on them.
Parameters
int $page: Pages always start at 1 and the highest available page is returned by ::selectPageMax(), which bases its information on the set limit that in turn gets returned by selectPageLimit(). When page numbers are given without any data in it, the resulting return value will be empty.
Return value
array[] Returns a non-associative array with item objects or the array is simply empty. The objects contain at least the following properties:
- data: the same as what what passed into createItem().
- item_id: the unique ID returned from createItem().
- created: timestamp when the item was put into the queue.
Overrides QueueInterface::selectPage
See also
\Drupal\purge\Plugin\Purge\Queue\QueueInterface::selectPageLimit
\Drupal\purge\Plugin\Purge\Queue\QueueInterface::selectPageMax
File
- src/
Plugin/ Purge/ Queue/ MemoryQueue.php, line 207
Class
- MemoryQueue
- A QueueInterface compliant volatile memory buffer queue.
Namespace
Drupal\purge\Plugin\Purge\QueueCode
public function selectPage($page = 1) {
if ($page < 1 || !is_int($page)) {
throw new \LogicException('Parameter $page has to be a positive integer.');
}
$this
->bufferInitialize();
// Calculate the start and end of the IDs we're looking for and iterate.
$items = [];
$limit = $this
->selectPageLimit();
$start = ($page - 1) * $limit + 1;
$end = $page * $limit + 1;
for ($id = $start; $id < $end; $id++) {
if (!isset($this->buffer[$id])) {
break;
}
$item = new \stdClass();
$item->item_id = $id;
$item->data = unserialize($this->buffer[$id][self::DATA]);
$item->expire = $this->buffer[$id][self::EXPIRE];
$item->created = $this->buffer[$id][self::CREATED];
$items[] = $item;
}
return $items;
}