Skip to content
Snippets Groups Projects
Commit 9483dbc4 authored by Igor Biki's avatar Igor Biki
Browse files

Merge branch 'feature/ISTWCMS-4917-ebremner-upcoming-dates' into '1.0.x'

Feature/istwcms 4917 ebremner upcoming dates

See merge request !118
parents 0900504e 803b7833
No related branches found
No related tags found
1 merge request!118Feature/istwcms 4917 ebremner upcoming dates
...@@ -11,6 +11,7 @@ use Drupal\Core\Url; ...@@ -11,6 +11,7 @@ use Drupal\Core\Url;
use Drupal\node\Entity\Node; use Drupal\node\Entity\Node;
use Drupal\simplify_menu\MenuItems; use Drupal\simplify_menu\MenuItems;
use Drupal\path_alias\AliasManager; use Drupal\path_alias\AliasManager;
use Symfony\Component\HttpFoundation\RequestStack;
/** /**
* Class UWService. * Class UWService.
...@@ -49,6 +50,13 @@ class UWService implements UWServiceInterface { ...@@ -49,6 +50,13 @@ class UWService implements UWServiceInterface {
*/ */
private $pathAliasManager; private $pathAliasManager;
/**
* The request stack.
*
* @var \Symfony\Component\HttpFoundation\RequestStack
*/
private $requestStack;
/** /**
* Default constructor. * Default constructor.
* *
...@@ -60,12 +68,15 @@ class UWService implements UWServiceInterface { ...@@ -60,12 +68,15 @@ class UWService implements UWServiceInterface {
* The simplify_menu menu items. * The simplify_menu menu items.
* @param \Drupal\path_alias\AliasManager $pathAliasManager * @param \Drupal\path_alias\AliasManager $pathAliasManager
* The Drupal path alias manager. * The Drupal path alias manager.
* @param \Symfony\Component\HttpFoundation\RequestStack $requestStack
* The request stack.
*/ */
public function __construct(EntityTypeManagerInterface $entityTypeManager, Connection $database, MenuItems $simplifyMenu, AliasManager $pathAliasManager) { public function __construct(EntityTypeManagerInterface $entityTypeManager, Connection $database, MenuItems $simplifyMenu, AliasManager $pathAliasManager, RequestStack $requestStack) {
$this->entityTypeManager = $entityTypeManager; $this->entityTypeManager = $entityTypeManager;
$this->database = $database; $this->database = $database;
$this->simplifyMenu = $simplifyMenu; $this->simplifyMenu = $simplifyMenu;
$this->pathAliasManager = $pathAliasManager; $this->pathAliasManager = $pathAliasManager;
$this->requestStack = $requestStack;
} }
/** /**
...@@ -607,41 +618,63 @@ class UWService implements UWServiceInterface { ...@@ -607,41 +618,63 @@ class UWService implements UWServiceInterface {
// Get all the dates. // Get all the dates.
$dates = $node->$field_name->getValue(); $dates = $node->$field_name->getValue();
// Get the date query parameter.
$date_parameter = $this->requestStack->getCurrentRequest()->query->get('date');
// If there is a date query parameter, convert
// to timestamp so we can compare against dates
// in the event. If there is no parameter, set
// the timestamp todays date.
if ($date_parameter) {
$check_date = strtotime($date_parameter['value']);
}
else {
$check_date = strtotime("now");
}
// Step through each of the dates and get // Step through each of the dates and get
// out correct values. // out correct values.
foreach ($dates as $date) { foreach ($dates as $date) {
// The all day case, duration is always 1439. // Ensure that the dates are greater than timestamp
if ($date['duration'] == '1439' && $date['end_value'] > strtotime("now")) { // that we generated above.
$return_dates[] = date('l, F j, Y', $date['value']) . ' (all day)'; if ($date['end_value'] > $check_date) {
$return_dates[] = $this->UwGetDate($date, 'event');
} }
else { }
}
// If the date is upcoming, meaning greater than right now. return $return_dates;
// Taking this out for now, will be putting it back, if }
// we figure out how to do this in the view.
// if ($date['end_value'] > strtotime("today")) {.
// If this is the same day, get the date and the start
// and end times.
if ($date['duration'] < '1439') {
$start_date = date('l, F j, Y g:i A', $date['value']);
$end_date = date('g:i A', $date['end_value']);
}
// This is not the day, get the start and end date with time. /**
else { * {@inheritDoc}
$start_date = date('l, F j, Y g:i A', $date['value']); */
$end_date = date('l, F j, Y g:i A', $date['end_value']); public function uwGetDate(array $date, string $type): string {
}
// Add the start and end date with timezone. // The all day case, duration is always 1439.
$return_dates[] = $start_date . ' - ' . $end_date . ' ' . date('T', $date['end_value']); if ($date['duration'] == '1439') {
// } $return_date = date('l, F j, Y', $date['value']) . ' (all day)';
} }
else {
// If this is the same day, get the date and the start
// and end times.
if ($date['duration'] < '1439') {
$start_date = date('l, F j, Y g:i A', $date['value']);
$end_date = date('g:i A', $date['end_value']);
}
// This is not the day, get the start and end date with time.
else {
$start_date = date('l, F j, Y g:i A', $date['value']);
$end_date = date('l, F j, Y g:i A', $date['end_value']);
} }
// Add the start and end date with timezone.
$return_date = $start_date . ' - ' . $end_date . ' ' . date('T', $date['end_value']);
} }
return $return_dates; return $return_date;
} }
/** /**
......
...@@ -93,6 +93,19 @@ interface UWServiceInterface { ...@@ -93,6 +93,19 @@ interface UWServiceInterface {
*/ */
public function uwGetDates(Node $node, string $field_name): array; public function uwGetDates(Node $node, string $field_name): array;
/**
* Get a date in the proper format.
*
* @param array $date
* An array of date info.
* @param string $type
* The type of date.
*
* @return string
* A converted date to a string.
*/
public function uwGetDate(array $date, string $type): string;
/** /**
* Gets image from node. * Gets image from node.
* *
......
...@@ -4,7 +4,7 @@ services: ...@@ -4,7 +4,7 @@ services:
arguments: ['@config.factory', '@current_user'] arguments: ['@config.factory', '@current_user']
uw_cfg_common.uw_service: uw_cfg_common.uw_service:
class: Drupal\uw_cfg_common\Service\UWService class: Drupal\uw_cfg_common\Service\UWService
arguments: ['@entity_type.manager', '@database', '@simplify_menu.menu_items', '@path_alias.manager'] arguments: ['@entity_type.manager', '@database', '@simplify_menu.menu_items', '@path_alias.manager', '@request_stack']
uw_cfg_common.route_subscriber: uw_cfg_common.route_subscriber:
class: Drupal\uw_cfg_common\Routing\UwNodeAccessRouteSubscriber class: Drupal\uw_cfg_common\Routing\UwNodeAccessRouteSubscriber
tags: tags:
......
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