From ca6c51aef760ff8d61a1c08757b8c9268546bdb7 Mon Sep 17 00:00:00 2001 From: Eric Lippmann Date: Thu, 10 Oct 2013 11:33:41 +0200 Subject: [PATCH] Monitoring/DataView: Add static method fromParams to create a view from a parameters array refs #4823 --- .../library/Monitoring/DataView/DataView.php | 27 +++++++++++++++++++ 1 file changed, 27 insertions(+) diff --git a/modules/monitoring/library/Monitoring/DataView/DataView.php b/modules/monitoring/library/Monitoring/DataView/DataView.php index c3909255b..3ee7f285a 100644 --- a/modules/monitoring/library/Monitoring/DataView/DataView.php +++ b/modules/monitoring/library/Monitoring/DataView/DataView.php @@ -99,6 +99,33 @@ abstract class DataView return $view; } + /** + * Create view from params + * + * @param array $params + * @param array $columns + * + * @return static + */ + public static function fromParams(array $params, array $columns = null) + { + $view = new static(Backend::createBackend($params['backend']), $columns); + $view->filter($params); + $order = isset($params['order']) ? $params['order'] : null; + if ($order !== null) { + if (strtolower($order) === 'desc') { + $order = self::SORT_DESC; + } else { + $order = self::SORT_ASC; + } + } + $view->sort( + isset($params['sort']) ? $params['sort'] : null, + $order + ); + return $view; + } + /** * Filter rows that match all of the given filters. If a filter is not valid, it's silently ignored *