mirror of
https://gitlab.com/Chill-Projet/chill-bundles.git
synced 2025-08-21 07:03:49 +00:00
cs: Fix code style (safe rules only).
This commit is contained in:
@@ -1,5 +1,12 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
* Chill is a software for social workers
|
||||
*
|
||||
* For the full copyright and license information, please view
|
||||
* the LICENSE file that was distributed with this source code.
|
||||
*/
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace Chill\MainBundle\Doctrine\DQL;
|
||||
@@ -8,23 +15,24 @@ use Doctrine\ORM\Query\AST\Functions\FunctionNode;
|
||||
use Doctrine\ORM\Query\AST\PathExpression;
|
||||
use Doctrine\ORM\Query\Lexer;
|
||||
use Doctrine\ORM\Query\Parser;
|
||||
use Exception;
|
||||
|
||||
/**
|
||||
* DQL function for OVERLAPS function in postgresql
|
||||
* DQL function for OVERLAPS function in postgresql.
|
||||
*
|
||||
* If a value is null in period start, it will be replaced by -infinity.
|
||||
* If a value is null in period end, it will be replaced by infinity
|
||||
*/
|
||||
class OverlapsI extends FunctionNode
|
||||
{
|
||||
private $firstPeriodStart;
|
||||
|
||||
private $firstPeriodEnd;
|
||||
|
||||
private $secondPeriodStart;
|
||||
private $firstPeriodStart;
|
||||
|
||||
private $secondPeriodEnd;
|
||||
|
||||
private $secondPeriodStart;
|
||||
|
||||
public function getSql(\Doctrine\ORM\Query\SqlWalker $sqlWalker)
|
||||
{
|
||||
return sprintf(
|
||||
@@ -36,36 +44,6 @@ class OverlapsI extends FunctionNode
|
||||
);
|
||||
}
|
||||
|
||||
protected function makeCase($sqlWalker, $part, string $position): string
|
||||
{
|
||||
switch ($position) {
|
||||
case 'start' :
|
||||
$p = '-infinity';
|
||||
break;
|
||||
case 'end':
|
||||
$p = 'infinity';
|
||||
break;
|
||||
default:
|
||||
throw new \Exception('Unexpected position value.');
|
||||
}
|
||||
|
||||
if ($part instanceof PathExpression) {
|
||||
return sprintf(
|
||||
"CASE WHEN %s IS NOT NULL THEN %s ELSE '%s'::date END",
|
||||
$part->dispatch($sqlWalker),
|
||||
$part->dispatch($sqlWalker),
|
||||
$p
|
||||
);
|
||||
}
|
||||
|
||||
return sprintf(
|
||||
"CASE WHEN %s::date IS NOT NULL THEN %s::date ELSE '%s'::date END",
|
||||
$part->dispatch($sqlWalker),
|
||||
$part->dispatch($sqlWalker),
|
||||
$p
|
||||
);
|
||||
}
|
||||
|
||||
public function parse(Parser $parser): void
|
||||
{
|
||||
$parser->match(Lexer::T_IDENTIFIER);
|
||||
@@ -92,4 +70,38 @@ class OverlapsI extends FunctionNode
|
||||
|
||||
$parser->match(Lexer::T_CLOSE_PARENTHESIS);
|
||||
}
|
||||
|
||||
protected function makeCase($sqlWalker, $part, string $position): string
|
||||
{
|
||||
switch ($position) {
|
||||
case 'start':
|
||||
$p = '-infinity';
|
||||
|
||||
break;
|
||||
|
||||
case 'end':
|
||||
$p = 'infinity';
|
||||
|
||||
break;
|
||||
|
||||
default:
|
||||
throw new Exception('Unexpected position value.');
|
||||
}
|
||||
|
||||
if ($part instanceof PathExpression) {
|
||||
return sprintf(
|
||||
"CASE WHEN %s IS NOT NULL THEN %s ELSE '%s'::date END",
|
||||
$part->dispatch($sqlWalker),
|
||||
$part->dispatch($sqlWalker),
|
||||
$p
|
||||
);
|
||||
}
|
||||
|
||||
return sprintf(
|
||||
"CASE WHEN %s::date IS NOT NULL THEN %s::date ELSE '%s'::date END",
|
||||
$part->dispatch($sqlWalker),
|
||||
$part->dispatch($sqlWalker),
|
||||
$p
|
||||
);
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user