From ae21baa41e55e50774b4e7d42e24686bf231c25f Mon Sep 17 00:00:00 2001 From: Johannes Meyer Date: Fri, 26 Jun 2015 14:54:15 +0200 Subject: [PATCH] Sortable: Allow to check for a particular sort rule --- library/Icinga/Data/SimpleQuery.php | 18 ++++++++++++++++-- library/Icinga/Data/Sortable.php | 4 +++- library/Icinga/Repository/RepositoryQuery.php | 6 ++++-- .../library/Monitoring/DataView/DataView.php | 6 ++++-- 4 files changed, 27 insertions(+), 7 deletions(-) diff --git a/library/Icinga/Data/SimpleQuery.php b/library/Icinga/Data/SimpleQuery.php index 9751a2756..b20cb02ab 100644 --- a/library/Icinga/Data/SimpleQuery.php +++ b/library/Icinga/Data/SimpleQuery.php @@ -341,11 +341,25 @@ class SimpleQuery implements QueryInterface, Queryable, Iterator /** * Whether an order is set * + * @param string $column + * * @return bool */ - public function hasOrder() + public function hasOrder($column = null) { - return !empty($this->order); + if (empty($this->order)) { + return false; + } elseif ($column === null) { + return true; + } + + foreach ($this->order as $rule) { + if ($rule[0] === $column) { + return true; + } + } + + return false; } /** diff --git a/library/Icinga/Data/Sortable.php b/library/Icinga/Data/Sortable.php index 9c837e3d3..9f4898d8e 100644 --- a/library/Icinga/Data/Sortable.php +++ b/library/Icinga/Data/Sortable.php @@ -36,9 +36,11 @@ interface Sortable /** * Whether an order is set * + * @param string $column + * * @return bool */ - public function hasOrder(); + public function hasOrder($column = null); /** * Get the order if any diff --git a/library/Icinga/Repository/RepositoryQuery.php b/library/Icinga/Repository/RepositoryQuery.php index 79e85ff92..e1294e50f 100644 --- a/library/Icinga/Repository/RepositoryQuery.php +++ b/library/Icinga/Repository/RepositoryQuery.php @@ -315,11 +315,13 @@ class RepositoryQuery implements QueryInterface, Iterator /** * Return whether any sort rules were applied to this query * + * @param string $column + * * @return bool */ - public function hasOrder() + public function hasOrder($column = null) { - return $this->query->hasOrder(); + return $this->query->hasOrder($column); } /** diff --git a/modules/monitoring/library/Monitoring/DataView/DataView.php b/modules/monitoring/library/Monitoring/DataView/DataView.php index 0f892f42c..b472fec65 100644 --- a/modules/monitoring/library/Monitoring/DataView/DataView.php +++ b/modules/monitoring/library/Monitoring/DataView/DataView.php @@ -294,11 +294,13 @@ abstract class DataView implements QueryInterface, IteratorAggregate /** * Whether an order is set * + * @param string $column + * * @return bool */ - public function hasOrder() + public function hasOrder($column = null) { - return $this->query->hasOrder(); + return $this->query->hasOrder($column); } /**