public function updateOptions($options, $updateOptions, $idQuestion)
 {
     try {
         foreach ($updateOptions as $updateOption) {
             if ($updateOption["id_response"] > 0) {
                 QuestionMultipleResponseFactory::populate($options[$updateOption["id_response"]], $updateOption);
                 $this->update($options[$updateOption["id_response"]]);
                 unset($options[$updateOption["id_response"]]);
             } else {
                 $option = new QuestionMultipleResponse();
                 $option->setDescription($updateOption["description"])->setIdQuestion($idQuestion);
                 $this->create($option);
             }
         }
     } catch (Exception $e) {
         $this->throwException("The QuestionMultipleResponses can't be saved \n", $e);
     }
     /*foreach ($headers as $header){
      		$header->setStatus(QuestionMatrixResponse::$Status["Inactive"]);
      		$this->update($header);
      	}*/
 }
示例#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"]);
     }
 }
示例#3
0
 /**
  *
  * @return array
  */
 public function createAction()
 {
     if ($this->getRequest()->isPost()) {
         $params = $this->getRequest()->getParams();
         try {
             $this->getQuestionCatalog()->beginTransaction();
             $question = QuestionFactory::createFromArray($params);
             $question->setStatus(Question::$Status["Active"]);
             if ($params["matrix"]) {
                 $question->setMatrix(Question::$Matrix["IsMatrix"]);
             }
             $this->getQuestionCatalog()->create($question);
             if ($question->isMatrix()) {
                 foreach ($params["row"] as $rowInfo) {
                     $row = new QuestionMatrixResponse();
                     $row->setDescription($rowInfo["description"]);
                     $row->setIdQuestion($question->getIdQuestion());
                     $row->setHeaderType(QuestionMatrixResponse::$HeaderType["Row"]);
                     $this->getMatrixResponseCatalog()->create($row);
                 }
                 foreach ($params["col"] as $colInfo) {
                     $col = new QuestionMatrixResponse();
                     $col->setDescription($colInfo["description"]);
                     $col->setIdQuestion($question->getIdQuestion());
                     $col->setHeaderType(QuestionMatrixResponse::$HeaderType["Col"]);
                     $this->getMatrixResponseCatalog()->create($col);
                 }
             }
             if ($question->getIdType() == Question::$Type["Multiple"]) {
                 foreach ($params["option"] as $optionInfo) {
                     $option = new QuestionMultipleResponse();
                     $option->setIdQuestion($question->getIdQuestion());
                     $option->setDescription($optionInfo["description"]);
                     $this->getMultipleResponseCatalog()->create($option);
                 }
             }
             $this->getQuestionCatalog()->commit();
             $this->setFlash('ok', $this->i18n->_("The question was saved"));
         } catch (Exception $e) {
             $this->getQuestionCatalog()->rollBack();
             $this->setFlash('error', $this->i18n->_($e->getMessage()));
         }
     }
     $this->_redirect('question/list');
 }