public function OpignoMessageThreadsSorting::query in Opigno messaging 3.x
Called to add the sort to a query.
Overrides SortPluginBase::query
File
- src/
Plugin/ views/ sort/ OpignoMessageThreadsSorting.php, line 77
Class
- OpignoMessageThreadsSorting
- Custom threads sorting handler: display the current one first, then others.
Namespace
Drupal\opigno_messaging\Plugin\views\sortCode
public function query() {
$this
->ensureMyTable();
$order = $this->options['order'];
// If the user is on the single thread page, the current thread should
// always be displayed at the top.
// The pager is working with ajax, so need to get the thread from the
// referer.
if ($this->request instanceof Request && $this->request
->isXmlHttpRequest()) {
$route = $this->request->server
->get('HTTP_REFERER');
$route_info = $this->router
->match($route);
$params = $route_info['_raw_variables'] ?? NULL;
$thread = $params instanceof ParameterBag ? $params
->get('private_message_thread') : NULL;
}
else {
$thread = $this->routeMatch
->getRawParameter('private_message_thread');
}
if ($thread) {
$this->query
->addOrderBy(NULL, "FIELD({$this->tableAlias}.id, {$thread})", $order, 'current_thread');
}
// Default sort by the last update.
$this->query
->addOrderBy(NULL, "{$this->tableAlias}.{$this->realField}", $order, 'by_date');
}