This commit is contained in:
2024-09-24 17:22:09 +03:00
parent cb2c719b1b
commit 349c2992dc
13 changed files with 314 additions and 52 deletions

View File

@ -20,6 +20,7 @@ class AdminThemeController extends AdminController
public function actionIndex(): void
{
$admin_theme_paths = Option::where("key", "admin_theme_paths")->first();
$dirs = [];
if ($admin_theme_paths){
$path = json_decode($admin_theme_paths->value);

View File

@ -14,9 +14,9 @@ $table->columns([
]);
$table->addAction(function ($row, $url){
$path = $row['path'];
$active_admin_theme = Option::where("key", "active_admin_theme")->first();
$active_admin_theme = \kernel\modules\option\service\OptionService::getItem('active_admin_theme');
$btn = "<a class='btn btn-primary' href='$url/activate/?p=$path' style='margin: 3px; width: 150px;' >Активировать</a>";
if ($path === $active_admin_theme->value){
if ($path === $active_admin_theme){
$btn = "Активна";
}

View File

@ -49,6 +49,20 @@ class OptionService
return false;
}
/**
* @param $key
* @return false|array|string
*/
public static function getItem($key): false|array|string
{
$item = Option::where("key", $key)->first();
if ($item){
return getConst($item->value);
}
return false;
}
// public function createOptionArr(): array
// {
// foreach (Option::all()->toArray() as $option) {

View File

@ -7,10 +7,13 @@ use Illuminate\Database\Eloquent\Model;
* @property string $username
* @property string $email
* @property string $password_hash
* @method static where(int[] $array)
* @method static find($id)
*/
class User extends Model {
const DEFAULT_USER_ROLE = 1;
const ADMIN_USER_ROLE = 9;
protected $table = 'user';
protected $fillable = ['username', 'email', 'password_hash', 'role'];
protected array $dates = ['deleted at'];

View File

@ -33,6 +33,11 @@ class UserService
return false;
}
public function getByField(string $field, string $value)
{
return User::where($field, $value)->first();
}
public static function createUsernameArr(): array
{
foreach (User::all()->toArray() as $user) {
@ -45,4 +50,26 @@ class UserService
return [];
}
public static function getAuthUser()
{
if (isset($_COOKIE['user_id'])){
$user = User::where("id", $_COOKIE['user_id'])->first();
if ($user){
return $user;
}
}
return false;
}
public static function getAuthUsername(): string
{
$user = self::getAuthUser();
if ($user){
return $user->username;
}
return '';
}
}