/** * */ public function reactivateAction() { $id = $this->getRequest()->getParam('id'); $pollResponse = PollResponseQuery::create()->findByPKOrThrow($id, $this->i18n->_("It does not exist the PollResponse with id {$id}")); try { $this->getPollResponseCatalog()->beginTransaction(); $this->getPollResponseCatalog()->update($pollResponse); $this->getPollResponseCatalog()->commit(); $this->setFlash('ok', $this->i18n->_("Se reactivo correctamente el PollResponse")); } catch (Exception $e) { $this->getPollResponseCatalog()->rollBack(); $this->setFlash('error', $this->i18n->_($e->getMessage())); } $this->_redirect('poll-response/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; }