mirror of
https://github.com/Karaka-Management/phpOMS.git
synced 2026-01-22 22:38:41 +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);
|
||||
$where2 = new Where(self::$db);
|
||||
|
||||
$hasConditionals = false;
|
||||
foreach (self::$conditionals as $condKey => $condValue) {
|
||||
if (($column = self::getColumnByMember($condKey)) !== null) {
|
||||
$where1->andWhere(static::$table . '_' . $searchDepth . '.' . $column, '=', $condValue);
|
||||
$hasConditionals = true;
|
||||
}
|
||||
}
|
||||
|
||||
$hasAutocompletes = false;
|
||||
foreach (static::$columns as $col) {
|
||||
if (isset($col['autocomplete']) && $col['autocomplete']) {
|
||||
$where2->where(static::$table . '_' . $searchDepth . '.' . $col['name'], 'LIKE', '%' . $search . '%', 'OR');
|
||||
$hasAutocompletes = true;
|
||||
}
|
||||
}
|
||||
|
||||
$query->andWhere($where1);
|
||||
$query->andWhere($where2);
|
||||
if ($hasConditionals) {
|
||||
$query->andWhere($where1);
|
||||
}
|
||||
|
||||
if ($searchDepth > 2) {
|
||||
if ($hasAutocompletes) {
|
||||
$query->andWhere($where2);
|
||||
}
|
||||
|
||||
if ($searchDepth > 1) {
|
||||
foreach (static::$ownsOne as $one) {
|
||||
$one['mapper']::findQuery($search, $searchDepth - 1, $query);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1471,6 +1471,8 @@ class Builder extends BuilderAbstract
|
|||
return $column->getColumn();
|
||||
} elseif ($column instanceof \Serializable) {
|
||||
return $column->serialize();
|
||||
} elseif ($column instanceof self) {
|
||||
return \md5($column->toSql());
|
||||
}
|
||||
|
||||
throw new \Exception();
|
||||
|
|
|
|||
|
|
@ -253,15 +253,16 @@ class Grammar extends GrammarAbstract
|
|||
$expression .= $this->compileSystem($element['column']);
|
||||
} elseif ($element['column'] instanceof \Closure) {
|
||||
$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) {
|
||||
$expression .= '(' . \rtrim($element['column']->toSql(), ';') . ')';
|
||||
} elseif ($element['column'] instanceof Where) {
|
||||
$expression .= '(' . \rtrim($this->compileWhereQuery($element['column']), ';') . ')';
|
||||
}
|
||||
|
||||
if (isset($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';
|
||||
$expression .= ' ' . $operator . ' ' . $this->compileValue($query, $element['value']);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -14,6 +14,8 @@ declare(strict_types=1);
|
|||
|
||||
namespace phpOMS\DataStorage\Database\Query;
|
||||
|
||||
use phpOMS\DataStorage\Database\Connection\ConnectionAbstract;
|
||||
|
||||
/**
|
||||
* Database query builder.
|
||||
*
|
||||
|
|
@ -24,4 +26,16 @@ namespace phpOMS\DataStorage\Database\Query;
|
|||
*/
|
||||
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