You are here

protected static function BrightcoveSubscription::loadByField in Brightcove Video Connect 8.2

Same name and namespace in other branches
  1. 8 src/Entity/BrightcoveSubscription.php \Drupal\brightcove\Entity\BrightcoveSubscription::loadByField()
  2. 3.x src/Entity/BrightcoveSubscription.php \Drupal\brightcove\Entity\BrightcoveSubscription::loadByField()

Loads the entity by a given field and value.

Parameters

string $field: The name of the field.

string|int $value: The field's value that needs to be checked to get a specific subscription.

Return value

\Drupal\brightcove\Entity\BrightcoveSubscription|null The default Brightcove Subscription for the given API client or NULL if not found.

Throws

\Drupal\brightcove\Entity\Exception\BrightcoveSubscriptionException If the field is not valid.

4 calls to BrightcoveSubscription::loadByField()
BrightcoveSubscription::load in src/Entity/BrightcoveSubscription.php
Loads the entity by it's internal Drupal ID.
BrightcoveSubscription::loadByBcSid in src/Entity/BrightcoveSubscription.php
Loads entity by it's Brightcove Subscription ID.
BrightcoveSubscription::loadByEndpoint in src/Entity/BrightcoveSubscription.php
Load a Subscription by its endpoint.
BrightcoveSubscription::loadDefault in src/Entity/BrightcoveSubscription.php
Loads the default subscription by API Client ID.

File

src/Entity/BrightcoveSubscription.php, line 203

Class

BrightcoveSubscription
Defines the Brightcove Subscription entity.

Namespace

Drupal\brightcove\Entity

Code

protected static function loadByField($field, $value) {

  /** @var \Drupal\Core\Database\Connection $connection */
  $connection = \Drupal::getContainer()
    ->get('database');
  $query = $connection
    ->select('brightcove_subscription', 'bs')
    ->fields('bs');
  switch ($field) {
    case 'bcsid':
      $query
        ->condition('bs.bcsid', $value);
      break;
    case 'default':
      $query
        ->condition('bs.api_client_id', $value)
        ->condition('bs.is_default', 1);
      break;
    case 'endpoint':
      $query
        ->condition('bs.endpoint', $value);
      break;
    case 'id':
      $query
        ->condition('bs.id', $value);
      break;
    default:
      throw new BrightcoveSubscriptionException('Invalid field type.');
  }
  $result = $query
    ->execute()
    ->fetchAssoc();
  if (empty($result)) {
    $result = [];
  }
  else {

    // Unserialize events.
    $result['events'] = unserialize($result['events']);
  }
  return self::createFromArray($result);
}