RecipientHandlerBase.php in Simplenews 8
File
src/Plugin/simplenews/RecipientHandler/RecipientHandlerBase.php
View source
<?php
namespace Drupal\simplenews\Plugin\simplenews\RecipientHandler;
use Drupal\Core\Plugin\PluginBase;
use Drupal\simplenews\RecipientHandler\RecipientHandlerInterface;
use Drupal\simplenews\SubscriberInterface;
class RecipientHandlerBase extends PluginBase implements RecipientHandlerInterface {
public $newsletter;
public function __construct(array $configuration, $plugin_id, $plugin_definition) {
parent::__construct($configuration, $plugin_id, $plugin_definition);
$this->newsletter = $configuration['newsletter'];
}
public function buildRecipientQuery() {
$select = \Drupal::database()
->select('simplenews_subscriber', 's');
$select
->innerJoin('simplenews_subscriber__subscriptions', 't', 's.id = t.entity_id');
$select
->addField('s', 'id', 'snid');
$select
->addField('s', 'mail');
$select
->addField('t', 'subscriptions_target_id', 'newsletter_id');
$select
->condition('t.subscriptions_target_id', $this->newsletter
->id());
$select
->condition('t.subscriptions_status', SIMPLENEWS_SUBSCRIPTION_STATUS_SUBSCRIBED);
$select
->condition('s.status', SubscriberInterface::ACTIVE);
return $select;
}
public function buildRecipientCountQuery() {
return $this
->buildRecipientQuery()
->countQuery();
}
public function count() {
return $this
->buildRecipientCountQuery()
->execute()
->fetchField();
}
}