PushNotificationsTokenQuery.php in Push Notifications 8
File
src/PushNotificationsTokenQuery.php
View source
<?php
namespace Drupal\push_notifications;
use Drupal\Core\Entity\EntityManagerInterface;
use Drupal\Core\Entity\Query\QueryFactory;
use Symfony\Component\DependencyInjection\ContainerInterface;
class PushNotificationsTokenQuery {
protected $entity_query;
protected $entityManager;
public function __construct(QueryFactory $entity_query, EntityManagerInterface $entityManager) {
$this->entity_query = $entity_query;
$this->entityManager = $entityManager;
}
public static function create(ContainerInterface $container) {
return new static($container
->get('entity.query'), $container
->get('entity.manager'));
}
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;
}
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,
));
$tokens = array();
foreach ($push_notifications_token as $pid => $push_notification_token) {
array_push($tokens, $push_notification_token
->getToken());
}
return $tokens;
}
public function getAllTokens() {
$push_notifications_token_storage = $this->entityManager
->getStorage('push_notifications_token');
$push_notifications_token = $push_notifications_token_storage
->loadMultiple();
$tokens = array();
foreach ($push_notifications_token as $pid => $push_notification_token) {
array_push($tokens, $push_notification_token
->getToken());
}
return $tokens;
}
}