Initial commit
This commit is contained in:
36
app/Services/XenforoService.php
Normal file
36
app/Services/XenforoService.php
Normal file
@@ -0,0 +1,36 @@
|
||||
<?php
|
||||
|
||||
namespace App\Services;
|
||||
|
||||
use Illuminate\Support\Facades\Cache;
|
||||
|
||||
class XenforoService {
|
||||
|
||||
private const array PERMISSIONS_KEPT = [ 'general', 'romhackplaza' ];
|
||||
private const int TTL_PERMISSIONS = 300;
|
||||
|
||||
public function getPermissions(int $userId, int $permissionCombinationId): array {
|
||||
|
||||
return Cache::remember("xf_permissions_{$userId}", self::TTL_PERMISSIONS, function() use($permissionCombinationId) {
|
||||
$row = \DB::connection('xenforo')
|
||||
->table('permission_combination')
|
||||
->where('permission_combination_id', $permissionCombinationId)
|
||||
->value('cache_value');
|
||||
|
||||
if( !$row )
|
||||
return [];
|
||||
|
||||
$data = json_decode($row, true);
|
||||
$data = array_intersect_key($data, array_flip(self::PERMISSIONS_KEPT));
|
||||
|
||||
return $data ?: [];
|
||||
|
||||
});
|
||||
|
||||
}
|
||||
|
||||
public function clearUserData(int $userId): void
|
||||
{
|
||||
Cache::forget("xf_permissions_{$userId}");
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user