Skip to content
Snippets Groups Projects
Commit 2675b7f1 authored by Owen Bush's avatar Owen Bush Committed by Owen Bush
Browse files

Issue #3150719 by owenbush, tylvis, MrPaulDriver, the_glitch: Hide an Event with full registrations

parent d483025b
No related branches found
No related tags found
No related merge requests found
Showing
with 693 additions and 6 deletions
...@@ -110,7 +110,7 @@ function recurring_events_registration_update_8003() { ...@@ -110,7 +110,7 @@ function recurring_events_registration_update_8003() {
]; ];
$reg_field_mappings = [ $reg_field_mappings = [
'event_registration__time_amount' =>'event_registration__instance_schedule_open_amount', 'event_registration__time_amount' => 'event_registration__instance_schedule_open_amount',
'event_registration__time_type' => 'event_registration__instance_schedule_open_units', 'event_registration__time_type' => 'event_registration__instance_schedule_open_units',
]; ];
......
...@@ -11,4 +11,60 @@ ...@@ -11,4 +11,60 @@
function recurring_events_registration_views_data_alter(array &$data) { function recurring_events_registration_views_data_alter(array &$data) {
// Set the default field for a view based on registrants. // Set the default field for a view based on registrants.
$data['registrant']['table']['base']['defaults']['field'] = 'email'; $data['registrant']['table']['base']['defaults']['field'] = 'email';
$data['eventinstance_field_data']['registration_availability'] = [
'title' => t('Registration Availability'),
'field' => [
'title' => t('Registration Availability'),
'help' => t('The number of registration spaces available for an event instance.'),
'field' => 'event_registration__capacity',
'id' => 'eventinstance_registration_availability',
],
'filter' => [
'title' => t('Registration Availability'),
'help' => t('Whether the event instance has availability.'),
'field' => 'event_registration__capacity',
'id' => 'eventinstance_registration_availability',
],
];
$data['eventinstance_field_data']['capacity'] = [
'title' => t('Capacity'),
'field' => [
'title' => t('Capacity'),
'help' => t('The number of registration spaces available for an event instance'),
'id' => 'eventinstance_capacity',
],
];
$data['eventinstance_field_data']['registration_count'] = [
'title' => t('Registration Count'),
'field' => [
'title' => t('Registration Count'),
'help' => t('The number of registrations for an event instance.'),
'id' => 'eventinstance_registration_count',
],
];
$data['eventinstance_field_data']['waitlist_count'] = [
'title' => t('Waitlist Count'),
'field' => [
'title' => t('Waitlist Count'),
'help' => t('The number of waitlisted registrants for an event instance.'),
'id' => 'eventinstance_waitlist_count',
],
];
// We do not want people adding the event_registration__ fields to views as
// they will not work. Instead for any fields necessary we create them above.
foreach ($data['eventseries_field_data'] as $field_name => $field) {
if (strpos($field_name, 'event_registration__') === 0) {
unset($data['eventseries_field_data'][$field_name]);
}
}
foreach ($data['eventseries_field_revision'] as $field_name => $field) {
if (strpos($field_name, 'event_registration__') === 0) {
unset($data['eventseries_field_revision'][$field_name]);
}
}
} }
...@@ -12,6 +12,7 @@ use Symfony\Component\DependencyInjection\ContainerInterface; ...@@ -12,6 +12,7 @@ use Symfony\Component\DependencyInjection\ContainerInterface;
use Drupal\Core\Messenger\Messenger; use Drupal\Core\Messenger\Messenger;
use Drupal\Core\Render\Renderer; use Drupal\Core\Render\Renderer;
use Drupal\recurring_events_registration\RegistrationCreationService; use Drupal\recurring_events_registration\RegistrationCreationService;
use Drupal\Core\Cache\CacheTagsInvalidatorInterface;
/** /**
* Provides a form for deleting Registrant entities. * Provides a form for deleting Registrant entities.
...@@ -41,6 +42,13 @@ class RegistrantDeleteForm extends ContentEntityDeleteForm { ...@@ -41,6 +42,13 @@ class RegistrantDeleteForm extends ContentEntityDeleteForm {
*/ */
protected $creationService; protected $creationService;
/**
* The cache tags invalidator.
*
* @var \Drupal\Core\Cache\CacheTagsInvalidatorInterface
*/
protected $cacheTagsInvalidator;
/** /**
* Constructs a RegistrantDeleteForm object. * Constructs a RegistrantDeleteForm object.
* *
...@@ -56,12 +64,15 @@ class RegistrantDeleteForm extends ContentEntityDeleteForm { ...@@ -56,12 +64,15 @@ class RegistrantDeleteForm extends ContentEntityDeleteForm {
* The renderer service. * The renderer service.
* @param \Drupal\recurring_events_registration\RegistrationCreationService $creation_service * @param \Drupal\recurring_events_registration\RegistrationCreationService $creation_service
* The creation service. * The creation service.
* @param \Drupal\Core\Cache\CacheTagsInvalidatorInterface $cache_tags_invalidator
* The cache tags invalidator.
*/ */
public function __construct(EntityRepositoryInterface $entity_repository, EntityTypeBundleInfoInterface $entity_type_bundle_info = NULL, TimeInterface $time = NULL, Messenger $messenger, Renderer $renderer, RegistrationCreationService $creation_service) { public function __construct(EntityRepositoryInterface $entity_repository, EntityTypeBundleInfoInterface $entity_type_bundle_info = NULL, TimeInterface $time = NULL, Messenger $messenger, Renderer $renderer, RegistrationCreationService $creation_service, CacheTagsInvalidatorInterface $cache_tags_invalidator) {
parent::__construct($entity_repository, $entity_type_bundle_info, $time); parent::__construct($entity_repository, $entity_type_bundle_info, $time);
$this->messenger = $messenger; $this->messenger = $messenger;
$this->renderer = $renderer; $this->renderer = $renderer;
$this->creationService = $creation_service; $this->creationService = $creation_service;
$this->cacheTagsInvalidator = $cache_tags_invalidator;
} }
/** /**
...@@ -74,7 +85,8 @@ class RegistrantDeleteForm extends ContentEntityDeleteForm { ...@@ -74,7 +85,8 @@ class RegistrantDeleteForm extends ContentEntityDeleteForm {
$container->get('datetime.time'), $container->get('datetime.time'),
$container->get('messenger'), $container->get('messenger'),
$container->get('renderer'), $container->get('renderer'),
$container->get('recurring_events_registration.creation_service') $container->get('recurring_events_registration.creation_service'),
$container->get('cache_tags.invalidator')
); );
} }
...@@ -146,6 +158,7 @@ class RegistrantDeleteForm extends ContentEntityDeleteForm { ...@@ -146,6 +158,7 @@ class RegistrantDeleteForm extends ContentEntityDeleteForm {
$entity = $this->entity; $entity = $this->entity;
$entity->delete(); $entity->delete();
$eventinstance = $entity->getEventInstance(); $eventinstance = $entity->getEventInstance();
$eventseries = $entity->getEventSeries();
$form_state->setRedirectUrl($eventinstance->toUrl('canonical')); $form_state->setRedirectUrl($eventinstance->toUrl('canonical'));
...@@ -156,6 +169,20 @@ class RegistrantDeleteForm extends ContentEntityDeleteForm { ...@@ -156,6 +169,20 @@ class RegistrantDeleteForm extends ContentEntityDeleteForm {
$this->messenger->addMessage($this->getDeletionMessage()); $this->messenger->addMessage($this->getDeletionMessage());
$this->logDeletionMessage(); $this->logDeletionMessage();
// Invalidate tags to ensure that views count fields are updated.
$tags = [];
switch ($this->creationService->getRegistrationType()) {
case 'series':
$tags[] = 'eventseries:' . $eventseries->id();
break;
case 'instance':
default:
$tags[] = 'eventinstance:' . $eventinstance->id();
break;
}
$this->cacheTagsInvalidator->invalidateTags($tags);
} }
/** /**
......
...@@ -13,6 +13,7 @@ use Drupal\Core\Config\ConfigFactory; ...@@ -13,6 +13,7 @@ use Drupal\Core\Config\ConfigFactory;
use Drupal\Core\Entity\EntityFieldManager; use Drupal\Core\Entity\EntityFieldManager;
use Drupal\Core\Routing\RouteMatchInterface; use Drupal\Core\Routing\RouteMatchInterface;
use Drupal\Core\Entity\EntityTypeManagerInterface; use Drupal\Core\Entity\EntityTypeManagerInterface;
use Drupal\Core\Cache\CacheTagsInvalidatorInterface;
/** /**
* Form controller for Registrant edit forms. * Form controller for Registrant edit forms.
...@@ -70,6 +71,13 @@ class RegistrantForm extends ContentEntityForm { ...@@ -70,6 +71,13 @@ class RegistrantForm extends ContentEntityForm {
*/ */
protected $entityTypeManager; protected $entityTypeManager;
/**
* The cache tags invalidator.
*
* @var \Drupal\Core\Cache\CacheTagsInvalidatorInterface
*/
protected $cacheTagsInvalidator;
/** /**
* {@inheritdoc} * {@inheritdoc}
*/ */
...@@ -82,7 +90,8 @@ class RegistrantForm extends ContentEntityForm { ...@@ -82,7 +90,8 @@ class RegistrantForm extends ContentEntityForm {
$container->get('config.factory'), $container->get('config.factory'),
$container->get('entity_field.manager'), $container->get('entity_field.manager'),
$container->get('current_route_match'), $container->get('current_route_match'),
$container->get('entity_type.manager') $container->get('entity_type.manager'),
$container->get('cache_tags.invalidator')
); );
} }
...@@ -105,6 +114,8 @@ class RegistrantForm extends ContentEntityForm { ...@@ -105,6 +114,8 @@ class RegistrantForm extends ContentEntityForm {
* The route match service. * The route match service.
* @param \Drupal\Core\Entity\EntityTypeManagerInterface $entity_type_manager * @param \Drupal\Core\Entity\EntityTypeManagerInterface $entity_type_manager
* The entity type manager service. * The entity type manager service.
* @param \Drupal\Core\Cache\CacheTagsInvalidatorInterface $cache_tags_invalidator
* The cache tags invalidator.
*/ */
public function __construct( public function __construct(
EntityRepositoryInterface $entity_repository, EntityRepositoryInterface $entity_repository,
...@@ -114,7 +125,8 @@ class RegistrantForm extends ContentEntityForm { ...@@ -114,7 +125,8 @@ class RegistrantForm extends ContentEntityForm {
ConfigFactory $config, ConfigFactory $config,
EntityFieldManager $field_manager, EntityFieldManager $field_manager,
RouteMatchInterface $route_match, RouteMatchInterface $route_match,
EntityTypeManagerInterface $entity_type_manager) { EntityTypeManagerInterface $entity_type_manager,
CacheTagsInvalidatorInterface $cache_tags_invalidator) {
$this->messenger = $messenger; $this->messenger = $messenger;
$this->creationService = $creation_service; $this->creationService = $creation_service;
$this->currentUser = $current_user; $this->currentUser = $current_user;
...@@ -122,6 +134,7 @@ class RegistrantForm extends ContentEntityForm { ...@@ -122,6 +134,7 @@ class RegistrantForm extends ContentEntityForm {
$this->fieldManager = $field_manager; $this->fieldManager = $field_manager;
$this->routeMatch = $route_match; $this->routeMatch = $route_match;
$this->entityTypeManager = $entity_type_manager; $this->entityTypeManager = $entity_type_manager;
$this->cacheTagsInvalidator = $cache_tags_invalidator;
parent::__construct($entity_repository); parent::__construct($entity_repository);
} }
...@@ -191,7 +204,7 @@ class RegistrantForm extends ContentEntityForm { ...@@ -191,7 +204,7 @@ class RegistrantForm extends ContentEntityForm {
'title' => [ 'title' => [
'#type' => 'markup', '#type' => 'markup',
'#prefix' => '<h3 class="registration-notice-title">', '#prefix' => '<h3 class="registration-notice-title">',
'#markup' => $this->t('We cannot complete your registration.'), '#markup' => $this->t('Registration full.'),
'#suffix' => '</h3>', '#suffix' => '</h3>',
], ],
'message' => [ 'message' => [
...@@ -408,6 +421,20 @@ class RegistrantForm extends ContentEntityForm { ...@@ -408,6 +421,20 @@ class RegistrantForm extends ContentEntityForm {
} }
$this->messenger->addMessage($message); $this->messenger->addMessage($message);
// Invalidate tags to ensure that views count fields are updated.
$tags = [];
switch ($this->creationService->getRegistrationType()) {
case 'series':
$tags[] = 'eventseries:' . $event_series->id();
break;
case 'instance':
default:
$tags[] = 'eventinstance:' . $event_instance->id();
break;
}
$this->cacheTagsInvalidator->invalidateTags($tags);
} }
else { else {
$this->messenger->addMessage($this->t('Unfortunately, registration is not available at this time.')); $this->messenger->addMessage($this->t('Unfortunately, registration is not available at this time.'));
......
<?php
namespace Drupal\recurring_events_registration\Plugin\views\field;
use Drupal\views\Plugin\views\field\FieldPluginBase;
use Drupal\views\ResultRow;
use Symfony\Component\DependencyInjection\ContainerInterface;
use Drupal\recurring_events_registration\RegistrationCreationService;
/**
* Field handler to show the availability of registrations for event instances.
*
* @ingroup views_field_handlers
*
* @ViewsField("eventinstance_capacity")
*/
class EventInstanceCapacity extends FieldPluginBase {
/**
* The registration creation service.
*
* @var \Drupal\recurring_events_registration\RegistrationCreationService
*/
protected $registrationCreationService;
/**
* Constructs a new EventInstanceCapacity object.
*
* @param array $configuration
* A configuration array containing information about the plugin instance.
* @param string $plugin_id
* The plugin ID for the plugin instance.
* @param mixed $plugin_definition
* The plugin implementation definition.
* @param \Drupal\recurring_events_registration\RegistrationCreationService $registration_creation_service
* The registration creation service.
*
* @throws \Drupal\Component\Plugin\Exception\InvalidPluginDefinitionException
*/
public function __construct(array $configuration, $plugin_id, $plugin_definition, RegistrationCreationService $registration_creation_service) {
parent::__construct($configuration, $plugin_id, $plugin_definition);
$this->registrationCreationService = $registration_creation_service;
}
/**
* {@inheritdoc}
*/
public static function create(ContainerInterface $container, array $configuration, $plugin_id, $plugin_definition) {
return new static(
$configuration,
$plugin_id,
$plugin_definition,
$container->get('recurring_events_registration.creation_service')
);
}
/**
* {@inheritdoc}
*/
public function query() {
// Leave empty to avoid a query on this field.
}
/**
* {@inheritdoc}
*/
public function render(ResultRow $values) {
$event = $values->_entity;
$this->registrationCreationService->setEventInstance($event);
$capacity = (int) $this->registrationCreationService->getEventSeries()->event_registration->capacity;
if ($capacity === -1) {
$capacity = $this->t('Unlimited');
}
return $capacity;
}
}
<?php
namespace Drupal\recurring_events_registration\Plugin\views\field;
use Drupal\views\Plugin\views\field\FieldPluginBase;
use Drupal\views\ResultRow;
use Symfony\Component\DependencyInjection\ContainerInterface;
use Drupal\recurring_events_registration\RegistrationCreationService;
/**
* Field handler to show the availability of registrations for event instances.
*
* @ingroup views_field_handlers
*
* @ViewsField("eventinstance_registration_availability")
*/
class EventInstanceRegistrationAvailability extends FieldPluginBase {
/**
* The registration creation service.
*
* @var \Drupal\recurring_events_registration\RegistrationCreationService
*/
protected $registrationCreationService;
/**
* Constructs a new EventInstanceRegistrationAvailability object.
*
* @param array $configuration
* A configuration array containing information about the plugin instance.
* @param string $plugin_id
* The plugin ID for the plugin instance.
* @param mixed $plugin_definition
* The plugin implementation definition.
* @param \Drupal\recurring_events_registration\RegistrationCreationService $registration_creation_service
* The registration creation service.
*
* @throws \Drupal\Component\Plugin\Exception\InvalidPluginDefinitionException
*/
public function __construct(array $configuration, $plugin_id, $plugin_definition, RegistrationCreationService $registration_creation_service) {
parent::__construct($configuration, $plugin_id, $plugin_definition);
$this->registrationCreationService = $registration_creation_service;
}
/**
* {@inheritdoc}
*/
public static function create(ContainerInterface $container, array $configuration, $plugin_id, $plugin_definition) {
return new static(
$configuration,
$plugin_id,
$plugin_definition,
$container->get('recurring_events_registration.creation_service')
);
}
/**
* {@inheritdoc}
*/
public function query() {
// Leave empty to avoid a query on this field.
}
/**
* {@inheritdoc}
*/
public function render(ResultRow $values) {
$event = $values->_entity;
$this->registrationCreationService->setEventInstance($event);
$capacity = (int) $this->registrationCreationService->retrieveAvailability();
if ($capacity === -1) {
$capacity = $this->t('Unlimited');
}
return $capacity;
}
}
<?php
namespace Drupal\recurring_events_registration\Plugin\views\field;
use Drupal\views\Plugin\views\field\FieldPluginBase;
use Drupal\views\ResultRow;
use Symfony\Component\DependencyInjection\ContainerInterface;
use Drupal\recurring_events_registration\RegistrationCreationService;
/**
* Field handler to show the count of registrations for event instances.
*
* @ingroup views_field_handlers
*
* @ViewsField("eventinstance_registration_count")
*/
class EventInstanceRegistrationCount extends FieldPluginBase {
/**
* The registration creation service.
*
* @var \Drupal\recurring_events_registration\RegistrationCreationService
*/
protected $registrationCreationService;
/**
* Constructs a new EventInstanceRegistrationCount object.
*
* @param array $configuration
* A configuration array containing information about the plugin instance.
* @param string $plugin_id
* The plugin ID for the plugin instance.
* @param mixed $plugin_definition
* The plugin implementation definition.
* @param \Drupal\recurring_events_registration\RegistrationCreationService $registration_creation_service
* The registration creation service.
*
* @throws \Drupal\Component\Plugin\Exception\InvalidPluginDefinitionException
*/
public function __construct(array $configuration, $plugin_id, $plugin_definition, RegistrationCreationService $registration_creation_service) {
parent::__construct($configuration, $plugin_id, $plugin_definition);
$this->registrationCreationService = $registration_creation_service;
}
/**
* {@inheritdoc}
*/
public static function create(ContainerInterface $container, array $configuration, $plugin_id, $plugin_definition) {
return new static(
$configuration,
$plugin_id,
$plugin_definition,
$container->get('recurring_events_registration.creation_service')
);
}
/**
* {@inheritdoc}
*/
public function query() {
// Leave empty to avoid a query on this field.
}
/**
* {@inheritdoc}
*/
public function render(ResultRow $values) {
$event = $values->_entity;
$this->registrationCreationService->setEventInstance($event);
return count($this->registrationCreationService->retrieveRegisteredParties(TRUE, FALSE));
}
}
<?php
namespace Drupal\recurring_events_registration\Plugin\views\field;
use Drupal\views\Plugin\views\field\FieldPluginBase;
use Drupal\views\ResultRow;
use Symfony\Component\DependencyInjection\ContainerInterface;
use Drupal\recurring_events_registration\RegistrationCreationService;
/**
* Field handler to show the count of waitlisted registrants.
*
* @ingroup views_field_handlers
*
* @ViewsField("eventinstance_waitlist_count")
*/
class EventInstanceWaitlistCount extends FieldPluginBase {
/**
* The registration creation service.
*
* @var \Drupal\recurring_events_registration\RegistrationCreationService
*/
protected $registrationCreationService;
/**
* Constructs a new EventInstanceWaitlistCount object.
*
* @param array $configuration
* A configuration array containing information about the plugin instance.
* @param string $plugin_id
* The plugin ID for the plugin instance.
* @param mixed $plugin_definition
* The plugin implementation definition.
* @param \Drupal\recurring_events_registration\RegistrationCreationService $registration_creation_service
* The registration creation service.
*
* @throws \Drupal\Component\Plugin\Exception\InvalidPluginDefinitionException
*/
public function __construct(array $configuration, $plugin_id, $plugin_definition, RegistrationCreationService $registration_creation_service) {
parent::__construct($configuration, $plugin_id, $plugin_definition);
$this->registrationCreationService = $registration_creation_service;
}
/**
* {@inheritdoc}
*/
public static function create(ContainerInterface $container, array $configuration, $plugin_id, $plugin_definition) {
return new static(
$configuration,
$plugin_id,
$plugin_definition,
$container->get('recurring_events_registration.creation_service')
);
}
/**
* {@inheritdoc}
*/
public function query() {
// Leave empty to avoid a query on this field.
}
/**
* {@inheritdoc}
*/
public function render(ResultRow $values) {
$event = $values->_entity;
$this->registrationCreationService->setEventInstance($event);
return count($this->registrationCreationService->retrieveRegisteredParties(FALSE, TRUE));
}
}
<?php
namespace Drupal\recurring_events_registration\Plugin\views\filter;
use Drupal\views\Plugin\views\filter\FilterPluginBase;
use Drupal\Core\Form\FormStateInterface;
use Symfony\Component\DependencyInjection\ContainerInterface;
use Drupal\recurring_events_registration\RegistrationCreationService;
/**
* Filter handler to show the availability of registrations for event instances.
*
* @ingroup views_filter_handlers
*
* @ViewsFilter("eventinstance_registration_availability")
*/
class EventInstanceRegistrationAvailability extends FilterPluginBase {
/**
* The registration creation service.
*
* @var \Drupal\recurring_events_registration\RegistrationCreationService
*/
protected $registrationCreationService;
/**
* Constructs a new EventInstanceRegistrationAvailability object.
*
* @param array $configuration
* A configuration array containing information about the plugin instance.
* @param string $plugin_id
* The plugin ID for the plugin instance.
* @param mixed $plugin_definition
* The plugin implementation definition.
* @param \Drupal\recurring_events_registration\RegistrationCreationService $registration_creation_service
* The registration creation service.
*
* @throws \Drupal\Component\Plugin\Exception\InvalidPluginDefinitionException
*/
public function __construct(array $configuration, $plugin_id, $plugin_definition, RegistrationCreationService $registration_creation_service) {
parent::__construct($configuration, $plugin_id, $plugin_definition);
$this->registrationCreationService = $registration_creation_service;
}
/**
* {@inheritdoc}
*/
public static function create(ContainerInterface $container, array $configuration, $plugin_id, $plugin_definition) {
return new static(
$configuration,
$plugin_id,
$plugin_definition,
$container->get('recurring_events_registration.creation_service')
);
}
/**
* {@inheritdoc}
*/
public function canExpose() {
return TRUE;
}
/**
* {@inheritdoc}
*/
protected function canBuildGroup() {
return FALSE;
}
/**
* {@inheritdoc}
*/
public function adminSummary() {
if ($this->isAGroup()) {
return $this->t('grouped');
}
if (!empty($this->options['exposed'])) {
return $this->t('exposed');
}
return $this->options['value'];
}
/**
* {@inheritdoc}
*/
protected function defineOptions() {
$options = parent::defineOptions();
$options['available'] = [
'default' => 'available',
];
return $options;
}
/**
* {@inheritdoc}
*/
public function getValueOptions() {
if (isset($this->valueOptions)) {
return $this->valueOptions;
}
$this->valueOptions = [
'available' => $this->t('Spaces Available'),
'full' => $this->t('Event Full'),
];
return $this->valueOptions;
}
/**
* {@inheritdoc}
*/
public function buildOptionsForm(&$form, FormStateInterface $form_state) {
parent::buildOptionsForm($form, $form_state);
$default_value = (array) $this->value;
$exposed = $form_state->get('exposed');
if ($exposed) {
if (empty($default_value)) {
$keys = array_keys($this->getValueOptions());
$default_value = array_shift($keys);
}
else {
$copy = $default_value;
$default_value = array_shift($copy);
}
}
if (!$this->isExposed()) {
$form['value'] = [
'#title' => $this->t('Availability.'),
'#type' => 'select',
'#options' => $this->getValueOptions(),
'#default_value' => $default_value,
];
}
}
/**
* {@inheritdoc}
*/
public function valueForm(&$form, FormStateInterface $form_state) {
parent::valueForm($form, $form_state);
$default_value = (array) $this->value;
$exposed = $form_state->get('exposed');
if ($exposed) {
if (empty($default_value)) {
$keys = array_keys($this->getValueOptions());
$default_value = array_shift($keys);
}
else {
$copy = $default_value;
$default_value = array_shift($copy);
}
}
if ($this->isExposed()) {
$form['value'] = [
'#title' => $this->t('Availability.'),
'#type' => 'select',
'#options' => $this->getValueOptions(),
'#default_value' => $default_value,
];
}
}
/**
* {@inheritdoc}
*/
public function query() {
// Set -1 as the default value so that if no events match the checks, then
// we should get no results, rather than all results.
$items = ['-1'];
$table = $this->ensureMyTable();
// Grab the current view being executed.
$view = clone $this->query->view;
$filters = $view->filter;
// Remove any instances of this filter from the filters.
if (!empty($filters)) {
foreach ($filters as $key => $filter) {
if ($filter instanceof EventInstanceRegistrationAvailability) {
unset($view->filter[$key]);
}
}
}
// Execute the current view with the filters removed, so we can reduce the
// number of event instances we need to examine to find their availability.
// This makes the query more efficient and avoids having to do messy union
// selects across multiple tables to determine the availability of an event.
$view->preExecute();
$view->execute();
$available = $this->value;
if (is_array($available)) {
$available = reset($this->value);
}
if (!empty($view->result)) {
foreach ($view->result as $key => $result) {
$this->registrationCreationService->setEventInstance($result->_entity);
$availability = $this->registrationCreationService->retrieveAvailability();
switch ($available) {
// Filtering for available events means unlimited availability of an
// availability greater than zero.
case 'available':
if ($availability === -1 || $availability > 0) {
$items[] = $result->_entity->id();
}
break;
// Filtering for full events means an event with exactly zero
// availability.
case 'full':
if ($availability == 0) {
$items[] = $result->_entity->id();
}
break;
}
}
}
// Filter this view by the events which match the availability above.
$items = implode(',', $items);
$this->query->addWhereExpression($this->options['group'], "$table.id IN (" . $items . ")");
}
}
...@@ -146,6 +146,26 @@ class RegistrationCreationService { ...@@ -146,6 +146,26 @@ class RegistrationCreationService {
$this->eventSeries = $event_series; $this->eventSeries = $event_series;
} }
/**
* Get the event instance.
*
* @return Drupal\recurring_events\Entity\EventInstance $event_instance
* The event instance.
*/
public function getEventInstance() {
return $this->eventInstance;
}
/**
* Get the event series.
*
* @return Drupal\recurring_events\Entity\EventSeries $event_series
* The event series.
*/
public function getEventSeries() {
return $this->eventSeries;
}
/** /**
* Retreive all registered parties. * Retreive all registered parties.
* *
......
...@@ -47,4 +47,26 @@ function recurring_events_views_data_alter(array &$data) { ...@@ -47,4 +47,26 @@ function recurring_events_views_data_alter(array &$data) {
$data['eventinstance_field_data']['date__end_value']['sort']['field_name'] = 'date'; $data['eventinstance_field_data']['date__end_value']['sort']['field_name'] = 'date';
$data['eventinstance_field_data']['date__end_value']['argument']['id'] = 'datetime'; $data['eventinstance_field_data']['date__end_value']['argument']['id'] = 'datetime';
$data['eventinstance_field_data']['date__end_value']['argument']['field_name'] = 'date'; $data['eventinstance_field_data']['date__end_value']['argument']['field_name'] = 'date';
// We do not want people adding the recurrence fields to views as they will
// not work. Instead for any fields necessary we create them above.
$fields = [
'consecutive_recurring_date__',
'daily_recurring_date__',
'weekly_recurring_date__',
'monthly_recurring_date__',
];
foreach ($fields as $field) {
foreach ($data['eventseries_field_data'] as $field_name => $field_info) {
if (strpos($field_name, $field) === 0) {
unset($data['eventseries_field_data'][$field_name]);
}
}
foreach ($data['eventseries_field_revision'] as $field_name => $field_info) {
if (strpos($field_name, $field) === 0) {
unset($data['eventseries_field_revision'][$field_name]);
}
}
}
} }
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment