protected function getEtapas()
 {
     if (!isset($this->_etapas)) {
         $this->_etapas = range(1, $this->_service->getOption('etapas'), 1);
     }
     return $this->_etapas;
 }
 /**
  * @see Core_Controller_Page_EditController#_save()
  */
 protected function _save()
 {
     // Instancia o objeto correto e passa para o service
     if ($this->_regra->get('parecerDescritivo') == RegraAvaliacao_Model_TipoParecerDescritivo::ANUAL_COMPONENTE) {
         $parecer = new Avaliacao_Model_ParecerDescritivoComponente(array('componenteCurricular' => $this->getRequest()->componenteCurricular, 'parecer' => $this->getRequest()->parecer, 'etapa' => $this->getRequest()->etapa));
     } else {
         $parecer = new Avaliacao_Model_ParecerDescritivoGeral(array('parecer' => $this->getRequest()->parecer, 'etapa' => $this->getRequest()->etapa));
     }
     $this->_service->addParecer($parecer);
     try {
         $this->_service->save();
     } catch (CoreExt_Service_Exception $e) {
         // Ok. Não pode promover por se tratar de progressão manual ou por estar em andamento
     } catch (Exception $e) {
         $this->mensagem = 'Erro no preenchimento do formulário. ';
         return FALSE;
     }
     return TRUE;
 }
 /**
  * @see Core_Controller_Page_EditController#_save()
  */
 protected function _save()
 {
     $nota = new Avaliacao_Model_NotaComponente(array('componenteCurricular' => $this->getRequest()->componenteCurricular, 'nota' => urldecode($this->getRequest()->nota), 'etapa' => $this->getRequest()->etapa));
     $this->_service->addNota($nota);
     if ($this->_regra->get('tipoPresenca') == RegraAvaliacao_Model_TipoPresenca::POR_COMPONENTE) {
         $quantidade = 0 < $this->getRequest()->falta ? (int) $this->getRequest()->falta : 0;
         $falta = new Avaliacao_Model_FaltaComponente(array('componenteCurricular' => $this->getRequest()->componenteCurricular, 'quantidade' => $quantidade, 'etapa' => $this->getRequest()->etapa));
         $this->_service->addFalta($falta);
     }
     if (trim($this->getRequest()->parecer) != '' && $this->_regra->get('parecerDescritivo') == RegraAvaliacao_Model_TipoParecerDescritivo::ETAPA_COMPONENTE) {
         $parecer = new Avaliacao_Model_ParecerDescritivoComponente(array('componenteCurricular' => $this->getRequest()->componenteCurricular, 'parecer' => $this->getRequest()->parecer, 'etapa' => $this->getRequest()->etapa));
         $this->_service->addParecer($parecer);
     }
     try {
         $this->_service->save();
     } catch (CoreExt_Service_Exception $e) {
         // Ok. Não pode promover por se tratar de progressão manual ou por estar em andamento
     } catch (Exception $e) {
         $this->mensagem = 'Erro no preenchimento do formulário. ';
         return FALSE;
     }
     return TRUE;
 }
 protected function _notasFaltasComponentes(Avaliacao_Service_Boletim $boletim)
 {
     $etapas = $boletim->getOption('etapas');
     $notas = $boletim->getNotasComponentes();
     if ($faltaPorComponente = $boletim->getRegra()->get('tipoPresenca') == RegraAvaliacao_Model_TipoPresenca::POR_COMPONENTE) {
         $faltas = $boletim->getFaltasComponentes();
     } else {
         $faltas = $boletim->getFaltasGerais();
     }
     $componentes = $boletim->getComponentes();
     $medias = $boletim->getMediasComponentes();
     $situacao = $boletim->getSituacaoAluno();
     $etapas = range(0, $etapas - 1);
     $altura_linha = 15;
     // Calcula o espaço disponível para as notas e faltas
     $extraColumns = 2 + ($situacao->recuperacao == TRUE ? 1 : 0);
     $total = 782 - (80 + 60 * $extraColumns + 120);
     $this->pdf->quadrado_relativo(30, $this->page_y, 782, $altura_linha, 0.5);
     $this->pdf->escreve_relativo_center('Módulos', 30, $this->page_y + 2, 80, 13);
     $this->pdf->linha_relativa(30, $this->page_y, 0, $altura_linha, 0.1);
     $this->pdf->linha_relativa(80 + 30, $this->page_y, 0, $altura_linha, 0.1);
     $matriculaSituacao = App_Model_MatriculaSituacao::getInstance();
     // Escreve as etapas
     $x = 80 + 30;
     $largura = $total / count($etapas);
     if ($faltaPorComponente) {
         $larguraDv = $largura / 2;
     } else {
         $larguraDv = $largura;
     }
     foreach ($etapas as $etapa) {
         $this->pdf->escreve_relativo_center($etapa + 1, $x, $this->page_y + 2, $largura, 13);
         $x += $largura;
         $this->pdf->linha_relativa($x, $this->page_y, 0, $altura_linha, 0.1);
     }
     // Escreve os campos para Média final, Falta e Situação
     $labels = array();
     $labels[] = 'Média final';
     if ($situacao->recuperacao) {
         $labels[] = 'Exame';
     }
     $labels[] = '% Presença';
     $labels[] = 'Situação';
     foreach ($labels as $label) {
         $largura = $label == 'Situação' ? 120 : 60;
         $this->pdf->escreve_relativo_center($label, $x, $this->page_y + 2, $largura, 13);
         $x += $largura;
         $this->pdf->linha_relativa($x, $this->page_y, 0, $altura_linha, 0.1);
     }
     // Escreve os rótulos para notas e faltas
     $x = 80 + 30;
     // Nova linha
     $this->page_y += 15;
     $this->pdf->quadrado_relativo(30, $this->page_y, 782, $altura_linha, 0.5);
     $this->pdf->escreve_relativo_center('Componentes', 30, $this->page_y + 2, 80, 13);
     $this->pdf->linha_relativa(30, $this->page_y, 0, $altura_linha, 0.1);
     $this->pdf->linha_relativa(110, $this->page_y, 0, $altura_linha, 0.1);
     foreach ($etapas as $etapa) {
         $this->pdf->escreve_relativo_center('Nota', $x, $this->page_y + 2, $larguraDv, 13);
         $x += $larguraDv;
         $this->pdf->linha_relativa($x, $this->page_y, 0, $altura_linha, 0.1);
         if ($faltaPorComponente) {
             $this->pdf->escreve_relativo_center('Falta', $x, $this->page_y + 2, $larguraDv, 13);
             $x += $larguraDv;
             $this->pdf->linha_relativa($x, $this->page_y, 0, $altura_linha, 0.1);
         }
     }
     for ($i = 0; $i < 3; $i++) {
         $x += 60;
         $this->pdf->linha_relativa($x, $this->page_y, 0, $altura_linha, 0.1);
     }
     $yNotas = $this->page_y;
     // Imprime as notas dos componentes
     foreach ($componentes as $id => $componente) {
         $this->page_y += 15;
         $this->pdf->quadrado_relativo(30, $this->page_y, 782, $altura_linha, 0.5);
         $this->pdf->escreve_relativo_center($componente, 30, $this->page_y + 2, 80, 13);
         $this->pdf->linha_relativa(110, $this->page_y, 0, $altura_linha, 0.1);
         $x = 110;
         foreach ($etapas as $etapa) {
             if (!$this->em_branco) {
                 $this->pdf->escreve_relativo_center($notas[$id][$etapa]->notaArredondada, $x, $this->page_y + 2, $larguraDv, 13);
             }
             $x += $larguraDv;
             $this->pdf->linha_relativa($x, $this->page_y, 0, $altura_linha, 0.1);
             if ($faltaPorComponente) {
                 if (!$this->em_branco) {
                     $this->pdf->escreve_relativo_center($faltas[$id][$etapa]->quantidade, $x, $this->page_y + 2, $larguraDv, 13);
                 }
                 $x += $larguraDv;
                 $this->pdf->linha_relativa($x, $this->page_y, 0, $altura_linha, 0.1);
             }
         }
         if ($faltaPorComponente) {
             $porcentagemPresenca = sprintf('%.2f', $situacao->falta->componentesCurriculares[$id]->porcentagemPresenca);
         } else {
             $porcentagemPresenca = '-';
         }
         // Média, presenção e situação
         $data = array();
         $data['media'] = $medias[$id][0]->mediaArredondada;
         if ($situacao->recuperacao) {
             $notaExame = $notas[$id][$etapa + 1];
             $data['rc'] = $notaExame->etapa == 'Rc' ? $notaExame->notaArredondada : '-';
         }
         $data['presenca'] = $porcentagemPresenca;
         $data['situacao'] = $matriculaSituacao->getValue($situacao->nota->componentesCurriculares[$id]->situacao);
         foreach ($data as $key => $value) {
             $largura = $key == 'situacao' ? 120 : 60;
             if (!$this->em_branco) {
                 $this->pdf->escreve_relativo_center($value, $x, $this->page_y + 2, $largura, 13);
             }
             $x += $largura;
             $this->pdf->linha_relativa($x, $this->page_y, 0, $altura_linha, 0.1);
         }
     }
     // Imprime a porcentagem total de presença e a situação
     $this->page_y += 15;
     $this->pdf->quadrado_relativo(30, $this->page_y, 782, $altura_linha, 0.5);
     $this->pdf->escreve_relativo_center('Faltas', 30, $this->page_y + 2, 80, 13);
     $this->pdf->linha_relativa(110, $this->page_y, 0, $altura_linha, 0.1);
     if (!$faltaPorComponente) {
         $x = 80 + 30;
         foreach ($etapas as $etapa) {
             $this->pdf->escreve_relativo_center($faltas[$etapa + 1]->quantidade, $x, $this->page_y + 2, $larguraDv, 13);
             $x += $larguraDv;
             $this->pdf->linha_relativa($x, $this->page_y, 0, $altura_linha, 0.1);
         }
         $x = $x + 60 * ($situacao->recuperacao ? 2 : 1);
     } else {
         $x = $x - (120 + 60);
     }
     if (!$this->em_branco) {
         $this->pdf->escreve_relativo_center(sprintf('%.2f', $situacao->falta->porcentagemPresenca), $x, $this->page_y + 2, 60, 13);
         $this->pdf->escreve_relativo_center($matriculaSituacao->getValue($situacao->falta->situacao), $x + 60, $this->page_y + 2, 120, 13);
     }
     for ($i = 0; $i < 3; $i++) {
         $this->pdf->linha_relativa($x, $this->page_y, 0, $altura_linha, 0.1);
         $x += 60;
     }
 }
 function renderHTML()
 {
     if ($_POST) {
         foreach ($_POST as $key => $value) {
             $this->{$key} = $value;
         }
     }
     if ($this->ref_ref_cod_serie) {
         $this->ref_cod_serie = $this->ref_ref_cod_serie;
     }
     $fonte = 'arial';
     $corTexto = '#000000';
     if (empty($this->ref_cod_turma)) {
         echo '
      <script>
        alert("Erro ao gerar relatório!\\nNenhuma turma selecionada!");
        window.parent.fechaExpansivel(\'div_dinamico_\'+(window.parent.DOM_divs.length-1));
      </script>';
         return TRUE;
     }
     $obj_escola = new clsPmieducarEscola($this->ref_cod_escola);
     $det_escola = $obj_escola->detalhe();
     $this->nm_escola = $det_escola['nome'];
     $obj_instituicao = new clsPmieducarInstituicao($det_escola['ref_cod_instituicao']);
     $det_instituicao = $obj_instituicao->detalhe();
     $this->nm_instituicao = $det_instituicao['nm_instituicao'];
     $obj_turma = new clsPmieducarTurma($this->ref_cod_turma);
     $det_turma = $obj_turma->detalhe();
     $this->nm_turma = $det_turma['nm_turma'];
     $obj_serie = new clsPmieducarSerie($this->ref_cod_serie);
     $det_serie = $obj_serie->detalhe();
     $this->nm_serie = $det_serie['nm_serie'];
     $eh_multi_seriado = FALSE;
     if (is_numeric($det_turma['ref_ref_cod_serie_mult'])) {
         $series = array();
         $series[$det_serie['cod_serie']] = $det_serie['nm_serie'];
         $obj_serie = new clsPmieducarSerie($det_turma['ref_ref_cod_serie_mult']);
         $det_serie = $obj_serie->detalhe();
         $this->nm_serie .= ' / ' . $det_serie['nm_serie'];
         $series[$det_serie['cod_serie']] = $det_serie['nm_serie'];
         $eh_multi_seriado = TRUE;
     }
     $this->pdf = new clsPDF('Resultado Final', 'Resultado Final', 'A4', '', FALSE, FALSE);
     $this->pdf->OpenPage();
     $this->addCabecalho();
     $this->pdf->linha_relativa(30, 140, 540, 0);
     $this->pdf->linha_relativa(30, 140, 0, 30);
     $this->pdf->linha_relativa(570, 140, 0, 30);
     $this->pdf->linha_relativa(30, 170, 540, 0);
     $this->pdf->linha_relativa(60, 140, 0, 30);
     $this->pdf->linha_relativa(320, 140, 0, 30);
     $this->pdf->linha_relativa(380, 140, 0, 30);
     $this->pdf->linha_relativa(490, 140, 0, 30);
     $this->pdf->linha_relativa(380, 155, 190, 0);
     $this->pdf->linha_relativa(530, 155, 0, 15);
     $this->pdf->linha_relativa(450, 155, 0, 15);
     $this->pdf->escreve_relativo('Ord', 35, 150, 20, 20, NULL, 10);
     $this->pdf->escreve_relativo('Nome do aluno', 70, 150, 160, 20, NULL, 10);
     $this->pdf->escreve_relativo('Aprovado', 325, 150, 160, 20, NULL, 10);
     $this->pdf->escreve_relativo('Reprovado', 410, 142, 160, 20, NULL, 10);
     $this->pdf->escreve_relativo('Desempenho', 384, 156, 160, 20, NULL, 10);
     $this->pdf->escreve_relativo('Faltas', 455, 156, 160, 20, NULL, 10);
     $this->pdf->escreve_relativo('Alf.', 500, 156, 160, 20, NULL, 10);
     $this->pdf->escreve_relativo('N. Alf.', 535, 156, 160, 20, NULL, 10);
     $obj_matricula = new clsPmieducarMatriculaTurma();
     $obj_matricula->setOrderby('m.ref_ref_cod_serie, nome_ascii');
     if ($this->is_padrao) {
         $this->semestre = NULL;
     }
     $lst_matricula = $obj_matricula->lista(NULL, $this->ref_cod_turma, NULL, NULL, NULL, NULL, NULL, NULL, 1, $this->ref_cod_serie, $this->ref_cod_curso, $this->ref_cod_escola, $this->ref_cod_instituicao, NULL, NULL, array(1, 2, 3), NULL, NULL, $this->ano, NULL, TRUE, NULL, NULL, TRUE, NULL, NULL, NULL, $det_turma['ref_ref_cod_serie_mult'], $this->semestre);
     $qtd_quebra = 43;
     $base = 155;
     $linha = 1;
     $total_aprovados = 0;
     $total_reprovados_desempenho = 0;
     $total_reprovados_nota = 0;
     $total_analfabetos = 0;
     $total_nao_analfabetos = 0;
     $ordem_mostra = 0;
     if (is_array($lst_matricula)) {
         foreach ($lst_matricula as $ordem => $matricula) {
             $obj_matricula = new clsPmieducarMatricula($matricula['ref_cod_matricula']);
             $det_matricula = $obj_matricula->detalhe();
             // Verifica se o aluno está aprovado ou reprovado
             $situacoes = array(App_Model_MatriculaSituacao::APROVADO, App_Model_MatriculaSituacao::REPROVADO);
             if (in_array($det_matricula['aprovado'], $situacoes)) {
                 $ordem_mostra++;
                 $ordem_mostra = sprintf('%02d', $ordem_mostra);
                 if ($linha % $qtd_quebra == 0) {
                     //nova pagina
                     $this->pdf->ClosePage();
                     $this->pdf->OpenPage();
                     $base = 30;
                     $linha = 0;
                     $this->pdf->linha_relativa(30, 30, 540, 0);
                     $qtd_quebra = 51;
                 }
                 $this->pdf->linha_relativa(30, $base + $linha * 15, 0, 15);
                 $this->pdf->linha_relativa(60, $base + $linha * 15, 0, 15);
                 $this->pdf->linha_relativa(30, $base + 15 + $linha * 15, 540, 0);
                 $this->pdf->linha_relativa(570, $base + $linha * 15, 0, 15);
                 // fim
                 $this->pdf->escreve_relativo($ordem_mostra, 40, $base + 3 + $linha * 15, 15, 15, NULL, 8);
                 if ($eh_multi_seriado) {
                     $this->pdf->escreve_relativo($matricula['nome'] . ' (' . $series[$det_matricula['ref_ref_cod_serie']] . ')', 65, $base + 3 + $linha * 15, 250, 15, NULL, 8);
                 } else {
                     $this->pdf->escreve_relativo($matricula['nome'], 65, $base + 3 + $linha * 15, 250, 15, NULL, 8);
                 }
                 /**
                  * Instancia o service de boletim e requisita os dados da situação
                  * do aluno. Graças ao service, são "apenas" 147 linhas de código
                  * mal-escrito a menos.
                  */
                 $boletim = new Avaliacao_Service_Boletim(array('matricula' => $matricula['ref_cod_matricula']));
                 $situacao = $boletim->getSituacaoAluno();
                 if (TRUE == $situacao->aprovado) {
                     $this->pdf->escreve_relativo('X', 345, $base + 3 + $linha * 15, 250, 15, NULL, 8);
                     $total_aprovados++;
                 } elseif (TRUE == $situacao->retidoFalta) {
                     $total_reprovados_desempenho++;
                     $this->pdf->escreve_relativo('X', 465, $base + 3 + $linha * 15, 250, 15, NULL, 8);
                 } else {
                     $total_reprovados_nota++;
                     $this->pdf->escreve_relativo('X', 410, $base + 3 + $linha * 15, 250, 15, NULL, 8);
                 }
                 // analfabeto
                 $obj_aluno = new clsPmieducarAluno($det_matricula['ref_cod_aluno']);
                 $obj_aluno->setCamposLista('analfabeto');
                 $det_aluno = $obj_aluno->detalhe();
                 if ($det_aluno['analfabeto'] == 0) {
                     $this->pdf->escreve_relativo('X', 507, $base + 3 + $linha * 15, 250, 15, NULL, 8);
                     // não alfabetizado
                     $total_analfabetos++;
                 } else {
                     $this->pdf->escreve_relativo('X', 545, $base + 3 + $linha * 15, 250, 15, NULL, 8);
                     // alfabetizado
                     $total_nao_analfabetos++;
                 }
                 $this->pdf->linha_relativa(320, $base + $linha * 15, 0, 15);
                 $this->pdf->linha_relativa(380, $base + $linha * 15, 0, 15);
                 $this->pdf->linha_relativa(490, $base + $linha * 15, 0, 15);
                 $this->pdf->linha_relativa(530, $base + $linha * 15, 0, 15);
                 $this->pdf->linha_relativa(450, $base + $linha * 15, 0, 15);
                 $linha++;
             }
         }
     }
     // Escrever total
     $this->pdf->linha_relativa(30, $base + $linha * 15, 0, 15);
     $this->pdf->escreve_relativo("Total", 35, $base + 3 + $linha * 15, 20, 15, NULL, 8);
     $this->pdf->escreve_relativo($total_aprovados, 345, $base + 3 + $linha * 15, 250, 15, null, 8);
     // aprovado
     $this->pdf->escreve_relativo($total_reprovados_desempenho, 465, $base + 3 + $linha * 15, 250, 15, NULL, 8);
     // desempenho
     $this->pdf->escreve_relativo($total_reprovados_nota, 410, $base + 3 + $linha * 15, 250, 15, NULL, 8);
     // faltas
     $this->pdf->escreve_relativo($total_analfabetos, 507, $base + 3 + $linha * 15, 250, 15, NULL, 8);
     // não alfabetizado
     $this->pdf->escreve_relativo($total_nao_analfabetos, 545, $base + 3 + $linha * 15, 250, 15, NULL, 8);
     // alfabetizado
     $this->pdf->linha_relativa(60, $base + $linha * 15, 0, 15);
     $this->pdf->linha_relativa(320, $base + $linha * 15, 0, 15);
     $this->pdf->linha_relativa(380, $base + $linha * 15, 0, 15);
     $this->pdf->linha_relativa(490, $base + $linha * 15, 0, 15);
     $this->pdf->linha_relativa(530, $base + $linha * 15, 0, 15);
     $this->pdf->linha_relativa(450, $base + $linha * 15, 0, 15);
     $this->pdf->linha_relativa(570, $base + $linha * 15, 0, 15);
     $this->pdf->linha_relativa(30, $base + ($linha + 1) * 15, 540, 0);
     $this->pdf->ClosePage();
     $this->pdf->CloseFile();
     $this->get_link = $this->pdf->GetLink();
     echo sprintf('
   <script>
     window.onload = function()
     {
       parent.EscondeDiv("LoadImprimir");
       window.location="download.php?filename=%s"
     }
   </script>', $this->get_link);
     echo sprintf('
   <html>
     <center>
       Se o download não iniciar automaticamente <br /><a target="blank" href="%s" style="font-size: 16px; color: #000000; text-decoration: underline;">clique aqui!</a><br><br>
       <span style="font-size: 10px;">Para visualizar os arquivos PDF, é necessário instalar o Adobe Acrobat Reader.<br>
         Clique na Imagem para Baixar o instalador<br><br>
         <a href="http://www.adobe.com.br/products/acrobat/readstep2.html" target="new"><br><img src="imagens/acrobat.gif" width="88" height="31" border="0"></a>
       </span>
     </center>
   </html>', $this->get_link);
 }
Example #6
0
 /**
  * @see clsCadastro#Gerar()
  */
 public function Gerar()
 {
     // Dados da matrícula
     $matricula = $this->_service->getOption('matriculaData');
     // Nome do aluno
     $nome = $matricula['nome'];
     // Nome da escola
     $escola = new clsPmieducarEscola($matricula['ref_ref_cod_escola']);
     $escola = $escola->detalhe();
     $escola = ucwords(strtolower($escola['nome']));
     // Nome do curso
     $curso = $matricula['curso_nome'];
     // Nome da série
     $serie = $matricula['serie_nome'];
     // Nome da turma
     $turma = $matricula['turma_nome'];
     // Situação da matrícula
     $situacao = App_Model_MatriculaSituacao::getInstance();
     $situacao = $situacao->getValue($matricula['aprovado']);
     // Dados da matrícula
     $this->addDetalhe(array('Aluno', $nome));
     $this->addDetalhe(array('Escola', $escola));
     $this->addDetalhe(array('Curso', $curso));
     $this->addDetalhe(array('Série/Turma', $serie . ' / ' . $turma));
     $this->addDetalhe(array('Situação', $situacao));
     // Booleano para saber se o tipo de nota é nenhum.
     $nenhumaNota = $this->_service->getRegra()->get('tipoNota') == RegraAvaliacao_Model_Nota_TipoValor::NENHUM;
     // Booleano para saber o tipo de presença em que ocorre apuração
     $porComponente = $this->_service->getRegra()->get('tipoPresenca') == RegraAvaliacao_Model_TipoPresenca::POR_COMPONENTE;
     // Dados da regra de avaliação
     $this->addDetalhe(array('Regra avaliação', $this->_service->getRegra()));
     $this->addDetalhe(array('Apuração de falta', $this->_service->getRegra()->tipoPresenca));
     $this->addDetalhe(array('Parecer descritivo', $this->_service->getRegra()->parecerDescritivo));
     $this->addDetalhe(array('Progressão', $this->_service->getRegra()->tipoProgressao));
     if ($nenhumaNota) {
         $media = 'Não usa nota';
     } else {
         $media = $this->_service->getRegra()->media;
     }
     $this->addDetalhe(array('Média', $media));
     // Cria um array com a quantidade de etapas de 1 a n
     $etapas = range(1, $this->_service->getOption('etapas'), 1);
     // Atributos para a tabela
     $attributes = array('style' => 'background-color: #A1B3BD; padding: 5px; text-align: center');
     // Atributos para a tabela de notas/faltas
     $zebra = array(0 => array('style' => 'background-color: #E4E9ED'), 1 => array('style' => 'background-color: #FFFFFF'));
     // Helper para criar links e urls
     $url = CoreExt_View_Helper_UrlHelper::getInstance();
     // Usa helper de tabela para criar a tabela de notas/faltas
     $table = CoreExt_View_Helper_TableHelper::getInstance();
     // Enum para situação de matrícula
     $situacao = App_Model_MatriculaSituacao::getInstance();
     // Situação do boletim do aluno
     $sit = $this->_situacao;
     // Títulos da tabela
     $labels = array();
     $labels[] = array('data' => 'Disciplinas', 'attributes' => $attributes);
     foreach ($etapas as $etapa) {
         $data = array('data' => sprintf('Etapa %d', $etapa));
         if ($nenhumaNota) {
             $data['colspan'] = 1;
         } else {
             $data['colspan'] = $porComponente ? 2 : 1;
         }
         $data['attributes'] = $attributes;
         $labels[] = $data;
     }
     // Flag para auxiliar na composição da tabela em casos onde o parecer
     // descritivo é lançado anualmente e por componente
     $parecerComponenteAnual = FALSE;
     $colspan = 0;
     if ($this->_service->getRegra()->get('parecerDescritivo') == RegraAvaliacao_Model_TipoParecerDescritivo::ANUAL_COMPONENTE) {
         if (TRUE == $this->_componenteEncerrado($sit->nota->componentesCurriculares)) {
             $parecerComponenteAnual = TRUE;
             $colspan++;
         }
     }
     // Colspan para tabela com labels e sublabels
     $colspan += $porComponente && $sit->recuperacao ? 4 : 3;
     if ($nenhumaNota) {
         $colspan--;
     }
     if (!$nenhumaNota) {
         $labels[] = array('data' => $porComponente ? '' : 'Média', 'attributes' => $attributes, 'colspan' => $porComponente ? $colspan : 1);
     }
     // Inclui coluna para % de presença geral.
     if (!$porComponente) {
         if ($sit->recuperacao) {
             $labels[] = array('data' => 'Exame', 'attributes' => $attributes);
         }
         if ($parecerComponenteAnual) {
             $labels[] = array('data' => 'Parecer', 'attributes' => $attributes);
         }
         $labels[] = array('data' => 'Presença', 'attributes' => $attributes);
         $labels[] = array('data' => 'Situação', 'attributes' => $attributes);
     }
     $table->addHeaderRow($labels);
     // Cria sub-header caso tenha faltas lançadas por componentes
     if ($porComponente) {
         $subLabels = array();
         $subLabels[] = array('attributes' => $attributes);
         for ($i = 0, $loop = count($etapas); $i < $loop; $i++) {
             if (!$nenhumaNota) {
                 $subLabels[] = array('data' => 'Nota', 'attributes' => $attributes);
             }
             $subLabels[] = array('data' => 'Falta', 'attributes' => $attributes);
         }
         if (!$nenhumaNota) {
             $subLabels[] = array('data' => 'Média', 'attributes' => $attributes);
         }
         if ($sit->recuperacao) {
             $subLabels[] = array('data' => 'Exame', 'attributes' => $attributes);
         }
         if ($porComponente) {
             if ($parecerComponenteAnual) {
                 $subLabels[] = array('data' => 'Parecer', 'attributes' => $attributes);
             }
             $subLabels[] = array('data' => 'Presença', 'attributes' => $attributes);
             $subLabels[] = array('data' => 'Situação', 'attributes' => $attributes);
         }
         $table->addHeaderRow($subLabels);
     }
     // Atributos usados pelos itens de dados
     $attributes = array('style' => 'padding: 5px; text-align: center');
     // Notas
     $componentes = $this->_service->getComponentes();
     $notasComponentes = $this->_service->getNotasComponentes();
     $mediasSituacoes = $this->_situacao->nota;
     $mediasComponentes = $this->_service->getMediasComponentes();
     $faltasComponentes = $this->_service->getFaltasComponentes();
     // Calcula as porcentagens de presença
     $faltasStats = $this->_service->getSituacaoFaltas();
     // Texto do link
     if ($nenhumaNota) {
         $linkText = 'falta';
         $linkPath = 'falta';
     } else {
         $linkText = $porComponente ? 'nota/falta' : 'nota';
         $linkPath = 'nota';
     }
     // Parâmetros para o link de nota/falta nova
     $newLink = array('text' => 'Lançar ' . $linkText, 'path' => $linkPath, 'query' => array('matricula' => $matricula['cod_matricula'], 'componenteCurricular' => 0));
     $iteration = 0;
     foreach ($componentes as $id => $componente) {
         $data = array();
         // Nome do componente curricular
         $data[] = array('data' => $componente, 'attributes' => array('style' => 'padding: 5px; text-align: left'));
         $notas = $notasComponentes[$id];
         $mediaSituacao = $mediasSituacoes->componentesCurriculares[$id];
         $medias = $mediasComponentes[$id];
         $faltas = $faltasComponentes[$id];
         $faltaStats = $faltasStats->componentesCurriculares[$id];
         $parecer = NULL;
         // Caso os pareceres sejam por componente e anuais, recupera a instância
         if ($parecerComponenteAnual) {
             $parecer = $this->_service->getPareceresComponentes();
             $parecer = $parecer[$id];
         }
         if ($porComponente == TRUE) {
             $new = $url->l('Lançar nota', 'nota', array('query' => array('matricula' => $matricula['cod_matricula'], 'componenteCurricular' => $id)));
         }
         $newLink['query']['componenteCurricular'] = $id;
         $new = $url->l($newLink['text'], $newLink['path'], array('query' => $newLink['query']));
         $update = array('query' => array('matricula' => $matricula['cod_matricula'], 'componenteCurricular' => $id, 'etapa' => 0));
         // Lista as notas do componente por etapa
         for ($i = 0, $loop = count($etapas); $i < $loop; $i++) {
             $nota = $falta = NULL;
             if (isset($notas[$i])) {
                 $update['query']['etapa'] = $notas[$i]->etapa;
                 $nota = $url->l($notas[$i]->notaArredondada, 'nota', $update);
             }
             if (isset($faltas[$i])) {
                 $update['query']['etapa'] = $faltas[$i]->etapa;
                 $linkPath = $nenhumaNota ? 'falta' : 'nota';
                 $falta = $url->l($faltas[$i]->quantidade, $linkPath, $update);
             }
             /*
              * Exibição muito dinâmica. Em resumo, os casos são:
              *
              * 1. nota & falta componente
              * 2. nota
              * 3. falta componente
              * 4. falta geral
              */
             if ($nenhumaNota) {
                 $colspan = 1;
             } elseif (!$nenhumaNota && $porComponente && is_null($falta)) {
                 $colspan = 2;
             } else {
                 $colspan = 1;
             }
             // Caso 1.
             if (!$nenhumaNota) {
                 if ($nota) {
                     // Caso 2: resolvido com colspan.
                     $data[] = array('data' => $nota, 'attributes' => $attributes, 'colspan' => $colspan);
                     if ($porComponente) {
                         $data[] = array('data' => $falta, 'attributes' => $attributes);
                     }
                 } else {
                     $data[] = array('data' => $new, 'attributes' => $attributes, 'colspan' => $colspan);
                     $new = '';
                 }
             } elseif ($nenhumaNota && $porComponente) {
                 if ($falta) {
                     $data[] = array('data' => $falta, 'attributes' => $attributes, 'colspan' => $colspan);
                 } else {
                     $data[] = array('data' => $new, 'attributes' => $attributes, 'colspan' => $colspan);
                     $new = '';
                 }
             } else {
                 $data[] = array('data' => '', 'attributes' => $attributes);
             }
         }
         // Média no componente curricular
         if (!$nenhumaNota) {
             $media = $medias[0]->mediaArredondada . ($medias[0]->etapa == 'Rc' ? ' (Rc)' : '');
             $data[] = array('data' => $media, 'attributes' => $attributes);
         }
         // Adiciona uma coluna extra caso aluno esteja em exame em alguma componente curricular
         if ($sit->recuperacao) {
             if ($mediaSituacao->situacao == App_Model_MatriculaSituacao::EM_EXAME || $mediaSituacao->situacao == App_Model_MatriculaSituacao::APROVADO_APOS_EXAME || $mediaSituacao->situacao == App_Model_MatriculaSituacao::REPROVADO) {
                 $link = $newLink;
                 $link['query']['componenteCurricular'] = $id;
                 $link['query']['etapa'] = 'Rc';
                 $notaRec = $i;
                 if (isset($notas[$notaRec]) && $notas[$notaRec]->etapa == 'Rc') {
                     $link['text'] = $notas[$notaRec]->notaArredondada;
                 }
                 $recuperacaoLink = $url->l($link['text'], $link['path'], array('query' => $link['query']));
                 $data[] = array('data' => $recuperacaoLink, 'attributes' => $attributes);
             } else {
                 $data[] = array('data' => '', 'attributes' => $attributes);
             }
         }
         // Adiciona uma coluna extra caso o parecer seja por componente ao final do ano
         if ($parecerComponenteAnual) {
             $link = array('text' => '', 'path' => 'parecer', 'query' => array('matricula' => $this->getRequest()->matricula));
             if (0 == count($parecer)) {
                 $text = 'Lançar';
             } else {
                 $text = 'Editar';
             }
             $link['query']['componenteCurricular'] = $id;
             // @todo Constante ou CoreExt_Enum
             $link['query']['etapa'] = 'An';
             $link = $url->l($text, $link['path'], array('query' => $link['query']));
             if (isset($mediaSituacao->situacao) && $mediaSituacao->situacao != App_Model_MatriculaSituacao::EM_ANDAMENTO) {
                 $data[] = array('data' => $link, 'attributes' => $attributes);
             } else {
                 $data[] = array('data' => '', 'attributes' => $attributes);
             }
         }
         // Informações extras como porcentagem de presença e situação do aluno
         if ($porComponente) {
             $data[] = array('data' => sprintf('%.2f%%', $faltaStats->porcentagemPresenca), 'attributes' => $attributes);
         } else {
             $data[] = array('data' => '', 'attributes' => $attributes);
         }
         $data[] = array('data' => $situacao->getValue($mediaSituacao->situacao), 'attributes' => $attributes);
         $iteration++;
         $class = $iteration % 2;
         $table->addBodyRow($data, $zebra[$class]);
     }
     $newLink = array('text' => 'Lançar falta', 'path' => 'falta', 'query' => array('matricula' => $matricula['cod_matricula']));
     // Situação geral das faltas
     $data = array(0 => array('data' => 'Faltas', 'attributes' => array('style' => 'padding: 5px; text-align: left')));
     $faltas = $this->_service->getFaltasGerais();
     $new = $url->l($newLink['text'], $newLink['path'], array('query' => $newLink['query']));
     // Listas faltas (para faltas no geral)
     for ($i = 1, $loop = count($etapas); $i <= $loop; $i++) {
         if (isset($faltas[$i])) {
             $link = $newLink;
             $link['query']['etapa'] = $faltas[$i]->etapa;
             $link = $porComponente ? '' : $url->l($faltas[$i]->quantidade, $link['path'], array('query' => $link['query']));
             $data[] = array('data' => $link, 'attributes' => $attributes);
             if ($porComponente) {
                 $data[] = array('data' => '', 'attributes' => $attributes);
             }
         } else {
             $new = $porComponente ? '' : $new;
             $data[] = array('data' => $new, 'attributes' => $attributes);
             $new = '';
             if ($porComponente && !$nenhumaNota) {
                 $data[] = array('data' => '', 'attributes' => $attributes);
             }
         }
     }
     if (!$nenhumaNota) {
         $data[] = array();
     }
     if ($sit->recuperacao) {
         $data[] = array('data' => '', 'attributes' => $attributes);
     }
     if ($parecerComponenteAnual) {
         $data[] = array('data' => '', 'attributes' => $attributes);
     }
     // Porcentagem presença
     $data[] = array('data' => sprintf('%.2f%%', $faltasStats->porcentagemPresenca), 'attributes' => $attributes);
     $data[] = array('data' => $situacao->getValue($sit->falta->situacao), 'attributes' => $attributes);
     $table->addFooterRow($data, $zebra[$class ^ 1]);
     // Adiciona linha com links para lançamento de parecer descritivo geral por etapa
     if ($this->_service->getRegra()->get('parecerDescritivo') == RegraAvaliacao_Model_TipoParecerDescritivo::ETAPA_GERAL) {
         $newLink = array('text' => 'Lançar parecer', 'path' => 'parecer', 'query' => array('matricula' => $matricula['cod_matricula']));
         $data = array(0 => array('data' => 'Pareceres', 'attributes' => array('style' => 'padding: 5px; text-align: left')));
         $pareceres = $this->_service->getPareceresGerais();
         for ($i = 1, $loop = count($etapas); $i <= $loop; $i++) {
             if (isset($pareceres[$i])) {
                 $link = $newLink;
                 $link['text'] = 'Editar parecer';
                 $link['query']['etapa'] = $i;
                 $data[] = array('data' => $url->l($link['text'], $link['path'], array('query' => $link['query'])), 'attributes' => $attributes);
             } else {
                 if ('' == $newLink) {
                     $link = '';
                 } else {
                     $link = $url->l($newLink['text'], $newLink['path'], array('query' => $newLink['query']));
                 }
                 $data[] = array('data' => $link, 'attributes' => $attributes);
                 $newLink = '';
             }
         }
         if ($sit->recuperacao) {
             $data[] = array('data' => '', 'attributes' => $attributes);
         }
         $data[] = array('data' => '', 'attributes' => $attributes);
         $data[] = array('data' => '', 'attributes' => $attributes);
         $table->addFooterRow($data);
     }
     // Adiciona tabela na página
     $this->addDetalhe(array('Disciplinas', '<div id="disciplinas">' . $table . '</div>'));
     // Adiciona link para lançamento de parecer descritivo anual geral
     if (FALSE == $sit->andamento && $this->_service->getRegra()->get('parecerDescritivo') == RegraAvaliacao_Model_TipoParecerDescritivo::ANUAL_GERAL) {
         if (0 == count($this->_service->getPareceresGerais())) {
             $label = 'Lançar';
         } else {
             $label = 'Editar';
         }
         $link = array('text' => $label . ' parecer descritivo do aluno', 'path' => 'parecer', 'query' => array('matricula' => $this->getRequest()->matricula));
         $this->addDetalhe(array('Parecer descritivo anual', $url->l($link['text'], $link['path'], array('query' => $link['query']))));
     }
     // Caso o tipo de progressão seja manual, a situação das notas/faltas não
     // esteja mais em "andamento" e a matrícula esteja em andamento, exibe
     // botões de ação
     if ($this->_service->getRegra()->get('tipoProgressao') == RegraAvaliacao_Model_TipoProgressao::NAO_CONTINUADA_MANUAL && FALSE == $sit->andamento && $matricula['aprovado'] == App_Model_MatriculaSituacao::EM_ANDAMENTO) {
         $link = array('text' => 'sim', 'path' => 'boletim', 'query' => array('matricula' => $this->getRequest()->matricula, 'promove' => 1));
         $sim = '<span class="confirm yes">' . $url->l($link['text'], $link['path'], array('query' => $link['query'])) . '</span>';
         $link['text'] = 'não (retém o aluno)';
         $link['query']['promove'] = 0;
         $nao = '<span class="confirm no">' . $url->l($link['text'], $link['path'], array('query' => $link['query'])) . '</span>';
         $links = '<div style="padding: 5px 0 5px 0">' . $sim . $nao . '</div>';
         $this->addDetalhe(array('Promover aluno?', $links));
     }
 }
 function getAlunoNotasFaltasTable($alunos_matriculados)
 {
     $fonte = 'arial';
     $corTexto = '#000000';
     $esquerda_original = 3;
     $espessura_linha = 0.3;
     $tam_texto = 9;
     $direita = 834;
     $altura = 20;
     $obj_serie = new clsPmieducarSerie($this->ref_cod_serie);
     $det_serie = $obj_serie->detalhe();
     $espacoDiv = $this->presencaGeral ? 1 : 2;
     foreach ($alunos_matriculados as $matricula => $aluno) {
         $boletim = new Avaliacao_Service_Boletim(array('matricula' => $matricula));
         $medias = $boletim->getMediasComponentes();
         if ($this->presencaGeral) {
             // Soma as faltas do aluno
             $faltas = array_sum(CoreExt_Entity::entityFilterAttr($boletim->getFaltasGerais(), 'etapa', 'quantidade'));
         } else {
             $faltas = $boletim->getFaltasComponentes();
         }
         $esquerda = $esquerda_original;
         // Matrícula
         $this->pdf->quadrado_relativo($esquerda, $this->page_y, $direita, $altura);
         $this->pdf->escreve_relativo($matricula, $esquerda, $this->page_y + 2, 45, 45, $fonte, $tam_texto, $corTexto, 'center');
         $this->pdf->linha_relativa($esquerda += 45, $this->page_y, 0, $altura);
         // Nome do aluno
         $espaco_nome = 150;
         $this->pdf->escreve_relativo($aluno['nome'], $esquerda, $this->page_y + 2, $espaco_nome, 45, $fonte, $tam_texto, $corTexto, 'center');
         $this->pdf->linha_relativa($esquerda += $espaco_nome, $this->page_y, 0, $altura);
         // Situação da matrícula
         $this->pdf->escreve_relativo(App_Model_MatriculaSituacao::getInstance()->getValue($aluno['aprovado']), $esquerda, $this->page_y + 4, 45, 45, $fonte, $tam_texto, $corTexto, 'center');
         $this->pdf->linha_relativa($esquerda += 45, $this->page_y, 0, $altura);
         $espacoComponentes = ceil(($direita - $esquerda) / (count($this->componentes) + ($this->presencaGeral ? 1 : 0)));
         // Exibe as médias e faltas do aluno
         foreach ($this->componentes as $id => $componente) {
             // Se não tem média, foi dispensado do componente
             if (!isset($medias[$id])) {
                 $media = 'D';
                 $faltas = 'D';
             } else {
                 $media = $medias[$id][0];
                 $media = $media->mediaArredondada;
                 if (!$this->presencaGeral) {
                     if (isset($faltas[$id])) {
                         $faltas = array_sum(CoreExt_Entity::entityFilterAttr($faltas[$id], 'id', 'quantidade'));
                     }
                 }
             }
             // Média
             $this->pdf->escreve_relativo($media, $esquerda, $this->page_y + 4, $espacoComponentes / $espacoDiv, 50, $fonte, $tam_texto + 1, $corTexto, 'center');
             $this->pdf->linha_relativa($esquerda + $espacoComponentes / $espacoDiv, $this->page_y, 0, $altura);
             // Exibe as faltas no componente curricular, caso a presença não seja geral
             if (!$this->presencaGeral) {
                 $this->pdf->escreve_relativo($faltas, $esquerda + $espacoComponentes / $espacoDiv, $this->page_y + 4, $espacoComponentes / $espacoDiv, 100, $fonte, $tam_texto + 1, $corTexto, 'center');
             }
             $esquerda += $espacoComponentes;
             $this->pdf->linha_relativa($esquerda, $this->page_y, 0, $altura);
         }
         // Exibe as faltas no total, caso a presença seja geral
         if ($this->presencaGeral) {
             $this->pdf->escreve_relativo($faltas, $esquerda, $this->page_y + 4, $espacoComponentes, 50, $fonte, $tam_texto + 1, $corTexto, 'center');
             $esquerda += $espacoComponentes;
             $this->pdf->linha_relativa($esquerda, $this->page_y, 0, $altura);
         }
         $this->page_y += $altura;
         if ($this->page_y > $this->pdf->altura - $altura * 2) {
             $this->pdf->ClosePage();
             $this->pdf->OpenPage();
             $this->addCabecalho();
         }
     }
 }
 function renderHTML()
 {
     if ($_POST) {
         foreach ($_POST as $key => $value) {
             $this->{$key} = $value;
         }
     }
     if ($this->ref_ref_cod_serie) {
         $this->ref_cod_serie = $this->ref_ref_cod_serie;
     }
     $this->ref_cod_modulo = explode('-', $this->ref_cod_modulo);
     $this->ref_cod_modulo = array_pop($this->ref_cod_modulo);
     $fonte = 'arial';
     $corTexto = '#000000';
     if (empty($this->ref_cod_turma)) {
         echo '<script>
          alert("Erro ao gerar relatório!\\nNenhuma turma selecionada!");
          window.parent.fechaExpansivel(\'div_dinamico_\'+(window.parent.DOM_divs.length-1));
        </script>';
         return TRUE;
     }
     if ($this->ref_cod_escola) {
         $obj_escola = new clsPmieducarEscola($this->ref_cod_escola);
         $det_escola = $obj_escola->detalhe();
         $this->nm_escola = $det_escola['nome'];
         $obj_instituicao = new clsPmieducarInstituicao($det_escola['ref_cod_instituicao']);
         $det_instituicao = $obj_instituicao->detalhe();
         $this->nm_instituicao = $det_instituicao['nm_instituicao'];
     }
     $obj_calendario = new clsPmieducarEscolaAnoLetivo();
     $lista_calendario = $obj_calendario->lista($this->ref_cod_escola, $this->ano, NULL, NULL, NULL, NULL, NULL, NULL, NULL, 1, NULL);
     $obj_turma = new clsPmieducarTurma($this->ref_cod_turma);
     $det_turma = $obj_turma->detalhe();
     $this->nm_turma = $det_turma['nm_turma'];
     $obj_serie = new clsPmieducarSerie($this->ref_cod_serie);
     $det_serie = $obj_serie->detalhe();
     $this->nm_serie = $det_serie['nm_serie'];
     $obj_pessoa = new clsPessoa_($det_turma['ref_cod_regente']);
     $det = $obj_pessoa->detalhe();
     $this->nm_professor = $det['nome'];
     //
     $regraMapper = new RegraAvaliacao_Model_RegraDataMapper();
     $this->regra = $regraMapper->find($det_serie['regra_avaliacao_id']);
     if (!$lista_calendario) {
         echo '<script>
          alert("Escola não possui calendário definido para este ano");
          window.parent.fechaExpansivel(\'div_dinamico_\'+(window.parent.DOM_divs.length-1));
        </script>';
         return TRUE;
     }
     $obj = new clsPmieducarSerie();
     $obj->setOrderby('cod_serie, etapa_curso');
     $lista_serie_curso = $obj->lista(NULL, NULL, NULL, $this->ref_cod_curso, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, 1, $this->ref_cod_instituicao);
     $obj_curso = new clsPmieducarCurso($this->ref_cod_curso);
     $det_curso = $obj_curso->detalhe();
     $this->nm_curso = $det_curso['nm_curso'];
     // Seleciona os alunos da turma
     $obj_matricula_turma = new clsPmieducarMatriculaTurma();
     $obj_matricula_turma->setOrderby('nome_ascii');
     $lst_matricula_turma = $obj_matricula_turma->lista($this->ref_cod_matricula, $this->ref_cod_turma, NULL, NULL, NULL, NULL, NULL, NULL, 1, $this->ref_cod_serie, $this->ref_cod_curso, $this->ref_cod_escola, $this->ref_cod_instituicao, NULL, NULL, array(1, 2, 3), NULL, NULL, $this->ano, NULL, NULL, NULL, NULL, TRUE, NULL, NULL, TRUE, NULL, $this->semestre);
     $componentes = $array_disc = $array_cab = array();
     if ('f' == $this->tipo && $this->regra->get('tipoPresenca') == RegraAvaliacao_Model_TipoPresenca::GERAL) {
         $array_disc = $array_cab = array("FALTAS");
     } else {
         try {
             $componentes = App_Model_IedFinder::getComponentesTurma($this->ref_cod_serie, $this->ref_cod_escola, $this->ref_cod_turma);
         } catch (App_Model_Exception $e) {
         }
     }
     if ($lst_matricula_turma) {
         $titulo = sprintf('Espelho de Notas Bimestral %dº Bimestre Ano %d', $this->ref_cod_modulo, $this->ano);
         $subtitulo = sprintf("%s\n%s\n%s\n%s -  Turma: %s             %s", $this->nm_instituicao, $this->nm_escola, $this->nm_curso, $this->nm_serie, $this->nm_turma, date('d/m/Y'));
         $relatorio = new relatorios($titulo, 210, FALSE, 'Espelho de Notas Bimestral', 'A4', $subtitulo);
         $relatorio->setMargem(20, 20, 50, 50);
         $relatorio->exibe_produzido_por = FALSE;
         if (0 == count($array_disc) && 0 < count($componentes)) {
             foreach ($componentes as $componente) {
                 $array_disc[$componente->id] = $componente;
                 $array_cab[] = str2upper($componente->abreviatura);
             }
             asort($array_disc);
             sort($array_cab);
         }
         $array_cab = array_merge(array('Cód.', 'Nome do Aluno'), $array_cab);
         $divisoes = array(40, 165);
         $divisoes_texto = array(40, 165);
         $tamanho_divisao = 32 + (10 - count($array_disc)) * 5;
         for ($ct = 0; $ct < 20; $ct++) {
             $divisoes[] = $tamanho_divisao;
             $divisoes_texto[] = $tamanho_divisao;
         }
         $relatorio->novalinha($array_cab, 0, 16, TRUE, 'arial', $divisoes, '#515151', '#D3D3D3', '#FFFFFF', FALSE, TRUE);
         foreach ($lst_matricula_turma as $matricula) {
             $boletim = new Avaliacao_Service_Boletim(array('matricula' => $matricula['ref_cod_matricula'], 'RegraDataMapper' => $regraMapper));
             $tam_fonte = NULL;
             $tam_linha = 16;
             $componentes = $boletim->getComponentes();
             foreach ($array_disc as $cid => $componente) {
                 // Presença geral, seleciona apenas a quantidade de faltas da etapa
                 if (0 == $cid) {
                     $faltas[$cid] = $boletim->getFalta($this->ref_cod_modulo);
                     break;
                 }
                 if (!in_array($cid, array_keys($componentes))) {
                     $notas[$cid] = 'D';
                     $faltas[$cid] = 'D';
                     continue;
                 }
                 $notas[$cid] = $boletim->getNotaComponente($cid, $this->ref_cod_modulo);
                 $faltas[$cid] = $boletim->getFalta($this->ref_cod_modulo, $cid);
             }
             // @todo WTF?!
             if (strlen($matricula['nome']) > 24) {
                 $matricula['nome'] = explode(' ', $matricula['nome']);
                 if (is_array($matricula['nome'])) {
                     $nome_aluno = array_shift($matricula['nome']);
                 }
                 if (is_array($matricula['nome'])) {
                     $nome_aluno .= ' ' . array_shift($matricula['nome']);
                 }
                 if (is_array($matricula['nome'])) {
                     $nome_aluno .= ' ' . array_pop($matricula['nome']);
                 }
                 $matricula['nome'] = $nome_aluno;
             }
             unset($array_val);
             $array_val = array();
             $array_val[] = $matricula['ref_cod_aluno'];
             $array_val[] = $matricula['nome'];
             foreach ($array_disc as $cid => $disc) {
                 if ($this->tipo == 'n') {
                     $array_val[] = $notas[$cid]->notaArredondada;
                     continue;
                 } else {
                     $array_val[] = $faltas[$cid]->quantidade;
                     continue;
                 }
                 $array_val[] = '';
             }
             $relatorio->novalinha($array_val, 0, $tam_linha, FALSE, 'arial', $divisoes_texto, '#515151', '#d3d3d3', '#FFFFFF', FALSE, TRUE, NULL, $tam_fonte);
         }
         $this->get_link = $relatorio->fechaPdf();
     }
     echo sprintf('
   <script>
     window.onload=function()
     {
       parent.EscondeDiv("LoadImprimir");
       window.location="download.php?filename=%s"
     }
   </script>', $this->get_link);
     echo sprintf('
   <html>
     <center>
       Se o download não iniciar automaticamente <br>
       <a target="blank" href="%s" style="font-size: 16px; color: #000000; text-decoration: underline;">clique aqui!</a><br><br>
       <span style="font-size: 10px;">
         Para visualizar os arquivos PDF, é necessário instalar o Adobe Acrobat Reader.<br>
         Clique na Imagem para Baixar o instalador<br><br>
         <a href="http://www.adobe.com.br/products/acrobat/readstep2.html" target="new"><br><img src="imagens/acrobat.gif" width="88" height="31" border="0"></a>
       </span>
     </center>
   </html>', $this->get_link);
 }
 function renderHTML()
 {
     if ($_POST) {
         foreach ($_POST as $key => $value) {
             $this->{$key} = $value;
         }
     }
     if ($this->ref_ref_cod_serie) {
         $this->ref_cod_serie = $this->ref_ref_cod_serie;
     }
     $fonte = 'arial';
     $corTexto = '#000000';
     if (!is_numeric($this->ref_cod_escola) || !is_numeric($this->ref_cod_curso) || !is_numeric($this->ref_cod_serie) || !is_numeric($this->ref_cod_turma) || !is_numeric($this->ano)) {
         print $this->getError();
         return;
     }
     // Instituição
     $obj_instituicao = new clsPmieducarInstituicao($this->ref_cod_instituicao);
     $nm_instituicao = $obj_instituicao->detalhe();
     $nm_instituicao = $nm_instituicao['nm_instituicao'];
     // Escola
     $obj_escola = new clsPmieducarEscola($this->ref_cod_escola);
     $nm_escola = $obj_escola->detalhe();
     $nm_escola = $nm_escola['nome'];
     // Curso
     $obj_curso = new clsPmieducarCurso($this->ref_cod_curso);
     $obj_curso->setCamposLista('media, media_exame, nm_curso');
     $det_curso = $obj_curso->detalhe();
     $nm_curso = $det_curso['nm_curso'];
     // Série
     $obj_serie = new clsPmieducarSerie($this->ref_cod_serie);
     $obj_serie->setCamposLista('nm_serie');
     $det_serie = $obj_serie->detalhe();
     $nm_serie = $det_serie['nm_serie'];
     $regraId = $det_serie['regra_avaliacao_id'];
     // Turma
     $obj_turma = new clsPmieducarTurma($this->ref_cod_turma);
     $obj_turma->setCamposLista('nm_turma');
     $det_turma = $obj_turma->detalhe();
     $nm_turma = $det_turma['nm_turma'];
     // Situação da matrícula do aluno (aprovado)
     $situacao = $this->ano == date('Y') ? App_Model_MatriculaSituacao::EM_ANDAMENTO : implode(', ', array(App_Model_MatriculaSituacao::APROVADO, App_Model_MatriculaSituacao::REPROVADO, App_Model_MatriculaSituacao::EM_ANDAMENTO));
     $sql = sprintf('
   SELECT
     m.cod_matricula,
     (
     SELECT
       nome
     FROM
       pmieducar.aluno al,
       cadastro.pessoa
     WHERE
       al.cod_aluno = m.ref_cod_aluno
       AND al.ref_idpes = pessoa.idpes
     ) AS nome
   FROM
     pmieducar.matricula m,
     pmieducar.matricula_turma mt
   WHERE
     mt.ref_cod_turma = %d
     AND mt.ref_cod_matricula = m.cod_matricula
     AND m.aprovado IN (%s)
     AND mt.ativo = 1
     AND m.ativo = 1
     AND m.ano = %d
   ORDER BY
     nome', $this->ref_cod_turma, $situacao, $this->ano);
     $db = new clsBanco();
     $db->Consulta($sql);
     // Mappers
     $regraMapper = new RegraAvaliacao_Model_RegraDataMapper();
     $componenteMapper = new ComponenteCurricular_Model_ComponenteDataMapper();
     $regra = $regraMapper->find($regraId);
     if (is_null($regra->formulaRecuperacao)) {
         $regra = 'A regra de avaliação dessa série não possui uma fórmula de cálculo de recuperação.';
     } else {
         $regra = sprintf('Recuperação: %s; fórmula: %s.', $regra->formulaRecuperacao, $regra->formulaRecuperacao->formulaMedia);
     }
     if ($db->Num_Linhas()) {
         $alunos = array();
         // Instancia objeto de relatório padrão
         $detalhes = sprintf('%s%s%s%s%s%s%s - Turma: %s         %s', $nm_instituicao, "\n", $nm_escola, "\n", $nm_curso, "\n", $nm_serie, $nm_turma, date('d/m/Y'));
         $relatorio = new relatorios('Relação de alunos em exame', 210, FALSE, 'Relação de alunos em exame', 'A4', $detalhes);
         $relatorio->exibe_produzido_por = FALSE;
         $relatorio->setMargem(20, 20, 20, 20);
         $relatorio->novalinha(array(sprintf('Nome Escola: %s    Ano: %d', $nm_escola, $this->ano)), 0, 12, TRUE, 'arial', FALSE, '#000000', '#d3d3d3', '#FFFFFF', FALSE, TRUE);
         $relatorio->novalinha(array(sprintf('Curso: %s    Ano/Série: %s    Turma: %s', $nm_curso, $nm_serie, $nm_turma)), 0, 12, TRUE, 'arial', FALSE, '#000000', '#d3d3d3', '#FFFFFF', FALSE, TRUE);
         $relatorio->novalinha(array(sprintf('%s    Data: %s', $regra, date('d/m/Y'))), 0, 12, TRUE, 'arial', FALSE, '#000000', '#d3d3d3', '#FFFFFF', FALSE, TRUE);
         $relatorio->novalinha(array('Mat.', 'Nome Aluno', 'Componentes', 'Média', 'Nota necessária (mín.)'), 0, 12, TRUE, 'arial', array(30, 180, 150, 60), '#515151', '#d3d3d3', '#FFFFFF', FALSE, TRUE);
         while ($db->ProximoRegistro()) {
             list($cod_matricula, $nome_aluno) = $db->Tupla();
             $boletim = new Avaliacao_Service_Boletim(array('matricula' => $cod_matricula, 'RegraDataMapper' => $regraMapper, 'ComponenteDataMapper' => $componenteMapper));
             $componentes = $boletim->getComponentes();
             $medias = $boletim->getMediasComponentes();
             $situacao = $boletim->getSituacaoComponentesCurriculares();
             if ($situacao->situacao != App_Model_MatriculaSituacao::EM_EXAME) {
                 continue;
             }
             foreach ($situacao->componentesCurriculares as $id => $situacaoComponente) {
                 if ($situacaoComponente->situacao != App_Model_MatriculaSituacao::EM_EXAME) {
                     continue;
                 }
                 $mediaRecuperacao = $boletim->preverNotaRecuperacao($id);
                 if (!is_null($mediaRecuperacao)) {
                     $previsao = sprintf('%s (%.2f)', $mediaRecuperacao->nome, $mediaRecuperacao->valorMinimo);
                 } else {
                     $previsao = 'Nenhuma nota possível.';
                 }
                 $data = array($cod_matricula, $nome_aluno, $componentes[$id], $medias[$id][0]->mediaArredondada, $previsao);
                 $relatorio->novalinha($data, 0, 12, FALSE, 'arial', array(30, 180, 150, 60), '#515151', '#d3d3d3', '#FFFFFF', FALSE, TRUE);
             }
         }
     } else {
         print $this->getError();
         return;
     }
     $this->get_link = $relatorio->fechaPdf();
     echo sprintf('
   <script>
     window.onload=function()
     {
       parent.EscondeDiv("LoadImprimir");
       window.location="download.php?filename=%s"
     }
   </script>', $this->get_link);
     echo sprintf('
   <html>
     <center>
       Se o download não iniciar automaticamente <br>
       <a target="blank" href="%s" style="font-size: 16px; color: #000000; text-decoration: underline;">clique aqui!</a><br><br>
       <span style="font-size: 10px;">
         Para visualizar os arquivos PDF, é necessário instalar o Adobe Acrobat Reader.<br>
         Clique na Imagem para Baixar o instalador<br><br>
         <a href="http://www.adobe.com.br/products/acrobat/readstep2.html" target="new"><br><img src="imagens/acrobat.gif" width="88" height="31" border="0"></a>
       </span>
     </center>
   </html>', $this->get_link);
 }