diff --git a/controllers/internals/User.php b/controllers/internals/User.php index 5f622b0..afbe264 100755 --- a/controllers/internals/User.php +++ b/controllers/internals/User.php @@ -140,6 +140,17 @@ namespace controllers\internals; } + /** + * Find a user by his id + * @param string $id : User id + * @return mixed array + */ + public function get ($id) + { + return $this->model_user->get($id); + } + + /** * Get a user by his api_key address * @param string $api_key : User api key diff --git a/daemons/Phone.php b/daemons/Phone.php index 366a9cd..b6a3122 100644 --- a/daemons/Phone.php +++ b/daemons/Phone.php @@ -140,7 +140,6 @@ class Phone extends AbstractDaemon //Get users settings $user_settings = $internal_setting->gets_for_user($this->phone['id_user']); - //Process smss foreach ($smss as $sms) { @@ -152,6 +151,8 @@ class Phone extends AbstractDaemon $this->process_for_webhook($sms, 'receive_sms', $user_settings); + $this->process_for_transfer($sms, $user_settings); + $internal_received->create($sms['at'], $sms['text'], $sms['origin'], $sms['destination'], 'unread', $is_command); } } @@ -216,6 +217,32 @@ class Phone extends AbstractDaemon } } } + + + /** + * Process a sms to transfer it by mail + * @param array $sms : The sms + * @param array $user_settings : Use settings + */ + private function process_for_transfer (array $sms, array $user_settings) + { + if (!$user_settings['transfer']) + { + return false; + } + + $internal_user = new \controllers\internals\User($this->bdd); + $user = $internal_user->get($this->phone['id_user']); + + if (!$user) + { + return false; + } + + $this->logger->info('Transfer sms to ' . $user['email'] . ' : ' . json_encode($sms)); + + \controllers\internals\Tool::send_email($user['email'], EMAIL_TRANSFER_SMS, ['sms' => $sms]); + } public function on_start() diff --git a/models/User.php b/models/User.php index 7ffb08b..44d8499 100755 --- a/models/User.php +++ b/models/User.php @@ -16,6 +16,17 @@ namespace models; */ class User extends \descartes\Model { + /** + * Find a user by his id + * @param string $id : User id + * @return mixed array + */ + public function get ($id) + { + return $this->_select_one('user', ['id' => $id]); + } + + /** * Find a user using his email * @param string $email : User email diff --git a/templates/email/transfer-sms.php b/templates/email/transfer-sms.php new file mode 100755 index 0000000..7f338a5 --- /dev/null +++ b/templates/email/transfer-sms.php @@ -0,0 +1,5 @@ +Vous avez reçu un nouveau SMS : +Date : +Origine : +Destination : +Message :