phase 8 and 9
This commit is contained in:
@@ -31,4 +31,14 @@ trait ParsesDateRange
|
||||
|
||||
return [$from, $to];
|
||||
}
|
||||
|
||||
private function previousPeriod(Carbon $from, Carbon $to): array
|
||||
{
|
||||
$days = $from->diffInDays($to) + 1;
|
||||
|
||||
$prevTo = $from->copy()->subDay();
|
||||
$prevFrom = $prevTo->copy()->subDays($days - 1);
|
||||
|
||||
return [$prevFrom, $prevTo];
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,37 @@
|
||||
<?php
|
||||
|
||||
namespace App\Http\Controllers\Concerns;
|
||||
|
||||
use App\Models\Segment;
|
||||
use App\Models\Website;
|
||||
use App\Services\AnalyticsQueryService;
|
||||
use Illuminate\Http\Request;
|
||||
use Illuminate\Support\Collection;
|
||||
|
||||
trait ParsesSegment
|
||||
{
|
||||
private function applySegment(Request $request, Website $website, AnalyticsQueryService $service): AnalyticsQueryService
|
||||
{
|
||||
$segmentId = $request->get('segment');
|
||||
if (! $segmentId) {
|
||||
return $service;
|
||||
}
|
||||
|
||||
$segment = $website->segments()->find($segmentId);
|
||||
if (! $segment) {
|
||||
return $service;
|
||||
}
|
||||
|
||||
return $service->withSegment($segment->matchingVisitorIds());
|
||||
}
|
||||
|
||||
private function activeSegment(Request $request, Website $website): ?Segment
|
||||
{
|
||||
$segmentId = $request->get('segment');
|
||||
if (! $segmentId) {
|
||||
return null;
|
||||
}
|
||||
|
||||
return $website->segments()->find($segmentId);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user