Add download survey user results in a zip BT#16852

pull/3128/head
Julio Montoya 6 years ago
parent 9c97d4d1cb
commit 2f4ccdbaba
  1. 8
      main/survey/reporting.php
  2. 4
      main/survey/survey.lib.php
  3. 14
      main/survey/surveyUtil.class.php
  4. 26
      main/survey/survey_list.php

@ -1,9 +1,8 @@
<?php
/* For licensing terms, see /license.txt */
/**
* @package chamilo.survey
*
* @author unknown, the initial survey that did not make it in 1.8 because of bad code
* @author Patrick Cool <patrick.cool@UGent.be>, Ghent University: cleanup,
* refactoring and rewriting large parts of the code
@ -62,6 +61,7 @@ if (!empty($exportReport) && !empty($format)) {
switch ($format) {
case 'xls':
$filename = 'survey_results_'.$survey_id.'.xlsx';
SurveyUtil::export_complete_report_xls($survey_data, $filename, $userId);
exit;
break;
@ -107,7 +107,7 @@ $interbreadcrumb[] = [
'name' => $urlname,
];
if ($action == 'overview') {
if ($action === 'overview') {
$tool_name = get_lang('Reporting');
} else {
$interbreadcrumb[] = [
@ -138,7 +138,7 @@ Display::display_header($tool_name, 'Survey');
SurveyUtil::handle_reporting_actions($survey_data, $people_filled);
// Content
if ($action == 'overview') {
if ($action === 'overview') {
$html = null;
$url = api_get_path(WEB_CODE_PATH).'survey/reporting.php?'.api_get_cidreq().'&';

@ -7,8 +7,6 @@ use Chamilo\CourseBundle\Entity\CSurveyInvitation;
/**
* Class SurveyManager.
*
* @package chamilo.survey
*
* @author Patrick Cool <patrick.cool@UGent.be>, Ghent University:
* cleanup, refactoring and rewriting large parts (if not all) of the code
* @author Julio Montoya <gugli100@gmail.com>, Personality Test modification
@ -2603,6 +2601,4 @@ class SurveyManager
return false;
}
}

@ -1605,11 +1605,11 @@ class SurveyUtil
*
* @version February 2007
*/
public static function export_complete_report_xls($survey_data, $filename, $user_id = 0)
public static function export_complete_report_xls($survey_data, $filename, $user_id = 0, $returnFile = false)
{
$course_id = api_get_course_int_id();
$user_id = (int) $user_id;
$surveyId = isset($_GET['survey_id']) ? (int) $_GET['survey_id'] : 0;
$surveyId = $survey_data['survey_id'];
if (empty($course_id) || empty($surveyId)) {
return false;
@ -1671,9 +1671,7 @@ class SurveyUtil
(isset($_POST['submit_question_filter']) && is_array($_POST['questions_filter']) &&
in_array($row['question_id'], $_POST['questions_filter']))
) {
if ($row['number_of_options'] == 0 &&
($row['type'] == 'open' || $row['type'] == 'comment')
) {
if ($row['number_of_options'] == 0 && ($row['type'] === 'open' || $row['type'] === 'comment')) {
$worksheet->setCellValueByColumnAndRow(
$column,
$line,
@ -1821,6 +1819,11 @@ class SurveyUtil
$file = api_get_path(SYS_ARCHIVE_PATH).api_replace_dangerous_char($filename);
$writer = new PHPExcel_Writer_Excel2007($spreadsheet);
$writer->save($file);
if ($returnFile) {
return $file;
}
DocumentManager::file_send_for_download($file, true, $filename);
return null;
@ -2827,6 +2830,7 @@ class SurveyUtil
$table->set_column_filter(8, 'anonymous_filter');
$actions = [
'export_all' => get_lang('Export'),
'send_to_tutors' => get_lang('SendToGroupTutors'),
'multiplicate' => get_lang('MultiplicateQuestions'),
'delete' => get_lang('DeleteSurvey'),

@ -86,6 +86,8 @@ if (isset($_POST['action']) && $_POST['action'] && isset($_POST['id']) && is_arr
api_not_allowed(true);
}
$exportList = [];
foreach ($_POST['id'] as $value) {
$surveyData = SurveyManager::get_survey($value);
if (empty($surveyData)) {
@ -94,6 +96,10 @@ if (isset($_POST['action']) && $_POST['action'] && isset($_POST['id']) && is_arr
$surveyData['title'] = strip_tags($surveyData['title']);
switch ($action) {
case 'export_all':
$filename = 'survey_results_'.$value.'.xlsx';
$exportList[] = @SurveyUtil::export_complete_report_xls($surveyData, $filename, 0, true);
break;
case 'send_to_tutors':
$result = SurveyManager::sendToTutors($value);
if ($result) {
@ -135,16 +141,30 @@ if (isset($_POST['action']) && $_POST['action'] && isset($_POST['id']) && is_arr
// delete the actual survey
SurveyManager::delete_survey($value);
Display::addFlash(
Display::return_message(get_lang('SurveysDeleted').': '.$surveyData['title'], 'confirmation', false)
);
break;
}
}
header('Location: '.$listUrl);
exit;
if ($action === 'export_all') {
$tempZipFile = api_get_path(SYS_ARCHIVE_PATH).api_get_unique_id().'.zip';
$zip = new PclZip($tempZipFile);
foreach ($exportList as $file) {
$zip->add($file, PCLZIP_OPT_REMOVE_ALL_PATH);
}
DocumentManager::file_send_for_download(
$tempZipFile,
true,
get_lang('Surveys').'-'.api_get_course_id().'-'.api_get_local_time().'.zip'
);
unlink($tempZipFile);
}
header('Location: '.$listUrl);
exit;
}
switch ($action) {

Loading…
Cancel
Save