Skip to content

Commit 12baaad

Browse files
author
Michael
committed
Minor improvements
1 parent e166820 commit 12baaad

File tree

1 file changed

+13
-5
lines changed

1 file changed

+13
-5
lines changed

src/BaseRepository.php

Lines changed: 13 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -75,8 +75,14 @@ public function buildQuery(array $filters = array(), $order = array(), $limit =
7575

7676
// Got a setup function?
7777
if(is_callable($this->setupFunction))
78+
{
79+
// Run it
7880
$queryBuilder = call_user_func($this->setupFunction, $this->alias, $queryBuilder);
7981

82+
// Clear it
83+
$this->setupFunction = null;
84+
}
85+
8086
// Defaults options
8187
$opt = array_merge(array(
8288
'disable_joins' => false
@@ -106,7 +112,7 @@ public function buildQuery(array $filters = array(), $order = array(), $limit =
106112
foreach($order AS $key => $val)
107113
{
108114
// Not got a dot, prefix table alias
109-
if(stripos($key, ".") === false)
115+
if(is_string($key) && stripos($key, ".") === false && in_array($key, $this->getClassMetadata($this->getClassName())->getColumnNames()))
110116
$key = $this->alias . "." . $key;
111117

112118
$queryBuilder->addOrderBy($key, $val);
@@ -133,8 +139,7 @@ public function buildQuery(array $filters = array(), $order = array(), $limit =
133139

134140
public function addCriteria(QueryBuilder $queryBuilder, Composite $expr, array $criteria)
135141
{
136-
$em = $this->getEntityManager();
137-
142+
// Got criteria
138143
if(count($criteria))
139144
{
140145
foreach($criteria AS $k => $v)
@@ -196,8 +201,11 @@ public function addCriteria(QueryBuilder $queryBuilder, Composite $expr, array $
196201
if(stripos($field, ".") === false)
197202
$field = $this->alias . "." . $field;
198203

204+
// Raw
205+
if($operator === 'raw')
206+
$expr->add($value);
199207
// Or
200-
if($operator === 'or')
208+
elseif($operator === 'or')
201209
$expr->add($this->addCriteria($queryBuilder, $queryBuilder->expr()->orX(), $value));
202210
// And
203211
elseif($operator === 'and')
@@ -355,7 +363,7 @@ public function prepareValue($value)
355363

356364
public function buildSearchCriteria(string $keywords, array $searchableColumns = array())
357365
{
358-
// Not no searchable columns
366+
// Got no searchable columns
359367
if(!count($searchableColumns))
360368
throw new \Exception("No searchable columns specified");
361369

0 commit comments

Comments
 (0)