class PushNotificationsTokenQuery in Push Notifications 8
Hierarchy
- class \Drupal\push_notifications\PushNotificationsTokenQuery
Expanded class hierarchy of PushNotificationsTokenQuery
1 file declares its use of PushNotificationsTokenQuery
1 string reference to 'PushNotificationsTokenQuery'
1 service uses PushNotificationsTokenQuery
File
- src/
PushNotificationsTokenQuery.php, line 14 - Contains Drupal\push_notifications\PushNotificationsTokenQuery.
Namespace
Drupal\push_notificationsView 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
Name | Modifiers | Type | Description | Overrides |
---|---|---|---|---|
PushNotificationsTokenQuery:: |
protected | property | ||
PushNotificationsTokenQuery:: |
protected | property | ||
PushNotificationsTokenQuery:: |
public static | function | ||
PushNotificationsTokenQuery:: |
public | function | Get all the push notification tokens. | |
PushNotificationsTokenQuery:: |
public | function | Get the push notification tokens by network. | |
PushNotificationsTokenQuery:: |
public | function | Get the push notification tokens by user ID. | |
PushNotificationsTokenQuery:: |
public | function | PushNotificationsTokenQuery constructor. |