Campaign_Landing_Pages.php
5 months ago
Campaign_UTM_Campaigns.php
5 months ago
Campaign_UTM_Mediums.php
5 months ago
Campaign_UTM_Sources.php
5 months ago
Campaigns.php
5 months ago
Cities.php
5 months ago
Countries.php
5 months ago
Device_Browsers.php
5 months ago
Device_OSS.php
5 months ago
Device_Types.php
5 months ago
Filter.php
5 months ago
Forms.php
5 months ago
Journeys.php
5 months ago
Link_Patterns.php
5 months ago
Links.php
5 months ago
Pages.php
5 months ago
Referrer_Types.php
5 months ago
Referrers.php
5 months ago
Rows.php
5 months ago
Link_Patterns.php
52 lines
| 1 | <?php |
| 2 | |
| 3 | namespace IAWP\Rows; |
| 4 | |
| 5 | use IAWP\Illuminate_Builder; |
| 6 | use IAWP\Models\Link_Pattern; |
| 7 | use IAWP\Query_Taps; |
| 8 | use IAWPSCOPED\Illuminate\Database\Query\Builder; |
| 9 | use IAWPSCOPED\Illuminate\Database\Query\JoinClause; |
| 10 | /** @internal */ |
| 11 | class Link_Patterns extends \IAWP\Rows\Rows |
| 12 | { |
| 13 | public function attach_filters(Builder $query) : void |
| 14 | { |
| 15 | $query->joinSub($this->get_filter_query(), 'click_rows', function (JoinClause $join) { |
| 16 | $join->on('click_rows.link_rule_id', '=', 'link_rules.link_rule_id'); |
| 17 | }); |
| 18 | } |
| 19 | protected function fetch_rows() : array |
| 20 | { |
| 21 | $rows = $this->query()->get()->all(); |
| 22 | return \array_map(function ($row) { |
| 23 | return new Link_Pattern($row); |
| 24 | }, $rows); |
| 25 | } |
| 26 | protected function sort_tie_breaker_column() : string |
| 27 | { |
| 28 | return 'link_name'; |
| 29 | } |
| 30 | protected function query(?bool $skip_pagination = \false) : Builder |
| 31 | { |
| 32 | if ($skip_pagination) { |
| 33 | $this->number_of_rows = null; |
| 34 | } |
| 35 | $records = Illuminate_Builder::new()->select(['link_rules.link_rule_id AS link_rule_id', 'link_rules.name AS link_name'])->selectRaw('COUNT(DISTINCT clicks.click_id) AS link_clicks')->from($this->tables::link_rules(), 'link_rules')->leftJoin($this->tables::links() . ' AS links', 'links.link_rule_id', '=', 'link_rules.link_rule_id')->leftJoin($this->tables::click_targets() . ' AS click_targets', 'click_targets.click_target_id', '=', 'links.click_target_id')->leftJoin($this->tables::clicked_links() . ' AS clicked_links', 'clicked_links.link_id', '=', 'links.id')->leftJoin($this->tables::clicks() . ' AS clicks', 'clicks.click_id', '=', 'clicked_links.click_id')->whereBetween('clicks.created_at', $this->get_current_period_iso_range())->when(\is_int($this->solo_record_id), function (Builder $query) { |
| 36 | $query->where('link_rules.link_rule_id', '=', $this->solo_record_id); |
| 37 | })->when(\is_int($this->number_of_rows), function (Builder $query) { |
| 38 | $query->limit($this->number_of_rows); |
| 39 | })->tap(Query_Taps::tap_authored_content_for_clicks())->when($this->examiner_config, function (Builder $query) { |
| 40 | $query->leftJoin($this->tables::views() . ' AS views', 'views.id', '=', 'clicks.view_id'); |
| 41 | $query->leftJoin($this->tables::sessions() . ' AS sessions', 'sessions.session_id', '=', 'views.session_id'); |
| 42 | $query->tap(Query_Taps::tap_related_to_examined_record($this->examiner_config)); |
| 43 | })->orderBy($this->sort_configuration->column(), $this->sort_configuration->direction())->orderBy('link_rules.name')->groupBy('link_rules.link_rule_id')->tap(fn(Builder $query) => $this->apply_record_filters($query)); |
| 44 | $outer_query = Illuminate_Builder::new()->select('*')->fromSub($records, 'records')->tap(fn(Builder $query) => $this->apply_aggregate_filters($query)); |
| 45 | if ($this->using_logical_or_operator() && $this->filtering_by_mixed_columns()) { |
| 46 | $og_outer_query = $outer_query; |
| 47 | $outer_query = Illuminate_Builder::new()->select('*')->fromSub($og_outer_query, 'records')->tap(fn(Builder $query) => $this->apply_or_filters($query))->tap(fn(Builder $query) => $this->apply_order_and_limit($query, $this->sort_configuration->column())); |
| 48 | } |
| 49 | return $outer_query; |
| 50 | } |
| 51 | } |
| 52 |