Avviato nuovo sistema statistiche
This commit is contained in:
+112
-140
@@ -8,6 +8,26 @@ class AnalyticsHelper {
|
||||
private static $COOKIE_NAME = "FDN_STAT_NUM";
|
||||
private static $COOKIE_TIME = "+1 year";
|
||||
|
||||
|
||||
public static function pageImpression($content, $d, $m, $y, $isUnique) {
|
||||
$dao = GlobalVariables::get("dao");
|
||||
if ($dao instanceof GenericDao) {
|
||||
$upd = [
|
||||
'$inc' => [
|
||||
'views' => 1
|
||||
]
|
||||
];
|
||||
if ($isUnique) {
|
||||
$upd['$inc']['unique'] = 1;
|
||||
}
|
||||
$dao->rawUpsert(
|
||||
PageViewStatsModel::class,
|
||||
PageViewStatsModel::getFilter($content, $d, $m, $y),
|
||||
$upd
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* La funzione si occupa del salvataggio vero e proprio della impression della pagina.
|
||||
* UTILIZZARE QUESTA FUNZIONE SOLO NELLA PAGINA DI BACKEND (stats/pageImpression.php). Nelle pagine base utilizzare invece la funzione di log
|
||||
@@ -15,37 +35,21 @@ class AnalyticsHelper {
|
||||
* @param string $content
|
||||
* @param string $source
|
||||
*/
|
||||
public static function savePageImpression($ip, $content, $source){
|
||||
$tmp = new stdClass();
|
||||
|
||||
$tmp->user = null;
|
||||
if (isset($_COOKIE[self::$COOKIE_NAME])){
|
||||
$id = $_COOKIE[self::$COOKIE_NAME];
|
||||
|
||||
$tmp->user = new stdClass();
|
||||
$tmp->user->id = $id;
|
||||
$tmp->user->isNew = false;
|
||||
if (GlobalVariables::get("dao")->count("StatisticModel",array("user.id"=>$id))==0){
|
||||
$tmp->user->isNew = true;
|
||||
}
|
||||
}
|
||||
|
||||
$tmp->content = $content;
|
||||
$tmp->source = $source;
|
||||
$tmp->ip = $ip;
|
||||
$tmp->statType = StatisticModel::STAT_TYPE_PAGE;
|
||||
$stat = new StatisticModel($tmp);
|
||||
GlobalVariables::get("dao")->save($stat);
|
||||
public static function savePageImpression($ip, $content, $source) {
|
||||
self::pageImpression(
|
||||
$content,
|
||||
intval(date('d')),
|
||||
intval(date('m')),
|
||||
intval(date('Y')),
|
||||
!isset($_COOKIE[self::$COOKIE_NAME])
|
||||
);
|
||||
self::prepareStatCookie();
|
||||
}
|
||||
|
||||
/**
|
||||
* La funzione si occupa di aggiungere una visualizzazione alla pagina corrente
|
||||
*/
|
||||
public static function logPageImpression(){
|
||||
if (!isset($_COOKIE[self::$COOKIE_NAME])){
|
||||
self::prepareStatCookie();
|
||||
}
|
||||
|
||||
$ip = $_SERVER['REMOTE_ADDR'];
|
||||
$content = $_SERVER['PHP_SELF'];
|
||||
$source = null;
|
||||
@@ -63,6 +67,21 @@ class AnalyticsHelper {
|
||||
}
|
||||
|
||||
|
||||
public static function notiziaImpression($content, $d, $m, $y) {
|
||||
$dao = GlobalVariables::get("dao");
|
||||
if ($dao instanceof GenericDao) {
|
||||
$dao->rawUpsert(
|
||||
ArticleStatsModel::class,
|
||||
ArticleStatsModel::getFilter($content, $d, $m, $y),
|
||||
[
|
||||
'$inc' => [
|
||||
'views' => 1
|
||||
]
|
||||
]
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* La funzione si occupa del salvataggio vero e proprio della impression della notizia.
|
||||
* UTILIZZARE QUESTA FUNZIONE SOLO NELLA PAGINA DI BACKEND (stats/notiziaImpression.php). Nelle pagine base utilizzare invece la funzione di log
|
||||
@@ -70,34 +89,13 @@ class AnalyticsHelper {
|
||||
* @param string $content
|
||||
* @param string $source
|
||||
*/
|
||||
public static function saveNotiziaImpression($ip, $notiziaId, $source){
|
||||
$tmp = new stdClass();
|
||||
|
||||
$tmp->user = null;
|
||||
if (isset($_COOKIE[self::$COOKIE_NAME])){
|
||||
$id = $_COOKIE[self::$COOKIE_NAME];
|
||||
|
||||
$tmp->user = new stdClass();
|
||||
$tmp->user->id = $id;
|
||||
$tmp->user->isNew = false;
|
||||
if (GlobalVariables::get("dao")->count("StatisticModel",array("user.id"=>$id))==0){
|
||||
$tmp->user->isNew = true;
|
||||
}
|
||||
}
|
||||
|
||||
$tmp->content = new stdClass();
|
||||
$notizia = GlobalVariables::get("dao")->getFirst("NotiziaModel",array("id"=>$notiziaId));
|
||||
if (!is_null($notizia)){
|
||||
$tmp->content->notizia = $notiziaId;
|
||||
$tmp->content->category = $notizia->category;
|
||||
|
||||
$tmp->source = $source;
|
||||
$tmp->ip = $ip;
|
||||
$tmp->statType = StatisticModel::STAT_TYPE_NOTIZIA;
|
||||
$stat = new StatisticModel($tmp);
|
||||
GlobalVariables::get("dao")->save($stat);
|
||||
}
|
||||
|
||||
public static function saveNotiziaImpression($ip, $notiziaId, $source) {
|
||||
self::notiziaImpression(
|
||||
$notiziaId,
|
||||
intval(date('d')),
|
||||
intval(date('m')),
|
||||
intval(date('Y'))
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -125,21 +123,44 @@ class AnalyticsHelper {
|
||||
* @param string $id
|
||||
*/
|
||||
public static function countNotiziaImpressions($id, $start = null, $end = null){
|
||||
$searchArray = array("statType"=>StatisticModel::STAT_TYPE_NOTIZIA,"content.notizia"=>$id);
|
||||
if (!is_null($start)){
|
||||
// $searchArray["date"]['$gte'] = new MongoDate($start);
|
||||
$searchArray["date"]['$gte'] = new MongoDB\BSON\UTCDateTime( $start * 1000 );
|
||||
|
||||
}
|
||||
if (!is_null($end)){
|
||||
// $searchArray["date"]['$lte'] = new MongoDate($end);
|
||||
$searchArray["date"]['$lte'] = new MongoDB\BSON\UTCDateTime( $end * 1000 );
|
||||
}
|
||||
return GlobalVariables::get("dao")->count("StatisticModel",$searchArray);
|
||||
$ret = GlobalVariables::get("dao")->aggregate(
|
||||
ArticleStatsModel::class,
|
||||
PipelineHelper::getNotiziaImpressions($id, $start, $end)
|
||||
);
|
||||
|
||||
return sizeof($ret) == 0 ? 0 : $ret[0]['tot'];
|
||||
}
|
||||
|
||||
|
||||
|
||||
public static function bannerImpression($bannerId, $d, $m, $y) {
|
||||
$dao = GlobalVariables::get("dao");
|
||||
if ($dao instanceof GenericDao) {
|
||||
$dao->rawUpsert(
|
||||
BannerStatsModel::class,
|
||||
BannerStatsModel::getFilter($bannerId, $d, $m, $y),
|
||||
[
|
||||
'$inc' => [
|
||||
'views' => 1
|
||||
]
|
||||
]
|
||||
);
|
||||
}
|
||||
}
|
||||
public static function bannerClick($bannerId, $d, $m, $y) {
|
||||
$dao = GlobalVariables::get("dao");
|
||||
if ($dao instanceof GenericDao) {
|
||||
$dao->rawUpsert(
|
||||
BannerStatsModel::class,
|
||||
BannerStatsModel::getFilter($bannerId, $d, $m, $y),
|
||||
[
|
||||
'$inc' => [
|
||||
'clicks' => 1
|
||||
]
|
||||
]
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* La funzione si occupa del salvataggio vero e proprio della impression del banner.
|
||||
* UTILIZZARE QUESTA FUNZIONE SOLO NELLA PAGINA DI BACKEND (stats/bannerImpression.php). Nelle pagine base utilizzare invece la funzione di log
|
||||
@@ -148,33 +169,12 @@ class AnalyticsHelper {
|
||||
* @param string $source
|
||||
*/
|
||||
public static function saveBannerImpression($ip, $bannerId, $source){
|
||||
$tmp = new stdClass();
|
||||
|
||||
$tmp->user = null;
|
||||
if (isset($_COOKIE[self::$COOKIE_NAME])){
|
||||
$id = $_COOKIE[self::$COOKIE_NAME];
|
||||
|
||||
$tmp->user = new stdClass();
|
||||
$tmp->user->id = $id;
|
||||
$tmp->user->isNew = false;
|
||||
if (GlobalVariables::get("dao")->count("StatisticModel",array("user.id"=>$id))==0){
|
||||
$tmp->user->isNew = true;
|
||||
}
|
||||
}
|
||||
|
||||
$tmp->content = new stdClass();
|
||||
$banner = GlobalVariables::get("dao")->getFirst("BannerModel",array("id"=>$bannerId));
|
||||
if (!is_null($banner)){
|
||||
$tmp->content->banner = $bannerId;
|
||||
$tmp->content->position = $banner->position;
|
||||
|
||||
$tmp->source = $source;
|
||||
$tmp->ip = $ip;
|
||||
$tmp->statType = StatisticModel::STAT_TYPE_BANNER_IMPRESSION;
|
||||
$stat = new StatisticModel($tmp);
|
||||
GlobalVariables::get("dao")->save($stat);
|
||||
}
|
||||
|
||||
self::bannerImpression(
|
||||
$bannerId,
|
||||
intval(date('d')),
|
||||
intval(date('m')),
|
||||
intval(date('Y'))
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -201,20 +201,16 @@ class AnalyticsHelper {
|
||||
}
|
||||
|
||||
/**
|
||||
* Restitusce il numero di impressions per una notizia
|
||||
* Restitusce il numero di impressions per un banner
|
||||
* @param string $id
|
||||
*/
|
||||
public static function countBannerImpressions($id, $start = null, $end = null){
|
||||
$searchArray = array("statType"=>StatisticModel::STAT_TYPE_BANNER_IMPRESSION,"content.banner"=>$id);
|
||||
if (!is_null($start)){
|
||||
// $searchArray["date"]['$gte'] = new MongoDate($start);
|
||||
$searchArray["date"]['$gte'] = new MongoDB\BSON\UTCDateTime($start * 1000);
|
||||
}
|
||||
if (!is_null($end)){
|
||||
// $searchArray["date"]['$lte'] = new MongoDate($end);
|
||||
$searchArray["date"]['$lte'] = new MongoDB\BSON\UTCDateTime($end * 1000);
|
||||
}
|
||||
return GlobalVariables::get("dao")->count("StatisticModel",$searchArray);
|
||||
$ret = GlobalVariables::get("dao")->aggregate(
|
||||
BannerStatsModel::class,
|
||||
PipelineHelper::getBannerImpressions($id, $start, $end)
|
||||
);
|
||||
|
||||
return sizeof($ret) == 0 ? 0 : $ret[0]['tot'];
|
||||
}
|
||||
|
||||
|
||||
@@ -226,32 +222,12 @@ class AnalyticsHelper {
|
||||
* @param string $source
|
||||
*/
|
||||
public static function saveBannerClick($bannerId, $source){
|
||||
$tmp = new stdClass();
|
||||
|
||||
$tmp->user = null;
|
||||
if (isset($_COOKIE[self::$COOKIE_NAME])){
|
||||
$id = $_COOKIE[self::$COOKIE_NAME];
|
||||
|
||||
$tmp->user = new stdClass();
|
||||
$tmp->user->id = $id;
|
||||
$tmp->user->isNew = false;
|
||||
if (GlobalVariables::get("dao")->count("StatisticModel",array("user.id"=>$id))==0){
|
||||
$tmp->user->isNew = true;
|
||||
}
|
||||
}
|
||||
|
||||
$tmp->content = new stdClass();
|
||||
$banner = GlobalVariables::get("dao")->getFirst("BannerModel",array("id"=>$bannerId));
|
||||
if (!is_null($banner)){
|
||||
$tmp->content->banner = $bannerId;
|
||||
$tmp->content->position = $banner->position;
|
||||
|
||||
$tmp->source = $source;
|
||||
$tmp->ip = $_SERVER['REMOTE_ADDR'];
|
||||
$tmp->statType = StatisticModel::STAT_TYPE_BANNER_CLICK;
|
||||
$stat = new StatisticModel($tmp);
|
||||
GlobalVariables::get("dao")->save($stat);
|
||||
}
|
||||
self::bannerClick(
|
||||
$bannerId,
|
||||
intval(date('d')),
|
||||
intval(date('m')),
|
||||
intval(date('Y'))
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -270,16 +246,12 @@ class AnalyticsHelper {
|
||||
* @param string $id
|
||||
*/
|
||||
public static function countBannerClicks($id, $start = null, $end = null){
|
||||
$searchArray = array("statType"=>StatisticModel::STAT_TYPE_BANNER_CLICK,"content.banner"=>$id);
|
||||
if (!is_null($start)){
|
||||
// $searchArray["date"]['$gte'] = new MongoDate($start);
|
||||
$searchArray["date"]['$gte'] = new MongoDB\BSON\UTCDateTime($start * 1000);
|
||||
}
|
||||
if (!is_null($end)){
|
||||
// $searchArray["date"]['$lte'] = new MongoDate($end);
|
||||
$searchArray["date"]['$lte'] = new MongoDB\BSON\UTCDateTime($end * 1000);
|
||||
}
|
||||
return GlobalVariables::get("dao")->count("StatisticModel",$searchArray);
|
||||
$ret = GlobalVariables::get("dao")->aggregate(
|
||||
BannerStatsModel::class,
|
||||
PipelineHelper::getBannerClicks($id, $start, $end)
|
||||
);
|
||||
|
||||
return sizeof($ret) == 0 ? 0 : $ret[0]['tot'];
|
||||
}
|
||||
|
||||
|
||||
@@ -314,7 +286,7 @@ class AnalyticsHelper {
|
||||
}
|
||||
|
||||
// $baseSearchArray = array("position"=>$position,"end"=>array('$gte'=>new MongoDate(strtotime("tomorrow"))),"categories"=>$category);
|
||||
$baseSearchArray = array("position"=>$position,"end"=>array('$gte'=>new MongoDB\BSON\UTCDateTime( strtotime("tomorrow") * 1000 ) ),"categories"=>$category);
|
||||
$baseSearchArray = array("position"=>$position,"end"=>array('$gte'=>new MongoDB\BSON\UTCDateTime( strtotime("tomorrow CET") * 1000 ) ),"categories"=>$category);
|
||||
// Prendi il primo dei "mai mostrati oggi" tra quelli non presenti nella pagina
|
||||
$todayPlusShown = array_merge($idList,$shown);
|
||||
if (sizeof($todayPlusShown)>0){
|
||||
|
||||
Reference in New Issue
Block a user