59 lines
1.5 KiB
PHP
59 lines
1.5 KiB
PHP
<?php
|
|
/*
|
|
Author: Riccardo Di Dato
|
|
Creation Date: 27/gen/2016
|
|
*/
|
|
|
|
/**
|
|
* {user:{id, isNew}, ip, content, source, data}
|
|
* @author Riccardo Di Dato
|
|
*/
|
|
class StatisticModel extends Model {
|
|
const STAT_TYPE_PAGE = 1;
|
|
const STAT_TYPE_NOTIZIA = 2;
|
|
const STAT_TYPE_BANNER_IMPRESSION = 3;
|
|
const STAT_TYPE_BANNER_CLICK = 4;
|
|
|
|
public static $STAT_TYPES = array(
|
|
self::STAT_TYPE_PAGE=>array("label"=>"Statistiche pagina"),
|
|
self::STAT_TYPE_NOTIZIA=>array("label"=>"Statistiche notizia"),
|
|
self::STAT_TYPE_BANNER_IMPRESSION=>array("label"=>"Statistiche pagina"),
|
|
self::STAT_TYPE_BANNER_CLICK=>array("label"=>"Statistiche pagina")
|
|
);
|
|
|
|
public function __construct($saveableObject = null){
|
|
parent::__construct($saveableObject);
|
|
|
|
$requiredProps = array("user","content","source", "ip", "statType");
|
|
|
|
if (!$this->hasProperty("date")){
|
|
// $this->date = new MongoDate();
|
|
$this->date = new MongoDB\BSON\UTCDateTime( time() * 1000 );
|
|
}
|
|
|
|
foreach ($requiredProps as $prop){
|
|
if (!$this->hasProperty($prop)){
|
|
throw new CoreException("Missing parameter '$prop' while calling ".get_called_class()."::__construct()");
|
|
}
|
|
}
|
|
|
|
if (!array_key_exists($this->statType, self::$STAT_TYPES)){
|
|
throw new CoreException("Invalid statistic type '".$this->statType."' while calling ".get_called_class()."::__construct()");
|
|
}
|
|
}
|
|
|
|
public function __set($attr,$value){
|
|
if (strcmp("statType", $attr)==0){
|
|
$value = intval($value);
|
|
}
|
|
return parent::__set($attr, $value);
|
|
}
|
|
|
|
public static function getCollectionName(){
|
|
return "statistics";
|
|
}
|
|
|
|
}
|
|
|
|
|
|
?>
|