예제 #1
0
 /**
  * @return array
  */
 public function withComplements()
 {
     return $this->map(function (Question $question) {
         if ($question->getIdType() == 4) {
             $responses = QuestionMultipleResponseQuery::create()->whereAdd(QuestionMultipleResponse::ID_QUESTION, $question->getIdQuestion())->find()->toCombo();
         }
         if ($question->isMatrix()) {
             $rows = QuestionMatrixResponseQuery::create()->whereAdd(QuestionMatrixResponse::ID_QUESTION, $question->getIdQuestion())->whereAdd(QuestionMatrixResponse::HEADER_TYPE, QuestionMatrixResponse::$HeaderType["Row"])->find();
             $cols = QuestionMatrixResponseQuery::create()->whereAdd(QuestionMatrixResponse::ID_QUESTION, $question->getIdQuestion())->whereAdd(QuestionMatrixResponse::HEADER_TYPE, QuestionMatrixResponse::$HeaderType["Col"])->find();
         }
         return array($question->getIdQuestion() => array("question" => $question, "responses" => $responses, "rows" => $rows, "cols" => $cols));
     });
 }
 /**
  *
  * @return array
  */
 public function listAction()
 {
     $this->view->page = $page = $this->getRequest()->getParam('page') ?: 1;
     if ($this->getRequest()->isPost()) {
         $this->view->post = $post = $this->getRequest()->getParams();
     }
     $total = PollMatrixResponseQuery::create()->filter($post)->count();
     $this->view->pollMatrixResponses = $pollMatrixResponses = PollMatrixResponseQuery::create()->filter($post)->page($page, $this->getMaxPerPage())->find();
     $this->view->paginator = $this->createPaginator($total, $page);
     $this->view->polls = \Application\Query\PollQuery::create()->find()->toCombo();
     $this->view->questions = \Application\Query\QuestionQuery::create()->find()->toCombo();
     $this->view->questionMatrixResponses = \Application\Query\QuestionMatrixResponseQuery::create()->find()->toCombo();
     $this->view->questionMatrixResponses = \Application\Query\QuestionMatrixResponseQuery::create()->find()->toCombo();
     $this->view->npdSheets = \Application\Query\NpdSheetQuery::create()->find()->toCombo();
     $this->view->respondents = \Application\Query\RespondentQuery::create()->find()->toCombo();
 }
예제 #3
0
 public function editquestionAction()
 {
     if ($this->getRequest()->isPost()) {
         $params = $this->getRequest()->getParams();
         //die("<pre>".print_r($params, true)."</pre>");
         $question = QuestionQuery::create()->findByPKOrThrow($params["id_question"], $this->i18n->_("The Question with id {$id} does not exist"));
         try {
             $this->getQuestionCatalog()->beginTransaction();
             QuestionFactory::populate($question, $params);
             if ($params["matrix"]) {
                 $question->setMatrix(Question::$Matrix["IsMatrix"]);
             } else {
                 $question->setMatrix(Question::$Matrix["NotMatrix"]);
             }
             $this->getQuestionCatalog()->update($question);
             if ($question->isMatrix()) {
                 foreach ($params["row"] as $row) {
                     if ($row["status"] == "change") {
                         $existRow = QuestionMatrixResponseQuery::create()->findByPKOrThrow($row["id_matrix_response"], $this->i18n->_("The Matrix Row with id {$row["id_matrix_response"]} does not exit"));
                         $existRow->setDescription($row["description"]);
                         $this->getMatrixResponseCatalog()->update($existRow);
                     } else {
                         if ($row["status"] == "add") {
                             $newRow = new QuestionMatrixResponse();
                             $newRow->setDescription($row["description"]);
                             $newRow->setIdQuestion($question->getIdQuestion());
                             $newRow->setHeaderType(QuestionMatrixResponse::$HeaderType["Row"]);
                             $this->getMatrixResponseCatalog()->create($newRow);
                         } else {
                             if ($row["status"] == "delete") {
                                 $existRow = QuestionMatrixResponseQuery::create()->findByPKOrThrow($row["id_matrix_response"], $this->i18n->_("The Matrix Row with id {$row["id_matrix_response"]} does not exit"));
                                 $this->getMatrixResponseCatalog()->deleteById($existRow->getIdMatrixResponse());
                             }
                         }
                     }
                 }
                 foreach ($params["col"] as $col) {
                     if ($col["status"] == "change") {
                         $existCol = QuestionMatrixResponseQuery::create()->findByPKOrThrow($col["id_matrix_response"], $this->i18n->_("The Matrix Col with id {$col["id_matrix_response"]} does not exit"));
                         $existCol->setDescription($col["description"]);
                         $this->getMatrixResponseCatalog()->update($existCol);
                     } else {
                         if ($col["status"] == "add") {
                             $newCol = new QuestionMatrixResponse();
                             $newCol->setDescription($col["description"]);
                             $newCol->setIdQuestion($question->getIdQuestion());
                             $newCol->setHeaderType(QuestionMatrixResponse::$HeaderType["Col"]);
                             $this->getMatrixResponseCatalog()->create($newCol);
                         } else {
                             if ($col["status"] == "delete") {
                                 $existCol = QuestionMatrixResponseQuery::create()->findByPKOrThrow($col["id_matrix_response"], $this->i18n->_("The Matrix Col with id {$col["id_matrix_response"]} does not exit"));
                                 $this->getMatrixResponseCatalog()->deleteById($existCol->getIdMatrixResponse());
                             }
                         }
                     }
                 }
             } else {
                 $matrix = QuestionMatrixResponseQuery::create()->whereAdd(QuestionMatrixResponse::ID_QUESTION, $question->getIdQuestion(), BaseQuery::EQUAL)->find();
                 while ($header = $matrix->read()) {
                     $this->getMatrixResponseCatalog()->deleteById($header->getIdMatrixResponse());
                 }
             }
             if ($question->getIdType() == Question::$Type["Multiple"]) {
                 foreach ($params["option"] as $option) {
                     if ($option["status"] == "change") {
                         $existOption = QuestionMultipleResponseQuery::create()->findByPKOrThrow($option["id_response"], $this->i18n->_("The Option with id {$option["id_response"]} does not exit"));
                         $existOption->setDescription($option["description"]);
                         $this->getMultipleResponseCatalog()->update($existOption);
                     } else {
                         if ($option["status"] == "add") {
                             $newOption = new QuestionMultipleResponse();
                             $newOption->setIdQuestion($question->getIdQuestion());
                             $newOption->setDescription($option["description"]);
                             $this->getMultipleResponseCatalog()->create($newOption);
                         } else {
                             if ($option["status"] == "delete") {
                                 $existOption = QuestionMultipleResponseQuery::create()->findByPKOrThrow($option["id_response"], $this->i18n->_("The Option with id {$option["id_response"]} does not exit"));
                                 $this->getMultipleResponseCatalog()->deleteById($existOption->getIdResponse());
                             }
                         }
                     }
                 }
             } else {
                 $options = QuestionMultipleResponseQuery::create()->whereAdd(QuestionMultipleResponse::ID_QUESTION, $question->getIdQuestion(), BaseQuery::EQUAL)->find();
                 while ($option = $options->read()) {
                     $this->getMultipleResponseCatalog()->deleteById($option->getIdResponse());
                 }
             }
             $this->getQuestionCatalog()->commit();
             $this->setFlash('ok', $this->i18n->_("The question was uptated"));
         } catch (Exception $e) {
             $this->getPollCatalog()->rollBack();
             $this->setFlash('error', $this->i18n->_($e->getMessage()));
         }
         $this->_redirect("poll/makequestionary/type/make/id/" . $params["id_poll"]);
     }
 }
예제 #4
0
 /**
  *
  * @return array
  */
 public function updateAction()
 {
     if ($this->getRequest()->isPost()) {
         $params = $this->getRequest()->getParams();
         $idQuestion = $this->getRequest()->getParam('id_question');
         $question = QuestionQuery::create()->findByPKOrThrow($idQuestion, $this->i18n->_("It does not exist the Question with id {$id}"));
         try {
             $this->getQuestionCatalog()->beginTransaction();
             QuestionFactory::populate($question, $params);
             if ($params["matrix"]) {
                 $question->setMatrix(Question::$Matrix["IsMatrix"]);
             } else {
                 $question->setMatrix(Question::$Matrix["NotMatrix"]);
             }
             $this->getQuestionCatalog()->update($question);
             $fills = QuestionMatrixResponseQuery::create()->actives()->whereAdd(QuestionMatrixResponse::ID_QUESTION, $question->getIdQuestion())->whereAdd(QuestionMatrixResponse::HEADER_TYPE, QuestionMatrixResponse::$HeaderType["Row"])->find();
             $this->getMatrixResponseCatalog()->updateRows($fills, $params["row"], $question->getIdQuestion());
             $colls = QuestionMatrixResponseQuery::create()->actives()->whereAdd(QuestionMatrixResponse::ID_QUESTION, $question->getIdQuestion())->whereAdd(QuestionMatrixResponse::HEADER_TYPE, QuestionMatrixResponse::$HeaderType["Col"])->find();
             $this->getMatrixResponseCatalog()->updateCols($colls, $params["col"], $question->getIdQuestion());
             $options = QuestionMultipleResponseQuery::create()->actives()->whereAdd(QuestionMultipleResponse::ID_QUESTION, $question->getIdQuestion())->find();
             $this->getMultipleResponseCatalog()->updateOptions($options, $params["option"], $question->getIdQuestion());
             $this->getQuestionCatalog()->commit();
             $this->setFlash('ok', $this->i18n->_("The Question was updated"));
         } catch (Exception $e) {
             $this->getQuestionCatalog()->rollBack();
             $this->setFlash('error', $this->i18n->_($e->getMessage()));
         }
     }
     $this->_redirect('question/list');
 }
 /**
  *
  */
 public function reactivateAction()
 {
     $id = $this->getRequest()->getParam('id');
     $questionMatrixResponse = QuestionMatrixResponseQuery::create()->findByPKOrThrow($id, $this->i18n->_("It does not exist the QuestionMatrixResponse with id {$id}"));
     try {
         $this->getQuestionMatrixResponseCatalog()->beginTransaction();
         $this->getQuestionMatrixResponseCatalog()->update($questionMatrixResponse);
         $this->getQuestionMatrixResponseCatalog()->commit();
         $this->setFlash('ok', $this->i18n->_("Se reactivo correctamente el QuestionMatrixResponse"));
     } catch (Exception $e) {
         $this->getQuestionMatrixResponseCatalog()->rollBack();
         $this->setFlash('error', $this->i18n->_($e->getMessage()));
     }
     $this->_redirect('question-matrix-response/list');
 }