Created
March 23, 2016 16:21
-
-
Save danilodorgam/d8ae3b534d0bdedb871d to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
defined('BASEPATH') OR exit('No direct script access allowed'); | |
class Api extends CI_Controller{ | |
//Função uasada para receber a prova finalizada e salvar no banco de dados | |
public function set_prova(){ | |
$this->load->model('apiModel'); | |
$post_date = file_get_contents("php://input"); | |
$data = json_decode($post_date); | |
//$this->apiModel->getIdBySlug($data->id); pega o ID da prova | |
//inserir dados no metadado | |
$this->apiModel->insert_metadado((int)$this->session->userdata("usuario")['id'], $data->nota,$data->acerto,$data->erro,(int)$this->apiModel->getIdBySlug($data->id)); | |
//pega o ID do meta dado e usar para inserir as perguntas/respostas no banco de dados | |
} | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
defined('BASEPATH') OR exit('No direct script access allowed'); | |
class ApiModel extends CI_Model{ | |
//insere o meta dado e retorna o ID | |
public function insert_metadado($usuario, $nota,$acerto,$erro,$tipo){ | |
$data = array( | |
'usuario' => (int)$usuario, | |
'slug' => (int)$nota, | |
'acerto' => (int)$acerto, | |
'erro' => (int)$erro, | |
'tipo' => (int)$tipo | |
); | |
var_dump($data); | |
$this->db->insert('simulado_metadado', $data); | |
//return $this->db->insert_id(); | |
} | |
//função para receber uma slug de configuração de prova e voltar o ID | |
public function getIdBySlug($slug){ | |
$this->db->from('prova_configuracao'); | |
$this->db->select('id'); | |
$this->db->where('slug =', $slug); | |
$query = $this->db->get(); | |
return $query->result_array()[0]['id']; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment