Statistics for Form Subscriptions
- added statistics_forms table - added corresponding model to record stats - record stats whenever someone subscribes via a form
This commit is contained in:
36
lib/Models/StatisticsForms.php
Normal file
36
lib/Models/StatisticsForms.php
Normal file
@@ -0,0 +1,36 @@
|
||||
<?php
|
||||
namespace MailPoet\Models;
|
||||
|
||||
if(!defined('ABSPATH')) exit;
|
||||
|
||||
class StatisticsForms extends Model {
|
||||
public static $_table = MP_STATISTICS_FORMS_TABLE;
|
||||
|
||||
function __construct() {
|
||||
parent::__construct();
|
||||
}
|
||||
|
||||
public static function record($form_id) {
|
||||
if($form_id > 0) {
|
||||
$today = date('Y-m-d');
|
||||
|
||||
// check if we already have a record for today
|
||||
$record = self::where('form_id', $form_id)
|
||||
->where('date', $today)
|
||||
->findOne();
|
||||
|
||||
if($record !== false) {
|
||||
$record->setExpr('count', 'count + 1')->save();
|
||||
} else {
|
||||
// create a new entry
|
||||
$record = self::create();
|
||||
$record->hydrate(array(
|
||||
'form_id' => $form_id,
|
||||
'date' => $today,
|
||||
'count' => 1
|
||||
));
|
||||
$record->save();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user