diff --git a/plugins/tps/birzha/actions/SendSMSAction.php b/plugins/tps/birzha/actions/SendSMSAction.php index e64aaaf9b..eb4ef415f 100644 --- a/plugins/tps/birzha/actions/SendSMSAction.php +++ b/plugins/tps/birzha/actions/SendSMSAction.php @@ -5,12 +5,13 @@ namespace TPS\Birzha\Actions; use Backend\Models\UserGroup as AdminGroupModel; use Illuminate\Support\Facades\Log; use RainLab\Notify\Classes\ActionBase; +use TPS\Birzha\Classes\SMS; class SendSMSAction extends ActionBase { public $recipientModes = [ 'user' => 'User phone number (if applicable)', - 'admin' => 'Back-end administrators phones', +// 'admin' => 'Back-end administrators phones', 'custom' => 'Specific phone number', ]; @@ -33,6 +34,9 @@ class SendSMSAction extends ActionBase { return [ 'send_to_mode' => 'required', + 'send_to_custom' => 'required_if:send_to_mode,custom', +// 'send_to_admin' => 'required_if:send_to_mode,admin', + 'message' => 'required' ]; } /** @@ -50,14 +54,14 @@ class SendSMSAction extends ActionBase return $modes; } - public function getSendToAdminOptions() - { - $options = ['' => '- All administrators -']; - - $groups = AdminGroupModel::lists('name', 'id'); - - return $options + $groups; - } +// public function getSendToAdminOptions() +// { +// $options = ['' => '- All administrators -']; +// +// $groups = AdminGroupModel::lists('name', 'id'); +// +// return $options + $groups; +// } public function getTitle() { @@ -66,43 +70,7 @@ class SendSMSAction extends ActionBase } return 'Send sms to customers'; } - public function getText() - { - $hostObj = $this->host; - $recipient = array_get($this->recipientModes, $hostObj->send_to_mode); - - if ($this->isAdminMode()) { - if ($groupId = $this->host->send_to_admin) { - if ($group = AdminGroupModel::find($groupId)) { - $adminText = $group->name; - } - else { - $adminText = '?'; - } - - $adminText .= ' admin group'; - } - else { - $adminText = 'all admins'; - } - return sprintf( - 'Send a sms to %s', - $adminText, - $hostObj->mail_template - ); - } - - if ($hostObj->mail_template) { - return sprintf( - 'Send smd to %s', - mb_strtolower($recipient), - $hostObj->mail_template - ); - } - - return parent::getText(); - } public function getActionIcon() { return 'icon-envelope-square'; @@ -115,10 +83,20 @@ class SendSMSAction extends ActionBase */ public function triggerAction($params) { - Log::info(json_encode($params)); - } - protected function isAdminMode() - { - return $this->host->send_to_mode == 'admin'; + + if($this->host->send_to_mode == 'user' && $params['user']){ + $to = $params['user']['username']; + + }else{ + $to = $this->host->send_to_custom; + } + + SMS::send($to,$this->host->message); + +// Log::info(json_encode($params)); } +// protected function isAdminMode() +// { +// return $this->host->send_to_mode == 'admin'; +// } } diff --git a/plugins/tps/birzha/actions/VerifyAction.php b/plugins/tps/birzha/actions/VerifyAction.php index 7dc4bdebc..b63684960 100644 --- a/plugins/tps/birzha/actions/VerifyAction.php +++ b/plugins/tps/birzha/actions/VerifyAction.php @@ -93,7 +93,7 @@ class VerifyAction extends ActionBase } private function sendSMS($phone,$code){ - $message = "tmex.gov.tm verification code: {$code}"; + $message = "tmex.gov.tm%20verification%20code:%20{$code}"; SMS::send($phone,$message); } diff --git a/plugins/tps/birzha/actions/sendsmsaction/fields.yaml b/plugins/tps/birzha/actions/sendsmsaction/fields.yaml index 18e7f3918..6c4551dce 100644 --- a/plugins/tps/birzha/actions/sendsmsaction/fields.yaml +++ b/plugins/tps/birzha/actions/sendsmsaction/fields.yaml @@ -19,13 +19,16 @@ fields: action: show field: send_to_mode condition: value[custom] +# +# send_to_admin: +# label: Send to admin group +# span: right +# type: dropdown +# trigger: +# action: show +# field: send_to_mode +# condition: value[admin] - send_to_admin: - label: Send to admin group - span: right - type: dropdown - trigger: - action: show - field: send_to_mode - condition: value[admin] - + message: + cssClass: radio-align + label: Message diff --git a/plugins/tps/birzha/classes/SMS.php b/plugins/tps/birzha/classes/SMS.php index eeae4fa32..81748d213 100644 --- a/plugins/tps/birzha/classes/SMS.php +++ b/plugins/tps/birzha/classes/SMS.php @@ -9,10 +9,9 @@ use October\Rain\Support\Facades\Http; class SMS { public static function send($to, $content){ - $url = env('SMS_API')."+99363432211/{$content}"; + $url = urlencode(env('SMS_API')."$to/{$content}"); try { $response = Http::get($url); - Log::info($response); } catch (Exception $exception){ Log::error($exception); diff --git a/plugins/tps/birzha/events/MessageReceivedEvent.php b/plugins/tps/birzha/events/MessageReceivedEvent.php index 380e9c813..0e4c151ee 100644 --- a/plugins/tps/birzha/events/MessageReceivedEvent.php +++ b/plugins/tps/birzha/events/MessageReceivedEvent.php @@ -21,23 +21,23 @@ class MessageReceivedEvent extends \RainLab\Notify\Classes\EventBase /** * Defines the usable parameters provided by this class. */ - public function defineParams() - { - return [ - 'name' => [ - 'title' => 'Name', - 'label' => 'Name of the user', - ], - // ... - ]; - } +// public function defineParams() +// { +// return [ +// 'name' => [ +// 'title' => 'Name', +// 'label' => 'Name of the user', +// ], +// // ... +// ]; +// } public static function makeParamsFromEvent(array $args, $eventName = null) { return [ 'user' => array_get($args, 0), - 'message' => array_get($args, 1) + 'message' => array_get($args, 1), ]; } } diff --git a/plugins/tps/birzha/events/PaymentReviewedEvent.php b/plugins/tps/birzha/events/PaymentReviewedEvent.php index 477383efd..6551e1bed 100644 --- a/plugins/tps/birzha/events/PaymentReviewedEvent.php +++ b/plugins/tps/birzha/events/PaymentReviewedEvent.php @@ -23,7 +23,6 @@ class PaymentReviewedEvent extends EventBase return [ 'payment' => array_get($args, 0), 'user' => array_get($args, 1), - 'message' => 'sizin balansynyz doldurldy' ]; }