You are here

class PushNotificationsTokenQuery in Push Notifications 8

Hierarchy

Expanded class hierarchy of PushNotificationsTokenQuery

1 file declares its use of PushNotificationsTokenQuery
PushNotificationForm.php in src/Form/PushNotificationForm.php
Contains Drupal\push_notifications\Form\PushNotificationForm.
1 string reference to 'PushNotificationsTokenQuery'
push_notifications.services.yml in ./push_notifications.services.yml
push_notifications.services.yml
1 service uses PushNotificationsTokenQuery
push_notifications.token_query in ./push_notifications.services.yml
Drupal\push_notifications\PushNotificationsTokenQuery

File

src/PushNotificationsTokenQuery.php, line 14
Contains Drupal\push_notifications\PushNotificationsTokenQuery.

Namespace

Drupal\push_notifications
View source
class PushNotificationsTokenQuery {

  /**
   * @var \Drupal\Core\Entity\Query\QueryFactory
   */
  protected $entity_query;

  /**
   * @var \Drupal\Core\Entity\EntityManagerInterface
   */
  protected $entityManager;

  /**
   * PushNotificationsTokenQuery constructor.
   *
   * @param \Drupal\Core\Entity\Query\QueryFactory $entity_query
   * @param \Drupal\Core\Entity\EntityManagerInterface $entityManager
   */
  public function __construct(QueryFactory $entity_query, EntityManagerInterface $entityManager) {
    $this->entity_query = $entity_query;
    $this->entityManager = $entityManager;
  }

  /**
   * @param \Symfony\Component\DependencyInjection\ContainerInterface $container
   * @return static
   */
  public static function create(ContainerInterface $container) {
    return new static($container
      ->get('entity.query'), $container
      ->get('entity.manager'));
  }

  /**
   * Get the push notification tokens by user ID.
   *
   * @param array $uids
   *   User IDs.
   * @return array|null
   */
  public function getTokensByUid($uids) {
    if (!is_array($uids)) {
      return NULL;
    }
    $push_notifications_token_storage = $this->entityManager
      ->getStorage('push_notifications_token');
    $push_notifications_token = $push_notifications_token_storage
      ->loadByProperties(array(
      'uid' => $uids,
    ));
    $tokens = array();
    foreach ($push_notifications_token as $pid => $push_notification_token) {
      array_push($tokens, $push_notification_token
        ->getToken());
    }
    return $tokens;
  }

  /**
   * Get the push notification tokens by network.
   *
   * @param array $networks
   *   Push Networks.
   * @return array|null
   */
  public function getTokensByNetwork($networks) {
    if (!is_array($networks)) {
      return NULL;
    }
    $push_notifications_token_storage = $this->entityManager
      ->getStorage('push_notifications_token');
    $push_notifications_token = $push_notifications_token_storage
      ->loadByProperties(array(
      'network' => $networks,
    ));

    // Retrieve all tokens into array.
    $tokens = array();
    foreach ($push_notifications_token as $pid => $push_notification_token) {
      array_push($tokens, $push_notification_token
        ->getToken());
    }
    return $tokens;
  }

  /**
   * Get all the push notification tokens.
   *
   * @return array
   */
  public function getAllTokens() {
    $push_notifications_token_storage = $this->entityManager
      ->getStorage('push_notifications_token');
    $push_notifications_token = $push_notifications_token_storage
      ->loadMultiple();

    // Retrieve all tokens into array.
    $tokens = array();
    foreach ($push_notifications_token as $pid => $push_notification_token) {
      array_push($tokens, $push_notification_token
        ->getToken());
    }
    return $tokens;
  }

}

Members

Namesort descending Modifiers Type Description Overrides
PushNotificationsTokenQuery::$entityManager protected property
PushNotificationsTokenQuery::$entity_query protected property
PushNotificationsTokenQuery::create public static function
PushNotificationsTokenQuery::getAllTokens public function Get all the push notification tokens.
PushNotificationsTokenQuery::getTokensByNetwork public function Get the push notification tokens by network.
PushNotificationsTokenQuery::getTokensByUid public function Get the push notification tokens by user ID.
PushNotificationsTokenQuery::__construct public function PushNotificationsTokenQuery constructor.