Feat: Organize videos by sector
This commit is contained in:
@@ -105,16 +105,33 @@ class AuthController extends Controller
|
||||
$user = auth()->user();
|
||||
$userId = $user->id;
|
||||
$role = $user->role_id;
|
||||
$userSector = $user->sector_id;
|
||||
|
||||
if ($role !== 1) {
|
||||
$stats = Video::query()
|
||||
->where('is_active', true)
|
||||
->whereHas('sectors', function ($s) use ($userSector) {
|
||||
$s->where('sectors.id', $userSector)
|
||||
->orWhere('sectors.slug', "global");
|
||||
})
|
||||
->selectRaw('
|
||||
COUNT(*) as active_count,
|
||||
COUNT(CASE WHEN EXISTS (
|
||||
SELECT 1 FROM video_views
|
||||
WHERE video_views.video_id = videos.id
|
||||
AND video_views.user_id = ?
|
||||
) THEN 1 END) as watched_count
|
||||
', [$userId])
|
||||
->first();
|
||||
} else {
|
||||
$stats = Video::selectRaw('
|
||||
COUNT(CASE WHEN is_active = 1 THEN 1 END) as active_count,
|
||||
COUNT(CASE WHEN is_active = 1 AND EXISTS (
|
||||
SELECT 1 FROM video_views
|
||||
WHERE video_views.video_id = videos.id
|
||||
AND video_views.user_id = ?
|
||||
) THEN 1 END) as watched_count
|
||||
', [$userId])
|
||||
COUNT(CASE WHEN is_active = 1 THEN 1 END) as active_count,
|
||||
COUNT(CASE WHEN is_active = 1 AND EXISTS (
|
||||
SELECT 1 FROM video_views
|
||||
WHERE video_views.video_id = videos.id
|
||||
AND video_views.user_id = ?
|
||||
) THEN 1 END) as watched_count
|
||||
', [$userId])
|
||||
->first();
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user