| 1 |
<?php |
| 2 |
|
| 3 |
namespace Sellkit\Admin\Components\Analytics\Alert; |
| 4 |
|
| 5 |
use Sellkit\Admin\Components\Analytics; |
| 6 |
use Sellkit\Database; |
| 7 |
|
| 8 |
defined( 'ABSPATH' ) || die(); |
| 9 |
|
| 10 |
/** |
| 11 |
* Components class. |
| 12 |
* |
| 13 |
* @since 1.1.0 |
| 14 |
*/ |
| 15 |
class Summary { |
| 16 |
|
| 17 |
/** |
| 18 |
* All valid discounts. |
| 19 |
* |
| 20 |
* @var $data array Discounts. |
| 21 |
*/ |
| 22 |
public $data; |
| 23 |
|
| 24 |
/** |
| 25 |
* Class instance. |
| 26 |
* |
| 27 |
* @since 1.1.0 |
| 28 |
* @var Summary |
| 29 |
*/ |
| 30 |
private static $instance = null; |
| 31 |
|
| 32 |
/** |
| 33 |
* Gets class instance. |
| 34 |
* |
| 35 |
* @since 1.1.0 |
| 36 |
* @return Summary |
| 37 |
*/ |
| 38 |
public static function get_instance() { |
| 39 |
if ( null === self::$instance ) { |
| 40 |
self::$instance = new self(); |
| 41 |
} |
| 42 |
|
| 43 |
return self::$instance; |
| 44 |
} |
| 45 |
|
| 46 |
/** |
| 47 |
* Class constructor. |
| 48 |
* |
| 49 |
* @since 1.1.0 |
| 50 |
*/ |
| 51 |
public function __construct() { |
| 52 |
$this->set_alert_details(); |
| 53 |
} |
| 54 |
|
| 55 |
/** |
| 56 |
* Set discount details. |
| 57 |
* |
| 58 |
* @since 1.1.0 |
| 59 |
*/ |
| 60 |
public function set_alert_details() { |
| 61 |
global $wpdb; |
| 62 |
|
| 63 |
$rule_id = sellkit_htmlspecialchars( INPUT_GET, 'target_id' ); |
| 64 |
|
| 65 |
$start_date = time() - ( 60 * 60 * 24 * Analytics::$date_range ); |
| 66 |
|
| 67 |
$sellkit_prefix = Database::DATABASE_PREFIX; |
| 68 |
$alert_table = "{$wpdb->prefix}{$sellkit_prefix}applied_alert"; |
| 69 |
|
| 70 |
// phpcs:disable |
| 71 |
$query_result = $wpdb->get_results( |
| 72 |
$wpdb->prepare( "SELECT SUM(impression) as impression, SUM(click) as click FROM {$alert_table} |
| 73 |
where applied_at > {$start_date} and rule_id " . Analytics::target_id_condition( $rule_id ) . " %d", $rule_id ), |
| 74 |
ARRAY_A ); |
| 75 |
|
| 76 |
$this->data['impression'] = ! empty( $query_result[0]['impression'] ) ? $query_result[0]['impression'] : 0; |
| 77 |
$this->data['click'] = ! empty( $query_result[0]['click'] ) ? $query_result[0]['click'] : 0; |
| 78 |
// phpcs:enable |
| 79 |
|
| 80 |
$this->data['target_title'] = sellkit_decode_entity_title( get_the_title( $rule_id ) ); |
| 81 |
} |
| 82 |
} |
| 83 |
|