- Enhance Redis methods (`exists`, `setEx`, `delete`, `get`, `set`) to ensure connection before execution. - Introduce short-lived caching for collected order invoices to minimize redundant processing and improve performance. - Add `pagination_helper` for dynamic WHERE clause construction in queries. - Refactor net amount calculation in `collected_order_invoices_o` for efficiency with batch processing. - Extend `listObjectsWithPaginationIfSet` to support additional WHERE clauses.
66 lines
1.4 KiB
PHP
66 lines
1.4 KiB
PHP
<?php
|
|
|
|
namespace routes;
|
|
|
|
/**
|
|
* Simple pagination helper to attach additional WHERE conditions to paginated queries.
|
|
* It mirrors the usage expected in routes: (new pagination_helper())->where->addCondition(...)
|
|
*/
|
|
class pagination_helper
|
|
{
|
|
public pagination_where $where;
|
|
|
|
public function __construct()
|
|
{
|
|
$this->where = new pagination_where();
|
|
}
|
|
|
|
/**
|
|
* Render the helper to a SQL snippet string.
|
|
*/
|
|
public function toSql(): string
|
|
{
|
|
return $this->where->toSql();
|
|
}
|
|
}
|
|
|
|
/**
|
|
* Condition factory. For now we only need CUSTOM to pass raw SQL, but this can be extended later.
|
|
*/
|
|
class pagination_condition_where
|
|
{
|
|
public static function CUSTOM(string $rawSql): string
|
|
{
|
|
return $rawSql;
|
|
}
|
|
}
|
|
|
|
/**
|
|
* Builder that collects WHERE conditions and can render them as a single SQL snippet.
|
|
*/
|
|
class pagination_where
|
|
{
|
|
/** @var string[] */
|
|
private array $conditions = [];
|
|
|
|
public function addCondition(string $condition): self
|
|
{
|
|
$condition = trim($condition);
|
|
if ($condition !== '') {
|
|
$this->conditions[] = $condition;
|
|
}
|
|
return $this;
|
|
}
|
|
|
|
/**
|
|
* Return the SQL snippet. If multiple conditions are provided, they are AND'ed together.
|
|
*/
|
|
public function toSql(): string
|
|
{
|
|
if (empty($this->conditions)) {
|
|
return '';
|
|
}
|
|
return '(' . implode(' AND ', $this->conditions) . ')';
|
|
}
|
|
}
|