mirror of
https://github.com/NNTmux/newznab-tmux.git
synced 2026-08-29 01:08:56 +00:00
Update user_excluded_categories
This commit is contained in:
@@ -35,4 +35,9 @@ class Category extends Model
|
||||
{
|
||||
return $this->hasMany(static::class, 'parentid');
|
||||
}
|
||||
|
||||
public function userExcludedCategory()
|
||||
{
|
||||
return $this->belongsTo('App\Models\UserExcludedCategory', 'categories_id');
|
||||
}
|
||||
}
|
||||
|
||||
+6
-14
@@ -22,20 +22,7 @@ class User extends Authenticatable
|
||||
/**
|
||||
* @var array
|
||||
*/
|
||||
protected $fillable = [
|
||||
'username',
|
||||
'password',
|
||||
'email',
|
||||
'user_roles_id',
|
||||
'created_at',
|
||||
'updated_at',
|
||||
'host',
|
||||
'rsstoken',
|
||||
'invites',
|
||||
'invitedby',
|
||||
'userseed',
|
||||
'notes',
|
||||
];
|
||||
protected $guarded = [];
|
||||
|
||||
/**
|
||||
* @var array
|
||||
@@ -71,4 +58,9 @@ class User extends Authenticatable
|
||||
{
|
||||
return $this->hasMany('App\Models\DnzbFailure', 'users_id');
|
||||
}
|
||||
|
||||
public function excludedCategory()
|
||||
{
|
||||
return $this->hasMany('App\Models\UserExcludedCategory', 'users_id');
|
||||
}
|
||||
}
|
||||
|
||||
@@ -6,5 +6,17 @@ use Illuminate\Database\Eloquent\Model;
|
||||
|
||||
class UserExcludedCategory extends Model
|
||||
{
|
||||
//
|
||||
protected $dateFormat = false;
|
||||
|
||||
protected $guarded = [];
|
||||
|
||||
public function user()
|
||||
{
|
||||
return $this->belongsTo('App\Models\User', 'users_id');
|
||||
}
|
||||
|
||||
public function category()
|
||||
{
|
||||
return $this->hasMany('App\Models\Category', 'categories_id');
|
||||
}
|
||||
}
|
||||
|
||||
+5
-4
@@ -2,6 +2,7 @@
|
||||
|
||||
namespace nntmux;
|
||||
|
||||
use App\Models\UserExcludedCategory;
|
||||
use nntmux\db\DB;
|
||||
use Carbon\Carbon;
|
||||
use App\Models\User;
|
||||
@@ -171,7 +172,7 @@ class Users
|
||||
*/
|
||||
public function delUserCategoryExclusions($uid): void
|
||||
{
|
||||
$this->pdo->queryExec(sprintf('DELETE FROM user_excluded_categories WHERE users_id = %d', $uid));
|
||||
UserExcludedCategory::query()->where('users_id', $uid)->delete();
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -987,7 +988,7 @@ class Users
|
||||
$this->delUserCategoryExclusions($uid);
|
||||
if (count($catids) > 0) {
|
||||
foreach ($catids as $catid) {
|
||||
$this->pdo->queryInsert(sprintf('INSERT INTO user_excluded_categories (users_id, categories_id, created_at) VALUES (%d, %d, now())', $uid, $catid));
|
||||
UserExcludedCategory::query()->insertGetId(['users_id' => $uid, 'categories_id' => $catid, 'created_at' => Carbon::now()]);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1000,7 +1001,7 @@ class Users
|
||||
public function getRoleCategoryExclusion($role): array
|
||||
{
|
||||
$ret = [];
|
||||
$categories = $this->pdo->query(sprintf('SELECT categories_id FROM role_excluded_categories WHERE role = %d', $role));
|
||||
$categories = UserExcludedCategory::query()->where('role', $role)->get(['categories_id']);
|
||||
foreach ($categories as $category) {
|
||||
$ret[] = $category['categories_id'];
|
||||
}
|
||||
@@ -1076,7 +1077,7 @@ class Users
|
||||
*/
|
||||
public function delCategoryExclusion($uid, $catid): void
|
||||
{
|
||||
$this->pdo->queryExec(sprintf('DELETE FROM user_excluded_categories WHERE users_id = %d AND categories_id = %d', $uid, $catid));
|
||||
UserExcludedCategory::query()->where(['users_id'=> $uid, 'categories_id' => $catid])->delete();
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
Reference in New Issue
Block a user