You are here

function DatabaseQueue::loadPaymentIds in Payment 8.2

Loads the IDs of payments available for referencing through an instance.

Parameters

string $category_id: The ID of the field instance to load payment IDs for.

integer $owner_id: The UID of the user for whom the payment should be available.

Return value

array

Overrides QueueInterface::loadPaymentIds

File

src/DatabaseQueue.php, line 220

Class

DatabaseQueue
Provides a database-based payment queue.

Namespace

Drupal\payment

Code

function loadPaymentIds($category_id, $owner_id) {
  $allowed_payment_status_ids = [];
  foreach ($this
    ->getAllowedPaymentStatusIds() as $payment_status_id) {
    $allowed_payment_status_ids = array_merge($allowed_payment_status_ids, array(
      $payment_status_id,
    ), $this->paymentStatusManager
      ->getDescendants($payment_status_id));
  }
  if (empty($allowed_payment_status_ids)) {
    throw new \RuntimeException('There are no allowed payment statuses. Use self::setAllowedPaymentStatusIds() to set the allowed payment statuses.');
  }
  $query = $this->database
    ->select('payment_queue', 'pq');
  $query
    ->addJoin('INNER', 'payment', 'p', 'p.id = pq.payment_id');
  $query
    ->addJoin('INNER', 'payment__payment_statuses', 'p_ps', 'p.id = p_ps.entity_id AND p.current_payment_status_delta = p_ps.delta');
  $query
    ->fields('pq', array(
    'payment_id',
  ))
    ->condition('pq.category_id', $category_id)
    ->condition('p_ps.payment_statuses_plugin_id', $allowed_payment_status_ids)
    ->condition('p.owner', $owner_id)
    ->condition('pq.queue_id', $this->queueId);
  $payment_ids = $query
    ->execute()
    ->fetchCol();
  return $this->eventDispatcher
    ->alterQueueLoadedPaymentIds($this->queueId, $category_id, $owner_id, $payment_ids);
}