-
-
Notifications
You must be signed in to change notification settings - Fork 50
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Serverside datatable user, role and permission
- Loading branch information
1 parent
a197be7
commit bf0dd80
Showing
11 changed files
with
255 additions
and
92 deletions.
There are no files selected for viewing
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,23 @@ | ||
<?php | ||
|
||
namespace agungsugiarto\boilerplate\Entities; | ||
|
||
class Collection | ||
{ | ||
/** | ||
* Return data to colection map datatable. | ||
* | ||
* @param array $data | ||
* | ||
* @return array | ||
*/ | ||
public function toColection(array $data, int $recordsTotal, int $recordsFiltered) | ||
{ | ||
return [ | ||
'draw' => service('request')->getGet('draw'), | ||
'recordsTotal' => $recordsTotal, | ||
'recordsFiltered' => $recordsFiltered, | ||
'data' => $data, | ||
]; | ||
} | ||
} |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,74 @@ | ||
<?php | ||
|
||
namespace agungsugiarto\boilerplate\Models; | ||
|
||
use Myth\Auth\Authorization\GroupModel as BaseModel; | ||
|
||
/** | ||
* Class Group. | ||
*/ | ||
class GroupModel extends BaseModel | ||
{ | ||
/** | ||
* Returns an array of all groups that a user is a member of. | ||
* | ||
* @param $userId | ||
* | ||
* @return object | ||
*/ | ||
public function getGroupsForUser(int $userId) | ||
{ | ||
$group = $this->builder() | ||
->join('auth_groups_users', 'auth_groups_users.group_id = auth_groups.id', 'left') | ||
->where('user_id', $userId) | ||
->get() | ||
->getResultObject(); | ||
|
||
$found = []; | ||
foreach ($group as $row) { | ||
$found[$row->id] = strtolower($row->name); | ||
} | ||
|
||
return $found; | ||
} | ||
|
||
/** | ||
* FInd with paginate data. | ||
* | ||
* @param int $length | ||
* @param int $start | ||
* | ||
* @return array | ||
*/ | ||
public function findPaginatedData(int $length, int $start, string $keyword = ''): ?array | ||
{ | ||
if ($keyword) { | ||
$this->builder() | ||
->groupStart() | ||
->like('name', $keyword) | ||
->orLike('description', $keyword) | ||
->groupEnd(); | ||
} | ||
|
||
return $this->builder()->limit($length, $start)->get()->getResultObject(); | ||
} | ||
|
||
/** | ||
* FInd with count all data. | ||
* | ||
* @param string $keyword | ||
* | ||
* @return int | ||
*/ | ||
public function countFindData(string $keyword = ''): int | ||
{ | ||
return $keyword ? $this->builder() | ||
->groupStart() | ||
->like('name', $keyword) | ||
->orLike('description', $keyword) | ||
->groupEnd() | ||
->countAllResults() | ||
|
||
: $this->builder()->countAllResults(); | ||
} | ||
} |
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,48 @@ | ||
<?php | ||
|
||
namespace agungsugiarto\boilerplate\Models; | ||
|
||
use Myth\Auth\Authorization\PermissionModel as BaseModel; | ||
|
||
class PermissionModel extends BaseModel | ||
{ | ||
/** | ||
* FInd with paginate data. | ||
* | ||
* @param int $length | ||
* @param int $start | ||
* | ||
* @return array | ||
*/ | ||
public function findPaginatedData(int $length, int $start, string $keyword = ''): ?array | ||
{ | ||
if ($keyword) { | ||
$this->builder() | ||
->groupStart() | ||
->like('name', $keyword) | ||
->orLike('description', $keyword) | ||
->groupEnd(); | ||
} | ||
|
||
return $this->builder()->limit($length, $start)->get()->getResultObject(); | ||
} | ||
|
||
/** | ||
* FInd with count all data. | ||
* | ||
* @param string $keyword | ||
* | ||
* @return int | ||
*/ | ||
public function countFindData(string $keyword = ''): int | ||
{ | ||
return $keyword ? $this->builder() | ||
->groupStart() | ||
->like('name', $keyword) | ||
->orLike('description', $keyword) | ||
->groupEnd() | ||
->countAllResults() | ||
|
||
: $this->builder()->countAllResults(); | ||
} | ||
} |
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,49 @@ | ||
<?php | ||
|
||
namespace agungsugiarto\boilerplate\Models; | ||
|
||
use Myth\Auth\Models\UserModel as BaseModel; | ||
|
||
class UserModel extends BaseModel | ||
{ | ||
/** | ||
* FInd with paginate data. | ||
* | ||
* @param int $length | ||
* @param int $start | ||
* | ||
* @return array | ||
*/ | ||
public function findPaginatedData(int $length, int $start, string $keyword = ''): ?array | ||
{ | ||
if ($keyword) { | ||
$this->builder() | ||
->groupStart() | ||
->like('username', $keyword) | ||
->orLike('email', $keyword) | ||
->groupEnd(); | ||
} | ||
|
||
return $this->builder()->where('deleted_at', null)->limit($length, $start)->get()->getResultObject(); | ||
} | ||
|
||
/** | ||
* FInd with count all data. | ||
* | ||
* @param string $keyword | ||
* | ||
* @return int | ||
*/ | ||
public function countFindData(string $keyword = ''): int | ||
{ | ||
return $keyword ? $this->builder() | ||
->groupStart() | ||
->like('username', $keyword) | ||
->orLike('email', $keyword) | ||
->groupEnd() | ||
->where('deleted_at', null) | ||
->countAllResults() | ||
|
||
: $this->builder()->where('deleted_at', null)->countAllResults(); | ||
} | ||
} |
Oops, something went wrong.