/** * overridden function from parent Np_Method * checks if db row exists * * @return bool */ protected function ValidateDB() { $tbl = new Application_Model_DbTable_Requests(Np_Db::slave()); $select = $tbl->select()->where('request_id =?', $this->getHeaderField("REQUEST_ID")); $result = $select->query()->fetchObject(); if ($result) { return false; //if there is already request with this request_id. } return true; }
public function getRequestIdByNumber($number) { $tbl = new Application_Model_DbTable_Requests(Np_Db::slave()); $select = $tbl->select(); $select->where('number =?', $number)->order('id DESC'); $result = $select->query()->fetchObject(); //take the last one if ($result) { return $result->request_id; } return FALSE; }
/** * gets row from requests table by request id * * @param type $reqId the request id * @return object DB RESPONSE */ public function getRequestByID($reqId) { $tbl = new Application_Model_DbTable_Requests(Np_Db::slave()); $select = $tbl->select(); $select->where('request_id = ?', (string) $reqId)->order('id DESC'); $result = $select->query()->fetch(); return $result; }
/** * creates object from requests table row by REQUEST_ID if response returns * requestValidateDB validation else FALSE * * @return bool */ protected function ValidateDB() { $tbl = new Application_Model_DbTable_Requests(Np_Db::slave()); $select = $tbl->select()->where('request_id =?', $this->getHeaderField("REQUEST_ID"))->order('id DESC'); $result = $select->query()->fetchObject(); if ($result !== FALSE) { // set the variables used in timers $msg_type = strtoupper($this->getHeaderField('MSG_TYPE')); if ($msg_type == 'UPDATE_RESPONSE' || $msg_type == "CANCEL_RESPONSE" || $msg_type == 'UPDATE') { if ($msg_type != 'UPDATE') { $select = Np_Db::slave()->select()->from('Transactions')->where('request_id =?', $this->getHeaderField("REQUEST_ID"))->order('id DESC'); } else { $select = Np_Db::slave()->select()->from('Transactions')->where('request_id =?', $this->getHeaderField("REQUEST_ID"))->where('message_type =?', "Request")->order('id DESC'); } $last_transaction = $select->query()->fetchObject(); $this->last_method = $last_transaction->message_type; $this->last_method_time = $last_transaction->last_transaction_time; } else { $this->last_method = $result->last_transaction; $this->last_method_time = $result->last_request_time; } $this->last_transfer_time = $result->transfer_time; return $this->RequestValidateDB($result); } return false; }
/** * * @return String transfer date of autocheck if it's autocheck else false */ protected function isAutoCheck() { $tbl = new Application_Model_DbTable_Requests(Np_Db::slave()); $select = $tbl->select()->where('request_id=?', $this->params['REQUEST_ID'])->order('id DESC'); $result = $select->query()->fetchObject(); if ($result && $result->auto_check) { return Application_Model_General::getDateTimeInTimeStamp($result->transfer_time); } return false; }
/** * check if we sent check already * * @param long $phone_number phone number to check * * @return true if we sent already check */ public static function previousCheck($phone_number) { $tbl = new Application_Model_DbTable_Requests(Np_Db::slave()); $select = $tbl->select()->where('phone_number=?', $phone_number)->where('status=?', "1")->order('id DESC'); $result = $select->query()->fetch(); if (!empty($result) && $result !== FALSE) { return false; } return true; }