Compare commits
No commits in common. "49af8f7d943fed36449eb67e549da91af9d3d020" and "b8ab352debd016a48562825b98013f921ecff1f1" have entirely different histories.
49af8f7d94
...
b8ab352deb
|
@ -161,7 +161,7 @@ interface AdapterInterface
|
|||
/**
|
||||
* Method called to verify phone status
|
||||
*
|
||||
* @return string : Return one phone status among 'available', 'unavailable', 'no_credit', 'limit_reached'
|
||||
* @return string : Return one phone status among 'available', 'unavailable', 'no_credit'
|
||||
*/
|
||||
public function check_phone_status(): string;
|
||||
|
||||
|
|
|
@ -1030,37 +1030,10 @@ namespace controllers\publics;
|
|||
return $this->json($return);
|
||||
}
|
||||
|
||||
// If user have activated phone limits, check if RaspiSMS phone limit have already been reached
|
||||
$limit_reached = false;
|
||||
if ((int) ($this->user['settings']['phone_limit'] ?? false))
|
||||
{
|
||||
$limits = $this->internal_phone->get_limits($id);
|
||||
|
||||
$remaining_volume = PHP_INT_MAX;
|
||||
foreach ($limits as $limit)
|
||||
{
|
||||
$startpoint = new \DateTime($limit['startpoint']);
|
||||
$consumed = $this->internal_sended->count_since_for_phone_and_user($this->user['id'], $id, $startpoint);
|
||||
$remaining_volume = min(($limit['volume'] - $consumed), $remaining_volume);
|
||||
}
|
||||
|
||||
if ($remaining_volume < 1)
|
||||
{
|
||||
$limit_reached = true;
|
||||
}
|
||||
}
|
||||
|
||||
if ($limit_reached)
|
||||
{
|
||||
$new_status = \models\Phone::STATUS_LIMIT_REACHED;
|
||||
}
|
||||
else
|
||||
{
|
||||
//Check status on provider side
|
||||
//Check adapter is working correctly with thoses names and data
|
||||
$adapter_classname = $phone['adapter'];
|
||||
$adapter_instance = new $adapter_classname($phone['adapter_data']);
|
||||
$new_status = $adapter_instance->check_phone_status();
|
||||
}
|
||||
|
||||
$status_update = $this->internal_phone->update_status($id, $new_status);
|
||||
$return['response'] = $new_status;
|
||||
|
|
|
@ -18,13 +18,11 @@ class Phone extends \descartes\Controller
|
|||
{
|
||||
private $internal_phone;
|
||||
private $internal_adapter;
|
||||
private $internal_sended;
|
||||
|
||||
public function __construct()
|
||||
{
|
||||
$bdd = \descartes\Model::_connect(DATABASE_HOST, DATABASE_NAME, DATABASE_USER, DATABASE_PASSWORD);
|
||||
$this->internal_phone = new \controllers\internals\Phone($bdd);
|
||||
$this->internal_sended = new \controllers\internals\Sended($bdd);
|
||||
$this->internal_adapter = new \controllers\internals\Adapter();
|
||||
|
||||
\controllers\internals\Tool::verifyconnect();
|
||||
|
@ -536,33 +534,7 @@ class Phone extends \descartes\Controller
|
|||
{
|
||||
$phone = $this->internal_phone->get_for_user($id_user, $id);
|
||||
|
||||
// If user have activated phone limits, check if RaspiSMS phone limit have already been reached
|
||||
$limit_reached = false;
|
||||
if ((int) ($_SESSION['user']['settings']['phone_limit'] ?? false))
|
||||
{
|
||||
$limits = $this->internal_phone->get_limits($id);
|
||||
|
||||
$remaining_volume = PHP_INT_MAX;
|
||||
foreach ($limits as $limit)
|
||||
{
|
||||
$startpoint = new \DateTime($limit['startpoint']);
|
||||
$consumed = $this->internal_sended->count_since_for_phone_and_user($_SESSION['user']['id'], $id, $startpoint);
|
||||
$remaining_volume = min(($limit['volume'] - $consumed), $remaining_volume);
|
||||
}
|
||||
|
||||
if ($remaining_volume < 1)
|
||||
{
|
||||
$limit_reached = true;
|
||||
}
|
||||
}
|
||||
|
||||
if ($limit_reached)
|
||||
{
|
||||
$new_status = \models\Phone::STATUS_LIMIT_REACHED;
|
||||
}
|
||||
else
|
||||
{
|
||||
//Check status on provider side
|
||||
//Check adapter is working correctly with thoses names and data
|
||||
$adapter_classname = $phone['adapter'];
|
||||
if (!call_user_func([$adapter_classname, 'meta_support_phone_status']))
|
||||
{
|
||||
|
@ -571,7 +543,6 @@ class Phone extends \descartes\Controller
|
|||
|
||||
$adapter_instance = new $adapter_classname($phone['adapter_data']);
|
||||
$new_status = $adapter_instance->check_phone_status();
|
||||
}
|
||||
|
||||
$status_update = $this->internal_phone->update_status($id, $new_status);
|
||||
}
|
||||
|
|
|
@ -1,38 +0,0 @@
|
|||
<?php
|
||||
|
||||
use Phinx\Migration\AbstractMigration;
|
||||
|
||||
class AddReachedLimitPhoneStatus extends AbstractMigration
|
||||
{
|
||||
/**
|
||||
* Change Method.
|
||||
*
|
||||
* Write your reversible migrations using this method.
|
||||
*
|
||||
* More information on writing migrations is available here:
|
||||
* https://book.cakephp.org/phinx/0/en/migrations.html
|
||||
*
|
||||
* The following commands can be used in this method and Phinx will
|
||||
* automatically reverse them when rolling back:
|
||||
*
|
||||
* createTable
|
||||
* renameTable
|
||||
* addColumn
|
||||
* addCustomColumn
|
||||
* renameColumn
|
||||
* addIndex
|
||||
* addForeignKey
|
||||
*
|
||||
* Any other destructive changes will result in an error when trying to
|
||||
* rollback the migration.
|
||||
*
|
||||
* Remember to call "create()" or "update()" and NOT "save()" when working
|
||||
* with the Table class.
|
||||
*/
|
||||
public function change()
|
||||
{
|
||||
$table = $this->table('phone');
|
||||
$table->changeColumn('status', 'enum', ['values' => ['available', 'unavailable', 'no_credit', 'limit_reached'], 'default' => 'available']);
|
||||
$table->save();
|
||||
}
|
||||
}
|
|
@ -17,7 +17,6 @@ namespace models;
|
|||
const STATUS_AVAILABLE = 'available';
|
||||
const STATUS_UNAVAILABLE = 'unavailable';
|
||||
const STATUS_NO_CREDIT = 'no_credit';
|
||||
const STATUS_LIMIT_REACHED = 'limit_reached';
|
||||
|
||||
/**
|
||||
* Return all phones that belongs to active users
|
||||
|
|
|
@ -112,10 +112,6 @@ jQuery(document).ready(function ()
|
|||
case 'no_credit':
|
||||
html += ' - <span class="text-warning">Plus de crédit</span>'
|
||||
break;
|
||||
|
||||
case 'limit_reached':
|
||||
html += ' - <span class="text-warning">Limite RaspiSMS atteinte</span>'
|
||||
break;
|
||||
}
|
||||
|
||||
return html
|
||||
|
|
Loading…
Reference in New Issue