Compteur de vues (n'inclut pas les vues des administrateurs)

This commit is contained in:
Yohann 2019-10-23 12:33:12 +02:00
parent 3e2690d819
commit 0b7e5c5e10
2 changed files with 21 additions and 1 deletions

View File

@ -40,6 +40,7 @@ class Config
private $start_phase4_date;
private $end_phase4_date;
private $index_page;
private $views;
public function initDB()
{
@ -58,7 +59,8 @@ class Config
('end_phase3_date_$YEAR', CURRENT_TIMESTAMP + INTERVAL 7 DAY),
('start_phase4_date_$YEAR', CURRENT_TIMESTAMP + INTERVAL 8 DAY),
('end_phase4_date_$YEAR', CURRENT_TIMESTAMP + INTERVAL 9 DAY),
('index_page_$YEAR', ?);")->execute([$index_template_page]);
('index_page_$YEAR', ?),
('views_$YEAR', 0);")->execute([$index_template_page]);
}
public function loadConfigValues()
@ -202,6 +204,22 @@ class Config
$this->index_page = $index_page;
}
public function getViews()
{
return $this->views;
}
public function incrViews()
{
global $DB, $YEAR;
if (isset($_SESSION["user_id"]) && $_SESSION["role"] == Role::ADMIN)
return;
$DB->exec("UPDATE `config` SET `value` = " . ($this->views + 1) . " WHERE `key` = 'views_$YEAR';");
$this->views++;
}
}
session_start();

View File

@ -1,3 +1,5 @@
<?php $CONFIG->incrViews() ?>
<!DOCTYPE html>
<html lang="fr">
<head>