/** * 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; }
/** * method to get requests by field * @param type $by */ public static function getRequests($filterValue, $filterBy = 'request_id', $fields = array(), $where = array(), $orderBy = 'id DESC', $limit = 1) { $tbl = new Application_Model_DbTable_Requests(Np_Db::slave()); $select = $tbl->select()->from($tbl->info(Zend_Db_Table_Abstract::NAME), $fields); $select->where($tbl->getAdapter()->quoteIdentifier($filterBy) . ' = ?', $filterValue)->order($orderBy)->limit(intval($limit)); foreach ($where as $cond => $value) { $select->where($cond, $value); } // print($select); return $select->query()->fetchAll(); }