diff options
Diffstat (limited to 'main/app/sprinkles/admin/src/Sprunje')
7 files changed, 563 insertions, 0 deletions
diff --git a/main/app/sprinkles/admin/src/Sprunje/ActivitySprunje.php b/main/app/sprinkles/admin/src/Sprunje/ActivitySprunje.php new file mode 100755 index 0000000..da4f0e3 --- /dev/null +++ b/main/app/sprinkles/admin/src/Sprunje/ActivitySprunje.php @@ -0,0 +1,80 @@ +<?php +/** + * UserFrosting (http://www.userfrosting.com) + * + * @link https://github.com/userfrosting/UserFrosting + * @license https://github.com/userfrosting/UserFrosting/blob/master/licenses/UserFrosting.md (MIT License) + */ +namespace UserFrosting\Sprinkle\Admin\Sprunje; + +use Illuminate\Database\Capsule\Manager as Capsule; +use UserFrosting\Sprinkle\Core\Facades\Debug; +use UserFrosting\Sprinkle\Core\Sprunje\Sprunje; + +/** + * ActivitySprunje + * + * Implements Sprunje for the activities API. + * + * @author Alex Weissman (https://alexanderweissman.com) + */ +class ActivitySprunje extends Sprunje +{ + protected $sortable = [ + 'occurred_at', + 'user', + 'description' + ]; + + protected $filterable = [ + 'occurred_at', + 'user', + 'description' + ]; + + protected $name = 'activities'; + + /** + * Set the initial query used by your Sprunje. + */ + protected function baseQuery() + { + $query = $this->classMapper->createInstance('activity'); + + return $query->joinUser(); + } + + /** + * Filter LIKE the user info. + * + * @param Builder $query + * @param mixed $value + * @return $this + */ + protected function filterUser($query, $value) + { + // Split value on separator for OR queries + $values = explode($this->orSeparator, $value); + $query->where(function ($query) use ($values) { + foreach ($values as $value) { + $query->orLike('users.first_name', $value) + ->orLike('users.last_name', $value) + ->orLike('users.email', $value); + } + }); + return $this; + } + + /** + * Sort based on user last name. + * + * @param Builder $query + * @param string $direction + * @return $this + */ + protected function sortUser($query, $direction) + { + $query->orderBy('users.last_name', $direction); + return $this; + } +} diff --git a/main/app/sprinkles/admin/src/Sprunje/GroupSprunje.php b/main/app/sprinkles/admin/src/Sprunje/GroupSprunje.php new file mode 100755 index 0000000..7c75691 --- /dev/null +++ b/main/app/sprinkles/admin/src/Sprunje/GroupSprunje.php @@ -0,0 +1,42 @@ +<?php +/** + * UserFrosting (http://www.userfrosting.com) + * + * @link https://github.com/userfrosting/UserFrosting + * @license https://github.com/userfrosting/UserFrosting/blob/master/licenses/UserFrosting.md (MIT License) + */ +namespace UserFrosting\Sprinkle\Admin\Sprunje; + +use Illuminate\Database\Capsule\Manager as Capsule; +use UserFrosting\Sprinkle\Core\Facades\Debug; +use UserFrosting\Sprinkle\Core\Sprunje\Sprunje; + +/** + * GroupSprunje + * + * Implements Sprunje for the groups API. + * + * @author Alex Weissman (https://alexanderweissman.com) + */ +class GroupSprunje extends Sprunje +{ + protected $name = 'groups'; + + protected $sortable = [ + 'name', + 'description' + ]; + + protected $filterable = [ + 'name', + 'description' + ]; + + /** + * {@inheritDoc} + */ + protected function baseQuery() + { + return $this->classMapper->createInstance('group')->newQuery(); + } +} diff --git a/main/app/sprinkles/admin/src/Sprunje/PermissionSprunje.php b/main/app/sprinkles/admin/src/Sprunje/PermissionSprunje.php new file mode 100755 index 0000000..c1803f1 --- /dev/null +++ b/main/app/sprinkles/admin/src/Sprunje/PermissionSprunje.php @@ -0,0 +1,93 @@ +<?php +/** + * UserFrosting (http://www.userfrosting.com) + * + * @link https://github.com/userfrosting/UserFrosting + * @license https://github.com/userfrosting/UserFrosting/blob/master/licenses/UserFrosting.md (MIT License) + */ +namespace UserFrosting\Sprinkle\Admin\Sprunje; + +use Illuminate\Database\Capsule\Manager as Capsule; +use UserFrosting\Sprinkle\Core\Facades\Debug; +use UserFrosting\Sprinkle\Core\Sprunje\Sprunje; + +/** + * PermissionSprunje + * + * Implements Sprunje for the permissions API. + * + * @author Alex Weissman (https://alexanderweissman.com) + */ +class PermissionSprunje extends Sprunje +{ + protected $name = 'permissions'; + + protected $sortable = [ + 'name', + 'properties' + ]; + + protected $filterable = [ + 'name', + 'properties', + 'info' + ]; + + protected $excludeForAll = [ + 'info' + ]; + + /** + * {@inheritDoc} + */ + protected function baseQuery() + { + return $this->classMapper->createInstance('permission')->newQuery(); + } + + /** + * Filter LIKE the slug, conditions, or description. + * + * @param Builder $query + * @param mixed $value + * @return $this + */ + protected function filterInfo($query, $value) + { + return $this->filterProperties($query, $value); + } + + /** + * Filter LIKE the slug, conditions, or description. + * + * @param Builder $query + * @param mixed $value + * @return $this + */ + protected function filterProperties($query, $value) + { + // Split value on separator for OR queries + $values = explode($this->orSeparator, $value); + $query->where(function ($query) use ($values) { + foreach ($values as $value) { + $query->orLike('slug', $value) + ->orLike('conditions', $value) + ->orLike('description', $value); + } + }); + return $this; + } + + /** + * Sort based on slug. + * + * @param Builder $query + * @param string $direction + * @return $this + */ + protected function sortProperties($query, $direction) + { + $query->orderBy('slug', $direction); + return $this; + } +} diff --git a/main/app/sprinkles/admin/src/Sprunje/PermissionUserSprunje.php b/main/app/sprinkles/admin/src/Sprunje/PermissionUserSprunje.php new file mode 100755 index 0000000..242681d --- /dev/null +++ b/main/app/sprinkles/admin/src/Sprunje/PermissionUserSprunje.php @@ -0,0 +1,48 @@ +<?php +/** + * UserFrosting (http://www.userfrosting.com) + * + * @link https://github.com/userfrosting/UserFrosting + * @license https://github.com/userfrosting/UserFrosting/blob/master/licenses/UserFrosting.md (MIT License) + */ +namespace UserFrosting\Sprinkle\Admin\Sprunje; + +use Illuminate\Database\Capsule\Manager as Capsule; +use UserFrosting\Sprinkle\Core\Facades\Debug; +use UserFrosting\Support\Exception\BadRequestException; +use UserFrosting\Support\Exception\NotFoundException; + +/** + * PermissionUserSprunje + * + * Implements Sprunje for retrieving a list of users for a specified permission. + * + * @author Alex Weissman (https://alexanderweissman.com) + */ +class PermissionUserSprunje extends UserSprunje +{ + protected $name = 'permission_users'; + + /** + * {@inheritDoc} + */ + protected function baseQuery() + { + // Requires a permission id + if (!isset($this->options['permission_id'])) { + throw new BadRequestException(); + } + + $permission = $this->classMapper->staticMethod('permission', 'find', $this->options['permission_id']); + + // If the permission doesn't exist, return 404 + if (!$permission) { + throw new NotFoundException; + } + + // Get permission users + $query = $permission->users()->withVia('roles_via'); + + return $query; + } +} diff --git a/main/app/sprinkles/admin/src/Sprunje/RoleSprunje.php b/main/app/sprinkles/admin/src/Sprunje/RoleSprunje.php new file mode 100755 index 0000000..c5e0f8b --- /dev/null +++ b/main/app/sprinkles/admin/src/Sprunje/RoleSprunje.php @@ -0,0 +1,67 @@ +<?php +/** + * UserFrosting (http://www.userfrosting.com) + * + * @link https://github.com/userfrosting/UserFrosting + * @license https://github.com/userfrosting/UserFrosting/blob/master/licenses/UserFrosting.md (MIT License) + */ +namespace UserFrosting\Sprinkle\Admin\Sprunje; + +use Illuminate\Database\Capsule\Manager as Capsule; +use UserFrosting\Sprinkle\Core\Facades\Debug; +use UserFrosting\Sprinkle\Core\Sprunje\Sprunje; + +/** + * RoleSprunje + * + * Implements Sprunje for the roles API. + * + * @author Alex Weissman (https://alexanderweissman.com) + */ +class RoleSprunje extends Sprunje +{ + protected $name = 'roles'; + + protected $sortable = [ + 'name', + 'description' + ]; + + protected $filterable = [ + 'name', + 'description', + 'info' + ]; + + protected $excludeForAll = [ + 'info' + ]; + + /** + * {@inheritDoc} + */ + protected function baseQuery() + { + return $this->classMapper->createInstance('role')->newQuery(); + } + + /** + * Filter LIKE name OR description. + * + * @param Builder $query + * @param mixed $value + * @return $this + */ + protected function filterInfo($query, $value) + { + // Split value on separator for OR queries + $values = explode($this->orSeparator, $value); + $query->where(function ($query) use ($values) { + foreach ($values as $value) { + $query->orLike('name', $value) + ->orLike('description', $value); + } + }); + return $this; + } +} diff --git a/main/app/sprinkles/admin/src/Sprunje/UserPermissionSprunje.php b/main/app/sprinkles/admin/src/Sprunje/UserPermissionSprunje.php new file mode 100755 index 0000000..6142e74 --- /dev/null +++ b/main/app/sprinkles/admin/src/Sprunje/UserPermissionSprunje.php @@ -0,0 +1,48 @@ +<?php +/** + * UserFrosting (http://www.userfrosting.com) + * + * @link https://github.com/userfrosting/UserFrosting + * @license https://github.com/userfrosting/UserFrosting/blob/master/licenses/UserFrosting.md (MIT License) + */ +namespace UserFrosting\Sprinkle\Admin\Sprunje; + +use Illuminate\Database\Capsule\Manager as Capsule; +use UserFrosting\Sprinkle\Core\Facades\Debug; +use UserFrosting\Support\Exception\BadRequestException; +use UserFrosting\Support\Exception\NotFoundException; + +/** + * UserPermissionSprunje + * + * Implements Sprunje for retrieving a list of permissions for a specified user. + * + * @author Alex Weissman (https://alexanderweissman.com) + */ +class UserPermissionSprunje extends PermissionSprunje +{ + protected $name = 'user_permissions'; + + /** + * {@inheritDoc} + */ + protected function baseQuery() + { + // Requires a user id + if (!isset($this->options['user_id'])) { + throw new BadRequestException(); + } + + $user = $this->classMapper->staticMethod('user', 'find', $this->options['user_id']); + + // If the user doesn't exist, return 404 + if (!$user) { + throw new NotFoundException; + } + + // Get user permissions + $query = $user->permissions()->withVia('roles_via'); + + return $query; + } +} diff --git a/main/app/sprinkles/admin/src/Sprunje/UserSprunje.php b/main/app/sprinkles/admin/src/Sprunje/UserSprunje.php new file mode 100755 index 0000000..12378f9 --- /dev/null +++ b/main/app/sprinkles/admin/src/Sprunje/UserSprunje.php @@ -0,0 +1,185 @@ +<?php +/** + * UserFrosting (http://www.userfrosting.com) + * + * @link https://github.com/userfrosting/UserFrosting + * @license https://github.com/userfrosting/UserFrosting/blob/master/licenses/UserFrosting.md (MIT License) + */ +namespace UserFrosting\Sprinkle\Admin\Sprunje; + +use Illuminate\Database\Capsule\Manager as Capsule; +use UserFrosting\Sprinkle\Core\Facades\Debug; +use UserFrosting\Sprinkle\Core\Facades\Translator; +use UserFrosting\Sprinkle\Core\Sprunje\Sprunje; + +/** + * UserSprunje + * + * Implements Sprunje for the users API. + * + * @author Alex Weissman (https://alexanderweissman.com) + */ +class UserSprunje extends Sprunje +{ + protected $name = 'users'; + + protected $listable = [ + 'status' + ]; + + protected $sortable = [ + 'name', + 'last_activity', + 'status' + ]; + + protected $filterable = [ + 'name', + 'last_activity', + 'status' + ]; + + protected $excludeForAll = [ + 'last_activity' + ]; + + /** + * {@inheritDoc} + */ + protected function baseQuery() + { + $query = $this->classMapper->createInstance('user'); + + // Join user's most recent activity + return $query->joinLastActivity()->with('lastActivity'); + } + + /** + * Filter LIKE the last activity description. + * + * @param Builder $query + * @param mixed $value + * @return $this + */ + protected function filterLastActivity($query, $value) + { + // Split value on separator for OR queries + $values = explode($this->orSeparator, $value); + $query->where(function ($query) use ($values) { + foreach ($values as $value) { + $query->orLike('activities.description', $value); + } + }); + return $this; + } + + /** + * Filter LIKE the first name, last name, or email. + * + * @param Builder $query + * @param mixed $value + * @return $this + */ + protected function filterName($query, $value) + { + // Split value on separator for OR queries + $values = explode($this->orSeparator, $value); + $query->where(function ($query) use ($values) { + foreach ($values as $value) { + $query->orLike('first_name', $value) + ->orLike('last_name', $value) + ->orLike('email', $value); + } + }); + return $this; + } + + /** + * Filter by status (active, disabled, unactivated) + * + * @param Builder $query + * @param mixed $value + * @return $this + */ + protected function filterStatus($query, $value) + { + // Split value on separator for OR queries + $values = explode($this->orSeparator, $value); + $query->where(function ($query) use ($values) { + foreach ($values as $value) { + if ($value == 'disabled') { + $query->orWhere('flag_enabled', 0); + } elseif ($value == 'unactivated') { + $query->orWhere('flag_verified', 0); + } elseif ($value == 'active') { + $query->orWhere(function ($query) { + $query->where('flag_enabled', 1)->where('flag_verified', 1); + }); + } + } + }); + return $this; + } + + /** + * Return a list of possible user statuses. + * + * @return array + */ + protected function listStatus() + { + return [ + [ + 'value' => 'active', + 'text' => Translator::translate('ACTIVE') + ], + [ + 'value' => 'unactivated', + 'text' => Translator::translate('UNACTIVATED') + ], + [ + 'value' => 'disabled', + 'text' => Translator::translate('DISABLED') + ] + ]; + } + + /** + * Sort based on last activity time. + * + * @param Builder $query + * @param string $direction + * @return $this + */ + protected function sortLastActivity($query, $direction) + { + $query->orderBy('activities.occurred_at', $direction); + return $this; + } + + /** + * Sort based on last name. + * + * @param Builder $query + * @param string $direction + * @return $this + */ + protected function sortName($query, $direction) + { + $query->orderBy('last_name', $direction); + return $this; + } + + /** + * Sort active, unactivated, disabled + * + * @param Builder $query + * @param string $direction + * @return $this + */ + protected function sortStatus($query, $direction) + { + $query->orderBy('flag_enabled', $direction)->orderBy('flag_verified', $direction); + return $this; + } +} |