AJAX
3 months ago
Admin_Page
3 months ago
Click_Tracking
5 months ago
ColumnOptions
6 months ago
Cron
9 months ago
Custom_WordPress_Columns
8 months ago
Data_Pruning
5 months ago
Date_Picker
3 months ago
Date_Range
5 months ago
Ecommerce
5 months ago
Email_Reports
3 months ago
Examiner
3 months ago
Favicon
5 months ago
Form_Submissions
5 months ago
Integrations
3 months ago
Interval
1 year ago
Journey
5 months ago
Migrations
5 months ago
Models
5 months ago
Overview
3 months ago
Public_API
5 months ago
Rows
3 months ago
Statistics
3 months ago
Tables
3 months ago
Utils
5 months ago
Views
5 months ago
WooCommerceOrderMetaBox
5 months ago
ActivationLifecycle.php
3 months ago
Admin_Bar_Stats.php
3 months ago
Appearance.php
1 year ago
Campaign_Builder.php
3 months ago
Capability_Manager.php
3 months ago
Chart.php
3 months ago
Chart_Data.php
1 year ago
Click_Tracking.php
3 months ago
ComplianzIntegration.php
3 months ago
Cron_Job.php
5 months ago
Cron_Manager.php
5 months ago
Current_Traffic_Finder.php
1 year ago
Dashboard_Options.php
6 months ago
Dashboard_Widget.php
2 years ago
Database.php
8 months ago
Database_Manager.php
5 months ago
Empty_Report_Option.php
2 years ago
Env.php
6 months ago
Examiner_Config.php
11 months ago
FetchFaviconsJob.php
5 months ago
Filters.php
3 months ago
Geo_Database_Health_Check_Job.php
9 months ago
Geo_Database_Manager.php
6 months ago
Geoposition.php
1 year ago
Icon_Directory.php
6 months ago
Icon_Directory_Factory.php
2 years ago
Illuminate_Builder.php
10 months ago
Independent_Analytics.php
5 months ago
Interrupt.php
3 months ago
Known_Referrers.php
6 months ago
MainWP.php
1 year ago
Map.php
9 months ago
Map_Data.php
1 year ago
Migration_Fixer_Job.php
5 months ago
Patch.php
1 year ago
Payload_Validator.php
9 months ago
Plugin_Conflict_Detector.php
6 months ago
Plugin_Group.php
6 months ago
Plugin_Group_Option.php
2 years ago
Query.php
1 year ago
Query_Taps.php
3 months ago
Quick_Stats.php
3 months ago
REST_API.php
3 months ago
Real_Time.php
3 months ago
Report.php
1 year ago
Report_Finder.php
6 months ago
Report_Options_Parser.php
9 months ago
Resource_Identifier.php
9 months ago
Settings.php
3 months ago
Sort_Configuration.php
9 months ago
Tables.php
8 months ago
Track_Resource_Changes.php
1 year ago
View_Counter.php
6 months ago
Views_Over_Time_Finder.php
1 year ago
VisitorSaltRefreshInterval.php
6 months ago
WP_Option_Cache_Bust.php
2 years ago
Query_Taps.php
137 lines
| 1 | <?php |
| 2 | |
| 3 | namespace IAWP; |
| 4 | |
| 5 | use IAWPSCOPED\Illuminate\Database\Query\Builder; |
| 6 | use IAWPSCOPED\Illuminate\Database\Query\JoinClause; |
| 7 | use IAWPSCOPED\Illuminate\Support\Str; |
| 8 | /** @internal */ |
| 9 | class Query_Taps |
| 10 | { |
| 11 | public static function tap_authored_content_check($should_join_resources = \true) |
| 12 | { |
| 13 | return function (Builder $query) use($should_join_resources) { |
| 14 | if (!\is_user_logged_in() || \IAWP\Capability_Manager::can_view_all_analytics()) { |
| 15 | return; |
| 16 | } |
| 17 | if ($should_join_resources) { |
| 18 | $resources_table = \IAWP\Query::get_table_name(\IAWP\Query::RESOURCES); |
| 19 | $query->leftJoin($query->raw($resources_table . ' AS resources'), function (JoinClause $join) { |
| 20 | $join->on('views.resource_id', '=', 'resources.id'); |
| 21 | }); |
| 22 | } |
| 23 | $query->where('resources.cached_author_id', '=', \get_current_user_id()); |
| 24 | }; |
| 25 | } |
| 26 | public static function tap_authored_content_for_clicks() |
| 27 | { |
| 28 | return function (Builder $query) { |
| 29 | if (!\is_user_logged_in() || \IAWP\Capability_Manager::can_view_all_analytics()) { |
| 30 | return; |
| 31 | } |
| 32 | $resources_table = \IAWP\Query::get_table_name(\IAWP\Query::RESOURCES); |
| 33 | $query->leftJoin($query->raw($resources_table . ' AS resources'), function (JoinClause $join) { |
| 34 | $join->on('views.resource_id', '=', 'resources.id'); |
| 35 | }); |
| 36 | $query->where('resources.cached_author_id', '=', \get_current_user_id()); |
| 37 | }; |
| 38 | } |
| 39 | public static function tap_related_to_examined_record(?\IAWP\Examiner_Config $config, array $tables = []) |
| 40 | { |
| 41 | return function (Builder $query) use($config, $tables) { |
| 42 | if (!$config) { |
| 43 | return; |
| 44 | } |
| 45 | $column = self::examiner_type_to_column($config->group()); |
| 46 | if (!$column) { |
| 47 | return; |
| 48 | } |
| 49 | if ($config->group() === 'referrer_type') { |
| 50 | $query->leftJoin(\IAWP\Tables::referrers() . ' AS referrers', 'sessions.referrer_id', '=', 'referrers.id'); |
| 51 | } |
| 52 | $campaign_groups = ['landing_page', 'utm_source', 'utm_medium', 'utm_campaign']; |
| 53 | if (\in_array($config->group(), $campaign_groups)) { |
| 54 | $query->leftJoin(\IAWP\Tables::campaigns() . ' AS campaigns', 'sessions.campaign_id', '=', 'campaigns.campaign_id'); |
| 55 | } |
| 56 | if ($config->group() === 'link' || $config->group() === 'link_pattern') { |
| 57 | if (!\in_array('clicks', $tables)) { |
| 58 | $query->leftJoin(\IAWP\Tables::clicks() . ' AS clicks', 'clicks.view_id', '=', 'views.id'); |
| 59 | } |
| 60 | $query->leftJoin(\IAWP\Tables::clicked_links() . ' AS clicked_links', 'clicked_links.click_id', '=', 'clicks.click_id'); |
| 61 | $query->leftJoin(\IAWP\Tables::links() . ' AS links', 'links.id', '=', 'clicked_links.link_id'); |
| 62 | } |
| 63 | $query->where($column, '=', $config->id()); |
| 64 | }; |
| 65 | } |
| 66 | public static function tap_related_to_examined_record_for_previous_period(?\IAWP\Examiner_Config $config, array $tables) |
| 67 | { |
| 68 | return function (Builder $query) use($config, $tables) { |
| 69 | if (!$config) { |
| 70 | return; |
| 71 | } |
| 72 | $column = self::examiner_type_to_column($config->group()); |
| 73 | if (!$column) { |
| 74 | return; |
| 75 | } |
| 76 | $table = Str::before($column, '.'); |
| 77 | if (!\in_array($table, $tables)) { |
| 78 | if ($table === 'views') { |
| 79 | $query->leftJoin(\IAWP\Tables::views() . ' AS views', 'sessions.session_id', '=', 'views.session_id'); |
| 80 | } |
| 81 | if ($table === 'referrers') { |
| 82 | $query->leftJoin(\IAWP\Tables::referrers() . ' AS referrers', 'sessions.referrer_id', '=', 'referrers.id'); |
| 83 | } |
| 84 | if ($table === 'campaigns') { |
| 85 | $query->leftJoin(\IAWP\Tables::campaigns() . ' AS campaigns', 'sessions.campaign_id', '=', 'campaigns.campaign_id'); |
| 86 | } |
| 87 | if ($table === 'links') { |
| 88 | if (!\in_array('views', $tables)) { |
| 89 | $query->leftJoin(\IAWP\Tables::views() . ' AS views', 'sessions.session_id', '=', 'views.session_id'); |
| 90 | } |
| 91 | $query->leftJoin(\IAWP\Tables::clicks() . ' AS clicks', 'views.id', '=', 'clicks.view_id'); |
| 92 | $query->leftJoin(\IAWP\Tables::clicked_links() . ' AS clicked_links', 'clicked_links.click_id', '=', 'clicks.click_id'); |
| 93 | $query->leftJoin(\IAWP\Tables::links() . ' AS links', 'links.id', '=', 'clicked_links.link_id'); |
| 94 | } |
| 95 | } |
| 96 | $query->where($column, '=', $config->id()); |
| 97 | }; |
| 98 | } |
| 99 | private static function examiner_type_to_column(string $group) : ?string |
| 100 | { |
| 101 | switch ($group) { |
| 102 | case 'page': |
| 103 | return 'views.resource_id'; |
| 104 | case 'referrer': |
| 105 | return 'sessions.referrer_id'; |
| 106 | case 'referrer_type': |
| 107 | return 'referrers.referrer_type_id'; |
| 108 | case 'country': |
| 109 | return 'sessions.country_id'; |
| 110 | case 'city': |
| 111 | return 'sessions.city_id'; |
| 112 | case 'device_type': |
| 113 | return 'sessions.device_type_id'; |
| 114 | case 'os': |
| 115 | return 'sessions.device_os_id'; |
| 116 | case 'browser': |
| 117 | return 'sessions.device_browser_id'; |
| 118 | case 'campaign': |
| 119 | return 'sessions.campaign_id'; |
| 120 | case 'landing_page': |
| 121 | return 'campaigns.landing_page_id'; |
| 122 | case 'utm_source': |
| 123 | return 'campaigns.utm_source_id'; |
| 124 | case 'utm_medium': |
| 125 | return 'campaigns.utm_medium_id'; |
| 126 | case 'utm_campaign': |
| 127 | return 'campaigns.utm_campaign_id'; |
| 128 | case 'link': |
| 129 | return 'links.id'; |
| 130 | case 'link_pattern': |
| 131 | return 'links.link_rule_id'; |
| 132 | default: |
| 133 | return null; |
| 134 | } |
| 135 | } |
| 136 | } |
| 137 |