/**
  * Método que insere um teste por capítulo no banco de dados.
  *
  * @param TesteTopico $teste O teste a ser inserido
  *
  * @return bool|int O código do teste inserido ou FALSE em caso de erro
  *
  * @throws TesteException
  */
 public function insert(Model $teste)
 {
     if (!count($teste->getQuestoes())) {
         throw new TesteException('Não foram encontradas questões para ' . 'o teste');
     }
     if ($teste instanceof TesteCapitulo) {
         $fk = "pk_capitulo";
     } else {
         $fk = "pk_conteudo";
     }
     $tIsert = $this->tg->insert(array("{$this->tabela}_pk_usuario" => $teste->getAluno()->getId(), "{$this->tabela}_{$fk}" => $teste->getAlvo()->getId(), "{$this->tabela}_ano" => $teste->getAno()));
     if (!$tIsert) {
         throw new TesteException('Não foi possível salvar o teste. ' . 'Tente novamente mais tarde');
     }
     $lastId = $this->tg->lastInsertId();
     //Salvando as questões do teste
     $query = "insert into testes.{$this->tabela}_questao(" . "{$this->tabela}_questao_pk_{$this->tabela}, " . "{$this->tabela}_questao_pk_questao" . ') values ';
     foreach ($teste->getQuestoes() as $questao) {
         $query .= "({$lastId}, {$questao->getId()}),";
     }
     $query = substr($query, 0, -1);
     $prepare = $this->tg->getPDO()->prepare($query);
     if (!$prepare->execute()) {
         $this->tg->getPDO()->rollBack();
         throw new TesteException('Não foi possível salvar o teste');
     }
     return $lastId;
 }