| 1 |
<?php |
| 2 |
/** |
| 3 |
* Handles interactions with the database table for email tracking. |
| 4 |
* |
| 5 |
* @package WP_Defender\Model |
| 6 |
*/ |
| 7 |
|
| 8 |
namespace WP_Defender\Model; |
| 9 |
|
| 10 |
use WP_Defender\DB; |
| 11 |
|
| 12 |
/** |
| 13 |
* Model for the email tracking table. |
| 14 |
*/ |
| 15 |
class Email_Track extends DB { |
| 16 |
|
| 17 |
/** |
| 18 |
* Table name. |
| 19 |
* |
| 20 |
* @var string |
| 21 |
*/ |
| 22 |
protected $table = 'defender_email_log'; |
| 23 |
|
| 24 |
/** |
| 25 |
* Primary key column. |
| 26 |
* |
| 27 |
* @var int |
| 28 |
* @defender_property |
| 29 |
*/ |
| 30 |
public $id; |
| 31 |
/** |
| 32 |
* Table column for timestamp. |
| 33 |
* |
| 34 |
* @var int |
| 35 |
* @defender_property |
| 36 |
*/ |
| 37 |
public $timestamp; |
| 38 |
/** |
| 39 |
* Table column for source. |
| 40 |
* |
| 41 |
* @var string |
| 42 |
* @defender_property |
| 43 |
*/ |
| 44 |
public $source; |
| 45 |
/** |
| 46 |
* Table column for to. |
| 47 |
* |
| 48 |
* @var string |
| 49 |
* @defender_property |
| 50 |
*/ |
| 51 |
public $to; |
| 52 |
|
| 53 |
/** |
| 54 |
* Count the number of records in the database table based on the provided filters. |
| 55 |
* |
| 56 |
* @param mixed $source The source to filter by. |
| 57 |
* @param mixed $email The email to filter by. |
| 58 |
* @param mixed $date_from The start date for the date range filter. |
| 59 |
* @param mixed $date_to The end date for the date range filter. |
| 60 |
* |
| 61 |
* @return int|null The number of records matching the provided filters, or null if an error occurred. |
| 62 |
*/ |
| 63 |
public static function count( $source, $email, $date_from, $date_to ) { |
| 64 |
$orm = self::get_orm(); |
| 65 |
|
| 66 |
return $orm->get_repository( self::class ) |
| 67 |
->where( 'source', $source ) |
| 68 |
->where( 'to', $email ) |
| 69 |
->where( 'timestamp', '>=', $date_from ) |
| 70 |
->where( 'timestamp', '<=', $date_to ) |
| 71 |
->count(); |
| 72 |
} |
| 73 |
} |
| 74 |
|