public function testSalvarNotasDeUmComponenteCurricularNoBoletimEmRecuperacao()
 {
     $notaAluno = $this->_getConfigOption('notaAluno', 'instance');
     $notas = array(new Avaliacao_Model_NotaComponente(array('componenteCurricular' => 1, 'nota' => 5, 'etapa' => 1)), new Avaliacao_Model_NotaComponente(array('componenteCurricular' => 1, 'nota' => 5, 'etapa' => 2)), new Avaliacao_Model_NotaComponente(array('componenteCurricular' => 1, 'nota' => 6, 'etapa' => 3)), new Avaliacao_Model_NotaComponente(array('componenteCurricular' => 1, 'nota' => 6, 'etapa' => 4)), new Avaliacao_Model_NotaComponente(array('componenteCurricular' => 1, 'nota' => 6, 'etapa' => 'Rc')));
     $media = new Avaliacao_Model_NotaComponenteMedia(array('notaAluno' => $notaAluno->id, 'componenteCurricular' => 1, 'media' => 5.7, 'mediaArredondada' => 5, 'etapa' => 'Rc'));
     $media->markOld();
     // Configura mock para Avaliacao_Model_NotaComponenteDataMapper
     $mock = $this->getCleanMock('Avaliacao_Model_NotaComponenteDataMapper');
     $mock->expects($this->at(0))->method('findAll')->with(array(), array('notaAluno' => $notaAluno->id), array('etapa' => 'ASC'))->will($this->returnValue(array()));
     $mock->expects($this->at(1))->method('save')->with($notas[0])->will($this->returnValue(TRUE));
     $mock->expects($this->at(2))->method('save')->with($notas[1])->will($this->returnValue(TRUE));
     $mock->expects($this->at(3))->method('save')->with($notas[2])->will($this->returnValue(TRUE));
     $mock->expects($this->at(4))->method('save')->with($notas[3])->will($this->returnValue(TRUE));
     $mock->expects($this->at(5))->method('save')->with($notas[4])->will($this->returnValue(TRUE));
     $mock->expects($this->at(6))->method('findAll')->with(array(), array('notaAluno' => $notaAluno->id), array('etapa' => 'ASC'))->will($this->returnValue($notas));
     $this->_setNotaComponenteDataMapperMock($mock);
     // Configura mock para Avaliacao_Model_NotaComponenteMediaDataMapper
     $mock = $this->getCleanMock('Avaliacao_Model_NotaComponenteMediaDataMapper');
     $mock->expects($this->at(0))->method('findAll')->with(array(), array('notaAluno' => $notaAluno->id))->will($this->returnValue(array()));
     $mock->expects($this->at(1))->method('find')->with(array($notaAluno->id, $this->_getConfigOption('matricula', 'cod_matricula')))->will($this->returnValue(array()));
     $mock->expects($this->at(2))->method('save')->with($media)->will($this->returnValue(TRUE));
     $this->_setNotaComponenteMediaDataMapperMock($mock);
     $service = $this->_getServiceInstance();
     $service->addNotas($notas);
     $service->saveNotas();
     $notasSalvas = $service->getNotas();
     $etapas = array_merge(range(1, count($this->_getConfigOptions('anoLetivoModulo'))), array('Rc'));
     foreach ($notasSalvas as $notaSalva) {
         $key = array_search($notaSalva->etapa, $etapas, FALSE);
         $this->assertTrue($key !== FALSE);
         unset($etapas[$key]);
     }
 }
Пример #2
0
 /**
  * Atualiza a média dos componentes curriculares.
  */
 protected function _updateNotaComponenteMedia()
 {
     require_once 'Avaliacao/Model/NotaComponenteMedia.php';
     $this->_loadNotaComponenteCurricular(FALSE);
     foreach ($this->_notasComponentes as $id => $notasComponentes) {
         // Cria um array onde o índice é a etapa
         $etapasNotas = CoreExt_Entity::entityFilterAttr($notasComponentes, 'etapa', 'nota');
         $notas = array('Se' => 0, 'Et' => $this->getOption('etapas'));
         // Cria o array formatado para o cálculo da fórmula da média
         foreach ($etapasNotas as $etapa => $nota) {
             if (is_numeric($etapa)) {
                 $notas['E' . $etapa] = $nota;
                 $notas['Se'] += $nota;
                 continue;
             }
             $notas[$etapa] = $nota;
         }
         // Calcula a média
         $media = $this->_calculaMedia($notas);
         // Cria uma nova instância de média, já com a nota arredondada e a etapa
         $notaComponenteCurricularMedia = new Avaliacao_Model_NotaComponenteMedia(array('notaAluno' => $this->_getNotaAluno()->id, 'componenteCurricular' => $id, 'media' => $media, 'mediaArredondada' => $this->arredondaNota($media), 'etapa' => $etapa));
         try {
             // Se existir, marca como "old" para possibilitar a atualização
             $this->getNotaComponenteMediaDataMapper()->find(array($notaComponenteCurricularMedia->get('notaAluno'), $notaComponenteCurricularMedia->get('componenteCurricular')));
             $notaComponenteCurricularMedia->markOld();
         } catch (Exception $e) {
             // Prossegue, sem problemas.
         }
         // Salva a média
         $this->getNotaComponenteMediaDataMapper()->save($notaComponenteCurricularMedia);
     }
 }
Пример #3
0
 /**
  * Testa o service adicionando notas de apenas um componente curricular,
  * para todas as etapas regulares (1 a 4).
  */
 public function testSalvarNotasDeUmComponenteCurricularNoBoletim()
 {
     $notaAluno = $this->_getConfigOption('notaAluno', 'instance');
     $notas = array(new Avaliacao_Model_NotaComponente(array('componenteCurricular' => 1, 'nota' => 7.25, 'etapa' => 1)), new Avaliacao_Model_NotaComponente(array('componenteCurricular' => 1, 'nota' => 9.25, 'etapa' => 2)), new Avaliacao_Model_NotaComponente(array('componenteCurricular' => 1, 'nota' => 8, 'etapa' => 3)), new Avaliacao_Model_NotaComponente(array('componenteCurricular' => 1, 'nota' => 8.5, 'etapa' => 4)));
     $media = new Avaliacao_Model_NotaComponenteMedia(array('notaAluno' => $notaAluno->id, 'componenteCurricular' => 1, 'media' => 8.25, 'mediaArredondada' => 8, 'etapa' => 4));
     $media->markOld();
     // Configura mock para Avaliacao_Model_NotaComponenteDataMapper
     $mock = $this->getCleanMock('Avaliacao_Model_NotaComponenteDataMapper');
     $mock->expects($this->at(0))->method('findAll')->with(array(), array('notaAluno' => $notaAluno->id), array('etapa' => 'ASC'))->will($this->returnValue(array()));
     $mock->expects($this->at(1))->method('save')->with($notas[0])->will($this->returnValue(TRUE));
     $mock->expects($this->at(2))->method('save')->with($notas[1])->will($this->returnValue(TRUE));
     $mock->expects($this->at(3))->method('save')->with($notas[2])->will($this->returnValue(TRUE));
     $mock->expects($this->at(4))->method('save')->with($notas[3])->will($this->returnValue(TRUE));
     $mock->expects($this->at(5))->method('findAll')->with(array(), array('notaAluno' => $notaAluno->id), array('etapa' => 'ASC'))->will($this->returnValue($notas));
     $this->_setNotaComponenteDataMapperMock($mock);
     // Configura mock para Avaliacao_Model_NotaComponenteMediaDataMapper
     $mock = $this->getCleanMock('Avaliacao_Model_NotaComponenteMediaDataMapper');
     $mock->expects($this->at(0))->method('findAll')->with(array(), array('notaAluno' => $notaAluno->id))->will($this->returnValue(array()));
     $mock->expects($this->at(1))->method('find')->with(array($notaAluno->id, $this->_getConfigOption('matricula', 'cod_matricula')))->will($this->returnValue(NULL));
     $mock->expects($this->at(2))->method('save')->with($media)->will($this->returnValue(TRUE));
     $this->_setNotaComponenteMediaDataMapperMock($mock);
     $service = $this->_getServiceInstance();
     $service->addNotas($notas);
     $service->saveNotas();
 }