1
0
Fork 0
mirror of https://github.com/RaspbianFrance/raspisms.git synced 2025-05-07 08:46:26 +02:00

First step of quota and using daemon

This commit is contained in:
osaajani 2021-06-08 02:00:48 +02:00
parent 3d19c4decb
commit 120f56fad7
12 changed files with 552 additions and 0 deletions
controllers/internals

View file

@ -219,6 +219,18 @@ namespace controllers\internals;
'error_message' => null,
];
//If we reached our max quota, do not send the message
$internal_quota = new Quota($this->bdd);
$nb_credits = $internal_quota::compute_credits_for_message($text); //Calculate how much credit the message require
if ($internal_quota->has_enough_credit($id_user, $nb_credits))
{
$return['error'] = false;
$return['error_message'] = 'Not enough credit to send message.';
return $return;
}
$at = (new \DateTime())->format('Y-m-d H:i:s');
$media_uris = [];
foreach ($medias as $media)
@ -253,6 +265,8 @@ namespace controllers\internals;
return $return;
}
$internal_quota->consume_credit($id_user, $nb_credits);
$sended_id = $this->create($id_user, $id_phone, $at, $text, $destination, $response['uid'] ?? uniqid(), $adapter->meta_classname(), $flash, $mms, $medias, $status);
$sended = [