Skip to content

Commit 6a62c05

Browse files
committed
IMPROVEMENT
Added Query Hook parameter when using QueryUsersCommand
1 parent e255154 commit 6a62c05

File tree

2 files changed

+18
-2
lines changed

2 files changed

+18
-2
lines changed

Diff for: src/Darryldecode/Backend/Base/Registrar/Registrar.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ class Registrar {
1313
/**
1414
* the laravel backend version
1515
*/
16-
const VERSION = '1.0.21';
16+
const VERSION = '1.0.22';
1717
const VERSION_NAME = 'Alpha';
1818

1919
/**

Diff for: src/Darryldecode/Backend/Components/User/Commands/QueryUsersCommand.php

+17-1
Original file line numberDiff line numberDiff line change
@@ -64,6 +64,10 @@ class QueryUsersCommand extends Command implements SelfHandling {
6464
* @var int|null
6565
*/
6666
private $id;
67+
/**
68+
* @var null
69+
*/
70+
private $queryHook;
6771

6872
/**
6973
* query users by parameters, note that when querying by groupId, with relations is disabled
@@ -79,6 +83,7 @@ class QueryUsersCommand extends Command implements SelfHandling {
7983
* @param bool $paginated
8084
* @param int $perPage
8185
* @param bool $disablePermissionChecking
86+
* @param null|callable $queryHook
8287
*/
8388
public function __construct($id = null,
8489
$firstName = null,
@@ -90,7 +95,8 @@ public function __construct($id = null,
9095
$orderSort = 'DESC',
9196
$paginated = true,
9297
$perPage = 15,
93-
$disablePermissionChecking = false)
98+
$disablePermissionChecking = false,
99+
$queryHook = null)
94100
{
95101
parent::__construct();
96102
$this->id = $id;
@@ -105,6 +111,7 @@ public function __construct($id = null,
105111
$this->with = $with;
106112
$this->args = get_defined_vars();
107113
$this->disablePermissionChecking = $disablePermissionChecking;
114+
$this->queryHook = $queryHook;
108115
}
109116

110117
/**
@@ -160,6 +167,15 @@ public function handle(User $user, Group $group, Dispatcher $dispatcher, Reposit
160167
});
161168
}
162169

170+
// trigger query hook if provided
171+
if( !is_null($this->queryHook) && (is_callable($this->queryHook)) )
172+
{
173+
if( $res = call_user_func($this->queryHook,$q) )
174+
{
175+
$q = $res;
176+
}
177+
}
178+
163179
if( $this->paginated )
164180
{
165181
$results = $q->paginate($this->perPage);

0 commit comments

Comments
 (0)