Skip to content

Commit 1da943e

Browse files
committed
added query hook for contents query API and some minor improvements
1 parent 1146dc8 commit 1da943e

File tree

5 files changed

+49
-13
lines changed

5 files changed

+49
-13
lines changed

src/Darryldecode/Backend/Components/ContentBuilder/Commands/QueryContentsCommand.php

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,10 @@ class QueryContentsCommand extends Command implements SelfHandling {
6060
* @var null
6161
*/
6262
private $endDate;
63+
/**
64+
* @var null
65+
*/
66+
private $queryHook;
6367

6468
/**
6569
* @param null $type
@@ -74,6 +78,7 @@ class QueryContentsCommand extends Command implements SelfHandling {
7478
* @param bool $disablePermissionChecking
7579
* @param null $startDate
7680
* @param null $endDate
81+
* @param null $queryHook
7782
*/
7883
public function __construct($type = null,
7984
$status = 'any',
@@ -86,7 +91,8 @@ public function __construct($type = null,
8691
$sortOrder = 'DESC',
8792
$disablePermissionChecking = false,
8893
$startDate = null,
89-
$endDate = null)
94+
$endDate = null,
95+
$queryHook = null)
9096
{
9197
parent::__construct();
9298
$this->type = $type;
@@ -102,6 +108,7 @@ public function __construct($type = null,
102108
$this->disablePermissionChecking = $disablePermissionChecking;
103109
$this->startDate = $startDate;
104110
$this->endDate = $endDate;
111+
$this->queryHook = $queryHook;
105112
}
106113

107114
/**
@@ -215,6 +222,15 @@ protected function query($contentType, $content)
215222
$q->ofEndDate($this->endDate);
216223
}
217224

225+
// trigger query hook if provided
226+
if( !is_null($this->queryHook) && (is_callable($this->queryHook)) )
227+
{
228+
if( $res = call_user_func($this->queryHook,$q) )
229+
{
230+
$q = $res;
231+
}
232+
}
233+
218234
// decide whether request wants paginated version or not
219235
if( $this->paginated )
220236
{

src/Darryldecode/Backend/Components/Navigation/Commands/ListCustomNavigationCommand.php

Lines changed: 21 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -32,15 +32,21 @@ class ListCustomNavigationCommand extends Command implements SelfHandling {
3232
* @var string
3333
*/
3434
private $orderSort;
35+
/**
36+
* @var null
37+
*/
38+
private $id;
3539

3640
/**
41+
* @param int|null $id
3742
* @param bool $paginated
3843
* @param int $perPage
3944
* @param string $orderBy
4045
* @param string $orderSort
4146
* @param bool $disablePermissionChecking
4247
*/
43-
public function __construct($paginated = true,
48+
public function __construct($id = null,
49+
$paginated = true,
4450
$perPage = 8,
4551
$orderBy = 'created_at',
4652
$orderSort = 'DESC',
@@ -53,6 +59,7 @@ public function __construct($paginated = true,
5359
$this->orderSort = $orderSort;
5460
$this->args = get_defined_vars();
5561
$this->disablePermissionChecking = $disablePermissionChecking;
62+
$this->id = $id;
5663
}
5764

5865
/**
@@ -74,13 +81,23 @@ public function handle(Navigation $navigation, Dispatcher $dispatcher)
7481
// fire before create event
7582
$dispatcher->fire('navigationBuilder.beforeQuery', array($this->args));
7683

77-
if( $this->paginated )
84+
if( $this->id && ($this->id!='') )
7885
{
79-
$res = $navigation->with(array())->paginate($this->perPage);
86+
if( ! $res = $navigation->with(array())->find($this->id) )
87+
{
88+
return new CommandResult(false, "Navigation does not exist.", null, 404);
89+
}
8090
}
8191
else
8292
{
83-
$res = $navigation->all();
93+
if( $this->paginated )
94+
{
95+
$res = $navigation->with(array())->paginate($this->perPage);
96+
}
97+
else
98+
{
99+
$res = $navigation->all();
100+
}
84101
}
85102

86103
// fire after create

src/Darryldecode/Backend/Components/User/Commands/CreateUserCommand.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -49,11 +49,11 @@ class CreateUserCommand extends Command implements SelfHandling {
4949
* @param $lastName
5050
* @param $email
5151
* @param $password
52-
* @param $permissions
53-
* @param $groups
52+
* @param array $permissions
53+
* @param array $groups
5454
* @param bool $disablePermissionChecking
5555
*/
56-
public function __construct($firstName, $lastName, $email, $password, $permissions, $groups, $disablePermissionChecking = false)
56+
public function __construct($firstName, $lastName, $email, $password, $permissions = array(), $groups = array(), $disablePermissionChecking = false)
5757
{
5858
parent::__construct();
5959
$this->firstName = $firstName;

src/Darryldecode/Backend/Components/User/Controllers/UserController.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -83,7 +83,7 @@ public function postCreate()
8383
'firstName' => $this->request->get('firstName', null),
8484
'lastName' => $this->request->get('lastName', null),
8585
'email' => $this->request->get('email', null),
86-
'password' => $this->request->get('password', array()),
86+
'password' => $this->request->get('password', null),
8787
'permissions' => $this->request->get('permissions', array()),
8888
'groups' => $this->request->get('groups', array()),
8989
)

src/Darryldecode/Backend/Components/User/Views/groups.blade.php

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -85,12 +85,15 @@
8585
<li data-ng-if="!groups.length" class="list-group-item text-center">Loading groups <i class="fa fa-spinner fa-spin"></i></li>
8686
<li data-ng-repeat="g in groups" class="list-group-item group-item-@{{$index}}">
8787
<p>
88-
<b>Group:</b> @{{g.name}}
89-
<button data-ng-click="edit.edit(g)" class="btn btn-default btn-sm"><i class="fa fa-pencil"></i> Edit</button>
90-
<button data-ng-click="group.trash(g.id, $index)" class="btn btn-warning btn-sm"><i class="fa fa-trash-o"></i> Delete</button>
88+
Group Name: <b>@{{g.name}}</b><br>
89+
Group ID: <b>[@{{g.id}}]</b>
90+
<span class="pull-right">
91+
<button data-ng-click="edit.edit(g)" class="btn btn-default btn-xs"><i class="fa fa-pencil"></i> Edit</button>
92+
<button data-ng-click="group.trash(g.id, $index)" class="btn btn-warning btn-xs"><i class="fa fa-trash-o"></i> Delete</button>
93+
</span>
9194
</p>
9295
<p>
93-
<b><i class="fa fa-lock"></i> Permissions:</b>
96+
<i class="fa fa-lock"></i> Permissions:
9497
<div class="clearfix">
9598
<label data-ng-repeat="(k,v) in g.permissions" class="permission pull-left label label-@{{(v==-1) ? 'danger' : 'success'}}">
9699
@{{k}}

0 commit comments

Comments
 (0)