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