/** * * @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 = QuestionMatrixResponseQuery::create()->filter($post)->count(); $this->view->questionMatrixResponses = $questionMatrixResponses = QuestionMatrixResponseQuery::create()->filter($post)->page($page, $this->getMaxPerPage())->find(); $this->view->paginator = $this->createPaginator($total, $page); $this->view->questions = \Application\Query\QuestionQuery::create()->find()->toCombo(); }
/** * * @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 = PollResponseQuery::create()->filter($post)->count(); $this->view->pollResponses = $pollResponses = PollResponseQuery::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->npdSheets = \Application\Query\NpdSheetQuery::create()->find()->toCombo(); $this->view->respondents = \Application\Query\RespondentQuery::create()->find()->toCombo(); }
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"]); } }
/** * */ public function reactivateAction() { $id = $this->getRequest()->getParam('id'); $question = QuestionQuery::create()->findByPKOrThrow($id, $this->i18n->_("It does not exist the Question with id {$id}")); try { $this->getQuestionCatalog()->beginTransaction(); $this->getQuestionCatalog()->update($question); $this->getQuestionCatalog()->commit(); $this->setFlash('ok', $this->i18n->_("Se reactivo correctamente el Question")); } 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; }