diff options
Diffstat (limited to 'library/X509/SortAdapter.php')
-rw-r--r-- | library/X509/SortAdapter.php | 46 |
1 files changed, 46 insertions, 0 deletions
diff --git a/library/X509/SortAdapter.php b/library/X509/SortAdapter.php new file mode 100644 index 0000000..5adb86b --- /dev/null +++ b/library/X509/SortAdapter.php @@ -0,0 +1,46 @@ +<?php +// Icinga Web 2 X.509 Module | (c) 2018 Icinga GmbH | GPLv2 + +namespace Icinga\Module\X509; + +use Icinga\Data\Sortable; +use ipl\Sql; + +/** + * @internal + */ +class SortAdapter implements Sortable +{ + protected $select; + + protected $callback; + + public function __construct(Sql\Select $select, \Closure $callback = null) + { + $this->select = $select; + $this->callback = $callback; + } + + public function order($field, $direction = null) + { + if ($this->callback !== null) { + $field = call_user_func($this->callback, $field) ?: $field; + } + + if ($direction === null) { + $this->select->orderBy($field); + } else { + $this->select->orderBy($field, $direction); + } + } + + public function hasOrder() + { + return $this->select->hasOrderBy(); + } + + public function getOrder() + { + return $this->select->getOrderBy(); + } +} |