RecentVisitors.php
23 lines
| 1 | <?php |
| 2 | |
| 3 | namespace IAWP\RealTime; |
| 4 | |
| 5 | use IAWP\Date_Range\Exact_Date_Range; |
| 6 | use IAWP\Examiner_Config; |
| 7 | use IAWP\Illuminate_Builder; |
| 8 | use IAWP\Query_Taps; |
| 9 | use IAWP\Tables; |
| 10 | /** @internal */ |
| 11 | class RecentVisitors |
| 12 | { |
| 13 | private int $visitors; |
| 14 | public function __construct(Exact_Date_Range $range, ?Examiner_Config $examiner_config) |
| 15 | { |
| 16 | $this->visitors = \intval(Illuminate_Builder::new()->selectRaw('COUNT(DISTINCT sessions.visitor_id) AS visitors')->from(Tables::views(), 'views')->leftJoin(Tables::sessions() . ' AS sessions', 'sessions.session_id', '=', 'views.session_id')->tap(Query_Taps::tap_related_to_examined_record($examiner_config))->whereBetween('viewed_at', [$range->iso_start(), $range->iso_end()])->value('visitors')); |
| 17 | } |
| 18 | public function visitors() : int |
| 19 | { |
| 20 | return $this->visitors; |
| 21 | } |
| 22 | } |
| 23 |