mirror of
https://github.com/RaspbianFrance/raspisms.git
synced 2025-04-20 16:37:48 +02:00
Add dynamic deletion of contacts
This commit is contained in:
parent
bd57db4fdd
commit
8315817388
6 changed files with 120 additions and 3 deletions
|
@ -234,7 +234,17 @@ namespace controllers\publics;
|
|||
$contacts_name[] = $contact['name'];
|
||||
}
|
||||
|
||||
$return['result'] = 'Contacts du groupe : ' . implode(', ', $contacts_name);
|
||||
$visible_names = array_slice($contacts_name, 0, 5);
|
||||
$how_many_more = count($contacts_name) - count($visible_names);
|
||||
|
||||
$result_text = 'Contacts du groupe : ' . implode(', ', $visible_names);
|
||||
|
||||
if ($how_many_more > 0)
|
||||
{
|
||||
$result_text .= ", et $how_many_more autres.";
|
||||
}
|
||||
|
||||
$return['result'] = $result_text;
|
||||
$return['success'] = true;
|
||||
echo json_encode($return);
|
||||
|
||||
|
|
|
@ -18,6 +18,7 @@ namespace controllers\publics;
|
|||
{
|
||||
private $internal_contact;
|
||||
private $internal_event;
|
||||
private $internal_conditional_group;
|
||||
|
||||
/**
|
||||
* Cette fonction est appelée avant toute les autres :
|
||||
|
@ -31,6 +32,7 @@ namespace controllers\publics;
|
|||
|
||||
$this->internal_contact = new \controllers\internals\Contact($bdd);
|
||||
$this->internal_event = new \controllers\internals\Event($bdd);
|
||||
$this->internal_conditional_group = new \controllers\internals\ConditionalGroup($bdd);
|
||||
|
||||
\controllers\internals\Tool::verifyconnect();
|
||||
}
|
||||
|
@ -83,6 +85,40 @@ namespace controllers\publics;
|
|||
|
||||
return $this->redirect(\descartes\Router::url('Contact', 'list'));
|
||||
}
|
||||
|
||||
/**
|
||||
* This function will delete a list of contacts depending on a condition
|
||||
*
|
||||
* @param string $_POST['condition'] : Condition to use to delete contacts
|
||||
* @param mixed $csrf
|
||||
*
|
||||
* @return boolean;
|
||||
*/
|
||||
public function conditional_delete($csrf)
|
||||
{
|
||||
if (!$this->verify_csrf($csrf))
|
||||
{
|
||||
\FlashMessage\FlashMessage::push('danger', 'Jeton CSRF invalid !');
|
||||
|
||||
return $this->redirect(\descartes\Router::url('Contact', 'list'));
|
||||
}
|
||||
|
||||
$condition = $_POST['condition'] ?? false;
|
||||
if (!$condition)
|
||||
{
|
||||
\FlashMessage\FlashMessage::push('danger', 'Vous devez fournir une condition !');
|
||||
|
||||
return $this->redirect(\descartes\Router::url('Contact', 'list'));
|
||||
}
|
||||
|
||||
$contacts_to_delete = $this->internal_conditional_group->get_contacts_for_condition_and_user($_SESSION['user']['id'], $condition);
|
||||
foreach ($contacts_to_delete as $contact)
|
||||
{
|
||||
$this->internal_contact->delete_for_user($_SESSION['user']['id'], $contact['id']);
|
||||
}
|
||||
|
||||
return $this->redirect(\descartes\Router::url('Contact', 'list'));
|
||||
}
|
||||
|
||||
/**
|
||||
* Cette fonction retourne la page d'ajout d'un contact.
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue