-
-
Notifications
You must be signed in to change notification settings - Fork 11
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Added a sorter for post hydration sorting.
Added notes to readme.
- Loading branch information
Mark Ogilvie
committed
May 7, 2018
1 parent
31863bf
commit f618a9a
Showing
5 changed files
with
197 additions
and
43 deletions.
There are no files selected for viewing
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
<?php | ||
|
||
namespace SpecShaper\GdprBundle\Utils; | ||
|
||
class Sorter | ||
{ | ||
public $firstSortOrder; | ||
|
||
protected $secondSortOrder; | ||
|
||
public function __construct($firstSortOrder, $secondSortOrder) | ||
{ | ||
$this->firstSortOrder = $firstSortOrder; | ||
$this->secondSortOrder = $secondSortOrder; | ||
} | ||
|
||
/** | ||
* Order an array by two fields, | ||
* | ||
* @param $a | ||
* @param $b | ||
* @return int | ||
*/ | ||
public function sortByTwoColumnsCallback($a, $b){ | ||
|
||
$firstOrder = $this->firstSortOrder; | ||
|
||
$secondOrder= $this->secondSortOrder; | ||
|
||
if ($a[$firstOrder] == $b[$firstOrder]) | ||
{ | ||
// employeeId is the same, sort by lastName | ||
if ($a[$secondOrder] > $b[$secondOrder]) return 1; | ||
} | ||
// sort the higher employeeId first: | ||
return $a[$firstOrder] < $b[$firstOrder] ? 1 : -1; | ||
} | ||
} |