2014-03-19 16:57:11 +01:00
|
|
|
<?php
|
2016-02-08 15:41:00 +01:00
|
|
|
/* Icinga Web 2 | (c) 2014 Icinga Development Team | GPLv2+ */
|
2014-03-19 16:57:11 +01:00
|
|
|
|
|
|
|
namespace Icinga\Protocol\File;
|
|
|
|
|
2014-05-07 13:55:35 +02:00
|
|
|
use Icinga\Data\SimpleQuery;
|
2014-07-21 14:09:40 +02:00
|
|
|
use Icinga\Data\Filter\Filter;
|
2014-03-19 16:57:11 +01:00
|
|
|
|
2014-04-02 13:23:18 +02:00
|
|
|
/**
|
2014-09-04 15:38:14 +02:00
|
|
|
* Class FileQuery
|
2014-04-02 13:23:18 +02:00
|
|
|
*
|
2014-09-04 15:29:11 +02:00
|
|
|
* Query for Datasource Icinga\Protocol\File\FileReader
|
2014-04-02 13:23:18 +02:00
|
|
|
*
|
|
|
|
* @package Icinga\Protocol\File
|
|
|
|
*/
|
2014-09-04 15:38:14 +02:00
|
|
|
class FileQuery extends SimpleQuery
|
2014-03-19 16:57:11 +01:00
|
|
|
{
|
2014-04-02 13:23:18 +02:00
|
|
|
/**
|
|
|
|
* Sort direction
|
|
|
|
*
|
|
|
|
* @var int
|
|
|
|
*/
|
2014-03-19 16:57:11 +01:00
|
|
|
private $sortDir;
|
|
|
|
|
2014-04-02 13:23:18 +02:00
|
|
|
/**
|
|
|
|
* Filters to apply on result
|
|
|
|
*
|
|
|
|
* @var array
|
|
|
|
*/
|
2014-03-19 16:57:11 +01:00
|
|
|
private $filters = array();
|
|
|
|
|
2014-04-01 16:29:09 +02:00
|
|
|
/**
|
|
|
|
* Nothing to do here
|
|
|
|
*/
|
2014-07-21 14:09:40 +02:00
|
|
|
public function applyFilter(Filter $filter)
|
2017-01-27 14:48:59 +01:00
|
|
|
{
|
|
|
|
}
|
2014-03-19 16:57:11 +01:00
|
|
|
|
2014-04-01 16:29:09 +02:00
|
|
|
/**
|
|
|
|
* Sort query result chronological
|
|
|
|
*
|
|
|
|
* @param string $dir Sort direction, 'ASC' or 'DESC' (default)
|
|
|
|
*
|
2014-09-04 15:38:14 +02:00
|
|
|
* @return FileQuery
|
2014-04-01 16:29:09 +02:00
|
|
|
*/
|
2014-07-21 14:09:40 +02:00
|
|
|
public function order($field, $direction = null)
|
2014-03-19 16:57:11 +01:00
|
|
|
{
|
2014-07-21 14:09:40 +02:00
|
|
|
$this->sortDir = (
|
|
|
|
$direction === null || strtoupper(trim($direction)) === 'DESC'
|
|
|
|
) ? self::SORT_DESC : self::SORT_ASC;
|
2014-03-19 16:57:11 +01:00
|
|
|
return $this;
|
|
|
|
}
|
|
|
|
|
2014-04-01 16:29:09 +02:00
|
|
|
/**
|
|
|
|
* Return true if sorting descending, false otherwise
|
|
|
|
*
|
|
|
|
* @return bool
|
|
|
|
*/
|
2014-03-19 16:57:11 +01:00
|
|
|
public function sortDesc()
|
|
|
|
{
|
|
|
|
return $this->sortDir === self::SORT_DESC;
|
|
|
|
}
|
|
|
|
|
2014-04-01 16:29:09 +02:00
|
|
|
/**
|
|
|
|
* Add an mandatory filter expression to be applied on this query
|
|
|
|
*
|
|
|
|
* @param string $expression the filter expression to be applied
|
|
|
|
*
|
2014-09-04 15:38:14 +02:00
|
|
|
* @return FileQuery
|
2014-04-01 16:29:09 +02:00
|
|
|
*/
|
|
|
|
public function andWhere($expression)
|
2014-03-19 16:57:11 +01:00
|
|
|
{
|
|
|
|
$this->filters[] = $expression;
|
|
|
|
return $this;
|
|
|
|
}
|
|
|
|
|
2014-04-01 16:29:09 +02:00
|
|
|
/**
|
|
|
|
* Get filters currently applied on this query
|
|
|
|
*
|
|
|
|
* @return array
|
|
|
|
*/
|
2014-03-19 16:57:11 +01:00
|
|
|
public function getFilters()
|
|
|
|
{
|
|
|
|
return $this->filters;
|
|
|
|
}
|
2014-07-21 14:09:40 +02:00
|
|
|
}
|