mirror of
https://github.com/RaspbianFrance/raspisms.git
synced 2025-04-20 16:37:48 +02:00
start adding mms to a lot of places, no tests, not done
This commit is contained in:
parent
b8e587a59e
commit
ff6b3e79df
24 changed files with 1174 additions and 788 deletions
|
@ -32,6 +32,7 @@ namespace controllers\publics;
|
|||
'CANNOT_CREATE' => 8,
|
||||
'SUSPENDED_USER' => 16,
|
||||
'CANNOT_DELETE' => 32,
|
||||
'CANNOT_UPLOAD_FILE' => 64,
|
||||
];
|
||||
|
||||
const ERROR_MESSAGES = [
|
||||
|
@ -41,6 +42,7 @@ namespace controllers\publics;
|
|||
'CANNOT_CREATE' => 'Cannot create a new entry.',
|
||||
'SUSPENDED_USER' => 'This user account is currently suspended.',
|
||||
'CANNOT_DELETE' => 'Cannot delete this entry.',
|
||||
'CANNOT_UPLOAD_FILE' => 'Failed to upload or save an uploaded file : ',
|
||||
];
|
||||
|
||||
private $internal_user;
|
||||
|
@ -52,6 +54,8 @@ namespace controllers\publics;
|
|||
private $internal_group;
|
||||
private $internal_conditional_group;
|
||||
private $internal_adapter;
|
||||
private $internal_media;
|
||||
private $internal_setting;
|
||||
private $user;
|
||||
|
||||
/**
|
||||
|
@ -73,6 +77,8 @@ namespace controllers\publics;
|
|||
$this->internal_group = new \controllers\internals\Group($bdd);
|
||||
$this->internal_conditional_group = new \controllers\internals\ConditionalGroup($bdd);
|
||||
$this->internal_adapter = new \controllers\internals\Adapter();
|
||||
$this->internal_media = new \controllers\internals\Media($bdd);
|
||||
$this->internal_setting = new \controllers\internals\Setting($bdd);
|
||||
|
||||
//If no user, quit with error
|
||||
$this->user = false;
|
||||
|
@ -93,6 +99,8 @@ namespace controllers\publics;
|
|||
exit(self::ERROR_CODES['INVALID_CREDENTIALS']);
|
||||
}
|
||||
|
||||
$this->user['settings'] = $this->internal_setting->gets_for_user($this->user['id']);
|
||||
|
||||
if (\models\User::STATUS_ACTIVE !== $this->user['status'])
|
||||
{
|
||||
$return = self::DEFAULT_RETURN;
|
||||
|
@ -108,14 +116,14 @@ namespace controllers\publics;
|
|||
/**
|
||||
* List all entries of a certain type for the current user, sorted by id.
|
||||
*
|
||||
* @param string $entry_type : Type of entries we want to list ['sended', 'received', 'scheduled', 'contact', 'group', 'conditional_group', 'phone']
|
||||
* @param string $entry_type : Type of entries we want to list ['sended', 'received', 'scheduled', 'contact', 'group', 'conditional_group', 'phone', 'media']
|
||||
* @param int $page : Pagination number, Default = 0. Group of 25 results.
|
||||
*
|
||||
* @return : List of entries
|
||||
*/
|
||||
public function get_entries(string $entry_type, int $page = 0)
|
||||
{
|
||||
$entry_types = ['sended', 'received', 'scheduled', 'contact', 'group', 'conditional_group', 'phone'];
|
||||
$entry_types = ['sended', 'received', 'scheduled', 'contact', 'group', 'conditional_group', 'phone', 'media'];
|
||||
|
||||
if (!\in_array($entry_type, $entry_types, true))
|
||||
{
|
||||
|
@ -179,6 +187,7 @@ namespace controllers\publics;
|
|||
* @param string $_POST['text'] : Text of the message to send
|
||||
* @param string $_POST['id_phone'] : Default null. Id of phone to send the message from. If 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['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
|
||||
|
@ -192,16 +201,20 @@ namespace controllers\publics;
|
|||
$text = $_POST['text'] ?? false;
|
||||
$id_phone = empty($_POST['id_phone']) ? null : $_POST['id_phone'];
|
||||
$flash = (bool) ($_POST['flash'] ?? false);
|
||||
$mms = (bool) ($_POST['mms'] ?? false);
|
||||
$numbers = $_POST['numbers'] ?? [];
|
||||
$contacts = $_POST['contacts'] ?? [];
|
||||
$groups = $_POST['groups'] ?? [];
|
||||
$conditional_groups = $_POST['conditional_groups'] ?? [];
|
||||
$files = $_FILES ?? [];
|
||||
|
||||
$numbers = \is_array($numbers) ? $numbers : [$numbers];
|
||||
$contacts = \is_array($contacts) ? $contacts : [$contacts];
|
||||
$groups = \is_array($groups) ? $groups : [$groups];
|
||||
$conditional_groups = \is_array($conditional_groups) ? $conditional_groups : [$conditional_groups];
|
||||
|
||||
$media_ids = [];
|
||||
|
||||
if (!$at)
|
||||
{
|
||||
$at = (new \DateTime())->format('Y-m-d H:i:s');
|
||||
|
@ -227,6 +240,17 @@ namespace controllers\publics;
|
|||
return $this->json($return);
|
||||
}
|
||||
|
||||
//TODO : Check if phone adapter support mms and if mms are enabled
|
||||
if (($this->user['settings']['mms'] ?? false) && $mms)
|
||||
{
|
||||
$return = self::DEFAULT_RETURN;
|
||||
$return['error'] = self::ERROR_CODES['INVALID_PARAMETER'];
|
||||
$return['message'] = self::ERROR_MESSAGES['INVALID_PARAMETER'] . 'mms is set to true, but mms are disabled in settings.';
|
||||
$this->auto_http_code(false);
|
||||
|
||||
return $this->json($return);
|
||||
}
|
||||
|
||||
foreach ($numbers as $key => $number)
|
||||
{
|
||||
$number = \controllers\internals\Tool::parse_phone($number);
|
||||
|
@ -251,7 +275,13 @@ namespace controllers\publics;
|
|||
return $this->json($return);
|
||||
}
|
||||
|
||||
if ($id_phone && !$this->internal_phone->get_for_user($this->user['id'], $id_phone))
|
||||
$phone = null;
|
||||
if ($id_phone)
|
||||
{
|
||||
$phone = $this->internal_phone->get_for_user($this->user['id'], $id_phone);
|
||||
}
|
||||
|
||||
if ($id_phone && !$phone)
|
||||
{
|
||||
$return = self::DEFAULT_RETURN;
|
||||
$return['error'] = self::ERROR_CODES['INVALID_PARAMETER'];
|
||||
|
@ -261,7 +291,74 @@ namespace controllers\publics;
|
|||
return $this->json($return);
|
||||
}
|
||||
|
||||
$scheduled_id = $this->internal_scheduled->create($this->user['id'], $at, $text, $id_phone, $flash, $numbers, $contacts, $groups, $conditional_groups);
|
||||
if ($id_phone && $mms && !$this->internal_phone->support_mms($id_phone, $this->internal_phone::MMS_SENDING))
|
||||
{
|
||||
$return = self::DEFAULT_RETURN;
|
||||
$return['error'] = self::ERROR_CODES['INVALID_PARAMETER'];
|
||||
$return['message'] = self::ERROR_MESSAGES['INVALID_PARAMETER'] . 'mms : You try to send a mms with a phone that does not support mms.';
|
||||
$this->auto_http_code(false);
|
||||
|
||||
return $this->json($return);
|
||||
}
|
||||
|
||||
//if try to send mms and no available phone support mms, return error
|
||||
if (!$id_phone && $mms)
|
||||
{
|
||||
$phones_supporting_mms = $this->internal_phone->gets_phone_supporting_mms_for_user($this->user['id'], $this->internal_phone::MMS_SENDING);
|
||||
if (!count($phones_supporting_mms))
|
||||
{
|
||||
$return = self::DEFAULT_RETURN;
|
||||
$return['error'] = self::ERROR_CODES['INVALID_PARAMETER'];
|
||||
$return['message'] = self::ERROR_MESSAGES['INVALID_PARAMETER'] . 'mms : You try to send a mms but you dont have any phone supporting mms. Please add at least one phone supporting mms before trying to send one.';
|
||||
$this->auto_http_code(false);
|
||||
|
||||
return $this->json($return);
|
||||
}
|
||||
}
|
||||
|
||||
foreach ($files as $file)
|
||||
{
|
||||
$user_media_path = PWD_DATA . '/medias/' . $this->user['id'];
|
||||
|
||||
//Create user medias dir if not exists
|
||||
if (!file_exists($user_media_path))
|
||||
{
|
||||
if (!mkdir($user_media_path, fileperms(PWD_DATA), true))
|
||||
{
|
||||
$return = self::DEFAULT_RETURN;
|
||||
$return['error'] = self::ERROR_CODES['CANNOT_UPLOAD_FILE'];
|
||||
$return['message'] = self::ERROR_MESSAGES['CANNOT_UPLOAD_FILE'] . ' : Because cannot create medias dir on server for the user.';
|
||||
$this->auto_http_code(false);
|
||||
|
||||
return $this->json($return);
|
||||
}
|
||||
}
|
||||
|
||||
$result = \controllers\internals\Tool::save_uploaded_file($file, $user_media_path);
|
||||
if ($result['success'] !== true)
|
||||
{
|
||||
$return = self::DEFAULT_RETURN;
|
||||
$return['error'] = self::ERROR_CODES['CANNOT_UPLOAD_FILE'];
|
||||
$return['message'] = self::ERROR_MESSAGES['CANNOT_UPLOAD_FILE'] . $file['name'] . ' with error : ' . $result['content'];
|
||||
$this->auto_http_code(false);
|
||||
|
||||
return $this->json($return);
|
||||
}
|
||||
|
||||
$new_filepath = 'medias/' . $this->user['id'] . '/' . $result['content'];
|
||||
$new_media_id = $this->internal_media->create($this->user['id'], $new_filepath);
|
||||
if (!$new_media_id)
|
||||
{
|
||||
$return = self::DEFAULT_RETURN;
|
||||
$return['error'] = self::ERROR_CODES['CANNOT_CREATE'];
|
||||
$return['message'] = self::ERROR_MESSAGES['CANNOT_CREATE'];
|
||||
$this->auto_http_code(false);
|
||||
|
||||
return $this->json($return);
|
||||
}
|
||||
}
|
||||
|
||||
$scheduled_id = $this->internal_scheduled->create($this->user['id'], $at, $text, $id_phone, $flash, $mms, $numbers, $contacts, $groups, $conditional_groups, $media_ids);
|
||||
if (!$scheduled_id)
|
||||
{
|
||||
$return = self::DEFAULT_RETURN;
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue