mirror of
https://github.com/RaspbianFrance/raspisms.git
synced 2025-04-22 01:16:26 +02:00
Finish add conditional groups
This commit is contained in:
parent
f4bbfa0152
commit
47b26e3cd2
15 changed files with 273 additions and 67 deletions
|
@ -178,4 +178,67 @@ namespace controllers\publics;
|
|||
|
||||
return $this->redirect(\descartes\Router::url('ConditionalGroup', 'list'));
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Try to get the preview of contacts for a conditionnal group
|
||||
* @param string $_POST['condition'] : Condition to apply
|
||||
* @return json string
|
||||
*/
|
||||
public function contacts_preview ()
|
||||
{
|
||||
$return = [
|
||||
'success' => false,
|
||||
'result' => 'Une erreur inconnue est survenue.',
|
||||
];
|
||||
|
||||
$condition = $_POST['condition'] ?? false;
|
||||
|
||||
if (!$condition)
|
||||
{
|
||||
$return['result'] = 'Vous devez renseigner une condition.';
|
||||
echo json_encode($return);
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
$internal_ruler = new \controllers\internals\Ruler();
|
||||
$valid_condition = $internal_ruler->validate_condition($condition, ['contact' => (object) ['datas' => (object) null]]);
|
||||
if (!$valid_condition)
|
||||
{
|
||||
$return['result'] = 'Syntaxe de la condition invalide.';
|
||||
echo json_encode($return);
|
||||
return false;
|
||||
}
|
||||
|
||||
$contacts = $this->internal_conditional_group->get_contacts_for_condition_and_user($_SESSION['user']['id'], $condition);
|
||||
if (!$contacts)
|
||||
{
|
||||
$return['result'] = 'Aucun contact dans le groupe.';
|
||||
echo json_encode($return);
|
||||
return false;
|
||||
}
|
||||
|
||||
$contacts_name = [];
|
||||
foreach ($contacts as $contact)
|
||||
{
|
||||
$contacts_name[] = $contact['name'];
|
||||
}
|
||||
|
||||
$return['result'] = "Contacts du groupe : " . implode(', ', $contacts_name);
|
||||
$return['success'] = true;
|
||||
echo json_encode($return);
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Return the list of groups as JSON
|
||||
*/
|
||||
public function json_list()
|
||||
{
|
||||
header('Content-Type: application/json');
|
||||
echo json_encode($this->internal_conditional_group->list_for_user($_SESSION['user']['id']));
|
||||
}
|
||||
}
|
||||
|
|
|
@ -148,27 +148,19 @@ namespace controllers\publics;
|
|||
return $this->redirect(\descartes\Router::url('Contact', 'add'));
|
||||
}
|
||||
|
||||
$clean_datas = null;
|
||||
if ($datas)
|
||||
$clean_datas = [];
|
||||
foreach ($datas as $key => $value)
|
||||
{
|
||||
$clean_datas = [];
|
||||
foreach ($datas as $key => $value)
|
||||
if ($value === "")
|
||||
{
|
||||
if ($value === "")
|
||||
{
|
||||
continue;
|
||||
}
|
||||
|
||||
$key = mb_ereg_replace('[\W]', '', $key);
|
||||
$clean_datas[$key] = (string) $value;
|
||||
continue;
|
||||
}
|
||||
|
||||
$key = mb_ereg_replace('[\W]', '', $key);
|
||||
$clean_datas[$key] = (string) $value;
|
||||
}
|
||||
$clean_datas = $clean_datas ?: null;
|
||||
|
||||
if ($clean_datas)
|
||||
{
|
||||
$clean_datas = json_encode($clean_datas);
|
||||
}
|
||||
$clean_datas = json_encode($clean_datas);
|
||||
|
||||
if (!$this->internal_contact->create($id_user, $number, $name, $clean_datas))
|
||||
{
|
||||
|
@ -210,7 +202,7 @@ namespace controllers\publics;
|
|||
$name = $contact['name'] ?? false;
|
||||
$number = $contact['number'] ?? false;
|
||||
$id_user = $_SESSION['user']['id'];
|
||||
$datas = $contact['datas'] ?? null;
|
||||
$datas = $contact['datas'] ?? [];
|
||||
|
||||
if (!$name || !$number)
|
||||
{
|
||||
|
@ -223,28 +215,18 @@ namespace controllers\publics;
|
|||
continue;
|
||||
}
|
||||
|
||||
$clean_datas = null;
|
||||
if ($datas)
|
||||
$clean_datas = [];
|
||||
foreach ($datas as $key => $value)
|
||||
{
|
||||
$clean_datas = [];
|
||||
foreach ($datas as $key => $value)
|
||||
if ($value === "")
|
||||
{
|
||||
if ($value === "")
|
||||
{
|
||||
continue;
|
||||
}
|
||||
|
||||
$key = mb_ereg_replace('[\W]', '', $key);
|
||||
$clean_datas[$key] = (string) $value;
|
||||
continue;
|
||||
}
|
||||
}
|
||||
$clean_datas = $clean_datas ?: null;
|
||||
|
||||
if ($clean_datas)
|
||||
{
|
||||
$clean_datas = json_encode($clean_datas);
|
||||
}
|
||||
|
||||
$key = mb_ereg_replace('[\W]', '', $key);
|
||||
$clean_datas[$key] = (string) $value;
|
||||
}
|
||||
$clean_datas = json_encode($clean_datas);
|
||||
|
||||
$nb_contacts_update += (int) $this->internal_contact->update_for_user($id_user, $id_contact, $number, $name, $clean_datas);
|
||||
}
|
||||
|
|
|
@ -129,6 +129,7 @@ namespace controllers\publics;
|
|||
$scheduleds[$key]['numbers'] = [];
|
||||
$scheduleds[$key]['contacts'] = [];
|
||||
$scheduleds[$key]['groups'] = [];
|
||||
$scheduleds[$key]['conditional_groups'] = [];
|
||||
|
||||
$numbers = $this->internal_scheduled->get_numbers($scheduled['id']);
|
||||
foreach ($numbers as $number)
|
||||
|
@ -147,6 +148,12 @@ namespace controllers\publics;
|
|||
{
|
||||
$scheduleds[$key]['groups'][] = (int) $group['id'];
|
||||
}
|
||||
|
||||
$conditional_groups = $this->internal_scheduled->get_conditional_groups($scheduled['id']);
|
||||
foreach ($conditional_groups as $conditional_group)
|
||||
{
|
||||
$scheduleds[$key]['conditional_groups'][] = (int) $conditional_group['id'];
|
||||
}
|
||||
}
|
||||
|
||||
$this->render('scheduled/edit', [
|
||||
|
@ -183,6 +190,7 @@ namespace controllers\publics;
|
|||
$numbers = $_POST['numbers'] ?? [];
|
||||
$contacts = $_POST['contacts'] ?? [];
|
||||
$groups = $_POST['groups'] ?? [];
|
||||
$conditional_groups = $_POST['conditional_groups'] ?? [];
|
||||
|
||||
if (empty($text))
|
||||
{
|
||||
|
@ -212,7 +220,7 @@ namespace controllers\publics;
|
|||
$numbers[$key] = $number;
|
||||
}
|
||||
|
||||
if (!$numbers && !$contacts && !$groups)
|
||||
if (!$numbers && !$contacts && !$groups && !$conditional_groups)
|
||||
{
|
||||
\FlashMessage\FlashMessage::push('danger', 'Vous devez renseigner au moins un destinataire pour le Sms.');
|
||||
return $this->redirect(\descartes\Router::url('Scheduled', 'add'));
|
||||
|
@ -226,7 +234,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($id_user, $at, $text, $origin, $flash, $numbers, $contacts, $groups, $conditional_groups);
|
||||
if (!$scheduled_id)
|
||||
{
|
||||
\FlashMessage\FlashMessage::push('danger', 'Impossible de créer le Sms.');
|
||||
|
@ -269,6 +277,7 @@ namespace controllers\publics;
|
|||
$numbers = $scheduled['numbers'] ?? [];
|
||||
$contacts = $scheduled['contacts'] ?? [];
|
||||
$groups = $scheduled['groups'] ?? [];
|
||||
$conditional_groups = $scheduled['conditional_groups'] ?? [];
|
||||
|
||||
$scheduled = $this->internal_scheduled->get($id_scheduled);
|
||||
if (!$scheduled || $scheduled['id_user'] !== $id_user)
|
||||
|
@ -305,7 +314,7 @@ namespace controllers\publics;
|
|||
$numbers[$key] = $number;
|
||||
}
|
||||
|
||||
if (!$numbers && !$contacts && !$groups)
|
||||
if (!$numbers && !$contacts && !$groups && !$conditional_groups)
|
||||
{
|
||||
$all_update_ok = false;
|
||||
|
||||
|
@ -319,7 +328,7 @@ namespace controllers\publics;
|
|||
return $this->redirect(\descartes\Router::url('Scheduled', 'add'));
|
||||
}
|
||||
|
||||
$success = $this->internal_scheduled->update_for_user($id_user, $id_scheduled, $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, $conditional_groups);
|
||||
if (!$success)
|
||||
{
|
||||
$all_update_ok = false;
|
||||
|
|
|
@ -62,10 +62,7 @@ namespace controllers\publics;
|
|||
return false;
|
||||
}
|
||||
|
||||
if ($contact['datas'])
|
||||
{
|
||||
$contact['datas'] = json_decode($contact['datas'], true);
|
||||
}
|
||||
$contact['datas'] = json_decode($contact['datas'], true);
|
||||
|
||||
$datas = [
|
||||
'contact' => $contact,
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue