First Commit

This commit is contained in:
marco
2026-09-01 10:46:29 -03:00
commit bf96b77e9c
10000 changed files with 3508600 additions and 0 deletions
+283
View File
@@ -0,0 +1,283 @@
<?php
/**
* SysCMS - Content Management System
*
* Copyright (c) 2025 Marco Costa
* All rights reserved.
*
* Author: Marco Costa
* Email: contato@syspanel.com.br
* Project: SysCMS
*
* This software is licensed, not sold.
* Permission is granted to use this software
* subject to the terms of the SysCMS Commercial License.
*
* Redistribution, sublicensing, resale, or
* disclosure of this software, in whole or in part,
* is strictly prohibited without prior written permission.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND.
*/
namespace App\Models;
use Illuminate\Database\Eloquent\Model;
use Illuminate\Database\Eloquent\Relations\BelongsToMany;
use Modules\Company\Models\Company;
class Module extends Model
{
/**
* The table associated with model.
*
* @var string
*/
protected $table = 'modules';
/**
* The primary key associated with table.
*
* @var string
*/
protected $primaryKey = 'modules_id';
/**
* The attributes that are mass assignable.
*
* @var array
*/
protected $fillable = [
'modules_name',
'modules_display_name',
'modules_description',
'modules_version',
'modules_author',
'modules_ative',
'modules_public',
'modules_blocked',
'modules_dependencies',
'modules_permissions',
'modules_settings',
'modules_path',
'modules_namespace',
'modules_icon',
'menu_side_bar',
'menu_nav_bar',
'modules_order'
];
/**
* The attributes that should be cast.
*
* @var array
*/
protected $casts = [
'modules_ative' => 'boolean',
'modules_public' => 'boolean',
'modules_blocked' => 'boolean',
'menu_side_bar' => 'boolean',
'menu_nav_bar' => 'boolean',
'modules_dependencies' => 'array',
'modules_permissions' => 'array',
'modules_settings' => 'array',
'modules_install_date' => 'datetime',
'modules_update_date' => 'datetime',
'created_at' => 'datetime',
'updated_at' => 'datetime'
];
/**
* The attributes that should be mutated to dates.
*
* @var array
*/
protected $dates = [
'modules_install_date',
'modules_update_date',
'created_at',
'updated_at'
];
/**
* Get companies that use this module.
*/
public function companies(): BelongsToMany
{
return $this->belongsToMany(Company::class, 'bus_modules', 'bus_modules_module_id', 'bus_modules_bus_id')
->withPivot(['bus_modules_is_enabled', 'bus_modules_settings', 'bus_modules_enabled_by', 'bus_modules_enabled_at', 'bus_modules_show_public_nav', 'bus_modules_show_dashboard_nav'])
->withTimestamps();
}
/**
* Scope to get only active modules.
*
* @param \Illuminate\Database\Eloquent\Builder $query
* @return \Illuminate\Database\Eloquent\Builder
*/
public function scopeActive($query)
{
return $query->where('modules_ative', true);
}
/**
* Scope to get only public modules.
*
* @param \Illuminate\Database\Eloquent\Builder $query
* @return \Illuminate\Database\Eloquent\Builder
*/
public function scopePublic($query)
{
return $query->where('modules_public', true);
}
/**
* Scope to get only blocked modules.
*
* @param \Illuminate\Database\Eloquent\Builder $query
* @return \Illuminate\Database\Eloquent\Builder
*/
public function scopeBlocked($query)
{
return $query->where('modules_blocked', true);
}
/**
* Scope to get modules by name.
*
* @param \Illuminate\Database\Eloquent\Builder $query
* @param string $name
* @return \Illuminate\Database\Eloquent\Builder
*/
public function scopeByName($query, string $name)
{
return $query->where('modules_name', $name);
}
/**
* Scope to order modules by order field.
*
* @param \Illuminate\Database\Eloquent\Builder $query
* @return \Illuminate\Database\Eloquent\Builder
*/
public function scopeOrdered($query)
{
return $query->orderBy('modules_order', 'asc');
}
/**
* Check if module is active.
*
* @return bool
*/
public function isActive(): bool
{
return $this->modules_ative;
}
/**
* Check if module is public.
*
* @return bool
*/
public function isPublic(): bool
{
return $this->modules_public;
}
/**
* Check if module is blocked.
*
* @return bool
*/
public function isBlocked(): bool
{
return $this->modules_blocked;
}
/**
* Get module icon with Bootstrap Icons classes.
*
* @return string
*/
public function getIconAttribute(): string
{
return $this->attributes['modules_icon'] ?? 'bi bi-gear';
}
/**
* Get module display name.
*
* @return string
*/
public function getDisplayNameAttribute(): string
{
return $this->modules_display_name ?: $this->modules_name;
}
/**
* Get module dependencies.
*
* @return array
*/
public function getDependenciesAttribute(): array
{
return $this->modules_dependencies ?? [];
}
/**
* Get module permissions.
*
* @return array
*/
public function getPermissionsAttribute(): array
{
return $this->modules_permissions ?? [];
}
/**
* Get module settings.
*
* @return array
*/
public function getSettingsAttribute(): array
{
return $this->modules_settings ?? [];
}
/**
* Get setting value.
*
* @param string $key
* @param mixed $default
* @return mixed
*/
public function getSetting(string $key, $default = null)
{
$settings = $this->getSettingsAttribute();
return $settings[$key] ?? $default;
}
/**
* Check if module has specific permission.
*
* @param string $permission
* @return bool
*/
public function hasPermission(string $permission): bool
{
return in_array($permission, $this->getPermissionsAttribute());
}
/**
* Check if module depends on another module.
*
* @param string $dependency
* @return bool
*/
public function hasDependency(string $dependency): bool
{
return in_array($dependency, $this->getDependenciesAttribute());
}
}