Exemplo n.º 1
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');
 }
Exemplo n.º 2
0
 public function createquestionAction()
 {
     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"]);
             } else {
                 $question->setMatrix(Question::$Matrix["NotMatrix"]);
             }
             $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);
                 }
             }
             $lastOrder = PollQuery::create()->addColumn("Poll2PollQuestions.order")->innerJoinQuestionPoll()->whereAdd("Poll." . Poll::ID_POLL, $params["id_poll"], BaseQuery::EQUAL)->addDescendingOrderBy('Poll2PollQuestions.order')->fetchOne();
             $this->getQuestionCatalog()->linkToPoll($question->getIdQuestion(), $params["id_poll"], $lastOrder + 1);
             $this->getQuestionCatalog()->commit();
             $this->setFlash('ok', $this->i18n->_("The question was created and added"));
         } 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);
 }