mirror of
https://gh.wpcy.net/https://github.com/elementor/one-click-accessibility.git
synced 2026-04-21 05:27:17 +08:00
* [APP-1108][APP-1109][APP-1110] Add analytics backend logic * [APP-1108][APP-1109][APP-1110] Add analytics backend logic * Add nonce to the widget settings * Update routes and DB table * Fix comments * Fix comments * Fix comments * Fix comments * Fix comments * Fix comments * [APP-1107] Add dashboard for analytics * [APP-1107] Add dashboard for analytics * [APP-1107] Add dashboard for analytics * [APP-1107] Add dashboard for analytics * [APP-1107] Add dashboard for analytics * [APP-1107] Add dashboard for analytics * [APP-1107] Add dashboard for analytics * [APP-1107] Add dashboard for analytics * [APP-1107] Add dashboard for analytics * [APP-1107] Add dashboard for analytics * [APP-1201] add accessibility rules * [APP-1107] fixed API endpoint * [APP-1107] fixed API endpoint * [APP-1107] fixed API endpoint * [APP-1107] add check for is_active * update to the latest * update to the latest * update to the latest * fix bugs, add changes * fix bugs, add changes * fix bugs, add changes * fix bugs, add changes
98 lines
2.1 KiB
PHP
98 lines
2.1 KiB
PHP
<?php
|
|
|
|
namespace EA11y\Modules\Analytics\Database;
|
|
|
|
use EA11y\Classes\Database\Entry;
|
|
|
|
if ( ! defined( 'ABSPATH' ) ) {
|
|
exit; // Exit if accessed directly
|
|
}
|
|
|
|
/**
|
|
* Class Analytics_Entry
|
|
*/
|
|
class Analytics_Entry extends Entry {
|
|
/**
|
|
* @var string
|
|
*/
|
|
public string $event;
|
|
|
|
/**
|
|
* @var string|null
|
|
*/
|
|
public ?string $value;
|
|
|
|
public static function get_helper_class(): string {
|
|
return Analytics_Table::get_class_name();
|
|
}
|
|
|
|
/**
|
|
* Get data for diagrams
|
|
* @param string $period
|
|
*
|
|
* @return array
|
|
*/
|
|
public static function get_data_dates_grouped( string $period ): array {
|
|
$fields = 'DATE(created_at) AS date, COUNT(*) AS total';
|
|
$where = [
|
|
[
|
|
'column' => 'created_at',
|
|
'value' => $period,
|
|
'operator' => '>',
|
|
'relation_after' => 'AND',
|
|
],
|
|
[
|
|
'column' => 'event',
|
|
'value' => 'widget-open',
|
|
'operator' => '=',
|
|
],
|
|
];
|
|
$order_by = [ 'date' => 'ASC' ];
|
|
$group_by = 'date';
|
|
return Analytics_Table::select( $fields, $where, null, null, '', $order_by, $group_by );
|
|
}
|
|
|
|
/**
|
|
* Get data for diagrams
|
|
* @param string $period
|
|
*
|
|
* @return array
|
|
*/
|
|
public static function get_data_events_grouped( string $period ): array {
|
|
$fields = 'event, value, COUNT(*) AS total';
|
|
$where = [
|
|
[
|
|
'column' => 'created_at',
|
|
'value' => $period,
|
|
'operator' => '>',
|
|
'relation_after' => 'AND',
|
|
],
|
|
[
|
|
'column' => 'event',
|
|
'value' => 'widget-open',
|
|
'operator' => '<>',
|
|
],
|
|
];
|
|
$order_by = [ 'total' => 'DESC' ];
|
|
$group_by = [ 'event', 'value' ];
|
|
return Analytics_Table::select( $fields, $where, null, null, '', $order_by, $group_by );
|
|
}
|
|
|
|
/**
|
|
* @param string $event
|
|
*
|
|
* @return bool
|
|
*/
|
|
public static function validate_item( string $event ): bool {
|
|
return in_array( $event, Analytics_Table::EVENTS, true );
|
|
}
|
|
|
|
/**
|
|
* Delete events oldest then 45 days
|
|
* @return void
|
|
*/
|
|
public static function delete_expired_entries() {
|
|
$query = 'DELETE FROM `' . Analytics_Table::table_name() . '` WHERE `' . Analytics_Table::CREATED_AT . '` < NOW() - INTERVAL 45 DAY';
|
|
Analytics_Table::query( $query );
|
|
}
|
|
}
|