mirror of
https://github.com/RaspbianFrance/raspisms.git
synced 2025-04-20 16:37:48 +02:00
Add support for tag in sms campaigns
This commit is contained in:
parent
2f74fa6173
commit
7483b9a8ae
15 changed files with 213 additions and 34 deletions
|
@ -232,6 +232,74 @@ namespace controllers\publics;
|
|||
return $this->json($return);
|
||||
}
|
||||
|
||||
/**
|
||||
* Return info about volume of sms sended for a period
|
||||
*
|
||||
* @param ?string $_POST['start'] : Date from which to get sms volume, format Y-m-d H:i:s. Default to null.
|
||||
* @param ?string $_POST['end'] : Date up to which to get sms volume, format Y-m-d H:i:s. Default to null.
|
||||
* @param ?string $_POST['tag'] : Tag to filter SMS by. If set, only sended sms with a matching tag will be counted. Default to null.
|
||||
*
|
||||
* @return : List of entries
|
||||
*/
|
||||
public function get_usage()
|
||||
{
|
||||
$start = $_GET['start'] ?? null;
|
||||
$end = $_GET['end'] ?? null;
|
||||
$tag = $_GET['tag'] ?? null;
|
||||
|
||||
$return = self::DEFAULT_RETURN;
|
||||
|
||||
if ($start)
|
||||
{
|
||||
if (!\controllers\internals\Tool::validate_date($start, 'Y-m-d H:i:s'))
|
||||
{
|
||||
$return = self::DEFAULT_RETURN;
|
||||
$return['error'] = self::ERROR_CODES['INVALID_PARAMETER'];
|
||||
$return['message'] = self::ERROR_MESSAGES['INVALID_PARAMETER'] . 'start must be a date of format "Y-m-d H:i:s".';
|
||||
$this->auto_http_code(false);
|
||||
|
||||
return $this->json($return);
|
||||
}
|
||||
|
||||
$start = new \DateTime($start);
|
||||
}
|
||||
|
||||
if ($end)
|
||||
{
|
||||
if (!\controllers\internals\Tool::validate_date($end, 'Y-m-d H:i:s'))
|
||||
{
|
||||
$return = self::DEFAULT_RETURN;
|
||||
$return['error'] = self::ERROR_CODES['INVALID_PARAMETER'];
|
||||
$return['message'] = self::ERROR_MESSAGES['INVALID_PARAMETER'] . 'end must be a date of format "Y-m-d H:i:s".';
|
||||
$this->auto_http_code(false);
|
||||
|
||||
return $this->json($return);
|
||||
}
|
||||
|
||||
$end = new \DateTime($end);
|
||||
}
|
||||
|
||||
$total_sended = 0;
|
||||
$phones_volumes = [];
|
||||
|
||||
$phones = $this->internal_phone->gets_for_user($this->user['id']);
|
||||
foreach ($phones as $phone)
|
||||
{
|
||||
$nb_sended = $this->internal_sended->count_since_for_phone_and_user($this->user['id'], $phone['id'], $start, $end, $tag);
|
||||
$total_sended += $nb_sended;
|
||||
$phones_volumes[$phone['id']] = $nb_sended;
|
||||
}
|
||||
|
||||
$return['response'] = [
|
||||
'total' => $total_sended,
|
||||
'phones_volumes' => $phones_volumes,
|
||||
];
|
||||
|
||||
$this->auto_http_code(true);
|
||||
|
||||
return $this->json($return);
|
||||
}
|
||||
|
||||
/**
|
||||
* Schedule a message to be send.
|
||||
*
|
||||
|
@ -241,6 +309,7 @@ namespace controllers\publics;
|
|||
* @param string $_POST['id_phone_group'] : Default null. Id of phone group to send the message from. If null abd id_phone null, use a random phone
|
||||
* @param string $_POST['flash'] : Default false. Is the sms a flash sms.
|
||||
* @param string $_POST['mms'] : Default false. Is the sms a mms.
|
||||
* @param string $_POST['tag'] : Default null. Tag to associate to every sms of the campaign.
|
||||
* @param string $_POST['numbers'] : Array of numbers to send message to
|
||||
* @param string $_POST['contacts'] : Array of ids of contacts to send message to
|
||||
* @param string $_POST['groups'] : Array of ids of groups to send message to
|
||||
|
@ -257,6 +326,7 @@ namespace controllers\publics;
|
|||
$id_phone_group = empty($_POST['id_phone_group']) ? null : $_POST['id_phone_group'];
|
||||
$flash = (bool) ($_POST['flash'] ?? false);
|
||||
$mms = (bool) ($_POST['mms'] ?? false);
|
||||
$tag = $_POST['tag'] ?? null;
|
||||
$numbers = $_POST['numbers'] ?? [];
|
||||
$contacts = $_POST['contacts'] ?? [];
|
||||
$groups = $_POST['groups'] ?? [];
|
||||
|
@ -505,7 +575,7 @@ namespace controllers\publics;
|
|||
}
|
||||
}
|
||||
|
||||
$scheduled_id = $this->internal_scheduled->create($this->user['id'], $at, $text, $id_phone, $id_phone_group, $flash, $mms, $numbers, $contacts, $groups, $conditional_groups, $media_ids);
|
||||
$scheduled_id = $this->internal_scheduled->create($this->user['id'], $at, $text, $id_phone, $id_phone_group, $flash, $mms, $tag, $numbers, $contacts, $groups, $conditional_groups, $media_ids);
|
||||
if (!$scheduled_id)
|
||||
{
|
||||
$return = self::DEFAULT_RETURN;
|
||||
|
|
|
@ -234,6 +234,7 @@ namespace controllers\publics;
|
|||
$at = $now;
|
||||
$text = $_POST['text'] ?? '';
|
||||
$destination = $_POST['destination'] ?? false;
|
||||
$tag = $_POST['tag'] ?? null;
|
||||
$id_phone = $_POST['id_phone'] ?? false;
|
||||
$files = $_FILES['medias'] ?? false;
|
||||
|
||||
|
@ -315,7 +316,7 @@ namespace controllers\publics;
|
|||
//Destinations must be an array of number
|
||||
$destinations = [['number' => $destination, 'data' => '[]']];
|
||||
|
||||
if (!$this->internal_scheduled->create($id_user, $at, $text, $id_phone, null, false, $mms, $destinations, [], [], [], $media_ids))
|
||||
if (!$this->internal_scheduled->create($id_user, $at, $text, $id_phone, null, false, $mms, $tag, $destinations, [], [], [], $media_ids))
|
||||
{
|
||||
$return['success'] = false;
|
||||
$return['message'] = 'Impossible de créer le Sms';
|
||||
|
|
|
@ -264,6 +264,7 @@ namespace controllers\publics;
|
|||
$at = $_POST['at'] ?? false;
|
||||
$text = $_POST['text'] ?? false;
|
||||
$flash = (bool) ($_POST['flash'] ?? false);
|
||||
$tag = ($_POST['tag'] ?? null) ?: null;
|
||||
$id_phone = empty($_POST['id_phone']) ? null : $_POST['id_phone'];
|
||||
$numbers = $_POST['numbers'] ?? [];
|
||||
$numbers = is_array($numbers) ? $numbers : [$numbers];
|
||||
|
@ -444,7 +445,7 @@ namespace controllers\publics;
|
|||
$id_phone = str_starts_with($original_id_phone, 'phone_') ? mb_substr($original_id_phone, mb_strlen('phone_')) : null;
|
||||
$id_phone_group = str_starts_with($original_id_phone, 'phonegroup_') ? mb_substr($original_id_phone, mb_strlen('phonegroup_')) : null;
|
||||
|
||||
$scheduled_id = $this->internal_scheduled->create($id_user, $at, $text, $id_phone, $id_phone_group, $flash, $mms, $numbers, $contacts, $groups, $conditional_groups, $media_ids);
|
||||
$scheduled_id = $this->internal_scheduled->create($id_user, $at, $text, $id_phone, $id_phone_group, $flash, $mms, $tag, $numbers, $contacts, $groups, $conditional_groups, $media_ids);
|
||||
if (!$scheduled_id)
|
||||
{
|
||||
\FlashMessage\FlashMessage::push('danger', 'Impossible de créer le Sms.');
|
||||
|
@ -484,6 +485,7 @@ namespace controllers\publics;
|
|||
$text = $scheduled['text'] ?? false;
|
||||
$id_phone = empty($scheduled['id_phone']) ? null : $scheduled['id_phone'];
|
||||
$flash = (bool) ($scheduled['flash'] ?? false);
|
||||
$tag = ($scheduled['tag'] ?? null) ?: null;
|
||||
$numbers = $scheduled['numbers'] ?? [];
|
||||
$contacts = $scheduled['contacts'] ?? [];
|
||||
$groups = $scheduled['groups'] ?? [];
|
||||
|
@ -665,7 +667,7 @@ namespace controllers\publics;
|
|||
$id_phone = str_starts_with($original_id_phone, 'phone_') ? mb_substr($original_id_phone, mb_strlen('phone_')) : null;
|
||||
$id_phone_group = str_starts_with($original_id_phone, 'phonegroup_') ? mb_substr($original_id_phone, mb_strlen('phonegroup_')) : null;
|
||||
|
||||
$this->internal_scheduled->update_for_user($id_user, $id_scheduled, $at, $text, $id_phone, $id_phone_group, $flash, $mms, $numbers, $contacts, $groups, $conditional_groups, $media_ids);
|
||||
$this->internal_scheduled->update_for_user($id_user, $id_scheduled, $at, $text, $id_phone, $id_phone_group, $flash, $mms, $tag, $numbers, $contacts, $groups, $conditional_groups, $media_ids);
|
||||
++$nb_update;
|
||||
}
|
||||
|
||||
|
|
|
@ -59,8 +59,9 @@ namespace controllers\publics;
|
|||
0 => 'phone_name',
|
||||
1 => 'searchable_destination',
|
||||
2 => 'text',
|
||||
3 => 'at',
|
||||
4 => 'status',
|
||||
3 => 'tag',
|
||||
4 => 'at',
|
||||
5 => 'status',
|
||||
];
|
||||
|
||||
$search = $_GET['search']['value'] ?? null;
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue