Beispiel #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));
     });
 }
Beispiel #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"]);
     }
 }
Beispiel #3
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 toExcelAction()
 {
     $id = $this->getRequest()->getParam("id");
     $focusGroup = FocusGroupQuery::create()->findByPKOrThrow($id, $this->i18n->_("The FocusGroup with id {$id} wasn't found"));
     $poll = PollQuery::create()->findByPKOrThrow($focusGroup->getIdPoll(), $this->i18n->_("The Poll with id {$focusGroup->getIdPoll()} wasn't found"));
     $participants = RespondentQuery::create()->innerJoinFocusGroup()->whereAdd('FocusGroup.' . FocusGroup::ID_FOCUS_GROUPS, $focusGroup->getIdFocusGroups())->find();
     $npds = NpdSheetQuery::create()->innerJoinFocusGroup()->whereAdd('FocusGroup.' . FocusGroup::ID_FOCUS_GROUPS, $focusGroup->getIdFocusGroups(), BaseQuery::EQUAL)->find()->toObjectArray();
     $images = array();
     $suppliers = array();
     foreach ($npds as $npd) {
         $npdSupplier = NpdSheetSupplierQuery::create()->whereAdd(NpdSheetSupplier::ID_NPD_SHEET, $npd->getIdNpdSheet())->findOne();
         if ($npdSupplier) {
             $supplier = SapSupplierQuery::create()->findByPK($npdSupplier->getIdSupplier());
         }
         $query = FileQuery::create()->addColumns(array("File.*"))->innerJoinNpdSheetSupplier()->whereAdd("File." . File::TYPE, $type, FileQuery::EQUAL)->whereAdd("NpdSheetSupplier." . NpdSheetSupplier::ID_NPD_SHEET, $npd->getIdNpdSheet());
         if ($supplier) {
             $query->whereAdd("NpdSheetSupplier." . NpdSheetSupplier::ID_SUPPLIER, $supplier->getIdSupplier());
             $suppliers[$npd->getIdNpdSheet()] = $supplier;
         }
         $images[$npd->getIdNpdSheet()] = $query->findOne();
         if (!$images[$npd->getIdNpdSheet()]) {
             if (null != ($npdImages = NpdSheetQuery::getNpdSheetFileObjects($npd->getIdNpdSheet(), File::$typeFile["typeImage"]))) {
                 $images[$npd->getIdNpdSheet()] = $npdImages->getOne();
             }
         }
     }
     $questions = QuestionQuery::create()->innerJoinPoll()->whereAdd("PollQuestions.id_poll", $poll->getIdPoll(), BaseQuery::EQUAL)->orderBy("PollQuestions.order")->find();
     $colors = ColorQuery::create()->find()->toCombo();
     require_once 'PHPExcel.php';
     $objPHPExcel = new PHPExcel();
     $activeSheet = $objPHPExcel->setActiveSheetIndex(0);
     $activeSheet->mergeCells('A1:A2')->setCellValue('A1', $this->i18n->_('NPD ID'))->mergeCells('B1:B2')->setCellValue('B1', $this->i18n->_('Supplier'))->mergeCells('C1:C2')->setCellValue('C1', $this->i18n->_('Image'))->mergeCells('D1:D2')->setCellValue('D1', $this->i18n->_('Description'))->mergeCells('E1:E2')->setCellValue('E1', $this->i18n->_('MX Price'));
     $i = 5;
     foreach ($participants as $participant) {
         $last = $i + $questions->count() - 1;
         $activeSheet->mergeCells($this->getExcelColumn($i) . '1:' . $this->getExcelColumn($last) . '1');
         $activeSheet->setCellValue($this->getExcelColumn($i) . '1', $participant->getName());
         foreach ($questions as $question) {
             $activeSheet->setCellValue($this->getExcelColumn($i) . '2', $question->getDescription());
             $i++;
         }
     }
     $i = 3;
     foreach ($npds as $npd) {
         $activeSheet->setCellValue("A{$i}", $npd->getIdNpdSheet());
         if ($suppliers[$npd->getIdNpdSheet()]) {
             $activeSheet->setCellValue("B{$i}", $suppliers[$npd->getIdNpdSheet()]->getName());
         }
         if ($images[$npd->getIdNpdSheet()]) {
             $link = new PHPExcel_Cell_Hyperlink();
             $link->setUrl($this->getFullBaseUrl() . '/' . $images[$npd->getIdNpdSheet()]->getContent());
             $activeSheet->setCellValue("C{$i}", $this->getFullBaseUrl() . '/' . $images[$npd->getIdNpdSheet()]->getContent())->setHyperlink("C{$i}", $link);
         }
         $activeSheet->setCellValue("D{$i}", $npd->getDescription());
         $activeSheet->setCellValue("E{$i}", $npd->getPrice());
         $j = 5;
         foreach ($participants as $participant) {
             $questions->rewind();
             while ($question = $questions->read()) {
                 if ($pollResponse = PollResponseQuery::create()->whereAdd(PollResponse::ID_FOCUS_GROUP, $focusGroup->getIdFocusGroups())->whereAdd(PollResponse::ID_POLL, $focusGroup->getIdPoll())->whereAdd(PollResponse::ID_NPD_SHEET, $npd->getIdNpdSheet())->whereAdd(PollResponse::ID_RESPONDENT, $participant->getIdRespondent())->whereAdd(PollResponse::ID_QUESTION, $question->getIdQuestion())->findOne()) {
                     $q = new Question();
                     if ($question->getIdType() == Question::$Type['Yes/No']) {
                         switch ($pollResponse->getResponse()) {
                             case "true":
                                 $pollResponse->setResponse('Si');
                                 break;
                             case "false":
                                 $pollResponse->setResponse('No');
                                 break;
                         }
                     }
                     if ($question->getIdType() == Question::$Type['Multiple']) {
                         $multipleResponseQuery = QuestionMultipleResponseQuery::create()->whereAdd(QuestionMultipleResponse::ID_QUESTION, $question->getIdQuestion())->find();
                         while ($multipleResponse = $multipleResponseQuery->read()) {
                             if ($pollResponse->getResponse() == $multipleResponse->getIdResponse()) {
                                 $pollResponse->setResponse($multipleResponse->getDescription());
                             }
                         }
                     }
                     $activeSheet->setCellValue($this->getExcelColumn($j) . $i, $pollResponse->getResponse());
                 }
                 $j++;
             }
         }
         $i++;
     }
     header("Content-Type: application/vnd.ms-excel");
     header("Content-Disposition: attachment; filename=\"{$focusGroup->getName()}.xlsx\"");
     header("Cache-Control: max-age=0");
     $objWriter = \PHPExcel_IOFactory::createWriter($objPHPExcel, 'Excel2007');
     $objWriter->save("php://output");
     exit;
 }
 /**
  *
  */
 public function reactivateAction()
 {
     $id = $this->getRequest()->getParam('id');
     $questionMultipleResponse = QuestionMultipleResponseQuery::create()->findByPKOrThrow($id, $this->i18n->_("It does not exist the QuestionMultipleResponse with id {$id}"));
     try {
         $this->getQuestionMultipleResponseCatalog()->beginTransaction();
         $this->getQuestionMultipleResponseCatalog()->update($questionMultipleResponse);
         $this->getQuestionMultipleResponseCatalog()->commit();
         $this->setFlash('ok', $this->i18n->_("Se reactivo correctamente el QuestionMultipleResponse"));
     } catch (Exception $e) {
         $this->getQuestionMultipleResponseCatalog()->rollBack();
         $this->setFlash('error', $this->i18n->_($e->getMessage()));
     }
     $this->_redirect('question-multiple-response/list');
 }