fix lot of errors, working dashboard

This commit is contained in:
osaajani 2019-11-14 22:33:00 +01:00
parent 27d2a6c5b2
commit 6d9b1289fd
27 changed files with 89 additions and 73 deletions

View File

@ -21,7 +21,7 @@ namespace controllers\internals;
*/
protected function get_model () : \descartes\Model
{
$this->model = $this->model ?? new \models\Command($this->$bdd);
$this->model = $this->model ?? new \models\Command($this->bdd);
return $this->model;
}

View File

@ -21,7 +21,7 @@ namespace controllers\internals;
*/
protected function get_model () : \descartes\Model
{
$this->model = $this->model ?? new \models\Contact($this->$bdd);
$this->model = $this->model ?? new \models\Contact($this->bdd);
return $this->model;
}

View File

@ -21,7 +21,7 @@ namespace controllers\internals;
*/
protected function get_model () : \descartes\Model
{
$this->model = $this->model ?? new \models\Event($this->$bdd);
$this->model = $this->model ?? new \models\Event($this->bdd);
return $this->model;
}
@ -40,7 +40,7 @@ namespace controllers\internals;
*/
public function get_lasts_by_date_for_user (int $id_user, int $nb_entry)
{
return $this->get_lasts_by_date_for_user($id_user, $nb_entry);
return $this->get_model()->get_lasts_by_date_for_user($id_user, $nb_entry);
}
@ -59,6 +59,6 @@ namespace controllers\internals;
'text' => $text,
];
return $this->model_event->insert($event);
return $this->get_model()->insert($event);
}
}

View File

@ -24,7 +24,7 @@ namespace controllers\internals;
*/
protected function get_model () : \descartes\Model
{
$this->model = $this->model ?? new \models\Event($this->$bdd);
$this->model = $this->model ?? new \models\Event($this->bdd);
return $this->model;
}

View File

@ -21,7 +21,7 @@ namespace controllers\internals;
*/
protected function get_model () : \descartes\Model
{
$this->model = $this->model ?? new \models\Phone($this->$bdd);
$this->model = $this->model ?? new \models\Phone($this->bdd);
return $this->model;
}

View File

@ -21,7 +21,7 @@ namespace controllers\internals;
*/
protected function get_model () : \descartes\Model
{
$this->model = $this->model ?? new \models\Received($this->$bdd);
$this->model = $this->model ?? new \models\Received($this->bdd);
return $this->model;
}
@ -105,7 +105,15 @@ namespace controllers\internals;
*/
public function count_by_day_since_for_user(int $id_user, $date)
{
return $this->get_model()->count_by_day_since_for_user($id_user, $date);
$counts_by_day = $this->get_model()->count_by_day_since_for_user($id_user, $date);
$return = [];
foreach ($counts_by_day as $count_by_day)
{
$return[$count_by_day['at_ymd']] = $count_by_day['nb'];
}
return $return;
}
@ -122,8 +130,8 @@ namespace controllers\internals;
/**
* Get SMS received since a date for a user
* @param $date : La date depuis laquelle on veux les SMS (au format 2014-10-25 20:10:05)
* @param int $id_user : User id
* @param $date : La date depuis laquelle on veux les SMS (au format 2014-10-25 20:10:05)
* @return array : Tableau avec tous les SMS depuis la date
*/
public function get_since_by_date_for_user(int $id_user, $date)

View File

@ -21,7 +21,7 @@ namespace controllers\internals;
*/
protected function get_model () : \descartes\Model
{
$this->model = $this->model ?? new \models\Scheduled($this->$bdd);
$this->model = $this->model ?? new \models\Scheduled($this->bdd);
return $this->model;
}

View File

@ -21,7 +21,7 @@ namespace controllers\internals;
*/
protected function get_model () : \descartes\Model
{
$this->model = $this->model ?? new \models\Sended($this->$bdd);
$this->model = $this->model ?? new \models\Sended($this->bdd);
return $this->model;
}
@ -126,6 +126,14 @@ namespace controllers\internals;
*/
public function count_by_day_since_for_user(int $id_user, $date)
{
return $this->get_model()->count_by_day_since_for_user($id_user, $date);
$counts_by_day = $this->get_model()->count_by_day_since_for_user($id_user, $date);
$return = [];
foreach ($counts_by_day as $count_by_day)
{
$return[$count_by_day['at_ymd']] = $count_by_day['nb'];
}
return $return;
}
}

View File

@ -21,7 +21,7 @@ namespace controllers\internals;
*/
protected function get_model () : \descartes\Model
{
$this->model = $this->model ?? new \models\SmsStop($this->$bdd);
$this->model = $this->model ?? new \models\SmsStop($this->bdd);
return $this->model;
}

View File

@ -182,7 +182,7 @@ namespace controllers\publics;
return $this->redirect(\descartes\Router::url('Account', 'show'));
}
$delete_account_result = $this->internal_user->delete($_SESSION['user']['id']);
$delete_account_result = $this->internal_user->delete_for_user($_SESSION['user']['id'], $_SESSION['user']['id']);
if (!$delete_account_result)
{
\FlashMessage\FlashMessage::push('danger', 'Impossible de supprimer le compte.');

View File

@ -37,7 +37,7 @@ namespace controllers\publics;
public function list($page = 0)
{
$page = (int) $page;
$commands = $this->internal_command->list(25, $page);
$commands = $this->internal_command->list_for_user($_SESSION['user']['id'], 25, $page);
$this->render('command/list', ['commands' => $commands]);
}
@ -62,7 +62,7 @@ namespace controllers\publics;
$ids = $_GET['ids'] ?? [];
foreach ($ids as $id)
{
$this->internal_command->delete($id);
$this->internal_command->delete_for_user($_SESSION['user']['id'], $id);
}
return $this->redirect(\descartes\Router::url('Command', 'list'));
@ -85,7 +85,7 @@ namespace controllers\publics;
{
$ids = $_GET['ids'] ?? [];
$commands = $this->internal_command->gets($ids);
$commands = $this->internal_command->gets_in_for_user($_SESSION['user']['id'], $ids);
$this->render('command/edit', [
'commands' => $commands,
@ -122,7 +122,7 @@ namespace controllers\publics;
return $this->redirect(\descartes\Router::url('Command', 'list'));
}
if (!$this->internal_command->create($name, $script, $admin))
if (!$this->internal_command->create($_SESSION['user']['id'], $name, $script, $admin))
{
\FlashMessage\FlashMessage::push('danger', 'Impossible de créer cette commande.');
@ -154,7 +154,7 @@ namespace controllers\publics;
$nb_commands_update = 0;
foreach ($_POST['commands'] as $command)
{
$update_command = $this->internal_command->update($command['id'], $command['name'], $command['script'], $command['admin']);
$update_command = $this->internal_command->update_for_user($_SESSION['user']['id'], $command['id'], $command['name'], $command['script'], $command['admin']);
$nb_commands_update += (int) $update_command;
}

View File

@ -43,7 +43,7 @@ namespace controllers\publics;
public function list($page = 0)
{
$page = (int) $page;
$contacts = $this->internal_contact->list($_SESSION['user']['id'], 25, $page);
$contacts = $this->internal_contact->list_for_user($_SESSION['user']['id'], 25, $page);
return $this->render('contact/list', ['contacts' => $contacts]);
}
@ -79,7 +79,7 @@ namespace controllers\publics;
continue;
}
$this->internal_contact->delete($id);
$this->internal_contact->delete_for_user($_SESSION['user']['id'], $id);
}
return $this->redirect(\descartes\Router::url('Contact', 'list'));
@ -144,7 +144,7 @@ namespace controllers\publics;
return $this->redirect(\descartes\Router::url('Contact', 'add'));
}
if (!$this->internal_contact->create($id_user, $number, $name))
if (!$this->internal_contact->create($_SESSION['user']['id'], $id_user, $number, $name))
{
\FlashMessage\FlashMessage::push('danger', 'Impossible de créer ce contact.');
@ -188,7 +188,7 @@ namespace controllers\publics;
continue;
}
$nb_contacts_update += $this->internal_contact->update($contact['id'], $_SESSION['user']['id'], $contact['number'], $contact['name']);
$nb_contacts_update += $this->internal_contact->update_for_user($_SESSION['user']['id'], $contact['id'], $_SESSION['user']['id'], $contact['number'], $contact['name']);
}
if ($nb_contacts_update !== \count($_POST['contacts']))
@ -209,6 +209,6 @@ namespace controllers\publics;
public function json_list()
{
header('Content-Type: application/json');
echo json_encode($this->internal_contact->list($_SESSION['user']['id']));
echo json_encode($this->internal_contact->list_for_user($_SESSION['user']['id']));
}
}

View File

@ -55,12 +55,12 @@ namespace controllers\publics;
$id_user = $_SESSION['user']['id'];
//Recupération des nombres des 4 panneaux d'accueil
$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);
$nb_contacts = $this->internal_contact->count_for_user($id_user);
$nb_groups = $this->internal_group->count_for_user($id_user);
$nb_scheduleds = $this->internal_scheduled->count_for_user($id_user);
$nb_commands = $this->internal_command->count_for_user($id_user);
$nb_sendeds = $this->internal_sended->count_for_user($id_user);
$nb_receiveds = $this->internal_received->count_for_user($id_user);
//Création de la date d'il y a une semaine
$now = new \DateTime();
@ -69,13 +69,13 @@ namespace controllers\publics;
$formated_date = $date->format('Y-m-d');
//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);
$receiveds = $this->internal_received->get_lasts_for_user_by_date($id_user, 10);
$events = $this->internal_event->get_lasts_by_date(10);
$sendeds = $this->internal_sended->get_lasts_by_date_for_user($id_user, 10);
$receiveds = $this->internal_received->get_lasts_by_date_for_user($id_user, 10);
$events = $this->internal_event->get_lasts_by_date_for_user($id_user, 10);
//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);
$nb_receiveds_by_day = $this->internal_received->count_for_user_by_day_since($id_user, $formated_date);
$nb_sendeds_by_day = $this->internal_sended->count_by_day_since_for_user($id_user, $formated_date);
$nb_receiveds_by_day = $this->internal_received->count_by_day_since_for_user($id_user, $formated_date);
//On va traduire ces données pour les afficher en graphique
$array_area_chart = [];

View File

@ -176,7 +176,7 @@ namespace controllers\publics;
return false;
}
if (!$this->internal_scheduled->create($id_user, $at, $text, false, false, $numbers))
if (!$this->internal_scheduled->create($_SESSION['user']['id'], $id_user, $at, $text, false, false, $numbers))
{
$return['success'] = false;
$return['message'] = 'Impossible de créer le Sms';
@ -199,7 +199,7 @@ namespace controllers\publics;
{
$_SESSION['discussion_wait_progress'] = isset($_SESSION['discussion_wait_progress']) ? $_SESSION['discussion_wait_progress'] : [];
$scheduleds = $this->internal_scheduled->gets($_SESSION['discussion_wait_progress']);
$scheduleds = $this->internal_scheduled->gets_in_for_user($_SESSION['user']['id'], $_SESSION['discussion_wait_progress']);
//On va chercher à chaque fois si on a trouvé le sms. Si ce n'est pas le cas c'est qu'il a été envoyé
$sendeds = [];

View File

@ -42,7 +42,7 @@ namespace controllers\publics;
{
$page = (int) $page;
$limit = 25;
$events = $this->internal_event->list($limit, $page);
$events = $this->internal_event->list_for_user($_SESSION['user']['id']$limit, $page);
$this->render('event/list', ['events' => $events, 'limit' => $limit, 'page' => $page, 'nb_results' => \count($events)]);
}
@ -73,7 +73,7 @@ namespace controllers\publics;
$ids = $_GET['ids'] ?? [];
foreach ($ids as $id)
{
$this->internal_event->delete($id);
$this->internal_event->delete_for_user($_SESSION['user']['id'], $id);
}
return $this->redirect(\descartes\Router::url('Event', 'list'));

View File

@ -45,7 +45,7 @@ namespace controllers\publics;
public function list($page = 0)
{
$page = (int) $page;
$groups = $this->internal_group->list(25, $page);
$groups = $this->internal_group->list_for_user($_SESSION['user']['id'], 25, $page);
foreach ($groups as $key => $group)
{
@ -74,7 +74,7 @@ namespace controllers\publics;
}
$ids = $_GET['ids'] ?? [];
$this->internal_group->delete($ids);
$this->internal_group->delete_for_user($_SESSION['user']['id'], $ids);
return $this->redirect(\descartes\Router::url('Group', 'list'));
}
@ -96,7 +96,7 @@ namespace controllers\publics;
{
$ids = $_GET['ids'] ?? [];
$groups = $this->internal_group->gets($ids);
$groups = $this->internal_group->gets_in_for_user($_SESSION['user']['id'], $ids);
foreach ($groups as $key => $group)
{
@ -134,7 +134,7 @@ namespace controllers\publics;
return $this->redirect(\descartes\Router::url('Group', 'add'));
}
$id_group = $this->internal_group->create($name, $contacts_ids);
$id_group = $this->internal_group->create($_SESSION['user']['id'], $name, $contacts_ids);
if (!$id_group)
{
\FlashMessage\FlashMessage::push('danger', 'Impossible de créer ce groupe.');
@ -169,7 +169,7 @@ namespace controllers\publics;
$nb_groups_update = 0;
foreach ($groups as $id => $group)
{
$nb_groups_update += (int) $this->internal_group->update($id, $group['name'], $group['contacts_ids']);
$nb_groups_update += (int) $this->internal_group->update_for_user($_SESSION['user']['id'], $id, $group['name'], $group['contacts_ids']);
}
if ($nb_groups_update !== \count($groups))
@ -190,6 +190,6 @@ namespace controllers\publics;
public function json_list()
{
header('Content-Type: application/json');
echo json_encode($this->internal_group->list());
echo json_encode($this->internal_group->list_for_user($_SESSION['user']['id']));
}
}

View File

@ -37,7 +37,7 @@ class Phone extends \descartes\Controller
{
$id_user = $_SESSION['user']['id'];
$page = (int) $page;
$phones = $this->internal_phone->list($id_user, 25, $page);
$phones = $this->internal_phone->list_for_user($_SESSION['user']['id']$id_user, 25, $page);
$adapters = [];
$adapters_metas = $this->internal_adapter->list_adapters();
@ -81,7 +81,7 @@ class Phone extends \descartes\Controller
$ids = $_GET['ids'] ?? [];
foreach ($ids as $id)
{
$this->internal_phone->delete($id);
$this->internal_phone->delete_for_user($_SESSION['user']['id'], $id);
}
return $this->redirect(\descartes\Router::url('Phone', 'list'));
@ -163,7 +163,7 @@ class Phone extends \descartes\Controller
}
$success = $this->internal_phone->create($id_user, $number, $adapter, $adapter_datas);
$success = $this->internal_phone->create($_SESSION['user']['id'], $id_user, $number, $adapter, $adapter_datas);
if (!$success)
{
\FlashMessage\FlashMessage::push('danger', 'Impossible de créer ce téléphone.');

View File

@ -45,7 +45,7 @@ namespace controllers\publics;
{
$page = (int) $page;
$limit = 25;
$receiveds = $this->internal_received->list($_SESSION['user']['id'], $limit, $page);
$receiveds = $this->internal_received->list_for_user($_SESSION['user']['id'], $limit, $page);
foreach ($receiveds as $key => $received)
{
@ -91,7 +91,7 @@ namespace controllers\publics;
continue;
}
$this->internal_received->delete($id);
$this->internal_received->delete_for_user($_SESSION['user']['id'], $id);
}
return $this->redirect(\descartes\Router::url('Received', 'list'));
@ -105,7 +105,7 @@ namespace controllers\publics;
public function popup()
{
$now = new \DateTime();
$receiveds = $this->internal_received->get_since_by_date_for_user($now->format('Y-m-d'), $_SESSION['user']['id']);
$receiveds = $this->internal_received->get_since_by_date_for_user($_SESSION['user']['id'], $now->format('Y-m-d'));
foreach ($receiveds as $key => $received)
{

View File

@ -42,7 +42,7 @@ namespace controllers\publics;
public function list($page = 0)
{
$page = (int) $page;
$scheduleds = $this->internal_scheduled->list($_SESSION['user']['id'], 25, $page);
$scheduleds = $this->internal_scheduled->list_for_user($_SESSION['user']['id'], 25, $page);
$this->render('scheduled/list', ['scheduleds' => $scheduleds]);
}
@ -72,7 +72,7 @@ namespace controllers\publics;
continue;
}
$this->internal_scheduled->delete($id);
$this->internal_scheduled->delete_for_user($_SESSION['user']['id'], $id);
}
return $this->redirect(\descartes\Router::url('Scheduled', 'list'));
@ -111,7 +111,7 @@ namespace controllers\publics;
}
$phones = $this->internal_phone->gets_for_user($_SESSION['user']['id']);
$scheduleds = $this->internal_scheduled->gets($ids);
$scheduleds = $this->internal_scheduled->gets_in_for_user($_SESSION['user']['id'], $ids);
//Pour chaque message on ajoute les numéros, les contacts & les groups
foreach ($scheduleds as $key => $scheduled)
@ -220,7 +220,7 @@ namespace controllers\publics;
}
$scheduled_id = $this->internal_scheduled->create($id_user, $at, $text, $origin, $flash, $numbers, $contacts, $groups);
$scheduled_id = $this->internal_scheduled->create($_SESSION['user']['id'], $id_user, $at, $text, $origin, $flash, $numbers, $contacts, $groups);
if (!$scheduled_id)
{
\FlashMessage\FlashMessage::push('danger', 'Impossible de créer le Sms.');
@ -313,7 +313,7 @@ namespace controllers\publics;
return $this->redirect(\descartes\Router::url('Scheduled', 'add'));
}
$success = $this->internal_scheduled->update($id_scheduled, $id_user, $at, $text, $origin, $flash, $numbers, $contacts, $groups);
$success = $this->internal_scheduled->update_for_user($_SESSION['user']['id'], $id_scheduled, $id_user, $at, $text, $origin, $flash, $numbers, $contacts, $groups);
if (!$success)
{
$all_update_ok = false;

View File

@ -43,7 +43,7 @@ namespace controllers\publics;
{
$page = (int) $page;
$limit = 25;
$sendeds = $this->internal_sended->list($_SESSION['user']['id'], $limit, $page);
$sendeds = $this->internal_sended->list_for_user($_SESSION['user']['id'], $limit, $page);
$this->render('sended/list', ['sendeds' => $sendeds, 'page' => $page, 'limit' => $limit, 'nb_results' => \count($sendeds)]);
}
@ -79,7 +79,7 @@ namespace controllers\publics;
continue;
}
$this->internal_sended->delete($id);
$this->internal_sended->delete_for_user($_SESSION['user']['id'], $id);
}
return $this->redirect(\descartes\Router::url('Sended', 'list'));

View File

@ -60,7 +60,7 @@ namespace controllers\publics;
return $this->redirect(\descartes\Router::url('Setting', 'show'));
}
$update_setting_result = $this->internal_setting->update($_SESSION['user']['id'], $setting_name, $setting_value);
$update_setting_result = $this->internal_setting->update_for_user($_SESSION['user']['id'], $_SESSION['user']['id'], $setting_name, $setting_value);
if (false === $update_setting_result)
{
\FlashMessage\FlashMessage::push('danger', 'Impossible de mettre à jour ce réglage.');

View File

@ -41,7 +41,7 @@ namespace controllers\publics;
{
$page = (int) $page;
$limit = 25;
$smsstops = $this->internal_sms_stop->list($limit, $page);
$smsstops = $this->internal_sms_stop->list_for_user($_SESSION['user']['id']$limit, $page);
$this->render('smsstop/list', ['page' => $page, 'smsstops' => $smsstops, 'limit' => $limit, 'nb_results' => \count($smsstops)]);
}
@ -72,7 +72,7 @@ namespace controllers\publics;
$ids = $_GET['ids'] ?? [];
foreach ($ids as $id)
{
$this->internal_sms_stop->delete($id);
$this->internal_sms_stop->delete_for_user($_SESSION['user']['id'], $id);
}
return $this->redirect(\descartes\Router::url('SmsStop', 'list'));

View File

@ -40,7 +40,7 @@ class User extends \descartes\Controller
public function list($page = 0)
{
$page = (int) $page;
$users = $this->internal_user->list(25, $page);
$users = $this->internal_user->list_for_user($_SESSION['user']['id'], 25, $page);
$this->render('user/list', ['users' => $users]);
}
@ -71,7 +71,7 @@ class User extends \descartes\Controller
$ids = $_GET['ids'] ?? [];
foreach ($ids as $id)
{
$this->internal_user->delete($id);
$this->internal_user->delete_for_user($_SESSION['user']['id'], $id);
}
return $this->redirect(\descartes\Router::url('User', 'list'));
@ -122,7 +122,7 @@ class User extends \descartes\Controller
return $this->redirect(\descartes\Router::url('User', 'add'));
}
$user_id = $this->internal_user->create($email, $password, $admin);
$user_id = $this->internal_user->create($_SESSION['user']['id'], $email, $password, $admin);
if (!$user_id)
{
\FlashMessage\FlashMessage::push('danger', 'Impossible de créer ce user.');

View File

@ -163,11 +163,11 @@ namespace models;
//If try to update destination, also check it does belong to user
if ($sets['set_destination'] ?? false)
{
$query .= ' AND :set_destination IN (SELECT number FROM phone WHERE id_user = :id_user)'
$query .= ' AND :set_destination IN (SELECT number FROM phone WHERE id_user = :id_user)';
}
$params['id'] = $id;
$params['id_user'] = $id_user;
$params['id_user'] = $id_user;
return $this->_run_query($query, $params, self::ROWCOUNT);
}
@ -336,7 +336,7 @@ namespace models;
";
$params = [
'id_user' => $id_user
'id_user' => $id_user,
'date' => $date,
'origin' => $origin,
];

View File

@ -163,11 +163,11 @@ namespace models;
//If try to update origin, also check it does belong to user
if ($sets['set_origin'] ?? false)
{
$query .= ' AND :set_origin IN (SELECT number FROM phone WHERE id_user = :id_user)'
$query .= ' AND :set_origin IN (SELECT number FROM phone WHERE id_user = :id_user)';
}
$params['id'] = $id;
$params['id_user'] = $id_user;
$params['id_user'] = $id_user;
return $this->_run_query($query, $params, self::ROWCOUNT);
}

View File

@ -100,7 +100,7 @@ namespace models;
* @param int $id : Entry id
* @return int : Number of removed rows
*/
public function delete_for_user(int $id_user, $id)
public function delete_for_user(int $id_user, int $id)
{
return $this->_delete($this->get_table_name(), ['id_user' => $id_user, 'id' => $id]);
}
@ -126,7 +126,7 @@ namespace models;
*
* @return int : number of modified rows
*/
public function update_for_user(int $id_user, $id, $entry)
public function update_for_user(int $id_user, int $id, array $entry)
{
return $this->_update($this->get_table_name(), $entry, ['id_user' => $id_user, 'id' => $id]);
}

View File

@ -210,7 +210,7 @@
</div>
<div class="panel-body">
<?php if (!$events) { ?>
Aucun évènement n'est encore survenus.
Aucun évènement n'est encore survenu.
<?php } else { ?>
<div class="list-group">
<?php foreach ($events as $event) { ?>