diff --git a/src/Acl/Model/Perfil.php b/src/Acl/Model/PerfilModel.php similarity index 87% rename from src/Acl/Model/Perfil.php rename to src/Acl/Model/PerfilModel.php index bf496ca..70106a5 100644 --- a/src/Acl/Model/Perfil.php +++ b/src/Acl/Model/PerfilModel.php @@ -5,7 +5,7 @@ use Illuminate\Database\Eloquent\Factories\HasFactory; use Illuminate\Database\Eloquent\Model; -class Perfil extends Model +class PerfilModel extends Model { use HasFactory; diff --git a/src/Acl/Model/PerfilPermissoes.php b/src/Acl/Model/PerfilPermissoesModel.php similarity index 84% rename from src/Acl/Model/PerfilPermissoes.php rename to src/Acl/Model/PerfilPermissoesModel.php index d6f45ef..7691c5c 100644 --- a/src/Acl/Model/PerfilPermissoes.php +++ b/src/Acl/Model/PerfilPermissoesModel.php @@ -5,7 +5,7 @@ use Illuminate\Database\Eloquent\Factories\HasFactory; use Illuminate\Database\Eloquent\Model; -class PerfilPermissoes extends Model +class PerfilPermissoesModel extends Model { use HasFactory; diff --git a/src/Acl/Model/PermissoesGrupoModel.php b/src/Acl/Model/PermissoesGrupoModel.php new file mode 100644 index 0000000..08f17a6 --- /dev/null +++ b/src/Acl/Model/PermissoesGrupoModel.php @@ -0,0 +1,14 @@ +model = $perfil; + } /** - * @param Perfil $perfil + * Realiza a pesquisa - Perfil Acl */ - public function __construct(Perfil $perfil) + public function findAll(int $filial): Collection { - $this->model = $perfil; + return $this->model::where('id_filial', $filial) + ->get() + ->map(function ($item) { + $data = $item; + $data->id_acl_perfil = $item->id; + $data->label = $item->nome; + return $data; + }); } } diff --git a/src/Acl/Repository/PerfilPermissoesAclRepository.php b/src/Acl/Repository/PerfilPermissoesAclRepository.php index d38c2c1..d0717de 100644 --- a/src/Acl/Repository/PerfilPermissoesAclRepository.php +++ b/src/Acl/Repository/PerfilPermissoesAclRepository.php @@ -2,22 +2,51 @@ namespace Orangecode\Acl\Repository; -use Orangecode\Acl\Model\PerfilPermissoes; +use Illuminate\Database\Eloquent\Collection; +use Illuminate\Support\Facades\DB; +use Orangecode\Acl\Model\PerfilPermissoesModel; +use Orangecode\Acl\Model\PermissoesModel; use Orangecode\Repository\Repository; use Orangecode\Repository\RepositoryDataBase; +/** + * Repository - Perfil Permissões Acl + */ class PerfilPermissoesAclRepository implements Repository { use RepositoryDataBase; - /** @var PerfilPermissoes */ - private PerfilPermissoes $model; + private PerfilPermissoesModel $model; + + private PermissoesModel $modelPermissoes; + + public function __construct( + PerfilPermissoesModel $perfil, + PermissoesModel $modelPermissoes + ) { + $this->model = $perfil; + $this->modelPermissoes = $modelPermissoes; + } /** - * @param PerfilPermissoes $perfil + * Realiza a pesquisa das permissões por perfil - Perfil Pemissões Acl */ - public function __construct(PerfilPermissoes $perfil) + public function findAll(int $perfil, int $grupo): Collection { - $this->model = $perfil; + $perfilPermissoes = DB::table('acl_perfil_permissoes') + ->where('id_perfil', $perfil) + ->get(); + return $this->modelPermissoes::where('id_permissoes_grupo', $grupo) + ->where('ativo', 'S') + ->orderBy('id') + ->get() + ->map(function ($item) use ($perfilPermissoes) { + $data = $item; + $data->active = !is_bool($perfilPermissoes->search(function ($value) use ($item) { + return $item->id == $value->id_permissoes; + })); + $data->label = $item->id . ' -> ' . $item->nome; + return $data; + }); } } diff --git a/src/Acl/Repository/PermissoesAclRepository.php b/src/Acl/Repository/PermissoesAclRepository.php index 5405a9e..d70d35f 100644 --- a/src/Acl/Repository/PermissoesAclRepository.php +++ b/src/Acl/Repository/PermissoesAclRepository.php @@ -2,22 +2,100 @@ namespace Orangecode\Acl\Repository; -use Orangecode\Acl\Model\Permissoes; +use Illuminate\Database\Eloquent\Collection; +use Illuminate\Support\Facades\DB; +use Orangecode\Acl\Model\PermissoesGrupoModel; +use Orangecode\Acl\Model\PermissoesModel; +use Orangecode\Acl\Model\PermissoesModuloModel; use Orangecode\Repository\Repository; use Orangecode\Repository\RepositoryDataBase; +/** + * Repository - Permissões Acl + */ class PermissoesAclRepository implements Repository { use RepositoryDataBase; - /** @var Permissoes */ - private Permissoes $model; + private PermissoesModel $model; + + private PermissoesGrupoModel $permissoesGrupo; + + private PermissoesModuloModel $permissoesModulo; + + public function __construct( + PermissoesModel $permissoes, + PermissoesGrupoModel $permissoesGrupo, + PermissoesModuloModel $permissoesModulo + ) { + $this->model = $permissoes; + $this->permissoesModulo = $permissoesModulo; + $this->permissoesGrupo = $permissoesGrupo; + } + + /** + * Realiza a pesquisa - Permissões Acl + */ + public function findAll(int $grupo = null): Collection + { + return $this->model::select('*') + ->where('ativo', 'S') + ->when(!empty($grupo) ? $grupo : false, function ($query, $grupo) { + $query->where('id_permissoes_grupo', $grupo); + }) + ->get(); + } + + /** + * Realiza a pesquisa dos módulos - Permissões Acl + */ + public function findModulo(): Collection + { + return $this->permissoesModulo::all() + ->map(function ($item) { + $data = $item; + $data->name = $item->nome; + return $data; + }); + } + + /** + * Realiza a pesquisa do grupo de permissões - Permissões Acl + */ + public function findGrupo(int $modulo = null): Collection + { + return $this->permissoesGrupo::select('*') + ->when(!empty($modulo) ? $modulo : false, function ($query, $modulo) { + $query->where('id_permissoes_modulo', $modulo); + }) + ->get() + ->map(function ($item) { + $data = $item; + $data->name = $item->nome; + return $data; + }); + } /** - * @param Permissoes $perfil + * Realiza a pesquisa permissões por usuário - Permissões Acl */ - public function __construct(Permissoes $perfil) + public function findAllUser(?int $grupo = null, ?int $user = null): Collection { - $this->model = $perfil; + $permissoes = DB::table('usuario_filial_acl_perfil') + ->select(['acl_perfil_permissoes.id_permissoes']) + ->join('acl_perfil', 'acl_perfil.id', '=', 'usuario_filial_acl_perfil.id_acl_perfil') + ->join('acl_perfil_permissoes', 'acl_perfil_permissoes.id_perfil', '=', 'acl_perfil.id') + ->where('usuario_filial_acl_perfil.id_usuario_filial', '=', $user) + ->get() + ->groupBy('id_permissoes') + ->keys() + ->all(); + return $this->model::select('*') + ->where('ativo', 'S') + ->whereNotIn('id', $permissoes) + ->when(!empty($grupo) ? $grupo : false, function ($query, $grupo) { + $query->where('id_permissoes_grupo', $grupo); + }) + ->get(); } } diff --git a/src/Acl/Repository/PermissoesUsuarioAclRepository.php b/src/Acl/Repository/PermissoesUsuarioAclRepository.php index b5865a6..d6b106f 100644 --- a/src/Acl/Repository/PermissoesUsuarioAclRepository.php +++ b/src/Acl/Repository/PermissoesUsuarioAclRepository.php @@ -2,22 +2,61 @@ namespace Orangecode\Acl\Repository; -use Orangecode\Acl\Model\PermissoesUsuario; +use Illuminate\Database\Eloquent\Collection; +use Illuminate\Support\Facades\DB; +use Orangecode\Acl\Model\PermissoesModel; +use Orangecode\Acl\Model\PermissoesUsuarioModel; use Orangecode\Repository\Repository; use Orangecode\Repository\RepositoryDataBase; +/** + * Repository - Permissões Usuário Acl + */ class PermissoesUsuarioAclRepository implements Repository { use RepositoryDataBase; - /** @var PermissoesUsuario */ - private PermissoesUsuario $model; + private PermissoesUsuarioModel $model; + + private PermissoesModel $permissoes; + + public function __construct( + PermissoesUsuarioModel $model, + PermissoesModel $permissoes + ) { + $this->model = $model; + $this->permissoes = $permissoes; + } /** - * @param PermissoesUsuario $perfil + * Realiza a pesquisa das permissões por usuário - Permissões Usuário Acl */ - public function __construct(PermissoesUsuario $perfil) + public function findAll(?int $grupo, ?int $user): Collection { - $this->model = $perfil; + $permissoesUser = $this->model::select('*') + ->where('id_usuario_filial', '=', $user) + ->get(); + $permissoes = DB::table('usuario_filial_acl_perfil') + ->select(['acl_perfil_permissoes.id_permissoes']) + ->join('acl_perfil', 'acl_perfil.id', '=', 'usuario_filial_acl_perfil.id_acl_perfil') + ->join('acl_perfil_permissoes', 'acl_perfil_permissoes.id_perfil', '=', 'acl_perfil.id') + ->where('usuario_filial_acl_perfil.id_usuario_filial', '=', $user) + ->get() + ->groupBy('id_permissoes') + ->keys() + ->all(); + return $this->permissoes::where('id_permissoes_grupo', $grupo) + ->whereNotIn('id', $permissoes) + ->where('ativo', 'S') + ->orderBy('id') + ->get() + ->map(function ($item) use ($permissoesUser) { + $data = $item; + $data->active = !is_bool($permissoesUser->search(function ($value) use ($item) { + return $item->id == $value->id_permissoes; + })); + $data->label = $item->id . ' -> ' . $item->nome; + return $data; + }); } } diff --git a/src/Acl/Service/PerfilAclService.php b/src/Acl/Service/PerfilAclService.php index 45eaca7..6b5f855 100644 --- a/src/Acl/Service/PerfilAclService.php +++ b/src/Acl/Service/PerfilAclService.php @@ -3,36 +3,19 @@ namespace Orangecode\Acl\Service; use Illuminate\Http\Request; -use Illuminate\Support\Collection; use Orangecode\Service\ServiceBase; -use Orangecode\Service\Response\ServiceResponse; use Orangecode\Acl\Repository\PerfilAclRepository; +/** + * Service - Perfil Acl + * + * @method findAll(int $filial) + */ class PerfilAclService extends ServiceBase { - /** - * @param PerfilAclRepository $repository - * @param ServiceResponse $response - */ - public function __construct(PerfilAclRepository $repository, ServiceResponse $response) - { - parent::__construct($repository, $response); - } - - /** - * Realiza a pesquisa do perfil por filial - * @param int $filial - * @return Collection - */ - public function findFilial(int $filial): Collection + public function __construct(PerfilAclRepository $repository) { - return $this->getModel()::where('id_filial', $filial) - ->get() - ->map(function ($item) { - $data = $item; - $data->label = $item->nome; - return $data; - }); + parent::__construct($repository); } /** diff --git a/src/Acl/Service/PerfilPermissoesAclService.php b/src/Acl/Service/PerfilPermissoesAclService.php index 0154d67..0e06d81 100644 --- a/src/Acl/Service/PerfilPermissoesAclService.php +++ b/src/Acl/Service/PerfilPermissoesAclService.php @@ -3,50 +3,20 @@ namespace Orangecode\Acl\Service; use Illuminate\Http\Request; -use Illuminate\Support\Collection; use Illuminate\Support\Facades\DB; use Orangecode\Service\ServiceBase; -use Orangecode\Service\Response\ServiceResponse; use Orangecode\Acl\Repository\PerfilPermissoesAclRepository; +/** + * Service - Perfil Permissões ACL + * + * @method findAll(int $perfil, int $grupo) + */ class PerfilPermissoesAclService extends ServiceBase { - /** @var PermissoesAclService */ - private PermissoesAclService $aclPermissoes; - - /** - * @param PerfilPermissoesAclRepository $repository - * @param ServiceResponse $response - * @param PermissoesAclService $aclPermissoes - */ - public function __construct(PerfilPermissoesAclRepository $repository, ServiceResponse $response, PermissoesAclService $aclPermissoes) - { - parent::__construct($repository, $response); - $this->aclPermissoes = $aclPermissoes; - } - - /** - * Realiza a pesquisa das permissões para perfil - * @param int $perfil - * @return Collection - */ - public function findAll(int $perfil, int $grupo): Collection + public function __construct(PerfilPermissoesAclRepository $repository) { - $perfilPermissoes = DB::table('acl_perfil_permissoes') - ->where('id_perfil', $perfil) - ->get(); - return $this->aclPermissoes->getModel()::where('id_permissoes_grupo', $grupo) - ->where('ativo', 'S') - ->orderBy('id') - ->get() - ->map(function ($item) use ($perfilPermissoes) { - $data = $item; - $data->active = !is_bool($perfilPermissoes->search(function ($value) use ($item) { - return $item->id == $value->id_permissoes; - })); - $data->label = $item->id . ' -> ' . $item->nome; - return $data; - }); + parent::__construct($repository); } /** diff --git a/src/Acl/Service/PermissoesAclService.php b/src/Acl/Service/PermissoesAclService.php index 9632ed7..279ffb0 100644 --- a/src/Acl/Service/PermissoesAclService.php +++ b/src/Acl/Service/PermissoesAclService.php @@ -2,96 +2,21 @@ namespace Orangecode\Acl\Service; -use Illuminate\Support\Collection; -use Illuminate\Support\Facades\DB; use Orangecode\Acl\Repository\PermissoesAclRepository; -use Orangecode\Service\Response\ServiceResponse; use Orangecode\Service\ServiceBase; +/** + * Service - Permissões Acl + * + * @method findModulo() + * @method findGrupo(?int $modulo = null) + * @method findAll(int $grupo = null) + * @method findAllUser(?int $grupo = null, ?int $user = null) + */ class PermissoesAclService extends ServiceBase { - /** - * @param PermissoesAclRepository $repository - * @param ServiceResponse $response - */ - public function __construct(PermissoesAclRepository $repository, ServiceResponse $response) + public function __construct(PermissoesAclRepository $repository) { - parent::__construct($repository, $response); - } - - /** - * Realiza a pesquisa por módulo - * @return Collection - */ - public function findModulo(): Collection - { - return DB::table('acl_permissoes_modulo') - ->get() - ->map(function ($item) { - $data = $item; - $data->name = $item->nome; - return $data; - }); - } - - /** - * Realiza a pesquisa do grupo - * @param int|null $modulo - * @return Collection - */ - public function findGrupo(int $modulo = null): Collection - { - return DB::table('acl_permissoes_grupo') - ->when(!empty($modulo) ? $modulo : false, function ($query, $modulo) { - $query->where('id_permissoes_modulo', $modulo); - }) - ->get() - ->map(function ($item) { - $data = $item; - $data->name = $item->nome; - return $data; - }); - ; - } - - /** - * Realiza a pesquisa das permissões - * @param int|null $grupo - * @return Collection - */ - public function findAll(int $grupo = null): Collection - { - return DB::table('acl_permissoes') - ->where('ativo', 'S') - ->when(!empty($grupo) ? $grupo : false, function ($query, $grupo) { - $query->where('id_permissoes_grupo', $grupo); - }) - ->get(); - } - - /** - * Realiza a pesquisa das permissões por usuário - * @param int|null $grupo - * @param int|null $user - * @return Collection - */ - public function findAllUser(int $grupo = null, int $user = null): Collection - { - $permissoes = DB::table('usuario_filial_acl_perfil') - ->select(['acl_perfil_permissoes.id_permissoes']) - ->join('acl_perfil', 'acl_perfil.id', '=', 'usuario_filial_acl_perfil.id_acl_perfil') - ->join('acl_perfil_permissoes', 'acl_perfil_permissoes.id_perfil', '=', 'acl_perfil.id') - ->where('usuario_filial_acl_perfil.id_usuario_filial', '=', $user) - ->get() - ->groupBy('id_permissoes') - ->keys() - ->all(); - return DB::table('acl_permissoes') - ->where('ativo', 'S') - ->whereNotIn('id', $permissoes) - ->when(!empty($grupo) ? $grupo : false, function ($query, $grupo) { - $query->where('id_permissoes_grupo', $grupo); - }) - ->get(); + parent::__construct($repository); } } diff --git a/src/Acl/Service/PermissoesUsuarioAclService.php b/src/Acl/Service/PermissoesUsuarioAclService.php index 99208fe..893bde1 100644 --- a/src/Acl/Service/PermissoesUsuarioAclService.php +++ b/src/Acl/Service/PermissoesUsuarioAclService.php @@ -3,62 +3,20 @@ namespace Orangecode\Acl\Service; use Illuminate\Http\Request; -use Illuminate\Support\Collection; use Illuminate\Support\Facades\DB; use Orangecode\Service\ServiceBase; -use Orangecode\Service\Response\ServiceResponse; use Orangecode\Acl\Repository\PermissoesUsuarioAclRepository; +/** + * Service - Permissões Usuário Acl + * + * @method findAll(int $grupo, int $user) + */ class PermissoesUsuarioAclService extends ServiceBase { - /** @var PermissoesAclService */ - private PermissoesAclService $aclPermissoes; - - /** - * @param PermissoesUsuarioAclRepository $repository - * @param ServiceResponse $response - * @param PermissoesAclService $aclPermissoes - */ - public function __construct( - PermissoesUsuarioAclRepository $repository, - ServiceResponse $response, - PermissoesAclService $aclPermissoes - ) { - parent::__construct($repository, $response); - $this->aclPermissoes = $aclPermissoes; - } - - /** - * Realiza a pesquisa das permissões por usuário - * @return Collection - */ - public function findAll(int $grupo, int $user): Collection + public function __construct(PermissoesUsuarioAclRepository $repository) { - $permissoesUser = DB::table('acl_permissoes_usuario') - ->where('id_usuario_filial', '=', $user) - ->get(); - $permissoes = DB::table('usuario_filial_acl_perfil') - ->select(['acl_perfil_permissoes.id_permissoes']) - ->join('acl_perfil', 'acl_perfil.id', '=', 'usuario_filial_acl_perfil.id_acl_perfil') - ->join('acl_perfil_permissoes', 'acl_perfil_permissoes.id_perfil', '=', 'acl_perfil.id') - ->where('usuario_filial_acl_perfil.id_usuario_filial', '=', $user) - ->get() - ->groupBy('id_permissoes') - ->keys() - ->all(); - return $this->aclPermissoes->getModel()::where('id_permissoes_grupo', $grupo) - ->whereNotIn('id', $permissoes) - ->where('ativo', 'S') - ->orderBy('id') - ->get() - ->map(function ($item) use ($permissoesUser) { - $data = $item; - $data->active = !is_bool($permissoesUser->search(function ($value) use ($item) { - return $item->id == $value->id_permissoes; - })); - $data->label = $item->id . ' -> ' . $item->nome; - return $data; - }); + parent::__construct($repository); } /**