Ejemplo n.º 1
0
 public function getArrayDevolutiveReturn($questionnaireId, $userId, $programaId, $blockId = null)
 {
     $this->Questionnaire = new Model_Questionnaire();
     $this->Alternative = new Model_Alternative();
     $this->Question = new Model_Question();
     try {
         $arrDevolutiveRAA = array();
         $arrCriteria = array();
         $arrBlocks = array();
         $arrQuestionnaire = array();
         $arrRadarData = array();
         // Definições do Questionário
         //@TODO - por em cache
         $questionnaireDefs = $this->Questionnaire->getQuestionnaireById($questionnaireId);
         $arrQuestionnaire['title'] = $questionnaireDefs->getTitle();
         $arrQuestionnaire['description'] = $questionnaireDefs->getDescription();
         $arrQuestionnaire['long_description'] = $questionnaireDefs->getLongDescription();
         $arrQuestionnaire['operation_beginning'] = Vtx_Util_Date::format_dma($questionnaireDefs->getOperationBeginning());
         $arrQuestionnaire['operation_ending'] = Vtx_Util_Date::format_dma($questionnaireDefs->getOperationEnding());
         // Definições da Questão
         $questionsDefs = $this->Question->getAllByQuestionnaireIdBlockId($questionnaireId, $blockId);
         $cacheQuestion = new Vtx_Cache_MPE_QuestionarioCache();
         /**
          * - metodo criado para refatorar 2 metodos que faziam a mesma coisa e estavam dentro do foreach
          * - metodo que retorna todas alternativas de todas as questoes de um bloco que um Usuario respondeu
          * - a utilizacao deste metodo reduziu media de 25% a qtd de queries chamadas pelo BD.
          * - no meu exemplo reduziu de 320 para 235.
          * - chamada: $isAnswered = $this->Question->setaQuestionResp($QuestionRespDbTable, $questionId);
          * @author esilva
          */
         $QuestionRespDbTable = $this->Question->getAnswerByBlockId($blockId, $userId, $programaId);
         //var_dump ($QuestionRespDbTable); exit;
         /**
          * 
          * Recupera dados de cada questao de um Bloco:
          * - enunciado questao 
          * - alternativas
          * - resposta
          * - resultado anual
          * 
          */
         foreach ($questionsDefs as $question_def) {
             $idBlock = "";
             $idCriterion = "";
             $questionId = $question_def->getId();
             $question_value = $question_def->getQuestao();
             // Grava a questão no array de devolutiva
             $arrDevolutiveRAA[$questionId]['designation'] = $question_def->getDesignacao();
             $arrDevolutiveRAA[$questionId]['value'] = $question_value;
             $arrDevolutiveRAA[$questionId]['text'] = $question_def->getTexto();
             // Verifica se existe Bloco válido e grava nos arrays de blocos e devolutiva
             $idBlock = $question_def->getBloco();
             if ($idBlock != "" && $idBlock != 0) {
                 $arrBlocks[$idBlock] = $question_def->getBlocoTitulo();
                 $arrDevolutiveRAA[$questionId]['block'] = $question_def->getBloco();
             }
             // Verifica se existe Critério válido e grava nos arrays de critérios e devolutiva
             $idCriterion = $question_def->getCriterio();
             if ($idCriterion != "" && $idCriterion != 0) {
                 $arrCriteria[$idCriterion] = $idCriterion . ". " . $question_def->getCriterioTitulo();
                 $arrDevolutiveRAA[$questionId]['criterion'] = $question_def->getCriterio();
             }
             $isAnswered['answerResult'] = null;
             //se empresa respondeu a questao
             //$isAnswered = $this->Question->isAnsweredByEnterprise($questionId,$userId, true);
             $isAnswered = $this->Question->setaQuestionResp($QuestionRespDbTable, $questionId);
             //var_dump('isAnswered',$isAnswered);
             if ($isAnswered['status']) {
                 // Recupera a resposta
                 //$answer = $this->Question->getQuestionAnswer($questionId,$userId);
                 //refatorado para otimizar queries executadas
                 $answer = $isAnswered['answerResult'];
                 $alternative_id = $answer['alternative_id'];
                 $arrDevolutiveRAA[$questionId]['alternative_id'] = $alternative_id;
                 $arrDevolutiveRAA[$questionId]['write_answer'] = isset($answer['answer_value']) ? $answer['answer_value'] : "";
                 if (count($answer['annual_result']) > 0) {
                     $arrDevolutiveRAA[$questionId]['annual_result'] = $answer['annual_result'];
                     $arrDevolutiveRAA[$questionId]['annual_result_unit'] = $answer['annual_result_unit'];
                 } else {
                     $arrDevolutiveRAA[$questionId]['annual_result'] = "";
                     $arrDevolutiveRAA[$questionId]['annual_result_unit'] = "";
                 }
                 // Recupera o feedback da alternativa escolhida
                 #$alternative =  $this->Alternative->getAlternativeById($alternative_id);
                 //recupera do cache
                 $alternative = $cacheQuestion->alternative($alternative_id, $this->Alternative);
                 $arrDevolutiveRAA[$questionId]['alternative_designation'] = $alternative->getDesignation();
                 $arrDevolutiveRAA[$questionId]['alternative_feedback'] = $alternative->getFeedbackDefault();
                 // Recupera os comentarios 1 do avaliador da resolução da questão
                 //REFACTORING
                 //$arrDevolutiveRAA[$questionId]['answer_feedback'] = $this->Question->getAnswerFeedback( $isAnswered['objAnswered']['AnswerIdValue'] );//$isAnswered['objAnswered']->getAnswerId());
                 $arrDevolutiveRAA[$questionId]['answer_feedback'] = $answer['AnswerFeedback'];
                 // Recupera os comentarios 2 do avaliador da resolução da questão
                 //REFACTORING
                 //$arrDevolutiveRAA[$questionId]['answer_feedback_improve'] = $this->Question->getAnswerFeedbackImprove($isAnswered['objAnswered']['AnswerIdValue']);
                 $arrDevolutiveRAA[$questionId]['answer_feedback_improve'] = $answer['AnswerFeedbackImprove'];
                 //AdditionalInfo
                 $arrDevolutiveRAA[$questionId]['additional_info'] = $answer['AdditionalInfo'];
             }
             // Recupera as alternativas da questão
             //$alternativesDefs =  $this->Alternative->getAllByQuestionId($questionId);
             //recupera do cache
             $alternativesDefs = $cacheQuestion->alternativasEQuestoes($questionId, $this->Alternative);
             //var_dump ('alternativesDefs: ', $alternativesDefs);
             //echo "<br><Br>";
             foreach ($alternativesDefs as $alternative_def) {
                 if (is_object($alternative_def)) {
                     $arr_alternative[$alternative_def->getDesignation()] = $alternative_def->getValue();
                 } else {
                     $arr_alternative[$alternative_def['Designation']] = $alternative_def['Value'];
                 }
             }
             $arrDevolutiveRAA[$questionId]['alternatives'] = $arr_alternative;
         }
         return array($arrDevolutiveRAA, $arrBlocks, $arrCriteria, $arrQuestionnaire);
     } catch (Vtx_UserException $e) {
         DbTable_Questionnaire::getInstance()->getAdapter()->rollBack();
         return array('status' => false, 'messageError' => $e->getMessage());
     } catch (Exception $e) {
         DbTable_Questionnaire::getInstance()->getAdapter()->rollBack();
         throw new Exception($e);
     }
 }
Ejemplo n.º 2
0
 /**
  * 
  * Consulta os criterios e dados de um bloco do BD ou recupera/grava no sistema de cache
  */
 public function cacheBlockAndCriterion($blocoId)
 {
     $mpeCache = new Vtx_Cache_MPE_QuestionarioCache();
     $blocoCacheModel = $mpeCache->BlocoECriterios($blocoId, $this);
     return $blocoCacheModel;
 }
Ejemplo n.º 3
0
 public function reportGlobalAction()
 {
     $this->incluirJoinRegionalForce = false;
     $filter = $this->_getParam('filter', null);
     $filter['show_only'] = 'candidatas';
     if (isset($filter['competition_id']) and $filter['competition_id'] != $this->competitionId) {
         throw new Exception('access denied');
         return;
     }
     $format = $this->_getParam('format', null);
     $render = $format == 'csv' ? 'report-global' : 'index';
     $this->_helper->viewRenderer->setRender($render);
     if (!$format) {
         self::indexAction();
         return;
     }
     $cacheQuestion = new Vtx_Cache_MPE_QuestionarioCache();
     $Qstn = new Model_Questionnaire();
     $alternativesByQuestion = $allAlternativeIds = array();
     $blockId = isset($filter['qstn']) ? $filter['qstn'] : Zend_Registry::get('configDb')->qstn->currentBlockIdNegocios;
     //$this->view->showRadar = $blockId==Model_Devolutive::BLOCO_GESTAOEMPRESA? true : false;
     $this->view->showRadar = false;
     $questions = $cacheQuestion->BlocoECriterios($blockId, $Qstn->getCurrentQstnRow());
     $this->view->questions = $questions = $questions[$blockId];
     foreach ($questions['Criterions'] as $criterion) {
         foreach ($criterion['Questions'] as $questionId => $question) {
             $alternativesQuestion = $cacheQuestion->alternativasEQuestoes($question['QuestionId'], new Model_Alternative());
             $alternativesByQuestion[$questionId] = $alternativesQuestion;
             foreach ($alternativesQuestion as $alternative) {
                 $allAlternativeIds[] = $alternative['Id'];
             }
         }
     }
     $this->filterAdditional = $filter;
     $this->filterAdditional['alternativesId'] = $allAlternativeIds;
     $this->view->alternativesByQuestion = $alternativesByQuestion;
     $this->fetchReturn = 'pairs';
     $this->fetchReturnForce = 'pairs';
     $this->tipoRelatorio = 'report-global-respostas';
     self::indexAction();
     $this->view->qtRespostasAlternativa = $this->view->getAllEnterprise;
     if (!$this->view->showRadar) {
         return;
     }
     $dataCriterios = $this->Enterprise->getAllByColAE($this->paramsBuscaServiceArea[0], $this->paramsBuscaServiceArea[1], $this->autoavaliacaoId, null, null, $this->filter, null, $format, 'assoc', 'report-global-criterios');
     $dataCriteriosPorcent = array();
     $this->view->dataCriterios = $dataCriterios['total'];
     $this->view->pontuacaoMaxima = $pontuacaoMaxima = Vtx_Util_Array::pontuacaoMaximaCriteriosGestao();
     $i = 0;
     foreach ($this->view->dataCriterios as $criterio => $pontuacao) {
         if ($i != 0) {
             $dataCriteriosPorcent[] = (double) $pontuacao / (double) $pontuacaoMaxima[$i] * 100;
         }
         $i++;
     }
     $this->view->dataCriteriosPoncent = $dataCriteriosPorcent;
 }