Files
piratepoet/lib/Models/StatisticsForms.php
Jonathan Labreuille ef461da77f Statistics for Form Subscriptions
- added statistics_forms table
- added corresponding model to record stats
- record stats whenever someone subscribes via a form
2016-04-26 15:16:37 +02:00

36 lines
807 B
PHP

<?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();
}
}
}
}