Update all controllers to standard behavior

This commit is contained in:
osaajani 2019-11-15 06:30:23 +01:00
parent 18c7cb019d
commit ccfc69baca
25 changed files with 112 additions and 125 deletions

View file

@ -68,17 +68,6 @@ namespace controllers\publics;
$ids = $_GET['ids'] ?? [];
foreach ($ids as $id)
{
$contact = $this->internal_contact->get($id);
if (!$contact)
{
continue;
}
if ($contact['id_user'] !== $_SESSION['user']['id'])
{
continue;
}
$this->internal_contact->delete_for_user($_SESSION['user']['id'], $id);
}
@ -101,8 +90,14 @@ namespace controllers\publics;
public function edit()
{
$ids = $_GET['ids'] ?? [];
$id_user = $_SESSION['user']['id'];
$contacts = $this->internal_contact->gets_for_user($ids, $id_user);
$contacts = $this->internal_contact->gets_in_for_user($id_user, $ids);
if (!$contacts)
{
return $this->redirect(\descartes\Router::url('Contact', 'list'));
}
$this->render('contact/edit', [
'contacts' => $contacts,
@ -144,7 +139,7 @@ namespace controllers\publics;
return $this->redirect(\descartes\Router::url('Contact', 'add'));
}
if (!$this->internal_contact->create($_SESSION['user']['id'], $id_user, $number, $name))
if (!$this->internal_contact->create($id_user, $number, $name))
{
\FlashMessage\FlashMessage::push('danger', 'Impossible de créer ce contact.');
@ -174,21 +169,9 @@ namespace controllers\publics;
}
$nb_contacts_update = 0;
foreach ($_POST['contacts'] as $contact)
{
$contact = $this->internal_contact->get($contact['id']);
if (!$contact)
{
continue;
}
if ($contact['id_user'] !== $_SESSION['user']['id'])
{
continue;
}
$nb_contacts_update += $this->internal_contact->update_for_user($_SESSION['user']['id'], $contact['id'], $_SESSION['user']['id'], $contact['number'], $contact['name']);
$nb_contacts_update += (int) $this->internal_contact->update_for_user($_SESSION['user']['id'], $contact['id'], $contact['number'], $contact['name']);
}
if ($nb_contacts_update !== \count($_POST['contacts']))

View file

@ -73,6 +73,7 @@ namespace controllers\publics;
$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_for_user($id_user, $formated_date);
$nb_receiveds_by_day = $this->internal_received->count_by_day_since_for_user($id_user, $formated_date);

View file

@ -44,11 +44,11 @@ namespace controllers\publics;
*/
public function list()
{
$discussions = $this->internal_received->get_discussions();
$discussions = $this->internal_received->get_discussions_for_user($_SESSION['user']['id']);
foreach ($discussions as $key => $discussion)
{
if (!$contact = $this->internal_contact->get_by_number($discussion['number']))
if (!$contact = $this->internal_contact->get_by_number_and_user($_SESSION['user']['id'], $discussion['number']))
{
continue;
}
@ -68,7 +68,7 @@ namespace controllers\publics;
*/
public function show($number)
{
$contact = $this->internal_contact->get_by_number($number);
$contact = $this->internal_contact->get_by_number_and_user($_SESSION['user']['id'], $number);
$this->render('discussion/show', [
'number' => $number,
@ -87,9 +87,11 @@ namespace controllers\publics;
$now = new \DateTime();
$now = $now->format('Y-m-d H:i:s');
$sendeds = $this->internal_sended->get_by_destination($number);
$receiveds = $this->internal_received->get_by_origin($number);
$scheduleds = $this->internal_scheduled->get_before_date_for_number($now, $number);
$id_user = $_SESSION['user']['id'];
$sendeds = $this->internal_sended->gets_by_destination_and_user($id_user, $number);
$receiveds = $this->internal_received->gets_by_origin_and_user($id_user, $number);
$scheduleds = $this->internal_scheduled->gets_before_date_for_number_and_user($id_user, $now, $number);
$messages = [];
@ -99,7 +101,7 @@ namespace controllers\publics;
'date' => htmlspecialchars($sended['at']),
'text' => htmlspecialchars($sended['text']),
'type' => 'sended',
'status' => ($sended['delivered'] ? 'delivered' : ($sended['failed'] ? 'failed' : '')),
'status' => $sended['status'],
];
}
@ -176,7 +178,7 @@ namespace controllers\publics;
return false;
}
if (!$this->internal_scheduled->create($_SESSION['user']['id'], $id_user, $at, $text, false, false, $numbers))
if (!$this->internal_scheduled->create($id_user, $at, $text, false, false, $numbers))
{
$return['success'] = false;
$return['message'] = 'Impossible de créer le Sms';

View file

@ -42,7 +42,7 @@ namespace controllers\publics;
{
$page = (int) $page;
$limit = 25;
$events = $this->internal_event->list_for_user($_SESSION['user']['id']$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)]);
}
@ -63,13 +63,6 @@ namespace controllers\publics;
return $this->redirect(\descartes\Router::url('Event', 'list'));
}
if (!\controllers\internals\Tool::is_admin())
{
\FlashMessage\FlashMessage::push('danger', 'Vous devez être admin pour pouvoir supprimer des events.');
return $this->redirect(\descartes\Router::url('Event', 'list'));
}
$ids = $_GET['ids'] ?? [];
foreach ($ids as $id)
{

View file

@ -74,7 +74,10 @@ namespace controllers\publics;
}
$ids = $_GET['ids'] ?? [];
$this->internal_group->delete_for_user($_SESSION['user']['id'], $ids);
foreach ($ids as $id)
{
$this->internal_group->delete_for_user($_SESSION['user']['id'], $id);
}
return $this->redirect(\descartes\Router::url('Group', 'list'));
}

View file

@ -49,7 +49,7 @@ namespace controllers\publics;
foreach ($receiveds as $key => $received)
{
if (!$contact = $this->internal_contact->get_by_number($received['origin']))
if (!$contact = $this->internal_contact->get_by_number_and_user($_SESSION['user']['id'], $received['origin']))
{
continue;
}
@ -78,19 +78,6 @@ namespace controllers\publics;
$ids = $_GET['ids'] ?? [];
foreach ($ids as $id)
{
$received = $this->internal_received->get($id);
if (!$received)
{
continue;
}
$is_owner = (bool) $this->internal_phone->get_by_number_and_user($received['destination'], $_SESSION['user']['id']);
if (!$is_owner)
{
continue;
}
$this->internal_received->delete_for_user($_SESSION['user']['id'], $id);
}
@ -109,7 +96,7 @@ namespace controllers\publics;
foreach ($receiveds as $key => $received)
{
if (!$contact = $this->internal_contact->get_by_number($received['origin']))
if (!$contact = $this->internal_contact->get_by_number_and_user($_SESSION['user']['id'], $received['origin']))
{
continue;
}

View file

@ -213,14 +213,14 @@ namespace controllers\publics;
}
if ($origin && !$this->internal_phone->get_by_number_for_user($id_user, $origin))
if ($origin && !$this->internal_phone->get_by_number_and_user($id_user, $origin))
{
\FlashMessage\FlashMessage::push('danger', 'Ce numéro n\'existe pas ou vous n\'en êtes pas propriétaire.');
return $this->redirect(\descartes\Router::url('Scheduled', 'add'));
}
$scheduled_id = $this->internal_scheduled->create($_SESSION['user']['id'], $id_user, $at, $text, $origin, $flash, $numbers, $contacts, $groups);
$scheduled_id = $this->internal_scheduled->create($id_user, $at, $text, $origin, $flash, $numbers, $contacts, $groups);
if (!$scheduled_id)
{
\FlashMessage\FlashMessage::push('danger', 'Impossible de créer le Sms.');
@ -307,13 +307,13 @@ namespace controllers\publics;
}
if ($origin && !$this->internal_phone->get_by_number_for_user($id_user, $origin))
if ($origin && !$this->internal_phone->get_by_number_and_user($id_user, $origin))
{
\FlashMessage\FlashMessage::push('danger', 'Ce numéro n\'existe pas ou vous n\'en êtes pas propriétaire.');
return $this->redirect(\descartes\Router::url('Scheduled', 'add'));
}
$success = $this->internal_scheduled->update_for_user($_SESSION['user']['id'], $id_scheduled, $id_user, $at, $text, $origin, $flash, $numbers, $contacts, $groups);
$success = $this->internal_scheduled->update_for_user($id_user, $id_scheduled, $at, $text, $origin, $flash, $numbers, $contacts, $groups);
if (!$success)
{
$all_update_ok = false;

View file

@ -67,18 +67,6 @@ namespace controllers\publics;
$ids = $_GET['ids'] ?? [];
foreach ($ids as $id)
{
$sended = $this->internal_sended->get($id);
if (!$sended)
{
continue;
}
$is_owner = (bool) $this->internal_phone->get_by_number_and_user($sended['origin'], $_SESSION['user']['id']);
if (!$is_owner)
{
continue;
}
$this->internal_sended->delete_for_user($_SESSION['user']['id'], $id);
}

View file

@ -41,7 +41,7 @@ namespace controllers\publics;
{
$page = (int) $page;
$limit = 25;
$smsstops = $this->internal_sms_stop->list_for_user($_SESSION['user']['id']$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)]);
}

View file

@ -30,6 +30,11 @@ class User extends \descartes\Controller
$this->internal_user = new \controllers\internals\User($bdd);
\controllers\internals\Tool::verifyconnect();
if (!\controllers\internals\Tool::is_admin())
{
return $this->redirect(\descartes\Router::url('Dashboard', 'show'));
}
}
/**