public function sendsmsAction() { $model = new WsServiceImport(); $messageModel = new WsServiceImportMessage(); $importToSend = $model->getImportToSend(); $servicesModel = new WsServiceSms(); $cfg = Zend_Registry::get('config'); while ($current = $importToSend->current()) { $services = Zend_Json::decode($current->services); $service = $servicesModel->getService($services[0]); $config = array('throwExceptions' => true, 'clientHash' => $cfg['services']['mrdebug']['hash'], 'serviceHash' => $service->service_hash); $http = new Zend_Controller_Request_Http(); $host = 'http://' . $http->getServer('HTTP_HOST') . '/ws/'; $config['wsdl'] = $host . 'sms/?wsdl'; $sms = new SmsSoapClient($config); if (!$model->checkStatus($current->id)) { $importToSend->next(); $current = $importToSend->current(); } if ($importToSend->valid()) { switch ($current->file_type) { case 1: $sms->registerNumber($current->phone_number)->registerContent($current->sms_text); $response = $sms->send(); break; case 2: $tags = Zend_Json::decode($current->tags); $msg = $current->sms_text; if (!empty($tags)) { foreach ($tags as $key => $tag) { $msg = preg_replace("/<" . $key . ">/", $tag, $msg); } } $sms->registerNumber($current->phone_number)->registerContent($msg); $response = $sms->send(); break; case 3: $sms->registerNumber($current->phone_number)->registerContent($current->sms_text); $response = $sms->send(); break; } if (isset($response->errorCode)) { $messageModel->changeStatus($current->msg_id, $response->errorCode, Zend_Json::encode($response->smsId)); } else { $messageModel->changeStatus($current->msg_id, $response->faultcode, NULL, $response->faultstring); } $importToSend->next(); } } }
public function import($file, $post) { $config = Zend_Registry::get('config'); $wsServiceImportModel = new WsServiceImport(); $wsServiceImportMessageModel = new WsServiceImportMessage(); $identity = Zend_Auth::getInstance()->getIdentity(); // dodanie informacji o imporcie $importInfo = array('ws_service_set_id' => $post['ws_service_set_id'], 'file_type' => $post['file_type'], 'created_by' => $identity->id); $importID = $wsServiceImportModel->insert($importInfo); //pobranie danych z csv $path = $config['uploads']['destination']; $data = array(); if ($fp = fopen($path . $file, 'r')) { $i = 0; while (!feof($fp)) { $row = fgetcsv($fp, filesize($path . $file), ';'); $data[$i] = $row; $i++; } fclose($fp); } //przygotowanie danych $headers = $data[0]; unset($data[0]); foreach ($data as $val) { if ($val) { $insertArray = array('ws_import_set_id' => $importID, 'phone_number' => $val[0]); switch ($post['file_type']) { case Logic_Ws_ServiceSet_ServiceSet::TYPE_CONST: break; case Logic_Ws_ServiceSet_ServiceSet::TYPE_VAR: $valTmp = $val; unset($headers[0]); unset($valTmp[0]); $tagsArray = array_combine($headers, $valTmp); if (empty($tagsArray)) { throw new Exception('Tags not found!'); } $insertArray = array_merge($insertArray, array('tags' => Zend_Json::encode($tagsArray))); break; case Logic_Ws_ServiceSet_ServiceSet::TYPE_ANY: $insertArray = array_merge($insertArray, array('message' => $val[1])); break; } //insert do bazy $wsServiceImportMessageModel->insert($insertArray); } } }