mirror of
https://github.com/NNTmux/newznab-tmux.git
synced 2026-08-29 17:28:55 +00:00
4ccbf6a967
[ci skip] [skip ci]
62 lines
1.4 KiB
PHP
62 lines
1.4 KiB
PHP
<?php
|
|
|
|
namespace App\Models;
|
|
|
|
use Illuminate\Support\Carbon;
|
|
use Illuminate\Database\Eloquent\Model;
|
|
|
|
class RoleExcludedCategory extends Model
|
|
{
|
|
protected $dateFormat = false;
|
|
|
|
protected $guarded = [];
|
|
|
|
public function role()
|
|
{
|
|
return $this->belongsTo(UserRole::class, 'user_roles_id');
|
|
}
|
|
|
|
public function category()
|
|
{
|
|
return $this->hasMany(Category::class, 'categories_id');
|
|
}
|
|
|
|
/**
|
|
* @param $role
|
|
*
|
|
* @return array
|
|
*/
|
|
public static function getRoleCategoryExclusion($role): array
|
|
{
|
|
$ret = [];
|
|
$categories = self::query()->where('user_roles_id', $role)->get(['categories_id']);
|
|
foreach ($categories as $category) {
|
|
$ret[] = $category['categories_id'];
|
|
}
|
|
|
|
return $ret;
|
|
}
|
|
|
|
/**
|
|
* @param $role
|
|
* @param $catids
|
|
*/
|
|
public static function addRoleCategoryExclusions($role, array $catids): void
|
|
{
|
|
self::delRoleCategoryExclusions($role);
|
|
if (\count($catids) > 0) {
|
|
foreach ($catids as $catid) {
|
|
self::query()->insertGetId(['user_roles_id' => $role, 'categories_id' => $catid, 'created_at' => Carbon::now()]);
|
|
}
|
|
}
|
|
}
|
|
|
|
/**
|
|
* @param $role
|
|
*/
|
|
public static function delRoleCategoryExclusions($role): void
|
|
{
|
|
self::query()->where('user_roles_id', $role)->delete();
|
|
}
|
|
}
|