public function saveToDB() { if ($this->getHeaderField("TRX_NO")) { //this is a request from provider! //save a new row in Requests DB $tbl = new Application_Model_DbTable_Requests(Np_Db::master()); $data = array('status' => 1, 'request_id' => $this->getHeaderField("REQUEST_ID"), 'phone_number' => $this->getBodyField("NUMBER"), 'from_provider' => $this->getHeaderField("TO"), 'to_provider' => $this->getHeaderField("FROM"), 'last_transaction' => $this->getHeaderField("MSG_TYPE")); return $tbl->insert($data); } //else //this request is from cron! internal is sending to all providers //don't save in Requests DB }
/** * overridden function from parent Np_Method * * inserts row to requests table * * @return bool */ public function saveToDB() { //INSERT into Requests if ($this->getHeaderField("TO") == Application_Model_General::getSettings('InternalProvider')) { // if the check received from external provider create request // request id already exists //else - it's from internal - already INSERT into Requests $data = array('request_id' => $this->getHeaderField("REQUEST_ID"), 'from_provider' => $this->getHeaderField("FROM"), 'to_provider' => $this->getHeaderField("TO"), 'status' => 1, 'last_transaction' => $this->getHeaderField("MSG_TYPE"), 'phone_number' => $this->getBodyField("NUMBER")); $tbl = new Application_Model_DbTable_Requests(Np_Db::master()); return $tbl->insert($data); } }
/** * overridden from parent * * inserts row to database * * @return type */ public function saveToDB() { //this is a request from provider! //save a new row in Requests DB if ($this->getHeaderField("FROM") != Application_Model_General::getSettings('InternalProvider')) { try { $flags = new stdClass(); $flags->publish_type = $this->getBodyField("PUBLISH_TYPE"); $tbl = new Application_Model_DbTable_Requests(Np_Db::master()); $data = array('request_id' => $this->getHeaderField("REQUEST_ID"), 'from_provider' => $this->getHeaderField("TO"), 'to_provider' => $this->getHeaderField("FROM"), 'status' => 1, 'last_transaction' => $this->getHeaderField("MSG_TYPE"), 'phone_number' => $this->getBodyField("NUMBER"), 'disconnect_time' => Application_Model_General::getDateTimeInSqlFormat($this->getBodyField("DISCONNECT_TIME")), 'connect_time' => Application_Model_General::getDateTimeInSqlFormat($this->getBodyField("CONNECT_TIME")), 'transfer_time' => Application_Model_General::getDateTimeInSqlFormat(), 'flags' => json_encode($flags)); return $tbl->insert($data); } catch (Exception $e) { error_log("Error on create record in transactions table: " . $e->getMessage()); } } return TRUE; }
/** * method to create request row in the table including unique request id * save to request table request_id has to be consisten to id of the table * * @return mixed request_id string or FALSE */ protected function createRequestId() { $tbl = new Application_Model_DbTable_Requests(Np_Db::master()); $adapter = $tbl->getAdapter(); $adapter->beginTransaction(); try { // we create temp request id because it build from the mysql internal id $temp_request_id = Application_Model_General::createRandKey(21); if (strtoupper($this->params['MSG_TYPE']) != 'UP_SYSTEM' && strtoupper($this->params['MSG_TYPE']) != 'DOWN_SYSTEM') { $row_insert = array('request_id' => $temp_request_id, 'status' => 1, 'last_transaction' => $this->params["MSG_TYPE"], 'phone_number' => $this->params["PHONE_NUMBER"]); if (isset($this->params['MSG_TYPE']) == 'CHECK') { // && isset($this->params['IDENTIFICATION_VALUE'])) { $flags = array(); if (isset($this->params['identification_value'])) { $this->params['identification_value'] = $this->params['IDENTIFICATION_VALUE']; } if (isset($this->params['NUMBER_TYPE'])) { $flags['number_type'] = $this->params['NUMBER_TYPE']; } if (!empty($flags)) { $row_insert['flags'] = json_encode($flags); } } } else { $row_insert = array('request_id' => $temp_request_id, 'status' => 1, 'last_transaction' => $this->params["MSG_TYPE"]); } // we set to from & to as the direction of number transfer if (strtoupper($this->params['MSG_TYPE']) != 'RETURN_NUMBER') { $row_insert['from_provider'] = $this->params["TO_PROVIDER"]; $row_insert['to_provider'] = $this->params["FROM_PROVIDER"]; } else { $row_insert['from_provider'] = $this->params["FROM_PROVIDER"]; $row_insert['to_provider'] = $this->params["TO_PROVIDER"]; } if (isset($this->params["AUTO_CHECK"]) && $this->params["AUTO_CHECK"]) { $row_insert['auto_check'] = 1; // $row_insert['transfer_time'] = Application_Model_General::getDateTimeInSqlFormat($this->params['PORT_TIME']); } $_id = $tbl->insert($row_insert); $id = substr("0000" . $_id, -5, 5); $request_id = "NP" . $this->params['FROM_PROVIDER'] . $this->params['TO_PROVIDER'] . date("ymd") . $id . "0001"; //ZZZZ $tbl->update(array('request_id' => $request_id), "id = " . $_id); $adapter->commit(); return $request_id; } catch (Exception $e) { error_log("Cannot create request ID. Reason: " . $e->getMessage()); $adapter->rollBack(); } return FALSE; }
/** * overridden function from parent Np_Method * * inserts row to requests table * * @return bool */ public function saveToDB() { if ($this->ValidateDB() === FALSE) { return FALSE; } if ($this->getHeaderField("FROM") != Application_Model_General::getSettings('InternalProvider')) { // if the check received from external provider create request // request id already exists //else - it's from internal - already INSERT into Requests try { $data = array('request_id' => $this->getHeaderField("REQUEST_ID"), 'from_provider' => $this->getHeaderField("TO"), 'to_provider' => $this->getHeaderField("FROM"), 'status' => 1, 'last_transaction' => $this->getHeaderField("MSG_TYPE"), 'phone_number' => $this->getBodyField("NUMBER")); $tbl = new Application_Model_DbTable_Requests(Np_Db::master()); return $tbl->insert($data); } catch (Exception $e) { error_log("Error on create record in transactions table: " . $e->getMessage()); } } }