Monitoring/DataView: Add static method fromParams to create a view from a parameters array

refs #4823
This commit is contained in:
Eric Lippmann 2013-10-10 11:33:41 +02:00
parent d479ab3536
commit ca6c51aef7
1 changed files with 27 additions and 0 deletions

View File

@ -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
*