flux-querybuilder/src/Functions/AggregateWindow.php

49 lines
1.6 KiB
PHP
Raw Normal View History

<?php
2024-03-30 16:44:38 +01:00
namespace Hosterra\FluxBuilder\Functions;
use Hosterra\FluxBuilder\Type;
use Hosterra\FluxBuilder\Type\ArrayType;
use Hosterra\FluxBuilder\Type\CustomType;
use Hosterra\FluxBuilder\Type\DurationType;
use Hosterra\FluxBuilder\Type\FnType;
class AggregateWindow extends Base {
/**
* @var string $every
*/
private $every;
/**
* @var string $fn
*/
private $fn;
/**
* @var array $options
*/
private $options;
public function __construct( $every, $fn, array $options = [] ) {
$this->every = $every;
$this->fn = $fn;
$this->options = $options;
}
public function __toString() {
$input = new ArrayType( array_filter( [
'every' => new DurationType( $this->every ),
'period' => isset( $this->options['period'] ) ? new DurationType( $this->options['period'] ) : null,
'offset' => isset( $this->options['offset'] ) ? new DurationType( $this->options['offset'] ) : null,
'fn' => new CustomType( $this->fn ),
'location' => isset( $this->options['location'] ) ? new Type( $this->options['location'] ) : null,
'column' => isset( $this->options['column'] ) ? new Type( $this->options['column'] ) : null,
'timeSrc' => isset( $this->options['timeSrc'] ) ? new Type( $this->options['timeSrc'] ) : null,
'timeDst' => isset( $this->options['timeDst'] ) ? new Type( $this->options['timeDst'] ) : null,
'createEmpty' => isset( $this->options['createEmpty'] ) && ! $this->options['createEmpty'] ?
new Type( $this->options['createEmpty'] ) : null,
] ) );
return '|> aggregateWindow(' . $input . ') ';
}
}