353d79911094bc0a33af911a24634eab85c55383
[yaffs-website] / web / core / modules / comment / src / Plugin / views / sort / Thread.php
1 <?php
2
3 namespace Drupal\comment\Plugin\views\sort;
4
5 use Drupal\views\Plugin\views\sort\SortPluginBase;
6
7 /**
8  * Sort handler for ordering by thread.
9  *
10  * @ingroup views_sort_handlers
11  *
12  * @ViewsSort("comment_thread")
13  */
14 class Thread extends SortPluginBase {
15
16   public function query() {
17     $this->ensureMyTable();
18
19     // See \Drupal\comment\CommentStorage::loadThread() for an explanation of
20     // the thinking behind this sort.
21     if ($this->options['order'] == 'DESC') {
22       $this->query->addOrderBy($this->tableAlias, $this->realField, $this->options['order']);
23     }
24     else {
25       $alias = $this->tableAlias . '_' . $this->realField . 'asc';
26       // @todo is this secure?
27       $this->query->addOrderBy(NULL, "SUBSTRING({$this->tableAlias}.{$this->realField}, 1, (LENGTH({$this->tableAlias}.{$this->realField}) - 1))", $this->options['order'], $alias);
28     }
29   }
30
31 }