Campaigns.php
10 months ago
Cities.php
10 months ago
Countries.php
10 months ago
Device_Browsers.php
10 months ago
Device_OSS.php
10 months ago
Device_Types.php
10 months ago
Filter.php
1 year ago
Forms.php
10 months ago
Link_Patterns.php
10 months ago
Links.php
10 months ago
Pages.php
10 months ago
Referrers.php
10 months ago
Rows.php
11 months ago
Link_Patterns.php
49 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->query(\true), '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 | private function query(?bool $skip_pagination = \false) : Builder |
| 27 | { |
| 28 | if ($skip_pagination) { |
| 29 | $this->number_of_rows = null; |
| 30 | } |
| 31 | $query = 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::clicked_links() . ' AS clicked_links', 'clicked_links.link_rule_id', '=', 'link_rules.link_rule_id')->leftJoin($this->tables::clicks() . ' AS clicks', 'clicks.click_id', '=', 'clicked_links.click_id')->leftJoin($this->tables::click_targets() . ' AS click_targets', 'click_targets.click_target_id', '=', 'clicks.click_target_id')->whereBetween('clicks.created_at', $this->get_current_period_iso_range())->when(\count($this->filters) > 0, function (Builder $query) { |
| 32 | foreach ($this->filters as $filter) { |
| 33 | if (!$this->is_a_calculated_column($filter->column())) { |
| 34 | $filter->apply_to_query($query); |
| 35 | } |
| 36 | } |
| 37 | })->when(\is_int($this->solo_record_id), function (Builder $query) { |
| 38 | $query->where('link_rules.link_rule_id', '=', $this->solo_record_id); |
| 39 | })->when(\is_int($this->number_of_rows), function (Builder $query) { |
| 40 | $query->limit($this->number_of_rows); |
| 41 | })->tap(Query_Taps::tap_authored_content_for_clicks())->when($this->examiner_config, function (Builder $query) { |
| 42 | $query->leftJoin($this->tables::views() . ' AS views', 'views.id', '=', 'clicks.view_id'); |
| 43 | $query->leftJoin($this->tables::sessions() . ' AS sessions', 'sessions.session_id', '=', 'views.session_id'); |
| 44 | $query->tap(Query_Taps::tap_related_to_examined_record($this->examiner_config)); |
| 45 | })->orderBy($this->sort_configuration->column(), $this->sort_configuration->direction())->orderBy('link_name')->groupBy('link_rules.link_rule_id'); |
| 46 | return $query; |
| 47 | } |
| 48 | } |
| 49 |