2019-10-29 14:57:13 +01:00
|
|
|
<?php
|
2019-10-30 00:30:39 +01:00
|
|
|
|
|
|
|
/*
|
2019-11-10 17:48:54 +01:00
|
|
|
* This file is part of RaspiSMS.
|
2019-10-30 00:30:39 +01:00
|
|
|
*
|
2019-11-10 17:48:54 +01:00
|
|
|
* (c) Pierre-Lin Bonnemaison <plebwebsas@gmail.com>
|
2019-10-30 00:30:39 +01:00
|
|
|
*
|
2019-11-10 17:48:54 +01:00
|
|
|
* This source file is subject to the GPL-3.0 license that is bundled
|
2019-10-30 00:30:39 +01:00
|
|
|
* with this source code in the file LICENSE.
|
|
|
|
*/
|
|
|
|
|
2019-10-29 14:57:13 +01:00
|
|
|
namespace controllers\publics;
|
2019-10-29 18:36:25 +01:00
|
|
|
|
|
|
|
/**
|
2019-10-30 00:30:39 +01:00
|
|
|
* Page d'index, qui gère l'affichage par défaut temporairement.
|
2019-10-29 18:36:25 +01:00
|
|
|
*/
|
|
|
|
class Dashboard extends \descartes\Controller
|
|
|
|
{
|
2019-10-30 00:17:10 +01:00
|
|
|
private $internal_sended;
|
|
|
|
private $internal_received;
|
|
|
|
private $internal_contact;
|
|
|
|
private $internal_group;
|
|
|
|
private $internal_scheduled;
|
|
|
|
private $internal_command;
|
|
|
|
private $internal_event;
|
|
|
|
|
2019-10-29 18:36:25 +01:00
|
|
|
/**
|
|
|
|
* Cette fonction est appelée avant toute les autres :
|
2019-10-30 00:30:39 +01:00
|
|
|
* Elle vérifie que l'utilisateur est bien connecté.
|
|
|
|
*
|
2019-10-29 18:36:25 +01:00
|
|
|
* @return void;
|
|
|
|
*/
|
2019-10-30 00:17:10 +01:00
|
|
|
public function __construct()
|
2019-10-29 14:57:13 +01:00
|
|
|
{
|
2019-10-30 00:17:10 +01:00
|
|
|
$bdd = \descartes\Model::_connect(DATABASE_HOST, DATABASE_NAME, DATABASE_USER, DATABASE_PASSWORD);
|
2019-10-30 00:30:39 +01:00
|
|
|
|
2019-11-07 16:17:18 +01:00
|
|
|
$this->internal_sended = new \controllers\internals\Sended($bdd);
|
2019-10-30 00:17:10 +01:00
|
|
|
$this->internal_received = new \controllers\internals\Received($bdd);
|
|
|
|
$this->internal_contact = new \controllers\internals\Contact($bdd);
|
|
|
|
$this->internal_group = new \controllers\internals\Group($bdd);
|
|
|
|
$this->internal_scheduled = new \controllers\internals\Scheduled($bdd);
|
|
|
|
$this->internal_command = new \controllers\internals\Command($bdd);
|
|
|
|
$this->internal_event = new \controllers\internals\Event($bdd);
|
2019-10-30 00:30:39 +01:00
|
|
|
|
2019-10-30 00:17:10 +01:00
|
|
|
\controllers\internals\Tool::verifyconnect();
|
2019-10-29 14:57:13 +01:00
|
|
|
}
|
|
|
|
|
2019-10-29 18:36:25 +01:00
|
|
|
/**
|
2019-10-30 00:30:39 +01:00
|
|
|
* Cette fonction est un alias de show.
|
|
|
|
*
|
2019-10-29 18:36:25 +01:00
|
|
|
* @return void;
|
|
|
|
*/
|
|
|
|
public function show()
|
|
|
|
{
|
2019-11-12 17:37:20 +01:00
|
|
|
$id_user = $_SESSION['user']['id'];
|
|
|
|
|
2019-10-29 18:36:25 +01:00
|
|
|
//Recupération des nombres des 4 panneaux d'accueil
|
2019-11-12 17:37:20 +01:00
|
|
|
$nb_contacts = $this->internal_contact->count($id_user);
|
|
|
|
$nb_groups = $this->internal_group->count($id_user);
|
|
|
|
$nb_scheduleds = $this->internal_scheduled->count($id_user);
|
|
|
|
$nb_commands = $this->internal_command->count($id_user);
|
|
|
|
$nb_sendeds = $this->internal_sended->count($id_user);
|
|
|
|
$nb_receiveds = $this->internal_received->count($id_user);
|
2019-10-29 14:57:13 +01:00
|
|
|
|
2019-10-29 18:36:25 +01:00
|
|
|
//Création de la date d'il y a une semaine
|
|
|
|
$now = new \DateTime();
|
|
|
|
$one_week = new \DateInterval('P7D');
|
|
|
|
$date = $now->sub($one_week);
|
|
|
|
$formated_date = $date->format('Y-m-d');
|
2019-10-29 14:57:13 +01:00
|
|
|
|
2019-10-30 00:17:10 +01:00
|
|
|
//Récupération des 10 derniers Sms envoyés, Sms reçus et evenements enregistrés. Par date.
|
|
|
|
$sendeds = $this->internal_sended->get_lasts_by_date(10);
|
2019-11-12 17:37:20 +01:00
|
|
|
$receiveds = $this->internal_received->get_lasts_for_user_by_date($id_user, 10);
|
2019-10-30 00:17:10 +01:00
|
|
|
$events = $this->internal_event->get_lasts_by_date(10);
|
2019-10-29 14:57:13 +01:00
|
|
|
|
2019-10-30 00:17:10 +01:00
|
|
|
//Récupération du nombre de Sms envoyés et reçus depuis les 7 derniers jours
|
|
|
|
$nb_sendeds_by_day = $this->internal_sended->count_by_day_since($formated_date);
|
2019-11-12 17:37:20 +01:00
|
|
|
$nb_receiveds_by_day = $this->internal_received->count_for_user_by_day_since($id_user, $formated_date);
|
2019-10-29 14:57:13 +01:00
|
|
|
|
2019-10-29 18:36:25 +01:00
|
|
|
//On va traduire ces données pour les afficher en graphique
|
2019-10-30 00:30:39 +01:00
|
|
|
$array_area_chart = [];
|
|
|
|
|
2019-10-29 18:36:25 +01:00
|
|
|
$today_less_7_day = new \DateTime();
|
|
|
|
$today_less_7_day->sub(new \DateInterval('P7D'));
|
|
|
|
$increment_day = new \DateInterval('P1D');
|
|
|
|
$i = 0;
|
|
|
|
|
|
|
|
//On va construire un tableau avec la date en clef, et les données pour chaque date
|
2019-10-30 00:30:39 +01:00
|
|
|
while ($i < 7)
|
|
|
|
{
|
2019-10-29 18:36:25 +01:00
|
|
|
$today_less_7_day->add($increment_day);
|
2019-10-30 00:30:39 +01:00
|
|
|
++$i;
|
2019-10-29 18:36:25 +01:00
|
|
|
$date_f = $today_less_7_day->format('Y-m-d');
|
2019-10-30 00:30:39 +01:00
|
|
|
$array_area_chart[$date_f] = [
|
2019-10-29 18:36:25 +01:00
|
|
|
'period' => $date_f,
|
|
|
|
'sendeds' => 0,
|
|
|
|
'receiveds' => 0,
|
2019-10-30 00:30:39 +01:00
|
|
|
];
|
2019-10-29 18:36:25 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
$total_sendeds = 0;
|
|
|
|
$total_receiveds = 0;
|
|
|
|
|
|
|
|
//0n remplie le tableau avec les données adaptées
|
2019-10-30 00:30:39 +01:00
|
|
|
foreach ($nb_sendeds_by_day as $date => $nb_sended)
|
|
|
|
{
|
2019-10-29 14:57:13 +01:00
|
|
|
$array_area_chart[$date]['sendeds'] = $nb_sended;
|
|
|
|
$total_sendeds += $nb_sended;
|
|
|
|
}
|
|
|
|
|
2019-10-30 00:30:39 +01:00
|
|
|
foreach ($nb_receiveds_by_day as $date => $nb_received)
|
|
|
|
{
|
2019-10-29 14:57:13 +01:00
|
|
|
$array_area_chart[$date]['receiveds'] = $nb_received;
|
|
|
|
$total_receiveds += $nb_received;
|
2019-10-29 18:36:25 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
$avg_sendeds = round($total_sendeds / 7, 2);
|
|
|
|
$avg_receiveds = round($total_receiveds / 7, 2);
|
|
|
|
|
|
|
|
$array_area_chart = array_values($array_area_chart);
|
|
|
|
|
2019-10-30 00:30:39 +01:00
|
|
|
$this->render('dashboard/show', [
|
2019-10-29 18:36:25 +01:00
|
|
|
'nb_contacts' => $nb_contacts,
|
2019-10-30 00:17:10 +01:00
|
|
|
'nb_groups' => $nb_groups,
|
2019-10-29 18:36:25 +01:00
|
|
|
'nb_scheduleds' => $nb_scheduleds,
|
|
|
|
'nb_commands' => $nb_commands,
|
|
|
|
'nb_sendeds' => $nb_sendeds,
|
|
|
|
'nb_receiveds' => $nb_receiveds,
|
|
|
|
'avg_sendeds' => $avg_sendeds,
|
|
|
|
'avg_receiveds' => $avg_receiveds,
|
|
|
|
'sendeds' => $sendeds,
|
|
|
|
'receiveds' => $receiveds,
|
|
|
|
'events' => $events,
|
|
|
|
'datas_area_chart' => json_encode($array_area_chart),
|
2019-10-30 00:30:39 +01:00
|
|
|
]);
|
2019-10-29 18:36:25 +01:00
|
|
|
}
|
|
|
|
}
|