improve prefilled of sms by allowing prefill of contacts + groups + conditional groups

This commit is contained in:
osaajani 2021-01-14 04:30:28 +01:00
parent e0eed18794
commit 063a8a899d
5 changed files with 20 additions and 19 deletions

View File

@ -96,9 +96,12 @@ namespace controllers\publics;
/**
* Cette fonction retourne la page d'ajout d'un scheduled.
*
* @param array? int $contacts_ids : Ids of contacts to prefilled
* @param array? int $groups_ids : Ids of groups to prefilled
* @param array? int $conditional_groups_ids : Ids of conditional groups to prefilled
* @param $prefilled : If we have prefilled some fields (possible values : 'contacts', 'groups', 'conditional_groups', false)
*/
public function add($prefilled = false)
public function add()
{
$now = new \DateTime();
$less_one_minute = new \DateInterval('PT1M');
@ -109,32 +112,31 @@ namespace controllers\publics;
$contacts = $this->internal_contact->gets_for_user($id_user);
$phones = $this->internal_phone->gets_for_user($id_user);
$contact_ids = (isset($_GET['contact_ids']) && is_array($_GET['contact_ids'])) ? $_GET['contact_ids'] : [];
$group_ids = (isset($_GET['group_ids']) && is_array($_GET['group_ids'])) ? $_GET['group_ids'] : [];
$conditional_group_ids = (isset($_GET['conditional_group_ids']) && is_array($_GET['conditional_group_ids'])) ? $_GET['conditional_group_ids'] : [];
$prefilled_contacts = [];
$prefilled_groups = [];
$prefilled_conditional_groups = [];
if ($prefilled)
if ($contact_ids)
{
$ids = $_GET['ids'] ?? [];
}
if ('contacts' === $prefilled)
{
foreach ($this->internal_contact->gets_in_for_user($id_user, $ids) as $contact)
foreach ($this->internal_contact->gets_in_for_user($id_user, $contact_ids) as $contact)
{
$prefilled_contacts[] = $contact['id'];
}
}
elseif ('groups' === $prefilled)
elseif ($group_ids)
{
foreach ($this->internal_group->gets_in_for_user($id_user, $ids) as $group)
foreach ($this->internal_group->gets_in_for_user($id_user, $group_ids) as $group)
{
$prefilled_groups[] = $group['id'];
}
}
elseif ('conditional_groups' === $prefilled)
elseif ($conditional_group_ids)
{
foreach ($this->internal_conditional_group->gets_in_for_user($id_user, $ids) as $conditional_group)
foreach ($this->internal_conditional_group->gets_in_for_user($id_user, $conditional_group_ids) as $conditional_group)
{
$prefilled_conditional_groups[] = $conditional_group['id'];
}

View File

@ -107,7 +107,6 @@
'list_json' => '/scheduled/json/',
'add' => [
'/scheduled/add/',
'/scheduled/add/{prefilled}/',
],
'create' => '/scheduled/create/{csrf}/',
'edit' => '/scheduled/edit/',

View File

@ -54,7 +54,7 @@
</div>
<div class="text-right col-xs-6 no-padding">
<strong>Action pour la séléction :</strong>
<button class="btn btn-default" type="submit" formaction="<?php echo \descartes\Router::url('Scheduled', 'add', ['prefilled' => 'conditional_groups']); ?>"><span class="fa fa-send"></span> Envoyer un message</button>
<button class="btn btn-default" type="submit" formaction="<?php echo \descartes\Router::url('Scheduled', 'add'); ?>"><span class="fa fa-send"></span> Envoyer un message</button>
<button class="btn btn-default" type="submit" formaction="<?php echo \descartes\Router::url('ConditionalGroup', 'edit'); ?>"><span class="fa fa-edit"></span> Modifier</button>
<button class="btn btn-default btn-confirm" type="submit" formaction="<?php echo \descartes\Router::url('ConditionalGroup', 'delete', ['csrf' => $_SESSION['csrf']]); ?>"><span class="fa fa-trash-o"></span> Supprimer</button>
</div>
@ -91,7 +91,7 @@ jQuery(document).ready(function ()
{
data: 'id',
render: function (data, type, row, meta) {
return '<input name="ids[]" type="checkbox" value="' + data + '">';
return '<input name="conditional_group_ids[]" type="checkbox" value="' + data + '">';
},
},
],

View File

@ -56,7 +56,7 @@
</div>
<div class="text-right col-xs-6 no-padding">
<strong>Action pour la séléction :</strong>
<button class="btn btn-default" type="submit" formaction="<?php echo \descartes\Router::url('Scheduled', 'add', ['prefilled' => 'contacts']); ?>"><span class="fa fa-send"></span> Envoyer un message</button>
<button class="btn btn-default" type="submit" formaction="<?php echo \descartes\Router::url('Scheduled', 'add'); ?>"><span class="fa fa-send"></span> Envoyer un message</button>
<button class="btn btn-default" type="submit" formaction="<?php echo \descartes\Router::url('Contact', 'edit'); ?>"><span class="fa fa-edit"></span> Modifier</button>
<button class="btn btn-default btn-confirm" type="submit" formaction="<?php echo \descartes\Router::url('Contact', 'delete', ['csrf' => $_SESSION['csrf']]); ?>"><span class="fa fa-trash-o"></span> Supprimer</button>
</div>
@ -147,7 +147,7 @@ jQuery(document).ready(function()
{
data: 'id',
render: function (data, type, row, meta) {
return '<input name="ids[]" type="checkbox" value="' + data + '">';
return '<input name="contact_ids[]" type="checkbox" value="' + data + '">';
},
},
],

View File

@ -54,7 +54,7 @@
</div>
<div class="text-right col-xs-6 no-padding">
<strong>Action pour la séléction :</strong>
<button class="btn btn-default" type="submit" formaction="<?php echo \descartes\Router::url('Scheduled', 'add', ['prefilled' => 'groups']); ?>"><span class="fa fa-send"></span> Envoyer un message</button>
<button class="btn btn-default" type="submit" formaction="<?php echo \descartes\Router::url('Scheduled', 'add'); ?>"><span class="fa fa-send"></span> Envoyer un message</button>
<button class="btn btn-default" type="submit" formaction="<?php echo \descartes\Router::url('Group', 'edit'); ?>"><span class="fa fa-edit"></span> Modifier</button>
<button class="btn btn-default btn-confirm" type="submit" formaction="<?php echo \descartes\Router::url('Group', 'delete', ['csrf' => $_SESSION['csrf']]); ?>"><span class="fa fa-trash-o"></span> Supprimer</button>
</div>
@ -91,7 +91,7 @@ jQuery(document).ready(function ()
{
data: 'id',
render: function (data, type, row, meta) {
return '<input name="ids[]" type="checkbox" value="' + data + '">';
return '<input name="group_ids[]" type="checkbox" value="' + data + '">';
},
},
],