mirror of
https://github.com/Karaka-Management/phpOMS.git
synced 2026-02-11 22:38:42 +00:00
fix findquery
This commit is contained in:
parent
d81bf80ada
commit
dcfc61e7a9
|
|
@ -335,22 +335,31 @@ class DataMapperAbstract implements DataMapperInterface
|
||||||
$where1 = new Where(self::$db);
|
$where1 = new Where(self::$db);
|
||||||
$where2 = new Where(self::$db);
|
$where2 = new Where(self::$db);
|
||||||
|
|
||||||
|
$hasConditionals = false;
|
||||||
foreach (self::$conditionals as $condKey => $condValue) {
|
foreach (self::$conditionals as $condKey => $condValue) {
|
||||||
if (($column = self::getColumnByMember($condKey)) !== null) {
|
if (($column = self::getColumnByMember($condKey)) !== null) {
|
||||||
$where1->andWhere(static::$table . '_' . $searchDepth . '.' . $column, '=', $condValue);
|
$where1->andWhere(static::$table . '_' . $searchDepth . '.' . $column, '=', $condValue);
|
||||||
|
$hasConditionals = true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
$hasAutocompletes = false;
|
||||||
foreach (static::$columns as $col) {
|
foreach (static::$columns as $col) {
|
||||||
if (isset($col['autocomplete']) && $col['autocomplete']) {
|
if (isset($col['autocomplete']) && $col['autocomplete']) {
|
||||||
$where2->where(static::$table . '_' . $searchDepth . '.' . $col['name'], 'LIKE', '%' . $search . '%', 'OR');
|
$where2->where(static::$table . '_' . $searchDepth . '.' . $col['name'], 'LIKE', '%' . $search . '%', 'OR');
|
||||||
|
$hasAutocompletes = true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
$query->andWhere($where1);
|
if ($hasConditionals) {
|
||||||
$query->andWhere($where2);
|
$query->andWhere($where1);
|
||||||
|
}
|
||||||
|
|
||||||
if ($searchDepth > 2) {
|
if ($hasAutocompletes) {
|
||||||
|
$query->andWhere($where2);
|
||||||
|
}
|
||||||
|
|
||||||
|
if ($searchDepth > 1) {
|
||||||
foreach (static::$ownsOne as $one) {
|
foreach (static::$ownsOne as $one) {
|
||||||
$one['mapper']::findQuery($search, $searchDepth - 1, $query);
|
$one['mapper']::findQuery($search, $searchDepth - 1, $query);
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -1471,6 +1471,8 @@ class Builder extends BuilderAbstract
|
||||||
return $column->getColumn();
|
return $column->getColumn();
|
||||||
} elseif ($column instanceof \Serializable) {
|
} elseif ($column instanceof \Serializable) {
|
||||||
return $column->serialize();
|
return $column->serialize();
|
||||||
|
} elseif ($column instanceof self) {
|
||||||
|
return \md5($column->toSql());
|
||||||
}
|
}
|
||||||
|
|
||||||
throw new \Exception();
|
throw new \Exception();
|
||||||
|
|
|
||||||
|
|
@ -253,15 +253,16 @@ class Grammar extends GrammarAbstract
|
||||||
$expression .= $this->compileSystem($element['column']);
|
$expression .= $this->compileSystem($element['column']);
|
||||||
} elseif ($element['column'] instanceof \Closure) {
|
} elseif ($element['column'] instanceof \Closure) {
|
||||||
$expression .= $element['column']();
|
$expression .= $element['column']();
|
||||||
|
} elseif ($element['column'] instanceof Where) {
|
||||||
|
$where = \rtrim($this->compileWhereQuery($element['column']), ';');
|
||||||
|
$expression .= '(' . (\stripos($where, 'WHERE ') === 0 ? \substr($where, 6) : $where) . ')';
|
||||||
} elseif ($element['column'] instanceof Builder) {
|
} elseif ($element['column'] instanceof Builder) {
|
||||||
$expression .= '(' . \rtrim($element['column']->toSql(), ';') . ')';
|
$expression .= '(' . \rtrim($element['column']->toSql(), ';') . ')';
|
||||||
} elseif ($element['column'] instanceof Where) {
|
|
||||||
$expression .= '(' . \rtrim($this->compileWhereQuery($element['column']), ';') . ')';
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if (isset($element['value'])) {
|
if (isset($element['value'])) {
|
||||||
$expression .= ' ' . \strtoupper($element['operator']) . ' ' . $this->compileValue($query, $element['value']);
|
$expression .= ' ' . \strtoupper($element['operator']) . ' ' . $this->compileValue($query, $element['value']);
|
||||||
} else {
|
} elseif (isset($element['value']) && !($element['column'] instanceof Where)) {
|
||||||
$operator = $element['operator'] === '=' ? 'IS' : 'IS NOT';
|
$operator = $element['operator'] === '=' ? 'IS' : 'IS NOT';
|
||||||
$expression .= ' ' . $operator . ' ' . $this->compileValue($query, $element['value']);
|
$expression .= ' ' . $operator . ' ' . $this->compileValue($query, $element['value']);
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -14,6 +14,8 @@ declare(strict_types=1);
|
||||||
|
|
||||||
namespace phpOMS\DataStorage\Database\Query;
|
namespace phpOMS\DataStorage\Database\Query;
|
||||||
|
|
||||||
|
use phpOMS\DataStorage\Database\Connection\ConnectionAbstract;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Database query builder.
|
* Database query builder.
|
||||||
*
|
*
|
||||||
|
|
@ -24,4 +26,16 @@ namespace phpOMS\DataStorage\Database\Query;
|
||||||
*/
|
*/
|
||||||
class Where extends Builder
|
class Where extends Builder
|
||||||
{
|
{
|
||||||
|
/**
|
||||||
|
* Constructor.
|
||||||
|
*
|
||||||
|
* @param ConnectionAbstract $connection Database connection
|
||||||
|
*
|
||||||
|
* @since 1.0.0
|
||||||
|
*/
|
||||||
|
public function __construct(ConnectionAbstract $connection)
|
||||||
|
{
|
||||||
|
parent::__construct($connection);
|
||||||
|
$this->type = QueryType::SELECT;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue
Block a user