/** * @param array $data * @throws Exception */ protected function setStatus($data) { if (!$this->isValidRequest('table')) { throw new Exception('Not valid request'); } $session = new SessionNamespace($this->resource); if (empty($data['rec_id'])) { throw new Exception('Record id empty'); } elseif (!is_string($data['rec_id']) && !is_numeric($data['rec_id'])) { throw new Exception('Record id not valid'); } elseif (empty($data['new_value']) || !is_string($data['new_value']) && !is_int($data['new_value'])) { throw new Exception('Switched value not valid'); } elseif (empty($session->access) || empty($session->access->change_status_field)) { throw new Exception('Switched field empty'); } if (isset($session->db) && !empty($session->db->table)) { $table = $session->db->table; } else { throw new Exception('Table not found'); } $primary_key = !empty($session->db->primary_id) ? $session->db->primary_id : 'id'; $primary_key = $this->db->quoteIdentifier($primary_key); $where = $this->db->quoteInto("{$primary_key} = ?", $data['rec_id']); $is_update = $this->db->update($table, array($session->access->change_status_field => $data['new_value']), $where); if (!$is_update) { throw new Exception('Error update data'); } }