Show upcoming talks in chronological order
Update the ordering of the future talks on the talks page so that upcoming talks are shown in chronological order (soonest first), followed by past talks in reverse chronological order (most recent first). This still uses the `created` date for ordering, which is updated automatically on saving the node to match the furthest future talk, but I may want to move that into a custom node property at some point. Fixes #140
This commit is contained in:
parent
b71f8cc7f8
commit
58d56220de
11 changed files with 331 additions and 7 deletions
40
web/modules/custom/opd_talks/src/Plugin/views/sort/Event.php
Normal file
40
web/modules/custom/opd_talks/src/Plugin/views/sort/Event.php
Normal file
|
@ -0,0 +1,40 @@
|
|||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace Drupal\opd_talks\Plugin\views\sort;
|
||||
|
||||
use Drupal\Core\Datetime\DrupalDateTime;
|
||||
use Drupal\datetime\DateTimeComputed;
|
||||
use Drupal\views\Plugin\views\sort\Date;
|
||||
use Drupal\views\Annotation\ViewsSort;
|
||||
|
||||
/**
|
||||
* @ViewsSort("event_sort")
|
||||
*/
|
||||
final class Event extends Date {
|
||||
|
||||
public function query() {
|
||||
$this->ensureMyTable();
|
||||
|
||||
$currentTime = time();
|
||||
$dateAlias = "$this->tableAlias.$this->realField";
|
||||
|
||||
// Is this event in the past?
|
||||
$this->query->addOrderBy(
|
||||
NULL,
|
||||
sprintf("%d > %s", $currentTime, $dateAlias),
|
||||
$this->options['order'],
|
||||
"in_past"
|
||||
);
|
||||
|
||||
// How far in the past/future is this event?
|
||||
$this->query->addOrderBy(
|
||||
NULL,
|
||||
sprintf('ABS(%s - %d)', $dateAlias, $currentTime),
|
||||
$this->options['order'],
|
||||
"distance_from_now"
|
||||
);
|
||||
}
|
||||
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue