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;
use Drupal\node\Entity\Node;
use Drupal\simplify_menu\MenuItems;
use Drupal\path_alias\AliasManager;
use Symfony\Component\HttpFoundation\RequestStack;
/**
* Class UWService.
......@@ -49,6 +50,13 @@ class UWService implements UWServiceInterface {
*/
private $pathAliasManager;
/**
* The request stack.
*
* @var \Symfony\Component\HttpFoundation\RequestStack
*/
private $requestStack;
/**
* Default constructor.
*
......@@ -60,12 +68,15 @@ class UWService implements UWServiceInterface {
* The simplify_menu menu items.
* @param \Drupal\path_alias\AliasManager $pathAliasManager
* 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->database = $database;
$this->simplifyMenu = $simplifyMenu;
$this->pathAliasManager = $pathAliasManager;
$this->requestStack = $requestStack;
}
/**
......@@ -607,41 +618,63 @@ class UWService implements UWServiceInterface {
// Get all the dates.
$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
// out correct values.
foreach ($dates as $date) {
// The all day case, duration is always 1439.
if ($date['duration'] == '1439' && $date['end_value'] > strtotime("now")) {
$return_dates[] = date('l, F j, Y', $date['value']) . ' (all day)';
// Ensure that the dates are greater than timestamp
// that we generated above.
if ($date['end_value'] > $check_date) {
$return_dates[] = $this->UwGetDate($date, 'event');
}
else {
}
}
// If the date is upcoming, meaning greater than right now.
// 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']);
}
return $return_dates;
}
// 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']);
}
/**
* {@inheritDoc}
*/
public function uwGetDate(array $date, string $type): string {
// Add the start and end date with timezone.
$return_dates[] = $start_date . ' - ' . $end_date . ' ' . date('T', $date['end_value']);
// }
}
// The all day case, duration is always 1439.
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 {
*/
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.
*
......
......@@ -4,7 +4,7 @@ services:
arguments: ['@config.factory', '@current_user']
uw_cfg_common.uw_service:
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:
class: Drupal\uw_cfg_common\Routing\UwNodeAccessRouteSubscriber
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