/**
  * Returns an singleton instance of this class
  *
  * @param object $config
  * @param object $args
  * @return
  */
 public static function getInstance($config, $args)
 {
     if (self::$instance == null) {
         self::$instance = new SmsGatewaysManager($config, $args);
     }
     return self::$instance;
 }
Example #2
0
 public function load()
 {
     $smsGatewaysManager = SmsGatewaysManager::getInstance($this->config, $this->args);
     $allSmsGateways = $smsGatewaysManager->selectAll();
     $smsGatewaysNamesArray = array();
     foreach ($allSmsGateways as $allSmsGateway) {
         $smsGatewaysNamesArray[$allSmsGateway->getId()] = $allSmsGateway->getName();
     }
     $defaultSmsGateway = $this->getCmsVar('sms_gateway_name');
     $this->addParam('defaultSmsGateway', $defaultSmsGateway);
     $this->addParam('smsGatewaysNames', $smsGatewaysNamesArray);
 }
Example #3
0
 public function service()
 {
     $sentSmsManager = SentSmsManager::getInstance($this->config, $this->args);
     $smsGatewaysManager = SmsGatewaysManager::getInstance($this->config, $this->args);
     $phoneNumber = $this->secure($_REQUEST['phone_number']);
     $gatewayId = $this->secure($_REQUEST['gateway']);
     $gateway = $smsGatewaysManager->selectByPK($gatewayId);
     if (!isset($gateway)) {
         $this->error(array('message' => 'Wrong gateway!'));
     }
     $message = $_REQUEST['message'];
     if (empty($message)) {
         $this->error(array('message' => 'Message can not be empty!'));
     }
     $validNumber = SentSmsManager::getValidArmenianNumber($phoneNumber);
     if (!isset($validNumber)) {
         $this->error(array('message' => 'Invalid phone number!'));
     }
     $sentSmsManager->sendSmsToArmenia($phoneNumber, $message, $gateway->getName());
     $this->ok();
 }
 /**
  * @param $toPhoneNumbers can be array or only one number
  */
 public function sendSmsToArmenia($toPhoneNumbers, $message, $sms_gateway_name = null)
 {
     if (!is_array($toPhoneNumbers)) {
         $toPhoneNumbers = array($toPhoneNumbers);
     }
     $smsGatewaysManager = SmsGatewaysManager::getInstance($this->config, $this->args);
     if (!isset($sms_gateway_name)) {
         $sms_gateway_name = $from = $this->getCmsVar('sms_gateway_name');
     }
     $smsGatewayDto = $smsGatewaysManager->getByName($sms_gateway_name);
     if (!isset($smsGatewayDto)) {
         return false;
     }
     $from = $this->getCmsVar('sms_from_phone_number');
     foreach ($toPhoneNumbers as $key => $pn) {
         $vpn = self::getValidArmenianNumber($pn, $smsGatewayDto->getInternationalCodePrefix());
         if ($vpn != null) {
             $httpSmsUrl = $smsGatewayDto->getHttpSmsUrl();
             $settingsMetadataJson = $smsGatewayDto->getSettingsMetadata();
             $settingsMetadata = json_decode($settingsMetadataJson, true);
             foreach ($settingsMetadata as $key => $value) {
                 $httpSmsUrl = str_replace('{' . trim($key) . '}', $value, $httpSmsUrl);
             }
             $httpSmsUrl = str_replace('{to}', $vpn, $httpSmsUrl);
             $httpSmsUrl = str_replace('{from}', urlencode($from), $httpSmsUrl);
             $httpSmsUrl = str_replace('{message}', urlencode($message), $httpSmsUrl);
             if ($this->getCmsVar('enable_sms') == 1) {
                 file_get_contents($httpSmsUrl);
             }
             $dto = $this->mapper->createDto();
             $dto->setTo($vpn);
             $dto->setFrom($from);
             $dto->setMessage($message);
             $this->mapper->insertDto($dto);
         }
     }
     return $message;
 }