Initial Commit

This commit is contained in:
Daeng Deni Mardaeni
2024-08-07 08:47:07 +07:00
commit 225b326a5e
60 changed files with 3408 additions and 0 deletions

51
app/Models/Base.php Normal file
View File

@@ -0,0 +1,51 @@
<?php
namespace Modules\Usermanagement\Models;
use Illuminate\Database\Eloquent\Model;
use Illuminate\Database\Eloquent\SoftDeletes;
use Spatie\Activitylog\LogOptions;
use Spatie\Activitylog\Traits\LogsActivity;
use Wildside\Userstamps\Userstamps;
/**
*
*/
class Base extends Model
{
use LogsActivity, SoftDeletes, Userstamps;
protected $connection;
/**
* Constructs a new instance of the class.
*
* @param array $attributes Optional attributes to initialize the object with.
*
* @return void
*/
public function __construct(array $attributes = [])
{
parent::__construct($attributes);
// Retrieve the module configuration from the module.json file
$modulePath = dirname(__FILE__, 3) . '/module.json';
$module = file_get_contents($modulePath);
$module = json_decode($module);
// Set the connection property to the database connection specified in the module configuration
$this->connection = $module->database;
}
/**
* Retrieves the activity log options for the User Management.
*
* @return LogOptions The activity log options.
*/
public function getActivitylogOptions()
: LogOptions
{
return LogOptions::defaults()->logAll()->useLogName('User Management : ');
}
}

33
app/Models/Permission.php Normal file
View File

@@ -0,0 +1,33 @@
<?php
namespace Modules\Usermanagement\Models;
use Spatie\Activitylog\LogOptions;
use Spatie\Activitylog\Traits\LogsActivity;
use Spatie\Permission\Models\Permission as SpatiePermission;
class Permission extends SpatiePermission
{
use LogsActivity;
/**
* Retrieve the activity log options for this permission.
*
* @return LogOptions The activity log options.
*/
public function getActivitylogOptions()
: LogOptions
{
return LogOptions::defaults()->logAll()->useLogName('User Management|Permissions : ');
}
/**
* Retrieve the permission group associated with this permission.
*
* @return \Illuminate\Database\Eloquent\Relations\BelongsTo The permission group relationship.
*/
public function group()
{
return $this->belongsTo(PermissionGroup::class, 'permission_group_id');
}
}

View File

@@ -0,0 +1,60 @@
<?php
namespace Modules\Usermanagement\Models;
use Spatie\Permission\Models\Role;
class PermissionGroup extends Base
{
protected $fillable = [
'name',
'slug'
];
/**
* Retrieves all permissions associated with a given permission group ID.
*
* @param int $id The ID of the permission group.
*
* @return \Illuminate\Database\Eloquent\Collection The collection of permissions.
*/
public static function getpermissionsByGroupId($id)
{
return Permission::where('permission_group_id', $id)->get();
}
/**
* Returns a relationship instance for the Permission model.
*
* @return \Illuminate\Database\Eloquent\Relations\HasMany
*/
public function permission()
{
return $this->hasMany(Permission::class);
}
/**
* Retrieves the roles associated with a given permission group.
*
* @param object $group The permission group object.
*
* @return array The array of roles associated with the permission group.
*/
public function roles($group)
{
$permission = Permission::where('permission_group_id', $group->id)->first();
$data = [];
$roles = Role::all();
foreach ($roles as $role) {
if ($role->hasPermissionTo($permission->name)) {
array_push($data, $role);
}
}
return $data;
}
}

25
app/Models/Role.php Normal file
View File

@@ -0,0 +1,25 @@
<?php
namespace Modules\Usermanagement\Models;
use Illuminate\Database\Eloquent\SoftDeletes;
use Spatie\Activitylog\LogOptions;
use Spatie\Activitylog\Traits\LogsActivity;
use Spatie\Permission\Models\Role as SpatieRole;
class Role extends SpatieRole
{
use softDeletes, LogsActivity;
/**
* Retrieve the activity log options for this role.
*
* @return LogOptions The activity log options.
*/
public function getActivitylogOptions()
: LogOptions
{
return LogOptions::defaults()->logAll()->useLogName('User Management|Roles : ');
}
}

73
app/Models/User.php Normal file
View File

@@ -0,0 +1,73 @@
<?php
namespace Modules\Usermanagement\Models;
use Illuminate\Database\Eloquent\SoftDeletes;
use Illuminate\Foundation\Auth\User as Authenticatable;
use Illuminate\Notifications\Notifiable;
use Spatie\Permission\Traits\HasRoles;
use Wildside\Userstamps\Userstamps;
/**
* Class User
*
* This class extends the Laravel's Authenticatable class and represents a User in the application.
* It includes traits for using factories, notifications, API tokens, and UUIDs.
*
* @property string $name The name of the user.
* @property string $email The email of the user.
* @property string $password The hashed password of the user.
* @property string $remember_token The token used for "remember me" functionality.
*
* @package App\Models
*/
class User extends Authenticatable
{
use Notifiable, Userstamps, HasRoles, softDeletes;
protected $guard_name = ['web'];
/**
* The attributes that are mass assignable.
*
* These are the attributes that can be set in bulk during a create or update operation.
*
* @var array<int, string>
*/
protected $fillable = [
'name',
'email',
'password',
];
/**
* The attributes that should be hidden for serialization.
*
* These are the attributes that will be hidden when the model is converted to an array or JSON.
*
* @var array<int, string>
*/
protected $hidden = [
'password',
'remember_token',
];
/**
* Get the attributes that should be cast.
*
* This method defines how the attributes should be cast when accessed.
* In this case, 'email_verified_at' is cast to 'datetime', 'password' is cast to 'hashed', and 'id' is cast to 'string'.
*
* @return array<string, string>
*/
protected function casts()
: array
{
return [
'email_verified_at' => 'datetime',
'password' => 'hashed',
'id' => 'string',
];
}
}