- WIP on SearchRequest attributes - Began working on removing 'Ulmus' class - WIP on removing SQL query building from Repository (which will become SqlRepository)
71 lines
1.6 KiB
PHP
71 lines
1.6 KiB
PHP
<?php
|
|
|
|
namespace Ulmus\Query;
|
|
|
|
use Ulmus\Repository\ConditionTrait;
|
|
|
|
class Join extends Fragment
|
|
{
|
|
use ConditionTrait;
|
|
|
|
const SQL_OUTER = "OUTER";
|
|
const SQL_TOKEN = "JOIN";
|
|
|
|
const TYPE_LEFT = "LEFT";
|
|
const TYPE_RIGHT = "RIGHT";
|
|
const TYPE_INNER = "INNER";
|
|
const TYPE_FULL = "FULL";
|
|
const TYPE_CROSS = "CROSS";
|
|
const TYPE_NATURAL = "NATURAL";
|
|
|
|
public bool $outer = false;
|
|
|
|
public array $joins = [];
|
|
|
|
public string $attachment = "ON";
|
|
|
|
public string $side;
|
|
|
|
public /*string|QueryBuilder*/ $table;
|
|
|
|
public ? string $alias;
|
|
|
|
public string $field;
|
|
|
|
public /*string|QueryBuilder*/ $value;
|
|
|
|
public /* QueryBuilder */ $queryBuilder;
|
|
|
|
public int $order = 40;
|
|
|
|
public const ORDER_VALUE = 0;
|
|
|
|
public int $joinOrder = 0;
|
|
|
|
public function __construct(QueryBuilderInterface $queryBuilder)
|
|
{
|
|
$cls = get_class($queryBuilder);
|
|
$this->queryBuilder = new $cls();
|
|
$this->queryBuilder->parent = $queryBuilder;
|
|
}
|
|
|
|
public function set(string $side, /* QueryBuilder|string */ $table, string $field, /* QueryBuilder|string */ $value)
|
|
{
|
|
$this->side = $side;
|
|
$this->table = $table;
|
|
|
|
$this->where($this->field = $field, $this->value = $value);
|
|
}
|
|
|
|
public function order() : float
|
|
{
|
|
return $this->order + ( $this->joinOrder / 100 );
|
|
}
|
|
|
|
public function render() : string
|
|
{
|
|
return $this->renderSegments([
|
|
strtoupper($this->side), $this->outer ? static::SQL_OUTER : "", static::SQL_TOKEN, $this->table, $this->alias ?? "", $this->attachment, $this->queryBuilder->render(true) ?? ""
|
|
]);
|
|
}
|
|
} |