Exemplo n.º 1
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');
 }
Exemplo n.º 2
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"]);
     }
 }
Exemplo n.º 3
0
 /**
  *
  * makeBean
  * @param array $resultset
  * @return \Application\Model\Bean\Question
  */
 protected function makeBean($resultset)
 {
     return QuestionFactory::createFromArray($resultset);
 }