Skip to content

Commit

Permalink
Callback triggers first; some Sortable reorganization
Browse files Browse the repository at this point in the history
  • Loading branch information
gbrock committed Aug 6, 2015
1 parent 7902520 commit 212b602
Showing 1 changed file with 11 additions and 16 deletions.
27 changes: 11 additions & 16 deletions src/Traits/Sortable.php
Original file line number Diff line number Diff line change
Expand Up @@ -35,13 +35,9 @@ public function scopeSorted($query, $field = false, $direction = false)
// is there a custom function for sorting this column?
$isCallableFunction = method_exists($this, $sortFunctionName);

// If the field requested isn't known to be sortable by our model, fail silently.
if(
!$isValueOfSortable &&
!$isKeyOfSortable &&
!$isCallableFunction
)
if(!$isValueOfSortable && !$isKeyOfSortable && !$isCallableFunction)
{
// If the field requested isn't known to be sortable by our model, fail silently.
return $query;
}

Expand All @@ -51,21 +47,20 @@ public function scopeSorted($query, $field = false, $direction = false)
$direction = config('gbrock-tables.default_direction');
}

if($isCallableFunction)
{
// Call custom function and return immediately
return call_user_func([$this, $sortFunctionName], $query, $direction);
}

// By default assume the $field is a member of the $sortable array
$sortField = strpos($field, '.') === FALSE ? $this->getTable() . '.' . $field : $field;

if($isKeyOfSortable)
{
// Set via key
$sortField = $this->sortable[$field];
}
elseif($isValueOfSortable)
{
// Does the passed field contain a period character?
$sortField = strpos($field, '.') === FALSE ? $this->getTable() . '.' . $field : $field;
}
elseif($isCallableFunction)
{
// Call custom function and return immediately
return call_user_func([$this, $sortFunctionName], $query, $direction);
}

// At this point, all should be well, continue.
return $query
Expand Down

0 comments on commit 212b602

Please sign in to comment.