使用邮政"OVERLAPS"的自定义原则扩展



我正在尝试将 postgres 中的 OVERLAPS 函数实现到 3.4 Symfony 项目中以进行日期范围匹配。

我做了以下扩展:

class DateOverlaps extends FunctionNode
{
public $rangeStart;
public $rangeEnd;
public $targetStart;
public $targetEnd;

public function parse(Parser $parser)
{
$parser->match(Lexer::T_IDENTIFIER);
$parser->match(Lexer::T_OPEN_PARENTHESIS);
$this->rangeStart = $parser->InputParameter();
$parser->match(Lexer::T_COMMA);
$this->rangeEnd = $parser->InputParameter();
$parser->match(Lexer::T_COMMA);
$this->targetStart = $parser->SingleValuedPathExpression();
$parser->match(Lexer::T_COMMA);
$this->targetEnd = $parser->SingleValuedPathExpression();
$parser->match(Lexer::T_CLOSE_PARENTHESIS);
}
/**
* @param SqlWalker $sqlWalker
*
* @return string
*/
public function getSql(SqlWalker $sqlWalker)
{
$rangeStart = $this->rangeStart->dispatch($sqlWalker);
$rangeEnd = $this->rangeEnd->dispatch($sqlWalker);
$targetStart = $this->targetStart->dispatch($sqlWalker);
$targetEnd = $this->targetEnd->dispatch($sqlWalker);
return "($rangeStart, $rangeEnd) OVERLAPS ($targetStart, $targetEnd)";
}
}

配置:

orm:
dql:
string_functions:
overlaps: AppBundleDriverDateOverlaps

并在一个简单的存储库中使用它,如下所示:

public function findRangedEvents(DateTime $start, DateTime $end)
{
$qb = $this->createQueryBuilder('event')
->where("overlaps(:start, :end, event.occuringDate, event.occuringEndDate)")
->setParameter('start', $start)
->setParameter('end', $end);
return $qb->getQuery()->getResult();
}

但是我收到这样的错误

"[Syntax Error] line 0, col -1: Error: Expected =, <, <=, <>, >, >=, !=, got end of string."

我尝试了许多不同的解析器函数,但我真的无法理解我缺少什么。

您可以使用以下条件来解决它

$qb->where("overlaps(:start, :end, event.occuringDate, event.occuringEndDate) = true")

相关内容

  • 没有找到相关文章

最新更新