Skip to main content

Black Friday 2025! Only until December 1st: coupon FRIDAY25 for 40% off Yearly/Lifetime membership!

Read more here

alkrauss48/simple-slides

98 stars
2 code files
View alkrauss48/simple-slides on GitHub

app/Jobs/AggregateDailyViews.php

Open in GitHub
use App\Models\AggregateView;
use App\Models\DailyView;
use Illuminate\Bus\Queueable;
use Illuminate\Contracts\Queue\ShouldQueue;
use Illuminate\Foundation\Bus\Dispatchable;
use Illuminate\Queue\InteractsWithQueue;
use Illuminate\Queue\SerializesModels;
 
class AggregateDailyViews implements ShouldQueue
{
use Dispatchable, InteractsWithQueue, Queueable, SerializesModels;
 
public function handle(): void
{
// Process daily views from presentation records
$presentationData = DailyView::whereNotNull('presentation_id')
->selectRaw('presentation_id, session_id, count(*) as total')
->groupBy('presentation_id', 'session_id')
->get()
->groupBy('presentation_id')
->map(function ($record) {
return [
'presentation_id' => $record[0]->presentation_id,
'unique_count' => $record->count(),
'total_count' => $record->sum('total'),
];
})->values()
->toArray();
 
// Process daily views from adhoc presentations
$adhocData = DailyView::whereNull('presentation_id')
->selectRaw('adhoc_slug, session_id, count(*) as total')
->groupBy('adhoc_slug', 'session_id')
->get()
->groupBy('adhoc_slug')
->map(function ($record) {
return [
'adhoc_slug' => $record[0]->adhoc_slug,
'unique_count' => $record->count(),
'total_count' => $record->sum('total'),
];
})->values()
->toArray();
 
// Note: Inserting these separately, since the columns are different.
AggregateView::insert($presentationData);
AggregateView::insert($adhocData);
 
DailyView::truncate();
}
}

app/Console/Kernel.php

Open in GitHub
use App\Jobs\AggregateDailyViews;
use Illuminate\Console\Scheduling\Schedule;
use Illuminate\Foundation\Console\Kernel as ConsoleKernel;
 
class Kernel extends ConsoleKernel
{
protected function schedule(Schedule $schedule): void
{
$schedule->job(new AggregateDailyViews)->daily();
}
 
// ...
}

We'd Love Your Feedback

Tell us what you like or what we can improve

Feel free to share anything you like or dislike about this page or the platform in general.