mirror of
https://github.com/RaspbianFrance/raspisms.git
synced 2025-04-20 16:37:48 +02:00
Add support for numbers with data on scheduled + add support for sending sms to a csv file
This commit is contained in:
parent
7fc7a8f245
commit
81fb987740
22 changed files with 635 additions and 114 deletions
|
@ -81,7 +81,7 @@ namespace controllers\internals;
|
|||
|
||||
exit($user ? 0 : 1);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Check if a user exists based on id.
|
||||
*
|
||||
|
|
|
@ -31,7 +31,7 @@ namespace controllers\internals;
|
|||
{
|
||||
return $this->get_model()->datatable_list_for_user($id_user, $limit, $offset, $search, $search_columns, $order_column, $order_desc, $count);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Return a contact for a user by a number.
|
||||
*
|
||||
|
|
|
@ -108,7 +108,7 @@ class Quota extends StandardController
|
|||
}
|
||||
|
||||
/**
|
||||
* Check if a message can be encoded as gsm0338 or if it must be UTF8
|
||||
* Check if a message can be encoded as gsm0338 or if it must be UTF8.
|
||||
*
|
||||
* @param string $text : Message to send
|
||||
*
|
||||
|
|
|
@ -48,8 +48,8 @@ use Symfony\Component\ExpressionLanguage\ExpressionLanguage;
|
|||
|
||||
return true;
|
||||
}
|
||||
catch (\Throwable $t) //Catch both, exceptions and php error
|
||||
{
|
||||
catch (\Throwable $t)
|
||||
{ //Catch both, exceptions and php error
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
@ -71,8 +71,8 @@ use Symfony\Component\ExpressionLanguage\ExpressionLanguage;
|
|||
|
||||
return (bool) $result;
|
||||
}
|
||||
catch (\Throwable $t) //Catch both, exceptions and php error
|
||||
{
|
||||
catch (\Throwable $t)
|
||||
{ //Catch both, exceptions and php error
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -24,7 +24,7 @@ namespace controllers\internals;
|
|||
* @param ?int $id_phone : Id of the phone to send message with, null by default
|
||||
* @param bool $flash : Is the sms a flash sms, by default false
|
||||
* @param bool $mms : Is the sms a mms, by default false
|
||||
* @param array $numbers : Numbers to send message to
|
||||
* @param array $numbers : Array of numbers to send message to, a number is an array ['number' => '+33XXX', 'data' => '{"key":"value", ...}']
|
||||
* @param array $contacts_ids : Contact ids to send message to
|
||||
* @param array $groups_ids : Group ids to send message to
|
||||
* @param array $conditional_group_ids : Conditional Groups ids to send message to
|
||||
|
@ -84,7 +84,7 @@ namespace controllers\internals;
|
|||
|
||||
foreach ($numbers as $number)
|
||||
{
|
||||
$this->get_model()->insert_scheduled_number($id_scheduled, $number);
|
||||
$this->get_model()->insert_scheduled_number($id_scheduled, $number['number'], $number['data']);
|
||||
}
|
||||
|
||||
$internal_contact = new Contact($this->bdd);
|
||||
|
@ -146,7 +146,7 @@ namespace controllers\internals;
|
|||
* @param ?int $id_phone : Id of the phone to send message with, null by default
|
||||
* @param bool $flash : Is the sms a flash sms, by default false
|
||||
* @param bool $mms : Is the sms a mms, by default false
|
||||
* @param array $numbers : Numbers to send message to
|
||||
* @param array $numbers : Array of numbers to send message to, a number is an array ['number' => '+33XXX', 'data' => '{"key":"value", ...}']
|
||||
* @param array $contacts_ids : Contact ids to send message to
|
||||
* @param array $groups_ids : Group ids to send message to
|
||||
* @param array $conditional_group_ids : Conditional Groups ids to send message to
|
||||
|
@ -201,7 +201,7 @@ namespace controllers\internals;
|
|||
|
||||
foreach ($numbers as $number)
|
||||
{
|
||||
$this->get_model()->insert_scheduled_number($id_scheduled, $number);
|
||||
$this->get_model()->insert_scheduled_number($id_scheduled, $number['number'], $number['data']);
|
||||
}
|
||||
|
||||
$internal_contact = new Contact($this->bdd);
|
||||
|
@ -496,6 +496,72 @@ namespace controllers\internals;
|
|||
return $smss_to_send_per_scheduled;
|
||||
}
|
||||
|
||||
/**
|
||||
* Parse a CSV file of numbers, potentially associated with datas.
|
||||
*
|
||||
* @param resource $file_handler : File handler pointing to the file
|
||||
*
|
||||
* @throws Exception : raise exception if file is not valid
|
||||
*
|
||||
* @return mixed : array of numbers ['number' => '+XXXX...', 'data' => ['key' => 'value', ...]]
|
||||
*/
|
||||
public function parse_csv_numbers_file($file_handler)
|
||||
{
|
||||
$numbers = [];
|
||||
|
||||
$head = null;
|
||||
$line_nb = 0;
|
||||
while ($line = fgetcsv($file_handler))
|
||||
{
|
||||
++$line_nb;
|
||||
if (null === $head)
|
||||
{
|
||||
$head = $line;
|
||||
|
||||
continue;
|
||||
}
|
||||
|
||||
//Padding line with '' entries to make sure its same length as head
|
||||
//this allow to mix users with data with users without data
|
||||
$line = array_pad($line, \count($head), '');
|
||||
|
||||
$line = array_combine($head, $line);
|
||||
if (false === $line)
|
||||
{
|
||||
continue;
|
||||
}
|
||||
|
||||
$phone_number = \controllers\internals\Tool::parse_phone($line[array_keys($line)[0]] ?? '');
|
||||
if (!$phone_number)
|
||||
{
|
||||
throw new \Exception('Erreur à la ligne ' . $line_nb . ' colonne 1, numéro de téléphone invalide.');
|
||||
}
|
||||
|
||||
$data = [];
|
||||
$i = 0;
|
||||
foreach ($line as $key => $value)
|
||||
{
|
||||
++$i;
|
||||
if ($i < 2)
|
||||
{ // Ignore first column
|
||||
continue;
|
||||
}
|
||||
|
||||
if ('' === $value)
|
||||
{
|
||||
continue;
|
||||
}
|
||||
|
||||
$key = mb_ereg_replace('[\W]', '', $key);
|
||||
$data[$key] = $value;
|
||||
}
|
||||
|
||||
$numbers[] = ['number' => $phone_number, 'data' => $data];
|
||||
}
|
||||
|
||||
return $numbers;
|
||||
}
|
||||
|
||||
/**
|
||||
* Return numbers for a scheduled message.
|
||||
*
|
||||
|
|
|
@ -39,14 +39,14 @@ namespace controllers\internals;
|
|||
* @param int $id_phone : Id of the number the message was send with
|
||||
* @param $at : Reception date
|
||||
* @param $text : Text of the message
|
||||
* @param string $destination : Number of the receiver
|
||||
* @param string $uid : Uid of the sms on the adapter service used
|
||||
* @param string $adapter : Name of the adapter service used to send the message
|
||||
* @param bool $flash : Is the sms a flash
|
||||
* @param bool $mms : Is the sms a MMS. By default false.
|
||||
* @param array $medias : Array of medias to link to the MMS
|
||||
* @param string $destination : Number of the receiver
|
||||
* @param string $uid : Uid of the sms on the adapter service used
|
||||
* @param string $adapter : Name of the adapter service used to send the message
|
||||
* @param bool $flash : Is the sms a flash
|
||||
* @param bool $mms : Is the sms a MMS. By default false.
|
||||
* @param array $medias : Array of medias to link to the MMS
|
||||
* @param ?int $originating_scheduled : Id of the scheduled message that was responsible for sending this message. By default null.
|
||||
* @param string $status : Status of a the sms. By default \models\Sended::STATUS_UNKNOWN
|
||||
* @param string $status : Status of a the sms. By default \models\Sended::STATUS_UNKNOWN
|
||||
*
|
||||
* @return mixed : false on error, new sended id else
|
||||
*/
|
||||
|
@ -220,11 +220,12 @@ namespace controllers\internals;
|
|||
* @param int $id_user : Id of user to create sended message for
|
||||
* @param int $id_phone : Id of the phone the message was send with
|
||||
* @param $text : Text of the message
|
||||
* @param string $destination : Number of the receiver
|
||||
* @param bool $flash : Is the sms a flash. By default false.
|
||||
* @param bool $mms : Is the sms a MMS. By default false.
|
||||
* @param array $medias : Array of medias to link to the MMS
|
||||
* @param string $status : Status of a the sms. By default \models\Sended::STATUS_UNKNOWN
|
||||
* @param string $destination : Number of the receiver
|
||||
* @param bool $flash : Is the sms a flash. By default false.
|
||||
* @param bool $mms : Is the sms a MMS. By default false.
|
||||
* @param array $medias : Array of medias to link to the MMS
|
||||
* @param string $status : Status of a the sms. By default \models\Sended::STATUS_UNKNOWN
|
||||
* @param null|mixed $originating_scheduled
|
||||
*
|
||||
* @return array : [
|
||||
* bool 'error' => false if success, true else
|
||||
|
@ -291,7 +292,7 @@ namespace controllers\internals;
|
|||
'medias' => $medias,
|
||||
'originating_scheduled' => $originating_scheduled,
|
||||
];
|
||||
|
||||
|
||||
$internal_webhook = new Webhook($this->bdd);
|
||||
$internal_webhook->trigger($id_user, \models\Webhook::TYPE_SEND_SMS, $sended);
|
||||
|
||||
|
|
|
@ -137,7 +137,7 @@ namespace controllers\internals;
|
|||
|
||||
/**
|
||||
* Get the model for the Controller.
|
||||
*
|
||||
*
|
||||
* @return \models\StandardModel
|
||||
*/
|
||||
abstract protected function get_model();
|
||||
|
|
|
@ -374,22 +374,24 @@ namespace controllers\internals;
|
|||
}
|
||||
|
||||
/**
|
||||
* Forge back an url parsed with PHP parse_url function
|
||||
*
|
||||
* Forge back an url parsed with PHP parse_url function.
|
||||
*
|
||||
* @param array $parsed_url : Parsed url returned by parse_url function
|
||||
*
|
||||
* @return string : The url as a string
|
||||
*/
|
||||
public static function unparse_url(array $parsed_url)
|
||||
{
|
||||
$scheme = isset($parsed_url['scheme']) ? $parsed_url['scheme'] . '://' : '';
|
||||
$host = isset($parsed_url['host']) ? $parsed_url['host'] : '';
|
||||
$port = isset($parsed_url['port']) ? ':' . $parsed_url['port'] : '';
|
||||
$user = isset($parsed_url['user']) ? $parsed_url['user'] : '';
|
||||
$pass = isset($parsed_url['pass']) ? ':' . $parsed_url['pass'] : '';
|
||||
$pass = ($user || $pass) ? "$pass@" : '';
|
||||
$path = isset($parsed_url['path']) ? $parsed_url['path'] : '';
|
||||
$query = isset($parsed_url['query']) ? '?' . $parsed_url['query'] : '';
|
||||
$scheme = isset($parsed_url['scheme']) ? $parsed_url['scheme'] . '://' : '';
|
||||
$host = isset($parsed_url['host']) ? $parsed_url['host'] : '';
|
||||
$port = isset($parsed_url['port']) ? ':' . $parsed_url['port'] : '';
|
||||
$user = isset($parsed_url['user']) ? $parsed_url['user'] : '';
|
||||
$pass = isset($parsed_url['pass']) ? ':' . $parsed_url['pass'] : '';
|
||||
$pass = ($user || $pass) ? "{$pass}@" : '';
|
||||
$path = isset($parsed_url['path']) ? $parsed_url['path'] : '';
|
||||
$query = isset($parsed_url['query']) ? '?' . $parsed_url['query'] : '';
|
||||
$fragment = isset($parsed_url['fragment']) ? '#' . $parsed_url['fragment'] : '';
|
||||
return "$scheme$user$pass$host$port$path$query$fragment";
|
||||
}
|
||||
|
||||
return "{$scheme}{$user}{$pass}{$host}{$port}{$path}{$query}{$fragment}";
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue